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
string str_greedy = xmltoa(e->Attribute("greedy"), "false");
double time = xmltof(e->Attribute("time"), 0);
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;
if (agent_id >= 0){
agents_max = 1;
......@@ -179,7 +181,7 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
}
auto source = std::shared_ptr<AgentsSource>(
new AgentsSource(id, caption, agents_max, group_id,
frequency, greedy, time, agent_id));
frequency, greedy, time, agent_id, startx, starty));
startDisSources.push_back(source);
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
Log->Write("INFO: \t...Done");
return true;
}
......@@ -30,8 +30,9 @@
#include "AgentsSource.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):
_id(id), _frequency(frequency), _maxAgents(max_agents), _groupID(group_id), _caption(caption), _greedy(greedy), _agent_id(agent_id), _time(time)
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), _startx(startx), _starty(starty)
{
_agentsGenerated=0;
_boundaries[0] = 0;
......@@ -145,6 +146,18 @@ int AgentsSource::GetMaxAgents() const
return _maxAgents;
}
float AgentsSource::GetStartX() const
{
return _startx;
}
float AgentsSource::GetStartY() const
{
return _starty;
}
void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution)
{
_startDistribution=startDistribution;
......
......@@ -49,7 +49,7 @@ public:
/**
* 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
......@@ -111,6 +111,8 @@ public:
int GetGroupId() const;
int GetId() const;
int GetAgentId() const;
float GetStartX() const;
float GetStartY() const;
double GetPlanTime() const;
int GetMaxAgents() const;
bool Greedy() const;
......@@ -129,10 +131,11 @@ private:
double _boundaries[4];// = { 0, 0, 0, 0 };
int _agent_id;
double _time;
float _startx;
float _starty;
std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution;
};
#endif /* AGENTSOURCE_H_ */
......@@ -122,12 +122,17 @@ bool AgentsSourcesManager::ProcessAllSources() const
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());
printf("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("\nINFO:\tSource %d generating %lu agents (%d remaining)\n",src->GetId(), peds.size(),src->GetPoolSize());
//ComputeBestPositionRandom(src.get(), peds);
//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) )
Log->Write("WARNING:\tThere was no place for some pedestrians");
......@@ -158,27 +163,26 @@ bool AgentsSourcesManager::ProcessAllSources() const
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)
{
Point v = (ped->GetExitLine()->ShortestPoint(ped->GetPos())- ped->GetPos()).Normalized();
double speed=ped->GetV0Norm();
Point v;
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;
ped->SetV(v);
ped->SetPos( Point(src->GetStartX(), src->GetStartY()) );
}
}
}
void AgentsSourcesManager::ComputeBestPositionCompleteRandom(AgentsSource* src,
vector<Pedestrian*>& peds)const
......
......@@ -137,7 +137,7 @@ private:
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
......
......@@ -142,6 +142,7 @@ bool PedDistributor::Distribute(Building *building) const {
}
}// check if directory
}//if we have a directoy
//------------------------------------- pack in function ------------
else{
......@@ -462,10 +463,11 @@ const vector<Point> PedDistributor::GetPositionsFromFile(std::string filename,
if(first_ids.size() != (unsigned)n){
Log->Write("ERROR: \tGetPositionsFromFile: number of peds <%d> does not match number of peds from file <%d>",
n, first_ids.size());
positions.clear();
}
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;
}
......@@ -608,7 +610,3 @@ void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions,
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