RepastHPC  2.3.1
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
repast::relogo::Observer Class Referenceabstract

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< Turtleturtles ()
 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 RelogoGridTypegrid ()
 Gets the grid managed by this Observer. More...
 
const RelogoSpaceTypespace ()
 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< RelogoLinklink (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...
 
PatchpatchAt (int x, int y)
 Gets the patch at the specified coordinates. More...
 
PatchpatchAt (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...
 
PatchpatchAtOffset (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 > &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. 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< Agentget ()
 

Protected Types

typedef SharedNetwork< RelogoAgent, RelogoLink, RelogoLinkContent, RelogoLinkContentManagerNetworkType
 

Protected Member Functions

NetworkTypefindNetwork (const std::string &name)
 

Protected Attributes

Properties _props
 
int _rank
 
GridDimensions localBounds
 
repast::SharedContext< RelogoAgentcontext
 
std::vector< repast::DataSet * > dataSets
 

Friends

class WorldCreator
 

Detailed Description

Implementation of a logo Observer.

Member Function Documentation

◆ _setup()

void repast::relogo::Observer::_setup ( Properties props)

Performs internal Relogo initialization.

Parameters
propsProperties collection that can be used to drive initialization

◆ addDataSet()

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.

Parameters
dataSetthe data set to add

◆ create() [1/2]

template<typename AgentType >
int repast::relogo::Observer::create ( size_t  count)

Create count number of agents of the specified type.

Parameters
countthe number of agents to create
Template Parameters
AgentTypethe 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.
Returns
the integer type id for agents of this type.

◆ create() [2/2]

template<typename AgentType , typename FactoryFunctor >
int repast::relogo::Observer::create ( size_t  count,
FactoryFunctor  agentCreator 
)

Create count number of agents of the specified type, using the specified FactoryFunctor.

Parameters
countthe number of agents to create
agentCreatora FactoryFunctor used to create the agents
Template Parameters
AgentTypethe type of agent to create. This must either be a Turtle or extend Turtle.
FactoryFunctora functor or function with the following signature AgentType* (AgentId id, Observer* obs).
Returns
an the integer id for agents of this type

◆ createLink() [1/2]

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.

Parameters
sourcethe source agent
targetthe target agent
networkNamethe name of the network to create the link in

◆ createLink() [2/2]

template<typename LinkCreator >
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.

Parameters
sourcethe source agent
targetthe target agent
networkNamethe name of the network to create the link in
Template Parameters
LinkCreatoran function or functor with the following signature RelogoLink* (Turtle* source, Turtle* target)

◆ get() [1/4]

template<typename AgentType >
AgentSet<AgentType> repast::relogo::Observer::get ( )

Gets all of the agents of the templated type and returns them in an AgentSet.

Template Parameters
AgentTypethe type of turtle agents to get
Returns
an agent set containing the agents

◆ get() [2/4]

template<typename AgentType >
void repast::relogo::Observer::get ( AgentSet< AgentType > &  agentSet)

Gets all of the agents of the templated type and puts them into the agentSet.

Parameters
agentSetthe AgentSet to put the found agents in
Template Parameters
AgentTypethe type of turtle agents to get
Returns
an agent set containing the agents

◆ get() [3/4]

void repast::relogo::Observer::get ( AgentSet< Turtle > &  turtles)

Gets all the turtles in this world and put them into the specified AgentSet.

Parameters
turtlesthe AgentSet to put the turtles in

◆ get() [4/4]

template<typename AgentType >
AgentType * repast::relogo::Observer::get ( const AgentId id)

Gets the turtle with the specified id or 0 if no such turtle is found.

Template Parameters
AgentTypethe type of the turtle to find
Returns
the turtle with the specified id, or 0.

◆ go()

virtual void repast::relogo::Observer::go ( )
pure virtual

Called every tick of the simulation.

Implementations of this method will implement that actual simulation behavior.

◆ grid()

const RelogoGridType * repast::relogo::Observer::grid ( )

Gets the grid managed by this Observer.

Returns
the grid managed by this Observer.

◆ hatch() [1/2]

template<typename AgentType >
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".

Parameters
the"parent" of the hatched agent
Template Parameters
AgentTypethe type of turtle to hatch

◆ hatch() [2/2]

template<typename AgentType , typename FactoryFunctor >
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.

Parameters
the"parent" of the hatched agent
agentCreatora FactoryFunctor used to create the agent
Template Parameters
FactoryFunctora functor or function with the following signature AgentType* (AgentId id, Observer* obs).
AgentTypethe type of turtle to hatch. This must either be Turtle or extend Turtle.

◆ inRadius()

template<typename AgentType >
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.

Parameters
centerthe center of the circle within whose radius we filter on
inSetthe set of agents to filter
outSetthe set that will contain the results of the radius filter
Template Parameters
thetype of agent to get

◆ link()

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.

Parameters
sourcethe source of the link
targetthe target of the link
networkNamethe name of the network to find link in

◆ maxPxcor()

int repast::relogo::Observer::maxPxcor ( ) const

Gets the maximum x coordinate of the patches managed by this Observer.

Returns
the maximum x coordinate of the patches managed by this Observer.

◆ maxPycor()

int repast::relogo::Observer::maxPycor ( ) const

Gets the maximum y coordinate of the patches managed by this Observer.

Returns
the maximum y coordinate of the patches managed by this Observer.

◆ minPxcor()

int repast::relogo::Observer::minPxcor ( ) const

Gets the minimum x coordinate of the patches managed by this Observer.

Returns
the minimum x coordinate of the patches managed by this Observer.

◆ minPycor()

int repast::relogo::Observer::minPycor ( ) const

Gets the minimum y coordinate of the patches managed by this Observer.

Returns
the minimum y coordinate of the patches managed by this Observer.

◆ patchAt() [1/3]

template<typename PatchType >
PatchType * repast::relogo::Observer::patchAt ( int  x,
int  y 
)

Gets the patch at the specified coordinates.

Parameters
xthe x coordinate
ythe y coordinate
Template Parameters
thepatch type
Returns
a pointer to the patch at x,y

◆ patchAt() [2/3]

Patch * repast::relogo::Observer::patchAt ( int  x,
int  y 
)

Gets the patch at the specified coordinates.

Parameters
xthe x coordinate
ythe y coordinate
Returns
a pointer to the patch at x,y

◆ patchAt() [3/3]

Patch * repast::relogo::Observer::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.

Parameters
location
dxthe delta along the x dimension
dythe delta along the y dimension
Returns
the patch at the delta from the specified location or 0 if the resulting location is outside the world.

◆ patchAtOffset()

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.

Parameters
location
headingthe heading away from location
distancedistance along heading
Returns
the patch at the delta from the specified location or 0 if the resulting location is outside the world.

◆ patches() [1/2]

template<typename PatchType >
AgentSet< PatchType > repast::relogo::Observer::patches

Gets an agent set of the all the patches.

Template Parameters
PatchTypethe patch type
Returns
all the patches.

◆ patches() [2/2]

template<typename PatchType >
void repast::relogo::Observer::patches ( AgentSet< PatchType > &  set)

Gets all the patches and places them in the specified set.

Parameters
setthe AgentSet to put the patches in
Template Parameters
PatchTypethe patch type

◆ predecessors()

template<typename AgentType >
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.

Parameters
agentthe agent to get the predecessors of
networkNamethe name of the network
outan AgentSet when the predecessors will be put
Template Parameters
AgentTypethe type of the predecessors

◆ randomPxcor()

int repast::relogo::Observer::randomPxcor ( )

Gets a random x coodinate of the patches managed by this Observer.

Returns
a random x coordinate of the patches managed by this Observer.

◆ randomPycor()

int repast::relogo::Observer::randomPycor ( )

Gets a random y coodinate of the patches managed by this Observer.

Returns
a random y coordinate of the patches managed by this Observer.

◆ randomXcor()

double repast::relogo::Observer::randomXcor ( )

Gets a random x coodinate of the turtles managed by this Observer.

Returns
a random x coordinate of the turtles managed by this Observer.

◆ randomYcor()

double repast::relogo::Observer::randomYcor ( )

Gets a random y coodinate of the turtles managed by this Observer.

Returns
a random y coordinate of the turtles managed by this Observer.

◆ rank()

int repast::relogo::Observer::rank ( ) const
inline

Gets the process rank of this Observer.

Returns
the process rank of this Observer.

◆ setup()

virtual void repast::relogo::Observer::setup ( Properties props)
inlinevirtual

Classes that extend this should include model initialization here.

Parameters
propsProperties collection that can be used to drive initialization

◆ space()

const RelogoSpaceType * repast::relogo::Observer::space ( )

Gets the space managed by this Observer.

Returns
the space managed by this Observer.

◆ successors()

template<typename AgentType >
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.

Parameters
agentthe agent to get the successors of
networkNamethe name of the network
outan AgentSet when the successors will be put
Template Parameters
AgentTypethe type of the successors

◆ synchronizeTurtleStates()

template<typename TurtleContent , typename Provider , typename Updater >
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.

Parameters
providerprovides TurtleContent given an AgentRequest
updaterupdates an existing agent given TurtleContent
Template Parameters
TurtleContentthe serializable struct or class that describes the state of turtles and patches
Providergiven an AgentRequest, a Provider provides the TurtleContent for the requested Turtles, implementing void provideContent(const AgentRequest&, std::vector<TurtleContent>&)
Updatergiven TurtleContent, an Updater updates an existing agent with the TurtleContent, implementing void updateAgent(const TurtleContent&).

◆ synchronizeTurtleStatus()

template<typename TurtleContent , typename Provider , typename Updater , typename AgentCreator >
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.

Parameters
providerthe class that provides agents given an AgentRequest
creatorcreates Turtles given TurtleContent
Template Parameters
TurtleContentthe serializable struct or class that describes a turtles state.
Providera class that provides TurtleContent from given an AgentRequest, implementing void provideContent(const repast::AgentRequest&, std::vector<TurtleContent>& out)
AgentCreatora class that can create agents from TurtleContent, implementing RelogoAgent* createAgent(TurtleContent&).

◆ turtlesAt() [1/2]

template<typename AgentType >
AgentSet< AgentType > repast::relogo::Observer::turtlesAt ( int  x,
int  y 
)

Gets all of the agents of the templated type at the specified patch location.

Template Parameters
AgentTypethe type of the agents
Returns
an agent list containing the agents at the specified location.

◆ turtlesAt() [2/2]

template<typename AgentType >
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.

Parameters
xthe x coordinate of the patch
ythe y coordinate of the patch
setthe AgentSet to add the found agents to
Template Parameters
AgentTypethe agent type

◆ turtlesOn() [1/2]

template<typename TurtleType >
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.

Parameters
agentSeta set of turtles or patches
outthe AgentSet where the found turtles will put
Template Parameters
TurtleTypethe type of the turtles to return

◆ turtlesOn() [2/2]

template<typename TurtleType >
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.

Parameters
agentthe turtle or patch used to determine which turtles to get
outthe agent set where the found turtles will be put
Template Parameters
TurtleTypethe type of the turtles to return

◆ who()

template<typename AgentType >
AgentType * repast::relogo::Observer::who ( const AgentId id)

Gets the agent with the specified id.

Parameters
idthe id of the agent to get
Template Parameters
AgentTypethe type of the agent to get
Returns
the agent with the specified id, or 0 if the agent is not found.

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