Commit 5c81985b authored by Mohcine Chraibi's avatar Mohcine Chraibi

Seems to fix the issue of duplicate agents

parent 2e7c66ad
Pipeline #9201 failed with stages
in 5 minutes and 29 seconds
...@@ -841,7 +841,7 @@ void Building::AddPedestrian(Pedestrian* ped) ...@@ -841,7 +841,7 @@ void Building::AddPedestrian(Pedestrian* ped)
for (unsigned int p = 0; p<_allPedestians.size(); p++) { for (unsigned int p = 0; p<_allPedestians.size(); p++) {
Pedestrian* ped1 = _allPedestians[p]; Pedestrian* ped1 = _allPedestians[p];
if (ped->GetID()==ped1->GetID()) { if (ped->GetID()==ped1->GetID()) {
cout << "Pedestrian already in the room ??? " << ped->GetID() << endl; cout << "Pedestrian " << ped->GetID() << " already in the room." << endl;
return; return;
} }
} }
...@@ -1047,5 +1047,3 @@ Transition* Building::GetTransitionByUID(int uid) const ...@@ -1047,5 +1047,3 @@ Transition* Building::GetTransitionByUID(int uid) const
//} //}
#endif // _SIMULATOR #endif // _SIMULATOR
...@@ -49,7 +49,7 @@ int main(int argc, char** argv) ...@@ -49,7 +49,7 @@ int main(int argc, char** argv)
Configuration* configuration = new Configuration(); Configuration* configuration = new Configuration();
// Parsing the arguments // Parsing the arguments
bool status = false; bool status = false;
{ {
//ArgumentParser* p = new ArgumentParser(configuration); //Memory Leak //ArgumentParser* p = new ArgumentParser(configuration); //Memory Leak
std::unique_ptr<ArgumentParser> p(new ArgumentParser(configuration)); std::unique_ptr<ArgumentParser> p(new ArgumentParser(configuration));
status = p->ParseArgs(argc, argv); status = p->ParseArgs(argc, argv);
......
...@@ -74,29 +74,31 @@ void AgentsSourcesManager::Run() ...@@ -74,29 +74,31 @@ void AgentsSourcesManager::Run()
bool finished = false; bool finished = false;
SetBuildingUpdated(false); SetBuildingUpdated(false);
long updateFrequency = 1; //TODO parse this from inifile long updateFrequency = 1; //TODO parse this from inifile
std::cout << KMAG << "RUN Starting thread manager with _lastUpdateTime " << _lastUpdateTime<< std::endl; /* std::cout << KMAG << "RUN Starting thread manager with _lastUpdateTime " << _lastUpdateTime<< std::endl; */
do do
{ {
int current_time = (int)Pedestrian::GetGlobalTime(); int current_time = (int)Pedestrian::GetGlobalTime();
if ((current_time != _lastUpdateTime) if ((current_time != _lastUpdateTime)
&& ((current_time % updateFrequency) == 0)) && ((current_time % updateFrequency) == 0))
{ {
std::cout << ">> RUN: current_time " << current_time << " last update " << _lastUpdateTime << std::endl; /* std::cout << ">> RUN: current_time " << current_time << " last update " << _lastUpdateTime << std::endl; */
if(AgentsQueueIn::IsEmpty()) if(AgentsQueueIn::IsEmpty())
//if queue is empty. Otherwise, wait for main thread to empty it and update _building //if queue is empty. Otherwise, wait for main thread to empty it and update _building
{ {
finished=ProcessAllSources(); finished=ProcessAllSources();
_lastUpdateTime = current_time; _lastUpdateTime = current_time;
SetBuildingUpdated(false); //SetBuildingUpdated(false);
} }
} }
// wait for main thread to update building // wait for main thread to update building
if(current_time >= GetMaxSimTime()) if(current_time >= GetMaxSimTime())
Please register or sign in to reply
break; // break if max simulation time is reached. break; // break if max simulation time is reached.
} while (!finished); } while (!finished);
std::cout << "Terminating agent manager thread" << RESET << std::endl; std::cout << ">> Terminating agent manager thread" << RESET << std::endl;
Log->Write("INFO:\tTerminating agent manager thread"); Log->Write("INFO:\tTerminating agent manager thread");
_isCompleted = true; _isCompleted = true;
} }
bool AgentsSourcesManager::ProcessAllSources() const bool AgentsSourcesManager::ProcessAllSources() const
...@@ -105,27 +107,33 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -105,27 +107,33 @@ bool AgentsSourcesManager::ProcessAllSources() const
bool empty=true; bool empty=true;
double current_time = Pedestrian::GetGlobalTime(); double current_time = Pedestrian::GetGlobalTime();
for(auto pp: _building->GetAllPedestrians()) vector<Pedestrian*> source_peds; // we have to collect peds from all sources, so that we can consider them while computing new positions
std::cout<< KMAG << "BUL: SOURCE: " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n"<< RESET;
for (const auto& src : _sources) for (const auto& src : _sources)
{ {
std::cout << KRED << "\nprocessing src: " << src->GetId() << " -- current time: " << current_time << " number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET; /* std::cout << KRED << "\nprocessing src: " << src->GetId() << " -- current time: " << current_time << " schedule: " << src->GetPlanTime() <<". number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET; */
if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps
{ {
vector<Pedestrian*> peds; vector<Pedestrian*> peds;
src->RemoveAgentsFromPool(peds, src->GetFrequency()); src->RemoveAgentsFromPool(peds, src->GetFrequency());
source_peds.reserve(source_peds.size() + peds.size());
Log->Write("> INFO:\tSource %d generating %d agents (%d remaining)\n",src->GetId(),peds.size(),src->GetPoolSize()); Log->Write("> INFO:\tSource %d generating %d agents (%d remaining)\n",src->GetId(),peds.size(),src->GetPoolSize());
//ComputeBestPositionRandom(src.get(), peds); //ComputeBestPositionRandom(src.get(), peds);
//todo: here every pedestrian needs an exitline //todo: here every pedestrian needs an exitline
if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building) )
if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building, source_peds) )
Log->Write("WARNING:\tThere was no place for some pedestrians"); Log->Write("WARNING:\tThere was no place for some pedestrians");
std::cout << KRED << ">> Add to queue " << peds.size() << "\n" << RESET; source_peds.insert(source_peds.end(), peds.begin(), peds.end());
for( auto pp: peds) /* std::cout << KRED << ">> Add to queue " << peds.size() << "\n" << RESET; */
std::cout << "pos " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n"; /* for( auto pp: peds) */
/* std::cout << "id: "<< pp->GetID() << " pos " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n"; */
/* std::cout << "------\n"; */
/* for( auto pp: source_peds) */
/* std::cout << "id: "<< pp->GetID() << " POS " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n"; */
AgentsQueueIn::Add(peds); AgentsQueueIn::Add(peds);
empty = false; empty = false;
//src->Dump(); //src->Dump();
...@@ -135,13 +143,13 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -135,13 +143,13 @@ bool AgentsSourcesManager::ProcessAllSources() const
empty = false; empty = false;
//src->Dump();//exit(0); //src->Dump();//exit(0);
} }
std::cout << "LEAVE AgentsSourcesManager::ProcessAllSources()\n"; /* std::cout << "LEAVE AgentsSourcesManager::ProcessAllSources()\n"; */
// std::cout << " Source building: "<< _building << " size " << _building->GetAllPedestrians().size()<< std::endl; // std::cout << " Source building: "<< _building << " size " << _building->GetAllPedestrians().size()<< std::endl;
// for(auto pp: _building->GetAllPedestrians()) // for(auto pp: _building->GetAllPedestrians())
// std::cout<< KBLU << "BUL: agentssourcesManager: " << pp->GetPos()._x << ", " << pp->GetPos()._y << RESET << std::endl; // std::cout<< KBLU << "BUL: agentssourcesManager: " << pp->GetPos()._x << ", " << pp->GetPos()._y << RESET << std::endl;
// //
std::cout << "========================\n"; /* std::cout << "========================\n"; */
return empty; return empty;
} }
...@@ -149,7 +157,6 @@ std::cout << "========================\n"; ...@@ -149,7 +157,6 @@ std::cout << "========================\n";
void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src, void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src,
vector<Pedestrian*>& peds)const vector<Pedestrian*>& peds)const
{ {
UNUSED(src);
peds[0]->SetPos( Point(10,5.5) ); peds[0]->SetPos( Point(10,5.5) );
peds[1]->SetPos( Point(10,4.9) ); peds[1]->SetPos( Point(10,4.9) );
peds[2]->SetPos( Point(10,4.3) ); peds[2]->SetPos( Point(10,4.3) );
......
...@@ -85,7 +85,7 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius ) ...@@ -85,7 +85,7 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius )
} }
bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds, bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds,
Building* building) Building* building, std::vector<Pedestrian*>& peds_queue)
{ {
bool return_value = true; bool return_value = true;
auto dist = src->GetStartDistribution(); auto dist = src->GetStartDistribution();
...@@ -96,6 +96,8 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*> ...@@ -96,6 +96,8 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
std::vector<Pedestrian*> existing_peds; std::vector<Pedestrian*> existing_peds;
std::vector<Pedestrian*> peds_without_place; std::vector<Pedestrian*> peds_without_place;
building->GetPedestrians(roomID, subroomID, existing_peds); building->GetPedestrians(roomID, subroomID, existing_peds);
existing_peds.insert(existing_peds.end(), peds_queue.begin(), peds_queue.end());
double radius = 0.3; //radius of a person, 0.3 is just some number(needed for the fake_peds bellow), will be changed afterwards double radius = 0.3; //radius of a person, 0.3 is just some number(needed for the fake_peds bellow), will be changed afterwards
SubRoom* subroom = building->GetRoom( roomID )->GetSubRoom(subroomID); SubRoom* subroom = building->GetRoom( roomID )->GetSubRoom(subroomID);
......
...@@ -30,67 +30,67 @@ class Point; ...@@ -30,67 +30,67 @@ class Point;
// TODO: bool IsSpace(SubRoom* subroom, Point& pt,Point& v1); // TODO: bool IsSpace(SubRoom* subroom, Point& pt,Point& v1);
/** /**
* Calculates if a point (which is inside the subroom) is far enough from the walls, transitions, crossings ( > radius of a person) * Calculates if a point (which is inside the subroom) is far enough from the walls, transitions, crossings ( > radius of a person)
* @param subroom * @param subroom
* @param pt * @param pt
*/ */
bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius ); bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius );
/** /**
* Position incoming pedestrian using voronoi from boost library * Position incoming pedestrian using voronoi from boost library
* @param src * @param src
* @param peds * @param peds
*/ */
bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds, Building* _building); bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds, Building* _building, std::vector<Pedestrian*>& peds_queue);
/** /**
* Position incoming pedestrian on the vertex with the greatest distance * Position incoming pedestrian on the vertex with the greatest distance
* @param discrete_positions, positions of existing pedestrians + fake pedestrians (but multiplied with the factor) * @param discrete_positions, positions of existing pedestrians + fake pedestrians (but multiplied with the factor)
* @param vd * @param vd
* @param subroom * @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex * @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex * @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person * @param radius, radius of a person
*/ */
void VoronoiBestVertexMax(const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, void VoronoiBestVertexMax(const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd,
SubRoom* subroom, double factor, voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, SubRoom* subroom, double factor, voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis,
double radius); double radius);
/** /**
* Position incoming pedestrian on the vertex with greater probability for greater distances * Position incoming pedestrian on the vertex with greater probability for greater distances
* @param discrete_positions * @param discrete_positions
* @param vd * @param vd
* @param subroom * @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex * @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex * @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person * @param radius, radius of a person
*/ */
void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor, void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor,
voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius); voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius);
void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor, void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor,
voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius); voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius);
void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor); void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor);
/** /**
* Position incoming pedestrian on a random vertex * Position incoming pedestrian on a random vertex
* @param discrete_positions * @param discrete_positions
* @param vd * @param vd
* @param subroom * @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex * @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex * @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person * @param radius, radius of a person
*/ */
void VoronoiBestVertexRand (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor, void VoronoiBestVertexRand (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor,
voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius ); voronoi_diagram<double>::const_vertex_iterator& max_it, double& max_dis, double radius );
/** /**
* Gives a person the mean velocity of his voronoi-neighbours * Gives a person the mean velocity of his voronoi-neighbours
* @param vd * @param vd
* @param chosen_it * @param chosen_it
* @param velocities_vector * @param velocities_vector
*/ */
void VoronoiAdjustVelocityNeighbour(voronoi_diagram<double>::const_vertex_iterator& chosen_it, Pedestrian* ped, void VoronoiAdjustVelocityNeighbour(voronoi_diagram<double>::const_vertex_iterator& chosen_it, Pedestrian* ped,
const std::vector<Point>& velocities_vector, const std::vector<int>& goal_vector); const std::vector<Point>& velocities_vector, const std::vector<int>& goal_vector);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment