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
......@@ -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);
......
......@@ -42,7 +42,7 @@ class Point;
* @param src
* @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);
/**
......
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