simulator.h 3.41 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>

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:
pitiot's avatar
pitiot committed
83
	Simulator(unsigned int config, unsigned int minSize, unsigned int nbAgent=1000, unsigned int nbObst=20, bool resolution =true) ;
84
85
86

	~Simulator() ;

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

	void doStep() ;

	bool reachedGoal() ;

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

99
100
	void setupPlanetScenario(unsigned int nbAgents, unsigned int nbObstacles);

101
102
103
	void addMovingObstacles(unsigned int nb);
	void addMovingObstacle(Dart d, unsigned int obstType=0);

David Cazier's avatar
David Cazier committed
104
	void addAgent(const VEC3& start,const VEC3& goals);
105
	void addAgent(const VEC3& start,const VEC3& goals, Dart d);
pitiot's avatar
maj    
pitiot committed
106
	
Pierre Kraemer's avatar
Pierre Kraemer committed
107
#ifndef SPATIAL_HASHING
108
	void addPathToObstacles();
pitiot's avatar
pitiot committed
109
	void addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal);
110
111
112
	void addPathToCorner() ;
	void addPathsToAgents() ;
	void addPathsToAgents_height() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
113
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
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
maj    
pitiot committed
123
	std::vector<MovingObstacle*> movingObstacles_;
pitiot's avatar
pitiot committed
124
	std::vector<MovingMesh*> movingMeshes_; //for visualization only
pitiot's avatar
pitiot committed
125
	int minSize;
pitiot's avatar
merging    
pitiot committed
126
	unsigned int config;
127
128
129
130
131
132
133
134
135
136
137
138
	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
139
140
	int avoidance;
	int nb_dead;
141
	bool multires;
142
	bool detect_agent_collision;
143
144
145
146
	ThreadUpdateInfo* tc1 ;
	ThreadUpdateInfo* tc2 ;
	ThreadUpdateInfo* tc3 ;
	ThreadUpdateInfo* tc4 ;
147
148
149

	long int time_agent;
	long int time_obstacle;
pitiot's avatar
maj    
pitiot committed
150
};
Pierre Kraemer's avatar
Pierre Kraemer committed
151
152

#endif