RepastHPC  2.3.1
AbstractRelogoAgent.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  * AbstractRelogoAgent.h
36  *
37  * Created on: Aug 17, 2010
38  * Author: nick
39  */
40 
41 #ifndef ABSTRACTRELOGOAGENT_H_
42 #define ABSTRACTRELOGOAGENT_H_
43 
44 #include "RelogoAgent.h"
45 #include "Observer.h"
46 #include "utility.h"
47 
48 namespace repast {
49 namespace relogo {
50 
56 
57 public:
58  AbstractRelogoAgent(AgentId id, Observer* observer);
59  virtual ~AbstractRelogoAgent();
60 
66  virtual int pxCor() const = 0;
67 
73  virtual int pyCor() const = 0;
74 
82  template<typename AgentType>
83  void inRadius(AgentSet<RelogoAgent>& inSet, double radius, AgentSet<AgentType>& outSet) const;
84 
96  template<typename PatchType>
97  PatchType* patchAt(double dx, double dy) const;
98 
106  template<typename AgentType>
107  void turtlesHere(AgentSet<AgentType>& set) const;
108 
118  template<typename AgentType>
120 
129  template<typename PatchType>
130  PatchType* patchAtHeadingAndDistance(float heading, double distance);
131 
139  template<typename AgentType>
140  void turtlesOn(AgentSet<AgentType>& out) const;
141 
152  template<typename AgentType>
154 
155 };
156 
157 template<typename AgentType>
158 void AbstractRelogoAgent::inRadius(AgentSet<RelogoAgent>& inSet, double radius, AgentSet<AgentType>& outSet) const {
159  _observer->inRadius<AgentType> (_location, inSet, radius, outSet);
160 }
161 
162 template<typename PatchType>
163 PatchType* AbstractRelogoAgent::patchAt(double dx, double dy) const {
164  return static_cast<PatchType*> (_observer->patchAt(_location, dx, dy));
165 }
166 
167 template<typename AgentType>
169  _observer->turtlesAt(pxCor(), pyCor(), set);
170 }
171 
172 template<typename AgentType>
175  turtlesHere(set);
176  return set;
177 }
178 
179 template<typename PatchType>
180 PatchType* AbstractRelogoAgent::patchAtHeadingAndDistance(float heading, double distance) {
181  std::vector<double> disp = calcDisplacementFromHeadingDistance(heading, distance);
182  return static_cast<PatchType*> (_observer->patchAt(_location, disp[0], disp[1]));
183 }
184 
185 template<typename AgentType>
187  _observer->turtlesOn(this, out);
188 }
189 
190 template<typename AgentType>
192  AgentSet<AgentType> agents;
193  turtlesOn<AgentType>(agents);
194  return agents;
195 
196 }
197 
198 }
199 }
200 
201 #endif /* ABSTRACTRELOGOAGENT_H_ */
repast::relogo::AbstractRelogoAgent::inRadius
void inRadius(AgentSet< RelogoAgent > &inSet, double radius, AgentSet< AgentType > &outSet) const
Gets all the agents in the inSet within the specified radius for this RelogoAgent and put them in the...
Definition: AbstractRelogoAgent.h:158
repast::relogo::AbstractRelogoAgent::pxCor
virtual int pxCor() const =0
Gets the patch x coordinate of the agent's location.
repast::relogo::AbstractRelogoAgent::turtlesOn
AgentSet< AgentType > turtlesOn() const
Gets the turtles that are on this patch or if this is a Turtle get the turtles that are on the patch ...
Definition: AbstractRelogoAgent.h:191
repast::relogo::RelogoAgent::distance
double distance(RelogoAgent *obj) const
Gets the distance from this RelogoAgent to the specified agent.
Definition: RelogoAgent.cpp:57
repast::relogo::Observer::inRadius
void inRadius(const Point< double > &center, AgentSet< RelogoAgent > &inSet, double radius, AgentSet< AgentType > &outSet)
Puts all the agents in the inSet that are of the specified type and within the specified radius from ...
Definition: Observer.h:821
repast::relogo::RelogoAgent
Base agent for Relogo.
Definition: RelogoAgent.h:60
repast::relogo::AbstractRelogoAgent::pyCor
virtual int pyCor() const =0
Gets the patch y coordinate of the agent's location.
repast::relogo::AbstractRelogoAgent
Abstract base class for turtles and patches.
Definition: AbstractRelogoAgent.h:55
repast::AgentId
Agent identity information.
Definition: AgentId.h:60
repast::relogo::AgentSet
Specialized indexable collection class for agents.
Definition: AgentSet.h:82
repast::relogo::AbstractRelogoAgent::patchAt
PatchType * patchAt(double dx, double dy) const
Gets the patch at direction dx, dy from the this agent.
Definition: AbstractRelogoAgent.h:163
repast::relogo::Observer::patchAt
PatchType * patchAt(int x, int y)
Gets the patch at the specified coordinates.
Definition: Observer.h:793
repast::relogo::AbstractRelogoAgent::turtlesHere
AgentSet< AgentType > turtlesHere() const
Gets all the turtles on this turtle's patch and returns them in an AgentSet.
Definition: AbstractRelogoAgent.h:173
repast::relogo::Observer::turtlesAt
AgentSet< AgentType > turtlesAt(int x, int y)
Gets all of the agents of the templated type at the specified patch location.
Definition: Observer.h:729
repast::relogo::Observer
Implementation of a logo Observer.
Definition: Observer.h:110
repast::relogo::AbstractRelogoAgent::patchAtHeadingAndDistance
PatchType * patchAtHeadingAndDistance(float heading, double distance)
Gets the patch at the specified heading and distance from this patch or turtle.
Definition: AbstractRelogoAgent.h:180
repast::relogo::Observer::turtlesOn
void turtlesOn(AgentSet< RelogoAgent > &agentSet, AgentSet< TurtleType > &out)
Gets all the turtles that are on any patches contained in the agentSet or on the patches where any tu...
Definition: Observer.h:808