RepastHPC
2.3.1
|
Implementation of a logo Observer. More...
#include <Observer.h>
Public Member Functions | |
void | addDataSet (repast::DataSet *dataSet) |
Adds a dataset to this Observer. More... | |
void | dataSetClose () |
Non API method for closing all the datasets at the end of a sim runs. | |
virtual void | go ()=0 |
Called every tick of the simulation. More... | |
virtual void | setup (Properties &props) |
Classes that extend this should include model initialization here. More... | |
void | _setup (Properties &props) |
Performs internal Relogo initialization. More... | |
int | minPxcor () const |
Gets the minimum x coordinate of the patches managed by this Observer. More... | |
int | minPycor () const |
Gets the minimum y coordinate of the patches managed by this Observer. More... | |
int | maxPxcor () const |
Gets the maximum x coordinate of the patches managed by this Observer. More... | |
int | maxPycor () const |
Gets the maximum y coordinate of the patches managed by this Observer. More... | |
int | randomPxcor () |
Gets a random x coodinate of the patches managed by this Observer. More... | |
int | randomPycor () |
Gets a random y coodinate of the patches managed by this Observer. More... | |
double | randomXcor () |
Gets a random x coodinate of the turtles managed by this Observer. More... | |
double | randomYcor () |
Gets a random y coodinate of the turtles managed by this Observer. More... | |
bool | spacePtToGridPt (std::vector< double > &spacePt, std::vector< int > &gridPt) |
template<typename AgentType > | |
AgentType * | hatch (RelogoAgent *parent) |
Hatchs an agent of the specified type. More... | |
template<typename AgentType , typename FactoryFunctor > | |
AgentType * | hatch (RelogoAgent *parent, FactoryFunctor agentCreator) |
Hatchs an agent of the specified type. More... | |
template<typename AgentType > | |
AgentType * | who (const AgentId &id) |
Gets the agent with the specified id. More... | |
template<typename AgentType > | |
int | create (size_t count) |
Create count number of agents of the specified type. More... | |
template<typename AgentType , typename FactoryFunctor > | |
int | create (size_t count, FactoryFunctor agentCreator) |
Create count number of agents of the specified type, using the specified FactoryFunctor. More... | |
void | removeAgent (const AgentId &id) |
Removes the specified turtle from the world. | |
template<typename AgentType > | |
AgentSet< AgentType > | get () |
Gets all of the agents of the templated type and returns them in an AgentSet. More... | |
AgentSet< Turtle > | turtles () |
Gets all the turtles in this world and return them in the AgentSet. | |
void | get (AgentSet< Turtle > &turtles) |
Gets all the turtles in this world and put them into the specified AgentSet. More... | |
template<typename AgentType > | |
void | get (AgentSet< AgentType > &agentSet) |
Gets all of the agents of the templated type and puts them into the agentSet. More... | |
template<typename AgentType > | |
AgentType * | get (const AgentId &id) |
Gets the turtle with the specified id or 0 if no such turtle is found. More... | |
template<typename AgentType > | |
AgentSet< AgentType > | turtlesAt (int x, int y) |
Gets all of the agents of the templated type at the specified patch location. More... | |
template<typename AgentType > | |
void | turtlesAt (int x, int y, AgentSet< AgentType > &set) |
Gets all of the agents of the templated type at the specified patch location and puts them in the specified set. More... | |
int | rank () const |
Gets the process rank of this Observer. More... | |
const RelogoGridType * | grid () |
Gets the grid managed by this Observer. More... | |
const RelogoSpaceType * | space () |
Gets the space managed by this Observer. More... | |
void | createLink (RelogoAgent *source, RelogoAgent *target, const std::string &networkName) |
Creates a link between the source and target agents in the named network. More... | |
template<typename LinkCreator > | |
void | createLink (RelogoAgent *source, RelogoAgent *target, const std::string &networkName, LinkCreator &creator) |
Creates a link between the source and target agents in the named network, using the specified LinkCreator. More... | |
boost::shared_ptr< RelogoLink > | link (RelogoAgent *source, RelogoAgent *target, const std::string &networkName) |
Gets the link, if any, between the source and target agents in the named network. More... | |
template<typename AgentType > | |
void | predecessors (RelogoAgent *agent, const std::string &networkName, AgentSet< AgentType > &out) |
Gets the network predecessors of the specified agent in the specified network and puts the result into out. More... | |
template<typename AgentType > | |
void | successors (RelogoAgent *agent, const std::string &networkName, AgentSet< AgentType > &out) |
Gets the network successors of the specified agent in the specified network and puts the result into out. More... | |
template<typename PatchType > | |
PatchType * | patchAt (int x, int y) |
Gets the patch at the specified coordinates. More... | |
Patch * | patchAt (int x, int y) |
Gets the patch at the specified coordinates. More... | |
Patch * | patchAt (Point< double > location, double dx, double dy) |
Gets the patch at the delta from the specified location or 0 if the resulting location is outside the world. More... | |
Patch * | patchAtOffset (Point< double > location, double heading, double distance) |
Gets the patch at the heading/distance offset from the specified location or 0 if the resulting location is outside the world. More... | |
template<typename PatchType > | |
AgentSet< PatchType > | patches () |
Gets an agent set of the all the patches. More... | |
template<typename PatchType > | |
void | patches (AgentSet< PatchType > &set) |
Gets all the patches and places them in the specified set. More... | |
template<typename TurtleType > | |
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 turtles in the agentSet are standing. More... | |
template<typename TurtleType > | |
void | turtlesOn (const RelogoAgent *agent, AgentSet< TurtleType > &out) |
Gets all the turtles that are on the patch if the agent is a patch, otherwise get all the agents on the patch where the agent is standing. More... | |
template<typename AgentType > | |
void | inRadius (const Point< double > ¢er, 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 the specified center into the outSet. More... | |
template<typename TurtleContent , typename Provider , typename Updater , typename AgentCreator > | |
void | synchronizeTurtleStatus (Provider &provider, Updater &updater, AgentCreator &creator, RepastProcess::EXCHANGE_PATTERN exchangePattern=RepastProcess::POLL) |
Synchronizes the status (moved or died) of all turtles across processes. More... | |
template<typename TurtleContent , typename Provider , typename Updater > | |
void | synchronizeTurtleStates (Provider &provider, Updater &updater) |
Synchronizes the state of any Turtles that are shared across processes. More... | |
template<typename TurtleContent , typename Provider , typename Updater , typename AgentCreator > | |
void | synchronize (Provider &provider, Updater &updater, AgentCreator &creator, RepastProcess::EXCHANGE_PATTERN exchangePattern=RepastProcess::POLL) |
template<typename Agent > | |
AgentSet< Agent > | get () |
Protected Types | |
typedef SharedNetwork< RelogoAgent, RelogoLink, RelogoLinkContent, RelogoLinkContentManager > | NetworkType |
Protected Member Functions | |
NetworkType * | findNetwork (const std::string &name) |
Protected Attributes | |
Properties | _props |
int | _rank |
GridDimensions | localBounds |
repast::SharedContext< RelogoAgent > | context |
std::vector< repast::DataSet * > | dataSets |
Friends | |
class | WorldCreator |
Implementation of a logo Observer.
void repast::relogo::Observer::_setup | ( | Properties & | props | ) |
Performs internal Relogo initialization.
props | Properties collection that can be used to drive initialization |
void repast::relogo::Observer::addDataSet | ( | repast::DataSet * | dataSet | ) |
Adds a dataset to this Observer.
This observer will schedule the dataset for recording and writing, and properly destroy the dataset.
dataSet | the data set to add |
int repast::relogo::Observer::create | ( | size_t | count | ) |
Create count number of agents of the specified type.
count | the number of agents to create |
AgentType | the type of agents to create. This must be a Turtle or a class that extends Turtle. It must have a constructor that takes an AgentId and a pointer to this Observer. |
int repast::relogo::Observer::create | ( | size_t | count, |
FactoryFunctor | agentCreator | ||
) |
Create count number of agents of the specified type, using the specified FactoryFunctor.
count | the number of agents to create |
agentCreator | a FactoryFunctor used to create the agents |
AgentType | the type of agent to create. This must either be a Turtle or extend Turtle. |
FactoryFunctor | a functor or function with the following signature AgentType* (AgentId id, Observer* obs). |
void repast::relogo::Observer::createLink | ( | RelogoAgent * | source, |
RelogoAgent * | target, | ||
const std::string & | networkName | ||
) |
Creates a link between the source and target agents in the named network.
source | the source agent |
target | the target agent |
networkName | the name of the network to create the link in |
void repast::relogo::Observer::createLink | ( | RelogoAgent * | source, |
RelogoAgent * | target, | ||
const std::string & | networkName, | ||
LinkCreator & | creator | ||
) |
Creates a link between the source and target agents in the named network, using the specified LinkCreator.
source | the source agent |
target | the target agent |
networkName | the name of the network to create the link in |
LinkCreator | an function or functor with the following signature RelogoLink* (Turtle* source, Turtle* target) |
AgentSet<AgentType> repast::relogo::Observer::get | ( | ) |
Gets all of the agents of the templated type and returns them in an AgentSet.
AgentType | the type of turtle agents to get |
void repast::relogo::Observer::get | ( | AgentSet< AgentType > & | agentSet | ) |
Gets all of the agents of the templated type and puts them into the agentSet.
agentSet | the AgentSet to put the found agents in |
AgentType | the type of turtle agents to get |
AgentType * repast::relogo::Observer::get | ( | const AgentId & | id | ) |
Gets the turtle with the specified id or 0 if no such turtle is found.
AgentType | the type of the turtle to find |
|
pure virtual |
Called every tick of the simulation.
Implementations of this method will implement that actual simulation behavior.
const RelogoGridType * repast::relogo::Observer::grid | ( | ) |
AgentType * repast::relogo::Observer::hatch | ( | RelogoAgent * | parent | ) |
Hatchs an agent of the specified type.
The new agent will have the location and heading of the specified "parent".
the | "parent" of the hatched agent |
AgentType | the type of turtle to hatch |
AgentType * repast::relogo::Observer::hatch | ( | RelogoAgent * | parent, |
FactoryFunctor | agentCreator | ||
) |
Hatchs an agent of the specified type.
The new agent will have the location and heading of the specified "parent" and will be created using the FactoryFunctor.
the | "parent" of the hatched agent |
agentCreator | a FactoryFunctor used to create the agent |
void repast::relogo::Observer::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 the specified center into the outSet.
center | the center of the circle within whose radius we filter on |
inSet | the set of agents to filter |
outSet | the set that will contain the results of the radius filter |
the | type of agent to get |
boost::shared_ptr< RelogoLink > repast::relogo::Observer::link | ( | RelogoAgent * | source, |
RelogoAgent * | target, | ||
const std::string & | networkName | ||
) |
Gets the link, if any, between the source and target agents in the named network.
source | the source of the link |
target | the target of the link |
networkName | the name of the network to find link in |
int repast::relogo::Observer::maxPxcor | ( | ) | const |
int repast::relogo::Observer::maxPycor | ( | ) | const |
int repast::relogo::Observer::minPxcor | ( | ) | const |
int repast::relogo::Observer::minPycor | ( | ) | const |
PatchType * repast::relogo::Observer::patchAt | ( | int | x, |
int | y | ||
) |
Gets the patch at the specified coordinates.
x | the x coordinate |
y | the y coordinate |
the | patch type |
Patch * repast::relogo::Observer::patchAt | ( | int | x, |
int | y | ||
) |
Gets the patch at the specified coordinates.
x | the x coordinate |
y | the y coordinate |
Gets the patch at the delta from the specified location or 0 if the resulting location is outside the world.
location | |
dx | the delta along the x dimension |
dy | the delta along the y dimension |
Patch * repast::relogo::Observer::patchAtOffset | ( | Point< double > | location, |
double | heading, | ||
double | distance | ||
) |
Gets the patch at the heading/distance offset from the specified location or 0 if the resulting location is outside the world.
location | |
heading | the heading away from location |
distance | distance along heading |
AgentSet< PatchType > repast::relogo::Observer::patches |
Gets an agent set of the all the patches.
PatchType | the patch type |
void repast::relogo::Observer::patches | ( | AgentSet< PatchType > & | set | ) |
Gets all the patches and places them in the specified set.
set | the AgentSet to put the patches in |
PatchType | the patch type |
void repast::relogo::Observer::predecessors | ( | RelogoAgent * | agent, |
const std::string & | networkName, | ||
AgentSet< AgentType > & | out | ||
) |
Gets the network predecessors of the specified agent in the specified network and puts the result into out.
agent | the agent to get the predecessors of |
networkName | the name of the network |
out | an AgentSet when the predecessors will be put |
AgentType | the type of the predecessors |
int repast::relogo::Observer::randomPxcor | ( | ) |
int repast::relogo::Observer::randomPycor | ( | ) |
double repast::relogo::Observer::randomXcor | ( | ) |
double repast::relogo::Observer::randomYcor | ( | ) |
|
inline |
|
inlinevirtual |
Classes that extend this should include model initialization here.
props | Properties collection that can be used to drive initialization |
const RelogoSpaceType * repast::relogo::Observer::space | ( | ) |
void repast::relogo::Observer::successors | ( | RelogoAgent * | agent, |
const std::string & | networkName, | ||
AgentSet< AgentType > & | out | ||
) |
Gets the network successors of the specified agent in the specified network and puts the result into out.
agent | the agent to get the successors of |
networkName | the name of the network |
out | an AgentSet when the successors will be put |
AgentType | the type of the successors |
void repast::relogo::Observer::synchronizeTurtleStates | ( | Provider & | provider, |
Updater & | updater | ||
) |
Synchronizes the state of any Turtles that are shared across processes.
If no turtles are shared across processes, then this does not need to be called.
provider | provides TurtleContent given an AgentRequest |
updater | updates an existing agent given TurtleContent |
TurtleContent | the serializable struct or class that describes the state of turtles and patches |
Provider | given an AgentRequest, a Provider provides the TurtleContent for the requested Turtles, implementing void provideContent(const AgentRequest&, std::vector<TurtleContent>&) |
Updater | given TurtleContent, an Updater updates an existing agent with the TurtleContent, implementing void updateAgent(const TurtleContent&). |
void repast::relogo::Observer::synchronizeTurtleStatus | ( | Provider & | provider, |
Updater & | updater, | ||
AgentCreator & | creator, | ||
RepastProcess::EXCHANGE_PATTERN | exchangePattern = RepastProcess::POLL |
||
) |
Synchronizes the status (moved or died) of all turtles across processes.
If any turtle may have moved into the grid portion managed by another process or if any turtle has died then this must be called prior to those turtles doing anything.
provider | the class that provides agents given an AgentRequest |
creator | creates Turtles given TurtleContent |
TurtleContent | the serializable struct or class that describes a turtles state. |
Provider | a class that provides TurtleContent from given an AgentRequest, implementing void provideContent(const repast::AgentRequest&, std::vector<TurtleContent>& out) |
AgentCreator | a class that can create agents from TurtleContent, implementing RelogoAgent* createAgent(TurtleContent&). |
AgentSet< AgentType > repast::relogo::Observer::turtlesAt | ( | int | x, |
int | y | ||
) |
Gets all of the agents of the templated type at the specified patch location.
AgentType | the type of the agents |
void repast::relogo::Observer::turtlesAt | ( | int | x, |
int | y, | ||
AgentSet< AgentType > & | set | ||
) |
Gets all of the agents of the templated type at the specified patch location and puts them in the specified set.
x | the x coordinate of the patch |
y | the y coordinate of the patch |
set | the AgentSet to add the found agents to |
AgentType | the agent type |
void repast::relogo::Observer::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 turtles in the agentSet are standing.
The result is placed in out.
agentSet | a set of turtles or patches |
out | the AgentSet where the found turtles will put |
TurtleType | the type of the turtles to return |
void repast::relogo::Observer::turtlesOn | ( | const RelogoAgent * | agent, |
AgentSet< TurtleType > & | out | ||
) |
Gets all the turtles that are on the patch if the agent is a patch, otherwise get all the agents on the patch where the agent is standing.
The result is placed in out.
agent | the turtle or patch used to determine which turtles to get |
out | the agent set where the found turtles will be put |
TurtleType | the type of the turtles to return |
AgentType * repast::relogo::Observer::who | ( | const AgentId & | id | ) |
Gets the agent with the specified id.
id | the id of the agent to get |
AgentType | the type of the agent to get |