simulator.h 2.73 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
#ifndef SIMULATOR_H
#define SIMULATOR_H

#include <limits>

#include "env_map.h"
#include "agent.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
8
#include "obstacle.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
9
//#include "moving_obstacle.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
10
11
12
13
14
15
16
#include "path_finder.h"

#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>

17
18
class ThreadUpdateInfo
{
19
20
21
22
public:
	std::vector<Agent*> ag_ ;
	unsigned int bMin_ ;
	unsigned int bMax_ ;
23
24
25

	// Constructor
	ThreadUpdateInfo(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
26
			bMin_(bMin), bMax_(bMax)
27
	{
28
		ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax) ;
29
30
31
	}

	// Destructor
32
33
34
	~ThreadUpdateInfo()
	{
	}
35
36
37

	void run()
	{
38
39
		// Thread execution stuff goes here
		for (unsigned int i = 0 ; i < ag_.size() ; ++i) {
Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
//			ag_[i]->updateObstacleNeighbors();
//			ag_[i]->updateAgentNeighbors();
42
43
			ag_[i]->computePrefVelocity() ;
			ag_[i]->computeNewVelocity() ;
44
45
		}
	}
46
} ;
47

48
49
class ThreadUpdatePos
{
50
51
52
53
public:
	std::vector<Agent*> ag_ ;
	unsigned int bMin_ ;
	unsigned int bMax_ ;
54
55

	// Constructor
56
57
	ThreadUpdatePos(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
			bMin_(bMin), bMax_(bMax)
58
	{
59
		ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax) ;
60
61
62
	}

	// Destructor
63
64
65
	~ThreadUpdatePos()
	{
	}
66

67
68
69
70
71
	void run()
	{
		// Thread execution stuff goes here
		for (unsigned int i = 0 ; i < ag_.size() ; ++i) {
			ag_[i]->update() ;
72
73
		}
	}
74
} ;
75

Pierre Kraemer's avatar
Pierre Kraemer committed
76
77
78
class Simulator
{
public:
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
	Simulator() ;

	Simulator(float timeStep, float neighborDist, unsigned int maxNeighbors, float timeHorizon,
			float timeHorizonObst, float radius, float maxSpeed,
			const VEC3& velocity = VEC3(0)) ;

	~Simulator() ;

	void init(unsigned int config, float dimension, bool enablePathFinding = false) ;
	void setupCircleScenario(unsigned int nbMaxAgent) ;
	void setupCorridorScenario(unsigned int nbMaxAgent) ;
	void setupCityScenario(float startX, float startY, int nbLines, int nbRank) ;
	void setupScenario(unsigned int nbMaxAgent) ;

	void doStep() ;

	bool reachedGoal() ;


	void setupMovingObstacle(unsigned int nbObstacles) ;
99

Pierre Kraemer's avatar
Pierre Kraemer committed
100
#ifndef SPATIAL_HASHING
101
102
103
	void addPathToCorner() ;
	void addPathsToAgents() ;
	void addPathsToAgents_height() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
104
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
105

106
107
108
109
110
111
112
113
114
115
	bool importAgents(std::string filename) ;
	bool exportAgents(std::string filename) ;

	void swapAgentsGoals() ;

	Geom::BoundingBox<VEC3> getAgentsBB() ;

	EnvMap envMap_ ;
	std::vector<Agent*> agents_ ;
//	std::vector<MovingObstacle*> movingObstacles_;
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	float timeStep_ ;
	float globalTime_ ;
	unsigned int nbSteps_ ;
	unsigned int nbStepsPerUnit_ ;

	unsigned int nbUpdates ;
	unsigned int nbSorts ;
	unsigned int nbRefineCandidate ;
	unsigned int nbCoarsenCandidate ;
	unsigned long nearNeighbors ;
	unsigned long totalNeighbors ;

	ThreadUpdateInfo* tc1 ;
	ThreadUpdateInfo* tc2 ;
	ThreadUpdateInfo* tc3 ;
	ThreadUpdateInfo* tc4 ;
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
134
135

#endif