simulator.h 2.76 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) :
David Cazier's avatar
David Cazier committed
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
		// Thread execution stuff goes here
David Cazier's avatar
David Cazier committed
39
40
		for (unsigned int i = 0; i < ag_.size(); ++i)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
41
42
//			ag_[i]->updateObstacleNeighbors();
//			ag_[i]->updateAgentNeighbors();
43
44
			ag_[i]->computePrefVelocity() ;
			ag_[i]->computeNewVelocity() ;
45
46
		}
	}
47
} ;
48

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
78
79
80
class Simulator
{
public:
David Cazier's avatar
David Cazier committed
81
	Simulator(int minSize) ;
82
83

	Simulator(float timeStep, float neighborDist, unsigned int maxNeighbors, float timeHorizon,
David Cazier's avatar
David Cazier committed
84
	          float timeHorizonObst, float radius, float maxSpeed, const VEC3& velocity = VEC3(0)) ;
85
86
87

	~Simulator() ;

David Cazier's avatar
David Cazier committed
88
	void init(unsigned int config, int minSize, float dimension, bool enablePathFinding = false) ;
89
90
91
92
93
94
95
96
97
98
	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