RepastHPC  2.3.1
Grid.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * Grid.h
36  *
37  * Created on: Aug 10, 2010
38  * Author: nick
39  */
40 
41 #ifndef GRID_H_
42 #define GRID_H_
43 
44 #include <vector>
45 #include <utility>
46 
47 #include "Projection.h"
48 #include "Point.h"
49 #include "GridDimensions.h"
50 #include "AgentId.h"
51 
52 namespace repast {
53 
61 template<typename T, typename GPType>
62 class Grid: public Projection<T> {
63  typedef typename Projection<T>::RADIUS RADIUS;
64 
65 public:
66 
73  Grid(std::string name) :
74  Projection<T> (name) {
75  }
76  virtual ~Grid() {
77  }
78 
86  virtual bool contains(const AgentId& id) = 0;
87 
96  virtual bool moveTo(const AgentId& id, const Point<GPType>& pt) = 0;
97 
114  virtual std::pair<bool, Point<GPType> > moveByVector(const T* agent, double distance,
115  const std::vector<double>& anglesInRadians) = 0;
116 
134  virtual std::pair<bool, Point<GPType> >
135  moveByDisplacement(const T* agent, const std::vector<GPType>& displacement) = 0;
136 
142  virtual const GridDimensions dimensions() const = 0;
143 
144  virtual const GridDimensions bounds() const = 0;
145 
146 
154  virtual T* getObjectAt(const Point<GPType>& pt) const = 0;
155 
163  virtual void getObjectsAt(const Point<GPType>& pt, std::vector<T*>& out) const = 0;
164 
175  virtual bool getLocation(const T* agent, std::vector<GPType>& out) const = 0;
176 
187  virtual bool getLocation(const AgentId& id, std::vector<GPType>& out) const = 0;
188 
198  virtual void getDisplacement(const Point<GPType>& pt1, const Point<GPType>& pt2, std::vector<GPType>& out) const = 0;
199 
208  virtual double getDistance(const Point<GPType>& pt1, const Point<GPType>& pt2) const = 0;
209 
218  virtual double getDistanceSq(const Point<GPType>& pt1, const Point<GPType>& pt2) const = 0;
219 
227  virtual void
228  translate(const Point<GPType>& location, const Point<GPType>& displacement, std::vector<GPType>& out) const = 0;
229 
236  virtual void
237  transform(const std::vector<GPType>& location, std::vector<GPType>& out) const = 0;
238 
244  virtual bool isPeriodic() const = 0;
245 
246  virtual ProjectionInfoPacket* getProjectionInfo(AgentId id, bool secondaryInfo = false, std::set<AgentId>* secondaryIds = 0, int destProc = -1 ) = 0;
247 
248  virtual void updateProjectionInfo(ProjectionInfoPacket* pip, Context<T>* context) = 0;
249 
250  virtual void getRequiredAgents(std::set<AgentId>& agentsToTest, std::set<AgentId>& agentsRequired, RADIUS radius = Projection<T>::PRIMARY){} // Grids allow all agents to be dropped b/c agent info not dependent on other agents
251 
252  virtual void getAgentsToPush(std::set<AgentId>& agentsToTest, std::map<int, std::set<AgentId> >& agentsToPush) = 0;
253 
254  virtual bool keepsAgentsOnSyncProj(){ return false; }
255 
256  virtual bool sendsSecondaryAgentsOnStatusExchange(){ return false; }
257 
258  virtual void getInfoExchangePartners(std::set<int>& psToSendTo, std::set<int>& psToReceiveFrom) = 0;
259 
260  virtual void getAgentStatusExchangePartners(std::set<int>& psToSendTo, std::set<int>& psToReceiveFrom) = 0;
261 
262  virtual void cleanProjectionInfo(std::set<AgentId>& agentsToKeep){}; // Grids don't do this
263 
264 };
265 
266 }
267 
268 #endif /* GRID_H_ */
repast::Grid::getDistanceSq
virtual double getDistanceSq(const Point< GPType > &pt1, const Point< GPType > &pt2) const =0
Gets the square of the distance between the two grid points.
repast::Grid::keepsAgentsOnSyncProj
virtual bool keepsAgentsOnSyncProj()
Should return true if the Projection implemented can 'keep' some (non-local) agents during a projecti...
Definition: Grid.h:254
repast::Grid::getInfoExchangePartners
virtual void getInfoExchangePartners(std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)=0
Gets the set of processes with which this Projection exchanges projection info.
repast::Grid::getObjectAt
virtual T * getObjectAt(const Point< GPType > &pt) const =0
Gets the first object found at the specified point, or NULL if there is no such object.
repast::Grid::getRequiredAgents
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...
Definition: Grid.h:250
repast::Grid::getDistance
virtual double getDistance(const Point< GPType > &pt1, const Point< GPType > &pt2) const =0
Gets the distance between the two grid points.
repast::Grid::Grid
Grid(std::string name)
Creates a Grid with the specified name.
Definition: Grid.h:73
repast::Grid::isPeriodic
virtual bool isPeriodic() const =0
Gets whether or not this grid is periodic (i.e.
repast::Grid::contains
virtual bool contains(const AgentId &id)=0
Gets whether or not this grid contains the agent with the specified id.
repast::Projection
Abstract base class for all Projections.
Definition: Projection.h:125
repast::Grid::getLocation
virtual bool getLocation(const T *agent, std::vector< GPType > &out) const =0
Gets the location of this agent and puts it in the specified vector.
repast::Grid::moveByDisplacement
virtual std::pair< bool, Point< GPType > > moveByDisplacement(const T *agent, const std::vector< GPType > &displacement)=0
Moves the specified object from its current location by the specified amount.
repast::Grid
Abstract interface for Grids and ContinuousSpaces.
Definition: Grid.h:62
repast::Grid::getObjectsAt
virtual void getObjectsAt(const Point< GPType > &pt, std::vector< T * > &out) const =0
Gets all the objects found at the specified point.
repast::Grid::sendsSecondaryAgentsOnStatusExchange
virtual bool sendsSecondaryAgentsOnStatusExchange()
Should return true if the Projection implemented will send secondary agents during a status exchange.
Definition: Grid.h:256
repast::Grid::translate
virtual void translate(const Point< GPType > &location, const Point< GPType > &displacement, std::vector< GPType > &out) const =0
Translates the specified location by the specified displacement put the result in out.
repast::Grid::getAgentsToPush
virtual void getAgentsToPush(std::set< AgentId > &agentsToTest, std::map< int, std::set< AgentId > > &agentsToPush)=0
Given a set of agents, gets the agents that this projection implementation must 'push' to other proce...
repast::Grid::getDisplacement
virtual void getDisplacement(const Point< GPType > &pt1, const Point< GPType > &pt2, std::vector< GPType > &out) const =0
Gets vector difference between point 1 and point 2, putting the result in out.
repast::Grid::transform
virtual void transform(const std::vector< GPType > &location, std::vector< GPType > &out) const =0
Transforms the specified location using the properties (e.g.
repast::Grid::getAgentStatusExchangePartners
virtual void getAgentStatusExchangePartners(std::set< int > &psToSendTo, std::set< int > &psToReceiveFrom)=0
Gets the set of processes with which this Projection exchanges agent status info- that is,...
repast::Projection::name
const std::string name() const
Gets the name of this projection.
Definition: Projection.h:164
repast::Grid::moveTo
virtual bool moveTo(const AgentId &id, const Point< GPType > &pt)=0
Moves the specified agent to the specified point.
repast::Grid::moveByVector
virtual std::pair< bool, Point< GPType > > moveByVector(const T *agent, double distance, const std::vector< double > &anglesInRadians)=0
Moves the specifed object the specified distance from its current position along the specified angle.
repast::Grid::dimensions
virtual const GridDimensions dimensions() const =0
Gets the dimensions of this Grid.