Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

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

#include <limits>
pitiot's avatar
maj  
pitiot 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
merging  
pitiot committed
10
#include "articulated_obstacle.h"
pitiot's avatar
maj  
pitiot committed
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>

pitiot's avatar
stats  
pitiot committed
19
20
timespec timespec_delta(const timespec& t1, const timespec& t2);

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

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

	// Destructor
36
37
38
	~ThreadUpdateInfo()
	{
	}
39
40
41

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

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

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

	// Destructor
68
69
70
	~ThreadUpdatePos()
	{
	}
71

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

Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
84
class Simulator
{
public:
pitiot's avatar
pitiot committed
85
	Simulator(unsigned int config, unsigned int minSize, unsigned int nbAgent=1000, unsigned int nbObst=20, bool resolution =true) ;
86
87
88

	~Simulator() ;

pitiot's avatar
pitiot committed
89
	void init(float dimension, unsigned int nbAgent, unsigned int nbObst, bool enablePathFinding = false) ;
90
91
92
93
94

	void doStep() ;

	bool reachedGoal() ;

David Cazier's avatar
David Cazier committed
95
96
	void setupCircleScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
	void setupCorridorScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
pitiot's avatar
merging  
pitiot committed
97
	void setupSnakeCorridorScenario(unsigned int nbAgents, unsigned int nbSnakes, int snakeSize) ;
pitiot's avatar
maj  
pitiot committed
98
	void setupCityScenario(int nbLines, int nbRank) ;
pitiot's avatar
pitiot committed
99
	void setupScenario(unsigned int nbMaxAgent, bool pedWay=false) ;
pitiot's avatar
maj  
pitiot committed
100

pitiot's avatar
up  
pitiot committed
101
	void setupPlanetScenario(unsigned int nbAgents, unsigned int nbObstacles, unsigned int nbx = 2,unsigned int nby= 2, float areaMin = 100.0f);
102

pitiot's avatar
up  
pitiot committed
103
	void addMovingObstacles(unsigned int nb, unsigned int type, float areaMin = 1400, int randLimace=12);
104
105
	void addMovingObstacle(Dart d, unsigned int obstType=0);

David Cazier's avatar
David Cazier committed
106
	void addAgent(const VEC3& start,const VEC3& goals);
107
	void addAgent(const VEC3& start,const VEC3& goals, Dart d);
pitiot's avatar
maj  
pitiot committed
108
	
Pierre Kraemer's avatar
Pierre Kraemer committed
109
#ifndef SPATIAL_HASHING
Thomas Jund's avatar
Thomas Jund committed
110
111
	void addPathToObstacles(CellMarker<FACE>& markForbid, bool goalCenterCell);
	void addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal, CellMarker<FACE>& markForbid, bool goalCenterCell);
112
113
114
	void addPathToCorner() ;
	void addPathsToAgents() ;
	void addPathsToAgents_height() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
115
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
116

117
118
119
120
121
122
123
124
	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
maj  
pitiot committed
125
	std::vector<MovingObstacle*> movingObstacles_;
pitiot's avatar
pitiot committed
126
	std::vector<MovingMesh*> movingMeshes_; //for visualization only
pitiot's avatar
pitiot committed
127
	int minSize;
pitiot's avatar
merging  
pitiot committed
128
	unsigned int config;
129
130
131
132
133
134
135
136
137
138
139
140
	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
maj  
pitiot committed
141
142
	int avoidance;
	int nb_dead;
143
	bool multires;
144
	bool detect_agent_collision;
145
146
147
148
	ThreadUpdateInfo* tc1 ;
	ThreadUpdateInfo* tc2 ;
	ThreadUpdateInfo* tc3 ;
	ThreadUpdateInfo* tc4 ;
149
150
151

	long int time_agent;
	long int time_obstacle;
pitiot's avatar
stats  
pitiot committed
152
153
	long int time_behave;
	long int time_multires;
pitiot's avatar
maj  
pitiot committed
154
};
Pierre Kraemer's avatar
Pierre Kraemer committed
155
156

#endif