RepastHPC  2.3.1
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType > Class Template Reference

Base grid implementation, implementing elements common to both Grids and ContinuousSpaces. More...

#include <BaseGrid.h>

Inheritance diagram for repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >:
repast::Grid< T, GPType > repast::Projection< T >

Public Types

typedef boost::transform_iterator< AgentFromGridPoint< T, GPType >, LocationMapConstIter > const_iterator
 A const iterator over shared_ptr<T>.
 
- Public Types inherited from repast::Projection< T >
enum  RADIUS { PRIMARY, SECONDARY }
 

Public Member Functions

 BaseGrid (std::string name, GridDimensions dimensions)
 Creates a BaseGrid with the specified name and dimensions. More...
 
virtual bool contains (const AgentId &id)
 Gets whether or not this grid contains the agent with the specified id. More...
 
virtual bool getLocation (const T *agent, std::vector< GPType > &pt) const
 Gets the location of this agent and puts it in the specified vector. More...
 
virtual bool getLocation (const AgentId &id, std::vector< GPType > &out) const
 Gets the location of this agent and puts it in the specified vectors. More...
 
virtual T * getObjectAt (const Point< GPType > &pt) const
 Gets the first object found at the specified point, or NULL if there is no such object. More...
 
virtual void getObjectsAt (const Point< GPType > &pt, std::vector< T * > &out) const
 Gets all the objects found at the specified point. More...
 
virtual bool moveTo (const T *agent, const std::vector< GPType > &newLocation)
 Moves the specified agent to the specified location. More...
 
virtual bool moveTo (const T *agent, const Point< GPType > &newLocation)
 Moves the specified agent to the specified location. More...
 
virtual bool moveTo (const AgentId &id, const std::vector< GPType > &newLocation)
 Moves the specified agent to the specified location. More...
 
virtual bool moveTo (const AgentId &id, const Point< GPType > &pt)
 Moves the specified agent to the specified point. More...
 
virtual std::pair< bool, Point< GPType > > moveByDisplacement (const T *agent, const std::vector< GPType > &displacement)
 Moves the specified object from its current location by the specified amount. More...
 
virtual std::pair< bool, Point< GPType > > moveByVector (const T *agent, double distance, const std::vector< double > &anglesInRadians)
 doc inherited from Grid
 
virtual const_iterator begin () const
 Gets an iterator over the agents in this BaseGrid starting with the first agent. More...
 
virtual const_iterator end () const
 Gets the end of an iterator over the agents in this BaseGrid. More...
 
virtual size_t size () const
 Gets the number of agents in this BaseGrid. More...
 
virtual double getDistance (const Point< GPType > &pt1, const Point< GPType > &pt2) const
 Gets the distance between the two grid points. More...
 
virtual double getDistanceSq (const Point< GPType > &pt1, const Point< GPType > &pt2) const
 Gets the square of the distance between the two grid points. More...
 
virtual void getDisplacement (const Point< GPType > &pt1, const Point< GPType > &pt2, std::vector< GPType > &out) const
 Gets vector difference between point 1 and point 2, putting the result in out. More...
 
virtual const GridDimensions dimensions () const
 Gets the dimensions of this Grid. More...
 
virtual void translate (const Point< GPType > &location, const Point< GPType > &displacement, std::vector< GPType > &out) const
 Translates the specified location by the specified displacement put the result in out. More...
 
