simulator.h 2.09 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef SIMULATOR_H
#define SIMULATOR_H

#include <limits>

#include "env_map.h"
#include "agent.h"
#include "path_finder.h"

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

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)
		{
			ag_[i]->updateObstacleNeighbors();
			ag_[i]->updateAgentNeighbors();
			ag_[i]->computePrefVelocity();
			ag_[i]->computeNewVelocity();
		}
	}
};

46
47
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
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
73
74
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();
	
	void doStep();
	
Thomas's avatar
Thomas committed
88
89
90
91
	bool reachedGoal();

	void setupCircleScenario(unsigned int nbMaxAgent);
	void setupCityScenario(float startX, float startY, int nbLines , int nbRank);
92
	void setupScenario(unsigned int nbMaxAgent);
93
	void addPathsToAgents();
Pierre Kraemer's avatar
Pierre Kraemer committed
94
95
96
97
98
99
	
	bool importAgents(std::string filename);
	bool exportAgents(std::string filename);
	
	void swapAgentsGoals();
	
Thomas's avatar
Thomas committed
100
101
	Geom::BoundingBox<VEC3> getAgentsBB();

Pierre Kraemer's avatar
Pierre Kraemer committed
102
103
104
105
106
	EnvMap envMap_;
	std::vector<Agent*> agents_;
	
	float globalTime_;
	float timeStep_;
107
108
109
110
111

	ThreadUpdateInfo* tc1;
	ThreadUpdateInfo* tc2;
	ThreadUpdateInfo* tc3;
	ThreadUpdateInfo* tc4;
Pierre Kraemer's avatar
Pierre Kraemer committed
112
113
114
};

#endif