Commit 6766950e authored by Mohcine Chraibi's avatar Mohcine Chraibi

🆕 Distribute source agents on a fixed position

parent 55fbde57
Pipeline #12992 passed with stages
in 6 minutes and 11 seconds
...@@ -172,6 +172,8 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist ...@@ -172,6 +172,8 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
string str_greedy = xmltoa(e->Attribute("greedy"), "false"); string str_greedy = xmltoa(e->Attribute("greedy"), "false");
double time = xmltof(e->Attribute("time"), 0); double time = xmltof(e->Attribute("time"), 0);
int agent_id = xmltoi(e->Attribute("agent_id"), -1); int agent_id = xmltoi(e->Attribute("agent_id"), -1);
float startx = xmltof(e->Attribute("startX"), std::numeric_limits<float>::quiet_NaN());
float starty = xmltof(e->Attribute("startY"), std::numeric_limits<float>::quiet_NaN());
bool greedy = (str_greedy == "true")?true:false; bool greedy = (str_greedy == "true")?true:false;
if (agent_id >= 0){ if (agent_id >= 0){
agents_max = 1; agents_max = 1;
...@@ -179,7 +181,7 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist ...@@ -179,7 +181,7 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
} }
auto source = std::shared_ptr<AgentsSource>( auto source = std::shared_ptr<AgentsSource>(
new AgentsSource(id, caption, agents_max, group_id, new AgentsSource(id, caption, agents_max, group_id,
frequency, greedy, time, agent_id)); frequency, greedy, time, agent_id, startx, starty));
startDisSources.push_back(source); startDisSources.push_back(source);
Log->Write("INFO:\tSource with id %d will be parsed (greedy = %d)!", id, greedy); Log->Write("INFO:\tSource with id %d will be parsed (greedy = %d)!", id, greedy);
...@@ -188,9 +190,3 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist ...@@ -188,9 +190,3 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
Log->Write("INFO: \t...Done"); Log->Write("INFO: \t...Done");
return true; return true;
} }
...@@ -30,8 +30,9 @@ ...@@ -30,8 +30,9 @@
#include "AgentsSource.h" #include "AgentsSource.h"
#include "Pedestrian.h" #include "Pedestrian.h"
AgentsSource::AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy, double time, int agent_id): AgentsSource::AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy, double time, int agent_id, float startx, float starty):
_id(id), _frequency(frequency), _maxAgents(max_agents), _groupID(group_id), _caption(caption), _greedy(greedy), _agent_id(agent_id), _time(time) _id(id), _frequency(frequency), _maxAgents(max_agents), _groupID(group_id), _caption(caption), _greedy(greedy), _agent_id(agent_id), _time(time), _startx(startx), _starty(starty)
{ {
_agentsGenerated=0; _agentsGenerated=0;
_boundaries[0] = 0; _boundaries[0] = 0;
...@@ -145,6 +146,18 @@ int AgentsSource::GetMaxAgents() const ...@@ -145,6 +146,18 @@ int AgentsSource::GetMaxAgents() const
return _maxAgents; return _maxAgents;
} }
float AgentsSource::GetStartX() const
{
return _startx;
}
float AgentsSource::GetStartY() const
{
return _starty;
}
void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution) void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution)
{ {
_startDistribution=startDistribution; _startDistribution=startDistribution;
......
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
/** /**
* Constructor * Constructor
*/ */
AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy, double time, int agent_id); AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy, double time, int agent_id, float startx, float starty);
/** /**
* Destructor * Destructor
...@@ -111,6 +111,8 @@ public: ...@@ -111,6 +111,8 @@ public:
int GetGroupId() const; int GetGroupId() const;
int GetId() const; int GetId() const;
int GetAgentId() const; int GetAgentId() const;
float GetStartX() const;
float GetStartY() const;
double GetPlanTime() const; double GetPlanTime() const;
int GetMaxAgents() const; int GetMaxAgents() const;
bool Greedy() const; bool Greedy() const;
...@@ -129,10 +131,11 @@ private: ...@@ -129,10 +131,11 @@ private:
double _boundaries[4];// = { 0, 0, 0, 0 }; double _boundaries[4];// = { 0, 0, 0, 0 };
int _agent_id; int _agent_id;
double _time; double _time;
float _startx;
float _starty;
std::vector<Pedestrian*> _agents; std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution; std::shared_ptr<StartDistribution> _startDistribution;
}; };
#endif /* AGENTSOURCE_H_ */ #endif /* AGENTSOURCE_H_ */
...@@ -122,12 +122,17 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -122,12 +122,17 @@ bool AgentsSourcesManager::ProcessAllSources() const
src->RemoveAgentsFromPool(peds, src->GetFrequency()); src->RemoveAgentsFromPool(peds, src->GetFrequency());
source_peds.reserve(source_peds.size() + peds.size()); 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("\nINFO:\tSource %d generating %d agents (%d remaining)\n",src->GetId(),peds.size(),src->GetPoolSize());
printf("INFO:\tSource %d generating %d agents (%d remaining)\n",src->GetId(), peds.size(),src->GetPoolSize()); printf("\nINFO:\tSource %d generating %lu 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(!std::isnan(src->GetStartX()) && !std::isnan(src->GetStartY()))
{
printf("INFO:\tSet source agent on fixed position (%.2f, %.2f)", src->GetStartX(), src->GetStartY());
InitFixedPosition(src.get(), peds);
}
else
if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building, source_peds) ) 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");
...@@ -158,27 +163,26 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -158,27 +163,26 @@ bool AgentsSourcesManager::ProcessAllSources() const
return empty; return empty;
} }
//4 agents frequency, just for an example
void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src,
vector<Pedestrian*>& peds)const
{
peds[0]->SetPos( Point(10,5.5) );
peds[1]->SetPos( Point(10,4.9) );
peds[2]->SetPos( Point(10,4.3) );
peds[3]->SetPos( Point(10,3.7) );
/*peds[0]->SetPos( Point(10,5.4) );
peds[1]->SetPos( Point(10,4.6) );
peds[2]->SetPos( Point(10,3.8) );*/
void AgentsSourcesManager::InitFixedPosition(AgentsSource* src,
vector<Pedestrian*>& peds)const
{
for(auto&& ped : peds) for(auto&& ped : peds)
{ {
Point v = (ped->GetExitLine()->ShortestPoint(ped->GetPos())- ped->GetPos()).Normalized(); Point v;
double speed=ped->GetV0Norm(); if (ped->GetExitLine()) {
v = (ped->GetExitLine()->ShortestPoint(ped->GetPos())- ped->GetPos()).Normalized();
} else {
const NavLine L = Line(Point(0, 0), Point(1,1));
ped->SetExitLine(&L); // set dummy line
v = Point(0., 0.);
}
double speed=ped->GetEllipse().GetV0();
v=v*speed; v=v*speed;
ped->SetV(v); ped->SetV(v);
ped->SetPos( Point(src->GetStartX(), src->GetStartY()) );
} }
} }
void AgentsSourcesManager::ComputeBestPositionCompleteRandom(AgentsSource* src, void AgentsSourcesManager::ComputeBestPositionCompleteRandom(AgentsSource* src,
vector<Pedestrian*>& peds)const vector<Pedestrian*>& peds)const
......
...@@ -137,7 +137,7 @@ private: ...@@ -137,7 +137,7 @@ private:
void ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent) const; void ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent) const;
void ComputeBestPositionDummy(AgentsSource* src, std::vector<Pedestrian*>& peds) const; void InitFixedPosition(AgentsSource* src, std::vector<Pedestrian*>& peds) const;
/** /**
* Position incoming pedestrians completely random * Position incoming pedestrians completely random
......
...@@ -142,6 +142,7 @@ bool PedDistributor::Distribute(Building *building) const { ...@@ -142,6 +142,7 @@ bool PedDistributor::Distribute(Building *building) const {
} }
}// check if directory }// check if directory
}//if we have a directoy }//if we have a directoy
//------------------------------------- pack in function ------------ //------------------------------------- pack in function ------------
else{ else{
...@@ -462,10 +463,11 @@ const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename, ...@@ -462,10 +463,11 @@ const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename,
if(first_ids.size() != (unsigned)n){ if(first_ids.size() != (unsigned)n){
Log->Write("ERROR: \tGetPositionsFromFile: number of peds <%d> does not match number of peds from file <%d>", Log->Write("ERROR: \tGetPositionsFromFile: number of peds <%d> does not match number of peds from file <%d>",
n, first_ids.size()); n, first_ids.size());
positions.clear(); positions.clear();
} }
else else
Log->Write("ERROR: \tGetPositionsFromFile: number of peds <%d> in file. To simulate <%d>", first_ids.size(), n); Log->Write("INFO: \tGetPositionsFromFile: number of peds <%d> in file. To simulate <%d>", first_ids.size(), n);
return positions; return positions;
} }
...@@ -608,7 +610,3 @@ void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions, ...@@ -608,7 +610,3 @@ void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions,
building->AddPedestrian(ped); building->AddPedestrian(ped);
} }
} }
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