All Classes Namespaces Files Functions Variables Typedefs Pages
SimulationEngine.h
Go to the documentation of this file.
1 /*
2  * SimulationEngine.h
3  *
4  *
5  * All rights are retained by the authors and the University of Minnesota.
6  * Please contact sjguy@cs.umn.edu for licensing inquiries.
7  *
8  * Authors: Ioannis Karamouzas, Brian Skinner, and Stephen J. Guy
9  * Contact: ioannis@cs.umn.edu
10  */
11 
17 #pragma once
18 
19 #include "Agent.h"
20 #include "LineObstacle.h"
21 #include <fstream>
22 
23 
31 namespace TTC {
32 
38 
39  protected:
40 
41 
43  float _dt;
44 
46  float _globalTime;
47 
50 
52  int _maxSteps;
53 
56 
59 
61  vector<Agent* > _agents;
62 
64  vector<LineObstacle* > _obstacles;
65 
66 
67  public:
72 
75 
83  void init(float xRange, float yRange);
84 
85 
90  void updateSimulation();
91 
96  bool endSimulation();
97 
102  void updateVisualisation();
103 
109  void exportSimulation(std::ofstream& file);
110 
115  void addAgent(AgentInitialParameters& parameters);
116 
121  void addObstacle(const std::pair<Vector2D, Vector2D>& lineSegment);
122 
123 
125 
126 
129 
131  const vector<Agent*> & getAgents() {return _agents;}
132 
134  const vector<LineObstacle*> & getObstacles() {return _obstacles;}
135 
140  Agent* getAgent(int id) {return _agents[id];}
141 
146  LineObstacle* getObstacle(int id) {return _obstacles[id];}
147 
149  float getTimeStep() const {return _dt;}
150 
155  void setTimeStep( float dt) { _dt = dt; }
156 
157 
159  int getMaxSteps() const {return _maxSteps;}
160 
165  void setMaxSteps( int steps) { _maxSteps = steps; }
166 
168  float getGlobalTime() const { return _globalTime; }
169 
171  int getNumAgents() const {return _agents.size();}
172 
174  int getIterationNumber() const {return _iteration;}
175 
177 
178  };
179 
180 }
181  extern TTC::SimulationEngine* simEngine;
182 
183 
LQProximityDatabase2D SpatialProximityDatabase
The spatial proximity database.
Definition: Proximity2D.h:153
void addAgent(AgentInitialParameters &parameters)
Add a new agent to the simulation given its default parameters.
Definition: SimulationEngine.cpp:127
A line segment obstacle class.
Definition: LineObstacle.h:25
void setMaxSteps(int steps)
Sets the maximum number of simulation steps.
Definition: SimulationEngine.h:165
void exportSimulation(std::ofstream &file)
Outputs a simulation step in a file.
Definition: SimulationEngine.cpp:115
vector< Agent * > _agents
The agents in the simulation.
Definition: SimulationEngine.h:61
int getMaxSteps() const
Returns the number of simulations steps.
Definition: SimulationEngine.h:159
void setTimeStep(float dt)
Sets the time step of the simulation.
Definition: SimulationEngine.h:155
LineObstacle * getObstacle(int id)
Returns the corresponding line obstacle given its id.
Definition: SimulationEngine.h:146
Simulates the anticipatory behavior of an agent.
Definition: Agent.h:31
bool _reachedGoals
Determine whether all agents have reached their goals.
Definition: SimulationEngine.h:55
The initial parameters for a single agent.
Definition: AgentInitialParameters.h:25
const vector< LineObstacle * > & getObstacles()
Returns the list of obstacles.
Definition: SimulationEngine.h:134
void updateSimulation()
Performs a simulation/integration step i.e. updates the acceleration, velocity and position of the si...
Definition: SimulationEngine.cpp:68
float getGlobalTime() const
Returns the global time of the simulation. Initially this time is set to zero.
Definition: SimulationEngine.h:168
int getNumAgents() const
Returns the number of agents in the simulation.
Definition: SimulationEngine.h:171
bool endSimulation()
This function determines whether the simulation has to stop i.e. when all characters have reached the...
Definition: SimulationEngine.cpp:97
SpatialProximityDatabase * _spatialDatabase
The proximity database.
Definition: SimulationEngine.h:58
The main class of the library.
Definition: SimulationEngine.h:37
float _globalTime
The current time in the simulation.
Definition: SimulationEngine.h:46
Contains the Agent class.
int _maxSteps
The maximum number of simulation steps.
Definition: SimulationEngine.h:52
float getTimeStep() const
Returns the time step of the simulation.
Definition: SimulationEngine.h:149
Contains the LineObstacle class.
const vector< Agent * > & getAgents()
Returns the list of agents in the simulation.
Definition: SimulationEngine.h:131
void init(float xRange, float yRange)
Initialization of the simulation engine. All characters in the library have the same time step...
Definition: SimulationEngine.cpp:56
int _iteration
The current iteration step.
Definition: SimulationEngine.h:49
void addObstacle(const std::pair< Vector2D, Vector2D > &lineSegment)
Add a new line obstacle to the simulation.
Definition: SimulationEngine.cpp:136
Agent * getAgent(int id)
Returns the corresponding agent given its id.
Definition: SimulationEngine.h:140
SpatialProximityDatabase * getSpatialDatabase()
Returns a pointer to the proximity database of the engine.
Definition: SimulationEngine.h:128
vector< LineObstacle * > _obstacles
The obstacles in the simulation.
Definition: SimulationEngine.h:64
void updateVisualisation()
Outputs a simulation step in the console.
Definition: SimulationEngine.cpp:102
float _dt
The time step in the simulation.
Definition: SimulationEngine.h:43
SimulationEngine()
Definition: SimulationEngine.cpp:24
~SimulationEngine()
Definition: SimulationEngine.cpp:31
int getIterationNumber() const
Returns the current simulation step.
Definition: SimulationEngine.h:174