virtual void transform (const std::vector< GPType > &location, std::vector< GPType > &out) const
 Transforms the specified location using the properties (e.g. More...
 
virtual bool isPeriodic () const
 Gets whether or not this grid is periodic (i.e. More...
 
virtual ProjectionInfoPacketgetProjectionInfo (AgentId id, bool secondaryInfo=false, std::set< AgentId > *secondaryIds=0, int destProc=-1)
 
virtual void updateProjectionInfo (ProjectionInfoPacket *pip, Context< T > *context)
 
virtual void getAgentsToPush (std::set< AgentId > &agentsToTest, std::map< int, std::set< AgentId > > &agentsToPush)
 Given a set of agents, gets the agents that this projection implementation must 'push' to other processes. More...
 
virtual void getInfoExchangePartners (std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)
 Gets the set of processes with which this Projection exchanges projection info. More...
 
virtual void getAgentStatusExchangePartners (std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)
 Gets the set of processes with which this Projection exchanges agent status info- that is, the set of processes from which agents can move to this one or to which they can move when moving from this one. More...
 
- Public Member Functions inherited from repast::Grid< T, GPType >
 Grid (std::string name)
 Creates a Grid with the specified name. More...
 
virtual const GridDimensions bounds () const =0
 
virtual void getRequiredAgents (std::set< AgentId > &agentsToTest, std::set< AgentId > &agentsRequired, RADIUS radius=Projection< T >::PRIMARY)
 Given a set of agents to test, gets the subset that must be kept in order to fulfill the projection's 'contract' to the specified radius. More...
 
virtual bool keepsAgentsOnSyncProj ()
 Should return true if the Projection implemented can 'keep' some (non-local) agents during a projection information synchronization operation. More...
 
virtual bool sendsSecondaryAgentsOnStatusExchange ()
 Should return true if the Projection implemented will send secondary agents during a status exchange. More...
 
virtual void cleanProjectionInfo (std::set< AgentId > &agentsToKeep)
 
- Public Member Functions inherited from repast::Projection< T >
 Projection (std::string name)
 Creates a projection with specified name. More...
 
const std::string name () const
 Gets the name of this projection.
 
void addFilterVal (int type)
 Adds an entry to the list of agent types that can be added to this projection. More...
 
void removeFilterVal (int type)
 Removes an entry from the list of agent types that can be added to this projection. More...
 
void clearFilter ()
 Clears the list of agent types that can be added to this projection; the result is that the filter is empty, and any agent can be added.
 
bool agentCanBeAdded (boost::shared_ptr< T > agent)
 Returns true if the agent can be added to the projection, which will be the case if the filter list is empty or if the agent's type is in the filter list. More...
 
virtual void getProjectionInfo (std::vector< AgentId > &agents, std::vector< ProjectionInfoPacket * > &packets, bool secondaryInfo=false, std::set< AgentId > *secondaryIds=0, int destProc=-1)
 Convenience wrapper that gets all of the projection information for the agents specified (calls implementation in child class that gets only the information for one agent).
 
void updateProjectionInfo (std::vector< ProjectionInfoPacket * > &pips, Context< T > *context)
 Updates the projection information for the agents in this projection according to the information contained in the vector of information packets passed.
 
virtual void balance ()
 

Protected Types

typedef AgentLocationMap::iterator LocationMapIter
 
typedef AgentLocationMap::const_iterator LocationMapConstIter
 

Protected Member Functions

virtual bool addAgent (boost::shared_ptr< T > agent)
 
virtual void removeAgent (T *agent)
 
LocationMapConstIter locationsBegin () const
 
LocationMapConstIter locationsEnd () const
 
T * get (const AgentId &id)
 

Protected Attributes

GPTransformer gpTransformer
 
Adder adder
 
- Protected Attributes inherited from repast::Projection< T >
std::string name_
 
std::set< int > filter
 

Detailed Description

template<typename T, typename CellAccessor, typename GPTransformer, typename Adder, typename GPType>
class repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >

Base grid implementation, implementing elements common to both Grids and ContinuousSpaces.

Standard grid and space types that provide defaults for the various template parameters can be found in Space in Space.h

Template Parameters
Tthe type of objects contained by this BaseGrid (generally the type of agents)
CellAccessorimplements the actual storage for the grid.
GPTransformertransforms cell points according to the topology (e.g. periodic) of the BaseGrid.
Adderdetermines how objects are added to the grid from its associated context.
GPTypethe coordinate type of the grid point locations; this must be an int or a double.

Constructor & Destructor Documentation

◆ BaseGrid()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::BaseGrid ( std::string  name,
GridDimensions  dimensions 
)

Creates a BaseGrid with the specified name and dimensions.

Parameters
namethe name of the BaseGrid
dimensionsthe dimensions of the BaseGrid

Member Function Documentation

◆ begin()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual const_iterator repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::begin ( ) const
inlinevirtual

Gets an iterator over the agents in this BaseGrid starting with the first agent.

The iterator derefrences into shared_ptr<T>. The actual agent can be accessed by derefrenceing the iter: (*iter)->getId() for example.

Returns
an iterator over the agents in this BaseGrid starting with the first agent.

◆ contains()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::contains ( const AgentId id)
virtual

Gets whether or not this grid contains the agent with the specified id.

Parameters
idthe id of the agent to check
Returns
true if the grid contains the agent, otherwise false.

Implements repast::Grid< T, GPType >.

◆ dimensions()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual const GridDimensions repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::dimensions ( ) const
inlinevirtual

◆ end()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual const_iterator repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::end ( ) const
inlinevirtual

Gets the end of an iterator over the agents in this BaseGrid.

Returns
the end of an iterator over the agents in this BaseGrid.

◆ getAgentStatusExchangePartners()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getAgentStatusExchangePartners ( std::set< int > &  psToSendTo,
std::set< int > &  psToReceiveFrom 
)
inlinevirtual

Gets the set of processes with which this Projection exchanges agent status info- that is, the set of processes from which agents can move to this one or to which they can move when moving from this one.

In the most general case this will be all other processors. However, simulations where agents move in spaces will usually exchange agents only with a small subset of 'neighbor' processes, which is knowable in advance and constant. To accommodate the general case, the algorithm for exchanging information must poll all other processes to see which are sending to this one; if this is known in advance, this additional (expensive) step can be skipped.

Implements repast::Grid< T, GPType >.

Reimplemented in repast::SharedBaseGrid< T, GPTransformer, Adder, GPType >, repast::SharedBaseGrid< RelogoAgent, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, int >, and repast::SharedBaseGrid< T, GPTransformer, Adder, double >.

◆ getAgentsToPush()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getAgentsToPush ( std::set< AgentId > &  agentsToTest,
std::map< int, std::set< AgentId > > &  agentsToPush 
)
inlinevirtual

Given a set of agents, gets the agents that this projection implementation must 'push' to other processes.

Generally spaces must push agents that are in 'buffer zones' and graphs must push local agents that are vertices to master edges where the other vertex is non- local. The results are returned per-process in the agentsToPush map.

Implements repast::Grid< T, GPType >.

Reimplemented in repast::SharedBaseGrid< T, GPTransformer, Adder, GPType >, repast::SharedBaseGrid< RelogoAgent, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, int >, and repast::SharedBaseGrid< T, GPTransformer, Adder, double >.

◆ getDisplacement()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getDisplacement ( const Point< GPType > &  pt1,
const Point< GPType > &  pt2,
std::vector< GPType > &  out 
) const
virtual

Gets vector difference between point 1 and point 2, putting the result in out.

Parameters
p1the first point
p2the second point
[out]thevector where the difference will be put

Implements repast::Grid< T, GPType >.

◆ getDistance()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
double repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getDistance ( const Point< GPType > &  pt1,
const Point< GPType > &  pt2 
) const
virtual

Gets the distance between the two grid points.

Parameters
p1the first point
p2the second point
Returns
the distance between pt1 and pt2.

Implements repast::Grid< T, GPType >.

◆ getDistanceSq()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
double repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getDistanceSq ( const Point< GPType > &  pt1,
const Point< GPType > &  pt2 
) const
virtual

Gets the square of the distance between the two grid points.

Parameters
p1the first point
p2the second point
Returns
the square of the distance between pt1 and pt2.

Implements repast::Grid< T, GPType >.

◆ getInfoExchangePartners()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getInfoExchangePartners ( std::set< int > &  psToSendTo,
std::set< int > &  psToReceiveFrom 
)
inlinevirtual

Gets the set of processes with which this Projection exchanges projection info.

In the most general case this will be all other processors; this is the case for graphs, where agent connections can be arbitrary. However, spaces usually exchange information only with a small subset of 'neighbor' processes, which is knowable in advance and constant. To accommodate the general case, the algorithm for exchanging information must poll all other processes to see which are sending to this one; if this is known in advance, this additional (expensive) step can be skipped.

Implements repast::Grid< T, GPType >.

Reimplemented in repast::SharedBaseGrid< T, GPTransformer, Adder, GPType >, repast::SharedBaseGrid< RelogoAgent, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, int >, and repast::SharedBaseGrid< T, GPTransformer, Adder, double >.

◆ getLocation() [1/2]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getLocation ( const AgentId id,
std::vector< GPType > &  out 
) const
virtual

Gets the location of this agent and puts it in the specified vectors.

The x coordinate will be the first value, the y the second and so on.

Parameters
idthe id of the agent whose location we want to get
[out]outthe agent's location will be put into this vector
Returns
true if the location was successfully found, otherwise false.

Implements repast::Grid< T, GPType >.

◆ getLocation() [2/2]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getLocation ( const T *  agent,
std::vector< GPType > &  out 
) const
virtual

Gets the location of this agent and puts it in the specified vector.

The x coordinate will be the first value, the y the second and so on.

Parameters
agentthe agent whose location we want to get
[out]thevector where the agents location will be put
Returns
true if the location was successfully found, otherwise false.

Implements repast::Grid< T, GPType >.

◆ getObjectAt()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
T * repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getObjectAt ( const Point< GPType > &  pt) const
virtual

Gets the first object found at the specified point, or NULL if there is no such object.

Returns
the first object found at the specified point, or NULL if there is no such object.

Implements repast::Grid< T, GPType >.

◆ getObjectsAt()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::getObjectsAt ( const Point< GPType > &  pt,
std::vector< T * > &  out 
) const
virtual

Gets all the objects found at the specified point.

The found objects will be put into the out parameter.

Parameters
ptthe point to get all the objects at
[out]outthe vector into which the found objects will be put

Implements repast::Grid< T, GPType >.

◆ isPeriodic()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::isPeriodic ( ) const
inlinevirtual

Gets whether or not this grid is periodic (i.e.

toroidal).

Returns
true if this Grid is periodic, otherwise false.

Implements repast::Grid< T, GPType >.

◆ moveByDisplacement()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
std::pair< bool, Point< GPType > > repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::moveByDisplacement ( const T *  agent,
const std::vector< GPType > &  displacement 
)
virtual

Moves the specified object from its current location by the specified amount.

For example moveByDisplacement(object, 3, -2, 1) will move the object by 3 along the x-axis, -2 along the y and 1 along the z. The displacement argument can be less than the number of dimensions in the space in which case the remaining argument will be set to 0. For example, moveByDisplacement(object, 3) will move the object 3 along the x-axis and 0 along the y and z axes, assuming a 3D grid.

Parameters
agentthe object to move
displacementthe amount to move the object
Returns
a pair containing a bool that indicates whether the move was a success or not, and the point where the agent was moved to.

Implements repast::Grid< T, GPType >.

◆ moveTo() [1/4]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::moveTo ( const AgentId id,
const Point< GPType > &  pt 
)
virtual

Moves the specified agent to the specified point.

Parameters
idthe id of the agent to move
ptwhere to move the agent to
Returns
true if the move was successful, otherwise false

Implements repast::Grid< T, GPType >.

Reimplemented in repast::SharedBaseGrid< RelogoAgent, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, GPType >, and repast::SharedBaseGrid< T, GPTransformer, Adder, double >.

◆ moveTo() [2/4]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::moveTo ( const AgentId id,
const std::vector< GPType > &  newLocation 
)
virtual

Moves the specified agent to the specified location.

Returns true if the move was successful otherwise false. The agent must be already added to the context associated with this space, otherwise this throws an out_of_range exception if the new location out of bounds.

Parameters
idthe id of the agent to move
newLocationthe location to move to
Returns
true if the move was successful, otherwise false

Reimplemented in repast::SharedBaseGrid< RelogoAgent, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, int >, repast::SharedBaseGrid< T, GPTransformer, Adder, GPType >, and repast::SharedBaseGrid< T, GPTransformer, Adder, double >.

◆ moveTo() [3/4]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::moveTo ( const T *  agent,
const Point< GPType > &  newLocation 
)
virtual

Moves the specified agent to the specified location.

Returns true if the move was successful otherwise false. The agent must be already added to the context associated with this space, otherwise this throws an out_of_range exception if the new location out of bounds.

Parameters
agentthe agent to move
newLocationthe location to move to
Returns
true if the move was successful, otherwise false

◆ moveTo() [4/4]

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
bool repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::moveTo ( const T *  agent,
const std::vector< GPType > &  newLocation 
)
virtual

Moves the specified agent to the specified location.

Returns true if the move was successful otherwise false. The agent must be already added to the context associated with this space, otherwise this throws an out_of_range exception if the new location out of bounds.

Parameters
agentthe agent to move
newLocationthe location to move to
Returns
true if the move was successful, otherwise false

◆ size()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual size_t repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::size ( ) const
inlinevirtual

Gets the number of agents in this BaseGrid.

Returns
the number of agents in this BaseGrid.

◆ transform()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::transform ( const std::vector< GPType > &  location,
std::vector< GPType > &  out 
) const
inlinevirtual

Transforms the specified location using the properties (e.g.

toroidal) of this space.

Parameters
locationthe location to transform
[out]outthe vector where the result of the transform will be put

Implements repast::Grid< T, GPType >.

◆ translate()

template<typename T , typename CellAccessor , typename GPTransformer , typename Adder , typename GPType >
virtual void repast::BaseGrid< T, CellAccessor, GPTransformer, Adder, GPType >::translate ( const Point< GPType > &  location,
const Point< GPType > &  displacement,
std::vector< GPType > &  out 
) const
inlinevirtual

Translates the specified location by the specified displacement put the result in out.

Parameters
locationthe initial location
displacementthe amount to translate the location by
[out]outthe vector where the result of the translation is put

Implements repast::Grid< T, GPType >.


The documentation for this class was generated from the following file: