simulator.h 2.49 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"
pitiot's avatar
pitiot 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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class ThreadUpdateInfo
{
public :
	std::vector<Agent*> ag_;
	unsigned int bMin_;
	unsigned int bMax_;

	// Constructor
	ThreadUpdateInfo(std::vector<Agent*> agents, unsigned int bMin, unsigned int bMax) :
		bMin_(bMin),
		bMax_(bMax)
	{
		ag_.insert(ag_.end(), agents.begin() + bMin, agents.begin() + bMax);
	}

	// Destructor
	~ThreadUpdateInfo() { }

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

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class ThreadUpdatePos
{
public :
	std::vector<Agent*> ag_;
	unsigned int bMin_;
	unsigned int bMax_;

	// Constructor
	ThreadUpdatePos(std::vector<Agent*> agents,unsigned int bMin,unsigned int bMax) :
		bMin_(bMin),
		bMax_(bMax)
	{
		ag_.insert(ag_.end(),agents.begin()+bMin,agents.begin()+bMax);
	}

	// Destructor
	~ThreadUpdatePos() { }

	void run() {
	    // Thread execution stuff goes here
		for (unsigned int i = 0; i < ag_.size(); ++i)
		{
			ag_[i]->update();
		}
	}
};

Pierre Kraemer's avatar
Pierre Kraemer committed
75
76
77
78
79
80
81
82
83
84
85
86
87
class Simulator
{
public:
	Simulator();
	
	Simulator(
		float timeStep, float neighborDist, unsigned int maxNeighbors,
		float timeHorizon, float timeHorizonObst, float radius,
		float maxSpeed, const VEC3& velocity = VEC3(0)
	);
	
	~Simulator();
	
Thomas's avatar
Thomas committed
88
89
	void init(unsigned int config, float dimension, bool enablePathFinding=false);

Pierre Kraemer's avatar
Pierre Kraemer committed
90
91
	void doStep();
	
Thomas's avatar
Thomas committed
92
93
94
95
	bool reachedGoal();

	void setupCircleScenario(unsigned int nbMaxAgent);
	void setupCityScenario(float startX, float startY, int nbLines , int nbRank);
96
	void setupScenario(unsigned int nbMaxAgent);
97
98
99

	void setupMovingObstacle(unsigned int nbObstacles);

Pierre Kraemer's avatar
Pierre Kraemer committed
100
#ifndef SPATIAL_HASHING
101
	void addPathToCorner();
102
	void addPathsToAgents();
Thomas's avatar
Thomas committed
103
	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
	
	bool importAgents(std::string filename);
	bool exportAgents(std::string filename);
	
	void swapAgentsGoals();
	
Thomas's avatar
Thomas committed
111
112
	Geom::BoundingBox<VEC3> getAgentsBB();

Pierre Kraemer's avatar
Pierre Kraemer committed
113
114
	EnvMap envMap_;
	std::vector<Agent*> agents_;
pitiot's avatar
pitiot committed
115
	std::vector<MovingObstacle*> movingObstacles_;
Pierre Kraemer's avatar
Pierre Kraemer committed
116

Pierre Kraemer's avatar
Pierre Kraemer committed
117
	float timeStep_;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
120
	float globalTime_;
	unsigned int nbSteps_;
	unsigned int nbStepsPerUnit_;
pitiot's avatar
pitiot committed
121
122
	int avoidance;
	int nb_dead;
123
124
125
126
	ThreadUpdateInfo* tc1;
	ThreadUpdateInfo* tc2;
	ThreadUpdateInfo* tc3;
	ThreadUpdateInfo* tc4;
Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
129
};

#endif