Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

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

#include <limits>
David Cazier's avatar
David Cazier committed
5
#include <time.h>
Pierre Kraemer's avatar
Pierre Kraemer committed
6
7
8

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

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

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

	// Constructor
	ThreadUpdateInfo(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
David Cazier's avatar
David Cazier committed
28
		bMin_(bMin), bMax_(bMax)
29
	{
30
		ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax) ;
31
32
33
	}

	// Destructor
34
35
36
	~ThreadUpdateInfo()
	{
	}
37
38
39

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

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

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

	// Destructor
66
67
68
	~ThreadUpdatePos()
	{
	}
69

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
87
88
89
	Simulator(
		float timeStep, float neighborDist, unsigned int maxNeighbors,
		float timeHorizon, float timeHorizonObst, float radius,
		float maxSpeed, const VEC3& velocity = VEC3(0)
	);
90
91
92

	~Simulator() ;

David Cazier's avatar
David Cazier committed
93
	void init(unsigned int config, int minSize, float dimension, bool enablePathFinding = false) ;
Thomas's avatar
Thomas committed
94

95
	void doStep() ;
Thomas's avatar
Thomas committed
96

97
	bool reachedGoal() ;
98

David Cazier's avatar
David Cazier committed
99
100
	void setupCircleScenario(unsigned int nbAgents) ;
	void setupCorridorScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
David Cazier's avatar
David Cazier committed
101
	void setupCityScenario(int nbLines, int nbRank) ;
102
103
	void setupScenario(unsigned int nbMaxAgent) ;

David Cazier's avatar
David Cazier committed
104
	void addAgent(const VEC3& start,const VEC3& goal);
105
	
106
	void setupMovingObstacle(unsigned int nbObstacles) ;
107

Pierre Kraemer's avatar
Pierre Kraemer committed
108
#ifndef SPATIAL_HASHING
109
110
111
	void addPathToCorner() ;
	void addPathsToAgents() ;
	void addPathsToAgents_height() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
113

114
115
116
117
118
119
120
121
122
	bool importAgents(std::string filename) ;
	bool exportAgents(std::string filename) ;

	void swapAgentsGoals() ;

	Geom::BoundingBox<VEC3> getAgentsBB() ;

	EnvMap envMap_ ;
	std::vector<Agent*> agents_ ;
pitiot's avatar
pitiot committed
123
	std::vector<MovingObstacle*> movingObstacles_;
124

125
126
127
128
129
130
131
132
133
134
135
136
	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 ;

pitiot's avatar
pitiot committed
137
138
	int avoidance;
	int nb_dead;
139

140
141
142
143
	ThreadUpdateInfo* tc1 ;
	ThreadUpdateInfo* tc2 ;
	ThreadUpdateInfo* tc3 ;
	ThreadUpdateInfo* tc4 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
144
145
146
};

#endif