39 #ifndef __SIMULATOR_BASE_H__
40 #define __SIMULATOR_BASE_H__
49 #include "mengeCommon.h"
59 #if HAVE_OPENMP || _OPENMP
71 template <
class Agent >
166 virtual bool isExpTarget(
const std::string & tagName ) {
return false; }
199 template <
class Agent >
205 template <
class Agent >
212 template <
class Agent >
214 assert( _spatialQuery != 0x0 &&
"Can't run without a spatial query instance defined" );
216 _spatialQuery->updateAgents();
217 int AGT_COUNT =
static_cast< int >( _agents.size() );
218 #pragma omp parallel for
219 for (
int i = 0; i < AGT_COUNT; ++i) {
220 computeNeighbors( &(_agents[i]) );
221 _agents[i].computeNewVelocity();
224 #pragma omp parallel for
225 for (
int i = 0; i < AGT_COUNT; ++i) {
226 _agents[i].update( TIME_STEP );
229 _globalTime += TIME_STEP;
235 template <
class Agent >
237 assert( _spatialQuery != 0x0 &&
"Can't run without a spatial query instance defined" );
239 const size_t AGT_COUNT = _agents.size();
240 std::vector< BaseAgent * > agtPointers( AGT_COUNT );
241 for (
size_t a = 0; a < AGT_COUNT; ++a ) {
242 agtPointers[ a ] = &_agents[a];
244 _spatialQuery->setAgents( agtPointers );
246 _spatialQuery->processObstacles();
253 template <
class Agent >
258 for (
size_t i = 0; i < _agents.size(); ++i ) {
259 _agents[ i ].initialize();
265 template <
class Agent >
270 agent._id = _agents.size();
275 _agents.push_back(agent);
277 return &_agents[ _agents.size() - 1 ];
282 template <
class Agent >
285 if ( paramName ==
"time_step" ) {
287 LOGICAL_TIME_STEP =
toFloat( value );
289 throw XMLParamException( std::string(
"Common parameters \"time_step\" value couldn't be converted to a float. Found the value: " ) + value );
300 template<
class Agent >
304 _spatialQuery->obstacleQuery(agent);
307 if ( agent->_maxNeighbors > 0 ) {
308 _spatialQuery->agentQuery(agent);
313 #endif // __SIMULATOR_BASE_H__
~SimulatorBase()
Destorys a simulator instance.
Definition: SimulatorBase.h:206
virtual void finalize()
After all agents and all obstacles have been added to the scene does the work to finish preparing the...
Definition: SimulatorInterface.cpp:107
virtual bool setProperties(BaseAgent *agent)
Sets the properties of the given agent based on the initializer's values.
Definition: AgentInitializer.cpp:185
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
void doStep()
Lets the simulator perform a simulation step and updates the two-dimensional _p and two-dimensional v...
Definition: SimulatorBase.h:213
virtual bool isExpTarget(const std::string &tagName)
Reports if the given Experiment attribute tag name belongs to this simulator.
Definition: SimulatorBase.h:166
Exception thrown when a utility function fails..
Definition: Utils.h:65
Vector2 _pos
The current 2D position of the agent.
Definition: BaseAgent.h:208
virtual BaseAgent * getAgent(size_t agentNo)
Accessor for agents.
Definition: SimulatorBase.h:117
virtual const BaseAgent * getAgent(size_t agentNo) const
Const accessor for agents.
Definition: SimulatorBase.h:128
Class which determines the agent properties for each new agent.
Definition: AgentInitializer.h:75
The basic simulator interface required by the fsm.
Definition: SimulatorInterface.h:66
A collection of convenience utilities.
The definition of the interface of the simulator required by the finite state machine.
virtual BaseAgent * addAgent(const Vector2 &pos, AgentInitializer *agentInit)
Add an agent with specified position to the simulator whose properties are defined by the given agent...
Definition: SimulatorBase.h:266
virtual bool hasExpTarget()
Reports if there are non-common Experiment parameters that this simulator requires in the XML file...
Definition: SimulatorBase.h:156
virtual bool initSpatialQuery()
Initalize spatial query structure.
Definition: SimulatorBase.h:236
virtual size_t getNumAgents() const
Returns the count of agents in the simulation.
Definition: SimulatorBase.h:147
Exception for invalid parameters from XML specification.
Definition: XMLSimulatorBase.h:78
std::vector< Agent > _agents
The collection of agents in the simulation.
Definition: SimulatorBase.h:192
Logger logger
Globally available Logger.
Definition: Logger.cpp:49
float toFloat(const std::string &value)
Converts a string to a float.
Definition: Utils.cpp:48
virtual bool setExpParam(const std::string ¶mName, const std::string &value)
Given an Experiment parameter name and value, sets the appropriate simulator parameter.
Definition: SimulatorBase.h:283
The base class for all objects which support agent spatial queries including: k-nearest agent neighbo...
Defines the basic agent properties and functionality that all simulation agents share.
Definition: BaseAgent.h:123
The infrastructure for initializing agent properties from the scene specification file...
SimulatorBase()
Constructs a simulator instance.
Definition: SimulatorBase.h:200
The namespace that contains the basic simulation mechanisms.
void computeNeighbors(Agent *agent)
Computes the neighbors for the given agent.
Definition: SimulatorBase.h:301
Defines the basic simulator. It is responsible for tracking agents and obstacles as well as initializ...
Definition: SimulatorBase.h:72
Error encountered but not handled.
Definition: Logger.h:69
virtual void finalize()
After all agents and all obstacles have been added to the scene does the work to finish preparing the...
Definition: SimulatorBase.h:254