simulator.h 2.95 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
maj    
pitiot committed
10
11
#include "moving_obstacle.h"
#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(unsigned int config, unsigned int minSize) ;
84
85
86

	~Simulator() ;

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

	void doStep() ;

	bool reachedGoal() ;

David Cazier's avatar
David Cazier committed
93
94
95
	void setupCircleScenario(unsigned int config, unsigned int nbAgents, unsigned int nbObstacles) ;
	void setupCorridorScenario(unsigned int config, unsigned int nbAgents, unsigned int nbObstacles) ;
	void setupCorridor2Scenario(unsigned int config, unsigned int nbAgents, unsigned int nbObstacles) ;
pitiot's avatar
maj    
pitiot committed
96
97
98
	void setupCityScenario(int nbLines, int nbRank) ;
	void setupScenario(unsigned int nbMaxAgent) ;

David Cazier's avatar
David Cazier committed
99
	void addAgent(const VEC3& start,const std::vector<VEC3>& goals);
pitiot's avatar
maj    
pitiot committed
100
	
Pierre Kraemer's avatar
Pierre Kraemer committed
101
#ifndef SPATIAL_HASHING
pitiot's avatar
pitiot committed
102
	void addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal);
103
104
105
	void addPathToCorner() ;
	void addPathsToAgents() ;
	void addPathsToAgents_height() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
107

108
109
110
111
112
113
114
115
116
	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
117
	std::vector<MovingObstacle*> movingObstacles_;
pitiot's avatar
pitiot committed
118
	int minSize;
119
120
121
122
123
124
125
126
127
128
129
130
	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
131
132
	int avoidance;
	int nb_dead;
133
	bool multires;
134
	bool detect_agent_collision;
135
136
137
138
	ThreadUpdateInfo* tc1 ;
	ThreadUpdateInfo* tc2 ;
	ThreadUpdateInfo* tc3 ;
	ThreadUpdateInfo* tc4 ;
pitiot's avatar
maj    
pitiot committed
139
};
Pierre Kraemer's avatar
Pierre Kraemer committed
140
141

#endif