Commit 85977972 authored by Mohcine Chraibi's avatar Mohcine Chraibi

Resolve "Sources"

parent 2ee17177
......@@ -89,6 +89,13 @@ void IODispatcher::WriteFooter()
it->WriteFooter();
}
}
void IODispatcher::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
for(auto const it : _outputHandlers)
{
it->WriteSources(sources);
}
}
string TrajectoriesJPSV04::WritePed(Pedestrian* ped)
......@@ -363,7 +370,22 @@ void TrajectoriesFLAT::WriteFooter()
{
}
void TrajectoriesFLAT::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
}
void TrajectoriesVTK::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
}
void TrajectoriesJPSV06::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
}
void TrajectoriesXML_MESH::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
}
/**
* VTK Implementation of the geometry and trajectories
......@@ -620,7 +642,21 @@ void TrajectoriesJPSV05::WriteHeader(long nPeds, double fps, Building* building,
tmp.append("\t</header>\n");
_outputHandler->Write(tmp);
}
void TrajectoriesJPSV05::WriteSources(const std::vector<std::shared_ptr<AgentsSource> > sources)
{
std::string tmp("");
for (const auto& src: sources) {
auto BB = src->GetBoundaries();
tmp += "<source id=\"" + std::to_string(src->GetId()) +
"\" caption=\"" + src->GetCaption() + "\"" +
" x_min=\"" + to_string(BB[0]) + "\"" +
" x_max=\"" + to_string(BB[1]) + "\"" +
" y_min=\"" + to_string(BB[2]) + "\"" +
" y_max=\"" + to_string(BB[3]) + "\" />\n";
}
_outputHandler->Write(tmp);
}
void TrajectoriesJPSV05::WriteGeometry(Building* building)
{
// just put a link to the geometry file
......@@ -645,7 +681,9 @@ void TrajectoriesJPSV05::WriteGeometry(Building* building)
embed_geometry.append("\t</geometry>\n");
_outputHandler->Write(embed_geometry);
//write sources
// if(building->G )
//
_outputHandler->Write("\t<AttributeDescription>");
_outputHandler->Write("\t\t<property tag=\"x\" description=\"xPosition\"/>");
_outputHandler->Write("\t\t<property tag=\"y\" description=\"yPosition\"/>");
......@@ -695,4 +733,3 @@ void TrajectoriesJPSV05::WriteFooter()
{
_outputHandler->Write("</trajectories>\n");
}
......@@ -38,6 +38,8 @@ extern OutputHandler* Log;
class Trajectories;
class AgentsSource;
class IODispatcher
{
private:
......@@ -53,6 +55,8 @@ public:
void WriteGeometry(Building* building);
void WriteFrame(int frameNr, Building* building);
void WriteFooter();
void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
class Trajectories
......@@ -67,6 +71,7 @@ public:
virtual void WriteGeometry(Building* building)=0;
virtual void WriteFrame(int frameNr, Building* building)=0;
virtual void WriteFooter()=0;
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >)=0;
void Write(const std::string& str)
{
......@@ -120,6 +125,7 @@ public:
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
......@@ -137,6 +143,7 @@ public:
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
......@@ -154,6 +161,7 @@ public:
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
......@@ -174,6 +182,7 @@ public:
//virtual void WriteFrame(int frameNr, Building* building);
//virtual void WriteFooter();
virtual void WriteGeometry(Building* building);
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
class TrajectoriesJPSV06: public Trajectories
......@@ -187,6 +196,8 @@ public:
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteSources(const std::vector<std::shared_ptr<AgentsSource> >);
};
#endif /* _IODISPATCHER_H */
......@@ -55,7 +55,7 @@ std::string ver_string(int a, int b, int c) {
std::string true_cxx =
#ifdef __clang__
"clang++";
#elif defined(__GNU__)
#elif defined(__GNUC__)
"g++";
#elif defined(__MINGW32__)
"MinGW";
......@@ -69,7 +69,7 @@ std::string true_cxx =
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__GNU__)
#elif defined(__GNUC__)
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__MINGW32__)
ver_string(__MINGW32__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
......
......@@ -170,20 +170,74 @@ bool PedDistributionParser::LoadPedDistribution(vector<std::shared_ptr<StartDist
int group_id = xmltoi(e->Attribute("group_id"), -1);
string caption = xmltoa(e->Attribute("caption"), "no caption");
string str_greedy = xmltoa(e->Attribute("greedy"), "false");
float percent = xmltof(e->Attribute("percent"), 1);
float rate = xmltof(e->Attribute("rate"), 1);
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;
float xmin = xmltof(e->Attribute("x_min"), std::numeric_limits<float>::lowest());
float xmax = xmltof(e->Attribute("x_max"), std::numeric_limits<float>::max());
float ymin = xmltof(e->Attribute("y_min"), std::numeric_limits<float>::lowest());
float ymax = xmltof(e->Attribute("y_max"), std::numeric_limits<float>::max());
float chunkAgents = xmltof(e->Attribute("N_create"), 1);
int timeMin = xmltof(e->Attribute("time_min"), std::numeric_limits<int>::min());
int timeMax = xmltof(e->Attribute("time_max"), std::numeric_limits<int>::max());
std::vector<float> boundaries = {xmin, xmax, ymin, ymax};
std::vector<int> lifeSpan = {timeMin, timeMax};
float SizeBB = 1;
bool isBigEnough = (abs(xmin-xmax) > SizeBB) && (abs(ymin-ymax) > SizeBB);
if(!isBigEnough )
{
Log->Write("Warning: Source %d got too small bounding box.\n\t BB [Dx, Dy] should be such Dx>%.2f and Dy>%.2f. Ignoring BB!!", id, SizeBB, SizeBB);
xmin = std::numeric_limits<float>::min();
xmax = std::numeric_limits<float>::max();
ymin = std::numeric_limits<float>::min();
ymax = std::numeric_limits<float>::max();
}
if(timeMin > timeMax)
{
Log->Write("Warning: Source %d given wrong life span. Assuming timeMin = timeMax.", id);
timeMin = timeMax;
}
if(time > 0)
{
timeMin = std::numeric_limits<int>::min();
timeMax = std::numeric_limits<int>::max();
Log->Write("Warning: Source %d. Planned time %d. Ignoring timeMin and timeMax (in case they are specified)", id, time);
}
if (agent_id >= 0){
agents_max = 1;
frequency = 1;
}
if(percent > 1)
{
Log->Write("Warning: Source %d. Passed erronuous percent <%.2f>. Set percent=1", id, percent);
percent = 1.0;
}
else if(percent < 0)
{
Log->Write("Warning: Source %d. Passed erronuous percent <%.2f>. Set percent=0 (this source is kinda inactive)", id, percent);
percent = 0.0;
}
auto source = std::shared_ptr<AgentsSource>(
new AgentsSource(id, caption, agents_max, group_id,
frequency, greedy, time, agent_id, startx, starty));
new AgentsSource(id,
caption,
agents_max,
group_id,
frequency,
greedy,
time,
agent_id,
startx,
starty,
percent,
rate,
chunkAgents,
boundaries,
lifeSpan));
startDisSources.push_back(source);
Log->Write("INFO:\tSource with id %d will be parsed (greedy = %d)!", id, greedy);
}
}
......
......@@ -112,7 +112,7 @@ bool Simulation::InitArgs()
case FORMAT_XML_PLAIN: {
OutputHandler* travisto = new SocketHandler(_config->GetHostname(),
_config->GetPort());
Trajectories* output = new TrajectoriesJPSV06();
Trajectories* output = new TrajectoriesJPSV05();
output->SetOutputHandler(travisto);
_iod->AddIO(output);
break;
......@@ -338,6 +338,9 @@ void Simulation::UpdateRoutesAndLocations()
}
}
// actualize routes for sources
if(_gotSources)
ped->FindRoute();
//finally actualize the route
if ( !_gotSources && ped->FindRoute() == -1) {
//a destination could not be found for that pedestrian
......@@ -419,6 +422,8 @@ void Simulation::RunHeader(long nPed)
if (nPed==-1) nPed = _nPeds;
_iod->WriteHeader(nPed, _fps, _building.get(), _seed);
_iod->WriteGeometry(_building.get());
if( _gotSources)
_iod->WriteSources( GetAgentSrcManager().GetSources());
int writeInterval = (int) ((1./_fps)/_deltaT+0.5);
writeInterval = (writeInterval<=0) ? 1 : writeInterval; // mustn't be <= 0
......
......@@ -9,7 +9,7 @@
<max_sim_time>5000</max_sim_time>
<!-- trajectories file and format -->
<trajectories format="xml-plain" fps="16" color_mode="final_goal">
<trajectories format="xml-plain" fps="16" color_mode="group">
<file location="trajectories.xml" />
<!-- <socket_ hostname="127.0.0.1" port="8989" /> -->
</trajectories>
......@@ -69,16 +69,32 @@
<!--persons information and distribution -->
<agents operational_model_id="3">
<agents_distribution>
<group group_id="0" room_id="0" subroom_id="0" number="20" router_id="1" agent_parameter_id="1" x_min="3" x_max="5" y_min="3" y_max="5" />
<group group_id="5" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" x_min="3" x_max="5" y_min="3" y_max="5" />
<group group_id="0" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
<group group_id="1" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
<group group_id="2" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
<group group_id="3" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
<group group_id="4" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
</agents_distribution>
<agents_sources><!-- frequency in persons/seconds -->
<source id="1" frequency="2" agents_max="5" group_id="0" caption="source 1" />
<source id="2" agent_id="3" time="5" group_id="0" caption="source 2" />
<source id="3" agent_id="2" time="3" group_id="0" caption="source 3" />
<source id="4" agent_id="8" time="7" group_id="0" caption="source 4" />
<source id="5" agent_id="9" time="7" group_id="0" caption="source 5" startX="8" startY="5.4" />
<source id="6" agent_id="10" time="7" group_id="0" caption="source 6" startX="13" startY="5" />
<!-- <source id="1" frequency="2" agents_max="5" group_id="0" caption="source 1" /> -->
<!-- <source id="2" agent_id="3" time="5" group_id="0" caption="source 2" /> -->
<!-- <source id="3" agent_id="2" time="3" group_id="0" caption="source 3" /> -->
<!-- <source id="4" agent_id="8" time="7" group_id="0" caption="source 4" /> -->
<!-- <source id="5" agent_id="9" time="7" group_id="0" caption="source 5" startX="8" startY="5.4" /> -->
<!-- <source id="6" agent_id="10" time="7" group_id="0" caption="source 6" startX="13" startY="5" /> -->
<source id="10" caption="new-source" time_min="5" time_max="30" frequency="5" N_create="10" agents_max="300"
group_id="0" x_min="0" x_max="3" y_min="0" y_max="3" percent="0.5" rate="2" greedy="true"/>
<source id="11" caption="new-source 2" time_min="5" time_max="30" frequency="7" N_create="10" agents_max="300"
group_id="1" x_min="6" x_max="9" y_min="6" y_max="9" percent="0.5" rate="2" greedy="true"/>
<source id="12" caption="new-source 3" time_min="5" time_max="30" frequency="9" N_create="10" agents_max="300"
group_id="2" x_min="6" x_max="9" y_min="0" y_max="3" percent="0.5" rate="2" greedy="true"/>
<source id="13" caption="new-source 4" time_min="5" time_max="30" frequency="11" N_create="10" agents_max="300"
group_id="3" x_min="0" x_max="3" y_min="6" y_max="9" percent="0.5" rate="2" greedy="true"/>
<source id="14" caption="nlow-source 5" time_min="5" time_max="30" frequency="11" N_create="10" agents_max="300"
group_id="4" x_min="3.5" x_max="5.5" y_min="3.5" y_max="5.5" percent="0.5" rate="2" greedy="true"/>
</agents_sources>
</agents>
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="boost" version="1.68.0.0" targetFramework="native" />
<package id="boost_filesystem-vc141" version="1.68.0.0" targetFramework="native" />
<package id="boost_system-vc141" version="1.68.0.0" targetFramework="native" />
</packages>
......@@ -30,15 +30,27 @@
#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, 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)
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,
float percent,
float rate,
int chunkAgents,
std::vector<float> boundaries,
std::vector<int> lifeSpan):
_id(id), _frequency(frequency), _maxAgents(max_agents), _groupID(group_id), _caption(caption), _greedy(greedy), _agent_id(agent_id), _time(time), _startx(startx), _starty(starty), _chunkAgents(chunkAgents), _percent(percent), _rate(rate)
{
_remainingAgents = _chunkAgents;
_agentsGenerated=0;
_boundaries[0] = 0;
_boundaries[1] = 0;
_boundaries[2] = 0;
_boundaries[3] = 0;
_boundaries = boundaries;
_lifeSpan = lifeSpan;
_agents.clear();
}
......@@ -97,17 +109,14 @@ void AgentsSource::SetAgentsGenerated(int agentsGenerated)
_agentsGenerated = agentsGenerated;
}
const double* AgentsSource::GetBoundaries() const
const std::vector<float> AgentsSource::GetBoundaries() const
{
return _boundaries;
}
void AgentsSource::Setboundaries(double * bounds)
void AgentsSource::Setboundaries(std::vector<float> bounds)
{
_boundaries[0]=bounds[0];
_boundaries[1]=bounds[1];
_boundaries[2]=bounds[2];
_boundaries[3]=bounds[3];
_boundaries=bounds;
}
const std::string& AgentsSource::GetCaption() const
......@@ -146,6 +155,38 @@ int AgentsSource::GetMaxAgents() const
return _maxAgents;
}
int AgentsSource::GetChunkAgents() const
{
return _chunkAgents;
}
int AgentsSource::GetRemainingAgents() const
{
return _remainingAgents;
}
int AgentsSource::ResetRemainingAgents()
{
_remainingAgents = _chunkAgents;
}
void AgentsSource::UpdateRemainingAgents(int remaining)
{
_remainingAgents = (remaining < _remainingAgents)? _remainingAgents - remaining:0;
}
float AgentsSource::GetPercent() const
{
return _percent;
}
float AgentsSource::GetRate() const
{
return _rate;
}
std::vector<int> AgentsSource::GetLifeSpan() const
{
return _lifeSpan;
}
float AgentsSource::GetStartX() const
{
return _startx;
......@@ -195,7 +236,7 @@ void AgentsSource::GenerateAgents(std::vector<Pedestrian*>& peds, int count, Bui
//std::cout << "AgentsSource::GenerateAgents Generates an Agent\n";
auto ped = GetStartDistribution()->GenerateAgent(building, &pid,emptyPositions);
if(ped->FindRoute()==-1) {
Log->Write("WARNING: Can not set destination for source agent %d", ped->GetID());
// Log->Write("WARNING: Can not set destination for source agent %d", ped->GetID());
// Sometimes the router can not find a target for ped
auto transitions = building->GetAllTransitions();
auto transition = transitions[0]; //dummy
......@@ -223,14 +264,24 @@ void AgentsSource::Dump() const
{
Log->Write("\n--------------------------");
Log->Write("Dumping Source");
Log->Write("Caption: %s", this->GetCaption().c_str());
Log->Write("ID: %d", _id);
Log->Write("Group ID: %d", _groupID);
Log->Write("Frequency: %d", _frequency);
Log->Write("Agents Max: %d", _maxAgents);
Log->Write("Agents Pool: %d", _agents.size());
Log->Write("Agent id: %d", this->GetAgentId());
Log->Write("Time: %f", this->GetPlanTime());
Log->Write(">> Caption : %s", this->GetCaption().c_str());
Log->Write(">> Source ID : %d", _id);
Log->Write(">> Group ID : %d", _groupID);
Log->Write(">> Frequency : %d", _frequency);
Log->Write(">> Agents Max : %d", _maxAgents);
Log->Write(">> Agents Pool: %d", _agents.size());
Log->Write(">> Agent id : %d", this->GetAgentId());
Log->Write(">> Time : %.2f", this->GetPlanTime());
Log->Write(">> StartX : %.2f", this->GetStartX());
Log->Write(">> StartY : %.2f", this->GetStartY());
Log->Write(">> Percent : %.2f", this->GetPercent());
Log->Write(">> Rate : %.2f", this->GetRate());
Log->Write(">> N_create : %d", this->GetChunkAgents());
auto tmpB = this->GetBoundaries();
Log->Write(">> Boundaries : X-axis [%.4f -- %.4f]", tmpB[0], tmpB[1]) ;
Log->Write(" Y-axis [%.4f -- %.4f]", tmpB[2], tmpB[3]);
auto tmpL = this->GetLifeSpan();
Log->Write(">> LifeSpan : [%d -- %d]", tmpL[0], tmpL[1]);
Log->Write("\n--------------------------\n");
//getc(stdin);
......
......@@ -49,7 +49,21 @@ public:
/**
* Constructor
*/
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);
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,
float percent,
float rate,
int chunkAgents,
std::vector<float> boundaries,
std::vector<int> lifeSpan);
/**
* Destructor
......@@ -64,7 +78,7 @@ public:
/**
* Generate a number of agents, based on the frequency given in the constructor.
* No agents are generated if the the maximum (_maxAgents) is reached.
* No agents are generated if the maximum (_maxAgents) is reached.
* @see _maxAgents
* @param ped
*/
......@@ -104,8 +118,8 @@ public:
int GetAgentsGenerated() const;
void SetAgentsGenerated(int agentsGenerated);
const double* GetBoundaries() const;
void Setboundaries(double * bounds);
const std::vector<float> GetBoundaries() const;
void Setboundaries(std::vector<float> bounds);
const std::string& GetCaption() const;
int GetFrequency() const;
int GetGroupId() const;
......@@ -115,27 +129,41 @@ public:
float GetStartY() const;
double GetPlanTime() const;
int GetMaxAgents() const;
int GetChunkAgents() const;
int GetRemainingAgents() const;
int ResetRemainingAgents();
void UpdateRemainingAgents(int remaining);
float GetPercent() const;
float GetRate() const;
std::vector<int> GetLifeSpan() const;
bool Greedy() const;
void SetStartDistribution(std::shared_ptr<StartDistribution>);
const std::shared_ptr<StartDistribution> GetStartDistribution() const;
private:
int _id=-1;
int _frequency=0;
int _frequency=1; /// create \var _chunkAgents every \var _frequency seconds
int _maxAgents=0;
int _groupID=-1;
std::string _caption="no caption";
bool _greedy = false;
int _agentsGenerated=0;
double _boundaries[4];// = { 0, 0, 0, 0 };
std::vector<float> _boundaries;
int _agent_id;
double _time;
float _startx;
float _starty;
double _time; /// planned generation time. here \var _maxAgents = 1
float _startx; /// \var _maxAgents = 1
float _starty; /// \var _maxAgents = 1
std::vector<int> _lifeSpan;
int _chunkAgents; /// generate \var chunk_agents per \var frequency seconds
int _remainingAgents; /// After generating \var chunk_agents \time \var
/// _percent per \var frequency seconds, this is the
/// remaining of agents still to be produced
float _percent=1.0; /// generate \var _percent * \var _chunkAgents
float _rate=1.0;
std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution;
};
#endif /* AGENTSOURCE_H_ */
......@@ -75,12 +75,12 @@ void AgentsSourcesManager::Run()
_isCompleted = false;
bool finished = 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; */
do
{
int current_time = (int)Pedestrian::GetGlobalTime();
/* std::cout << KBLU << ">> RUN: current_time " << current_time << " last update " << _lastUpdateTime << "\n" << RESET; */
// std::cout << KBLU << ">> RUN: current_time " << current_time << " last update " << _lastUpdateTime << "\n" << RESET;
if ((current_time != _lastUpdateTime)
&& ((current_time % updateFrequency) == 0))
......@@ -106,23 +106,42 @@ void AgentsSourcesManager::Run()
bool AgentsSourcesManager::ProcessAllSources() const
{
/* std::cout << "\nSTART AgentsSourcesManager::ProcessAllSources()\n"; */
// std::cout << "\nSTART AgentsSourcesManager::ProcessAllSources()\n";
bool empty=true;
double current_time = Pedestrian::GetGlobalTime();
double current_time = (int)Pedestrian::GetGlobalTime();
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 << " schedule time: " << src->GetPlanTime() <<". number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET; */
// std::cout << KRED << "\nprocessing src: " << src->GetId() << " -- current time: " << current_time << " schedule time: " << src->GetPlanTime() <<". number of peds in building " << _building->GetAllPedestrians().size() << "\n" << RESET;
if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps
auto srcLifeSpan = src-> GetLifeSpan();
bool inTime = (current_time >= srcLifeSpan[0]) && (current_time <= srcLifeSpan[1]);
// inTime is always true if src got some PlanTime (default values
// if src has no PlanTime, then this is set to 0. In this case inTime
// is important in the following condition
bool newCycle = std::fmod(current_time, src->GetFrequency()) == 0;
bool subCycle;
subCycle = (current_time > src->GetFrequency())?std::fmod((current_time-src->GetFrequency()), src->GetRate()) == 0:false;
if(newCycle)
src->ResetRemainingAgents();
bool timeToCreate = newCycle || subCycle;
// if(subCycle)
// std::cout << KGRN << " freq: " << src->GetFrequency() << ", rate: " << src->GetRate() << ", " << ": remaining: " << src->GetRemainingAgents() <<"\n" << RESET; std::cout << " <<<< time to create " << timeToCreate << " newCycle: " << newCycle << ", subcycle: " << subCycle << ", inTime: " << inTime<< "\n";
if (timeToCreate && src->GetPoolSize() && (src->GetPlanTime() <= current_time) && inTime && src->GetRemainingAgents())// maybe diff<eps
{
vector<Pedestrian*> peds;
src->RemoveAgentsFromPool(peds, src->GetFrequency());
src->RemoveAgentsFromPool(peds, src->GetChunkAgents() * src->GetPercent());
src->UpdateRemainingAgents(src->GetChunkAgents() * src->GetPercent());
source_peds.reserve(source_peds.size() + peds.size());
Log->Write("\nINFO:\tSource %d generating %d agents (%d remaining)\n",src->GetId(),peds.size(),src->GetPoolSize());
Log->Write("\nINFO:\tSource %d generating %d agents at %3.3f s, %d (%d remaining in pool)\n",src->GetId(),peds.size(), current_time,src->GetRemainingAgents(),src->GetPoolSize());
printf("\nINFO:\tSource %d generating %lu agents (%d remaining)\n",src->GetId(), peds.size(),src->GetPoolSize());
//ComputeBestPositionRandom(src.get(), peds);
......@@ -148,18 +167,21 @@ bool AgentsSourcesManager::ProcessAllSources() const
empty = false;
//src->Dump();
}
if (src->GetPlanTime() > current_time) // for the case we still expect
bool timeConstraint = (src->GetPlanTime() > current_time) || (current_time < srcLifeSpan[1]);
if (timeConstraint) // for the case we still expect
// agents coming
empty = false;
//src->Dump();//exit(0);
}
/* std::cout << "LEAVE AgentsSourcesManager::ProcessAllSources()\n"; */
// std::cout << " Source building: "<< _building << " size " << _building->GetAllPedestrians().size()<< std::endl;
// std::cout << "LEAVE AgentsSourcesManager::ProcessAllSources()\n";
// std::cout << current_time << "\n";
// std::cout << " Source building: "<< _building << " size " << _building->GetAllPedestrians().size()<< " empty = " << empty << 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;
}
......
......@@ -41,6 +41,15 @@ double Pedestrian::_globalTime = 0.0;
int Pedestrian::_agentsCreated=1;
double Pedestrian::_minPremovementTime = FLT_MAX;
AgentColorMode Pedestrian::_colorMode=BY_VELOCITY;
std::vector<int> colors = {
0,
255,
35,
127,
90,
};
Pedestrian::Pedestrian()
{
......@@ -1178,7 +1187,10 @@ int Pedestrian::GetColor() const
case BY_GROUP:
{
key = std::to_string(_group);
key = std::to_string(_group); // @todo find a better solution to get
// colors clearly distinguishable form
// each other
return(colors[_group%colors.size()]);
}
break;
......
......@@ -1534,8 +1534,8 @@ void UnivFFviaFM::writeFF(const std::string& filename, std::vector<int> targetID
Log->Write("FloorfieldViaFM::writeFF(): writing to file %s: There are %d targets.", filename.c_str(), targetID.size());