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)
for (unsigned int p = 0; p<_allPedestians.size(); p++) {
Pedestrian* ped1 = _allPedestians[p];
if (ped->GetID()==ped1->GetID()) {
cout << "Pedestrian already in the room ??? " << ped->GetID() << endl;
cout << "Pedestrian " << ped->GetID() << " already in the room." << endl;
return;
}
}
......@@ -1047,5 +1047,3 @@ Transition* Building::GetTransitionByUID(int uid) const
//}
#endif // _SIMULATOR
......@@ -49,7 +49,7 @@ int main(int argc, char** argv)
Configuration* configuration = new Configuration();
// Parsing the arguments
bool status = false;
{
{
//ArgumentParser* p = new ArgumentParser(configuration); //Memory Leak
std::unique_ptr<ArgumentParser> p(new ArgumentParser(configuration));
status = p->ParseArgs(argc, argv);
......
......@@ -74,29 +74,31 @@ void AgentsSourcesManager::Run()
bool finished = false;
SetBuildingUpdated(false);
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
{
int current_time = (int)Pedestrian::GetGlobalTime();
if ((current_time != _lastUpdateTime)
&& ((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 queue is empty. Otherwise, wait for main thread to empty it and update _building
{
finished=ProcessAllSources();
_lastUpdateTime = current_time;
SetBuildingUpdated(false);
//SetBuildingUpdated(false);
}
}
// wait for main thread to update building
if(current_time >= GetMaxSimTime())
Please register or sign in to reply
break; // break if max simulation time is reached.
} 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");
_isCompleted = true;
}
bool AgentsSourcesManager::ProcessAllSources() const
......@@ -105,27 +107,33 @@ bool AgentsSourcesManager::ProcessAllSources() const
bool empty=true;
double current_time = Pedestrian::GetGlobalTime();
for(auto pp: _building->GetAllPedestrians())
std::cout<< KMAG << "BUL: SOURCE: " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n"<< RESET;
vector<Pedestrian*> source_peds; // we have to collect peds from all sources, so that we can consider them while computing new positions
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
{
vector<Pedestrian*> peds;
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());
//ComputeBestPositionRandom(src.get(), peds);
//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");
std::cout << KRED << ">> Add to queue " << peds.size() << "\n" << RESET;
for( auto pp: peds)
std::cout << "pos " << pp->GetPos()._x << ", " << pp->GetPos()._y << "\n";
source_peds.insert(source_peds.end(), peds.begin(), peds.end());
/* std::cout << KRED << ">> Add to queue " << peds.size() << "\n" << RESET; */
/* 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);
empty = false;
//src->Dump();
......@@ -135,13 +143,13 @@ bool AgentsSourcesManager::ProcessAllSources() const
empty = false;
//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;
// for(auto pp: _building->GetAllPedestrians())
// std::cout<< KBLU << "BUL: agentssourcesManager: " << pp->GetPos()._x << ", " << pp->GetPos()._y << RESET << std::endl;
//
std::cout << "========================\n";
/* std::cout << "========================\n"; */
return empty;
}
......@@ -149,7 +157,6 @@ std::cout << "========================\n";
void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src,
vector<Pedestrian*>& peds)const
{
UNUSED(src);
peds[0]->SetPos( Point(10,5.5) );
peds[1]->SetPos( Point(10,4.9) );
peds[2]->SetPos( Point(10,4.3) );
......
......@@ -85,7 +85,7 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius )
}
bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds,
Building* building)
Building* building, std::vector<Pedestrian*>& peds_queue)
{
bool return_value = true;
auto dist = src->GetStartDistribution();
......@@ -96,6 +96,8 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
std::vector<Pedestrian*> existing_peds;
std::vector<Pedestrian*> peds_without_place;
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
SubRoom* subroom = building->GetRoom( roomID )->GetSubRoom(subroomID);
......
......@@ -30,67 +30,67 @@ class Point;
// 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)
* @param subroom
* @param pt
*/
bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius );
/**
* Position incoming pedestrian using voronoi from boost library
* @param src
* @param peds
*/
bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds, Building* _building);
/**
* 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 vd
* @param subroom
* @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 radius, 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 pt
*/
bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius );
/**
* Position incoming pedestrian using voronoi from boost library
* @param src
* @param peds
*/
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
* @param discrete_positions, positions of existing pedestrians + fake pedestrians (but multiplied with the factor)
* @param vd
* @param subroom
* @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 radius, radius of a person
*/
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,
double radius);
/**
* Position incoming pedestrian on the vertex with greater probability for greater distances
* @param discrete_positions
* @param vd
* @param subroom
* @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 radius, radius of a person
*/
void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor,
/**
* Position incoming pedestrian on the vertex with greater probability for greater distances
* @param discrete_positions
* @param vd
* @param subroom
* @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 radius, radius of a person
*/
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);
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);
void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_diagram<double>& vd, SubRoom* subroom, double factor);
/**
* Position incoming pedestrian on a random vertex
* @param discrete_positions
* @param vd
* @param subroom
* @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 radius, radius of a person
*/
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 );
/**
* Gives a person the mean velocity of his voronoi-neighbours
* @param vd
* @param chosen_it
* @param velocities_vector
*/
/**
* Position incoming pedestrian on a random vertex
* @param discrete_positions
* @param vd
* @param subroom
* @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 radius, radius of a person
*/
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 );
/**
* Gives a person the mean velocity of his voronoi-neighbours
* @param vd
* @param chosen_it
* @param velocities_vector
*/
void VoronoiAdjustVelocityNeighbour(voronoi_diagram<double>::const_vertex_iterator& chosen_it, Pedestrian* ped,
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