Commit 0c8fb4ac authored by Mohcine Chraibi's avatar Mohcine Chraibi

Merge branch 'event_injection' into 'develop'

Event injection

See merge request !14
parents 92457ae9 b1ce1d82
Pipeline #6297 failed with stages
......@@ -148,3 +148,4 @@ idea/codeStyleSettings.xml
*.log
*.pdf
/Utest/rimea_tests/figures
cmake-build-debug
......@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
## v0.8.3 [unreleased]
### Added
- New attributes for sources `agent_id` and `time` for scheduling agent's appearance. See #258 for discussion.
- Router tests
- Option for printing progressbar: `<progressbar/>` cfc65f22
......
......@@ -170,10 +170,16 @@ 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");
double time = xmltof(e->Attribute("time"), 0);
int agent_id = xmltoi(e->Attribute("agent_id"), -1);
bool greedy = (str_greedy == "true")?true:false;
if (agent_id >= 0){
agents_max = 1;
frequency = 1;
}
auto source = std::shared_ptr<AgentsSource>(
new AgentsSource(id, caption, agents_max, group_id,
frequency, greedy));
frequency, greedy, time, agent_id));
startDisSources.push_back(source);
Log->Write("INFO:\tSource with id %d will be parsed (greedy = %d)!", id, greedy);
......
......@@ -505,8 +505,9 @@ double Simulation::RunBody(double maxSimTime)
// Log->ProgressBar(initialnPeds, initialnPeds-_nPeds, t);
bar->Progressed(initialnPeds-_nPeds);
else
if ((frameNr < 100 && frameNr % 10 == 0) ||
(frameNr > 100 && frameNr % 100 == 0))
if ((!_gotSources) &&
((frameNr < 100 && frameNr % 10 == 0) ||
(frameNr > 100 && frameNr % 100 == 0)))
printf("time: %6.2f (%4.0f) | Agents: %6ld / %d [%4.1f%%]\n", t , maxSimTime, _nPeds, initialnPeds, (double)(initialnPeds-_nPeds)/initialnPeds*100);
......
......@@ -5,7 +5,7 @@
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<!-- geometry file -->
<geometry>bidirectional_geo.xml</geometry>
<geometry>geometry.xml</geometry>
<max_sim_time>5000</max_sim_time>
<!-- trajectories file and format -->
......@@ -19,13 +19,13 @@
<!--<hybrid_simulation server="zam597" port="9999" />-->
<!-- where to store the logs -->
<!--<logfile>outputfiles/log.txt</logfile> -->
<!-- <logfile>log.txt</logfile> -->
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- doors states are: close or open -->
<doors>
<!-- <door trans_id="5" caption="exit" state="close" /> -->
<!-- <door trans_id="1" caption="exit" state="open" /> -->
</doors>
</traffic_constraints>
......@@ -73,22 +73,22 @@
<!--persons information and distribution -->
<agents operational_model_id="3">
<agents_distribution>
<group group_id="0" 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="20" router_id="1" agent_parameter_id="1" x_min="3" x_max="5" y_min="3" y_max="5" />
<group group_id="1" room_id="1" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" goal_id="2" />
<group group_id="2" room_id="2" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
<group group_id="3" room_id="3" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" goal_id="2" />
<group group_id="4" room_id="4" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" goal_id="2" />
<!-- real start group -->
<group group_id="5" room_id="0" subroom_id="0" number="60" router_id="1" agent_parameter_id="1" goal_id="2" y_min="5.2"/>
<group group_id="5" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" goal_id="2" y_min="5.2"/>
<group group_id="6" room_id="2" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" goal_id="4" />
<group group_id="7" room_id="1" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" start_x="4.5" start_y="-1.63" goal_id="4" />
</agents_distribution>
<agents_sources><!-- frequency in persons/seconds -->
<source id="1" frequency="2" agents_max="80" group_id="6" caption="source 1" />
<source_ id="2" frequency="5" agents_max="80" group_id="5" caption="source 2" />
<source_ id="3" frequency="10" agents_max="50" group_id="3" caption="source 3" />
<source_ id="4" frequency="10" agents_max="50" group_id="4" caption="source 4" />
<source id="1" frequency="2" agents_max="5" group_id="6" caption="source 1" />
<source id="2" agent_id="3" time="5" group_id="5" caption="source 2" />
<source id="3" agent_id="2" time="3" group_id="5" caption="source 3" />
<source id="4" agent_id="8" time="7" group_id="5" caption="source 4" />
</agents_sources>
</agents>
......
......@@ -449,15 +449,15 @@ Point VelocityModel::ForceRepRoom(Pedestrian* ped, SubRoom* subroom) const
{
f += ForceRepWall(ped,*(static_cast<Line*>(goal)), centroid, inside);
}
int uid1= goal->GetUniqueID();
int uid2=ped->GetExitIndex();
// ignore my transition consider closed doors
//closed doors are considered as wall
if((uid1 != uid2) || (goal->IsOpen()==false ))
{
f += ForceRepWall(ped,*(static_cast<Line*>(goal)), centroid, inside);
}
// int uid1= goal->GetUniqueID();
// int uid2=ped->GetExitIndex();
// // ignore my transition consider closed doors
// //closed doors are considered as wall
// if((uid1 != uid2) || (goal->IsOpen()==false ))
// {
// f += ForceRepWall(ped,*(static_cast<Line*>(goal)), centroid, inside);
// }
}
return f;
......@@ -482,7 +482,7 @@ Point VelocityModel::ForceRepWall(Pedestrian* ped, const Line& w, const Point& c
e_iw = dist / Distance;
}
else {
Log->Write("WARNING:\t Velocity: forceRepWall() ped %d is too near to the wall (dist=%f)", ped->GetID(), Distance);
Log->Write("WARNING:\t Velocity: forceRepWall() ped %d [%f, %f] is too near to the wall [%f, %f]-[%f, %f] (dist=%f)", ped->GetID(), ped->GetPos()._y, ped->GetPos()._y, w.GetPoint1()._x, w.GetPoint1()._y, w.GetPoint2()._x, w.GetPoint2()._y,Distance);
Point new_dist = centroid - ped->GetPos();
new_dist = new_dist/new_dist.Norm();
//printf("new distance = (%f, %f) inside=%d\n", new_dist._x, new_dist._y, inside);
......
......@@ -30,8 +30,8 @@
#include "AgentsSource.h"
#include "Pedestrian.h"
AgentsSource::AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy):
_id(id), _frequency(frequency), _maxAgents(max_agents), _groupID(group_id), _caption(caption), _greedy(greedy)
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)
{
_agentsGenerated=0;
_boundaries[0] = 0;
......@@ -129,6 +129,17 @@ int AgentsSource::GetId() const
return _id;
}
int AgentsSource::GetAgentId() const
{
return _agent_id;
}
double AgentsSource::GetPlanTime() const
{
return _time;
}
int AgentsSource::GetMaxAgents() const
{
return _maxAgents;
......@@ -147,7 +158,23 @@ const std::shared_ptr<StartDistribution> AgentsSource::GetStartDistribution() co
void AgentsSource::GenerateAgents(std::vector<Pedestrian*>& peds, int count, Building* building)
{
std::vector<Point> emptyPositions;
int pid=Pedestrian::GetAgentsCreated(); // will be discarded
int pid;
// if(this->GetAgentId() < 0)
// {
// // TODO: get the reserved ids by other sources
// std::vector<int> reserved_ids;
// for (const auto &source: _start_dis_sources)
// if(source->GetAgentId() >= 0)
// reserved_ids.push_back(source->GetAgentId());
// while( std::find(reserved_ids.begin(), reserved_ids.end(), pid) != reserved_ids.end() ){
// std::cout << "\n\nSOURCE SORRY " << pid << " is reserved!\n";
// pid += 1;
// }
// }
pid = (this->GetAgentId() >=0 )?this->GetAgentId() : Pedestrian::GetAgentsCreated() + building->GetAllPedestrians().size();
for(int i=0;i<count;i++)
{
peds.push_back(_startDistribution->GenerateAgent(building, &pid,emptyPositions));
......@@ -159,11 +186,15 @@ 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("\n--------------------------\n");
//getc(stdin);
}
......@@ -49,7 +49,7 @@ public:
/**
* Constructor
*/
AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy);
AgentsSource(int id, const std::string& caption,int max_agents,int group_id,int frequency, bool greedy, double time, int agent_id);
/**
* Destructor
......@@ -110,6 +110,8 @@ public:
int GetFrequency() const;
int GetGroupId() const;
int GetId() const;
int GetAgentId() const;
double GetPlanTime() const;
int GetMaxAgents() const;
bool Greedy() const;
void SetStartDistribution(std::shared_ptr<StartDistribution>);
......@@ -125,6 +127,8 @@ private:
bool _greedy = false;
int _agentsGenerated=0;
double _boundaries[4];// = { 0, 0, 0, 0 };
int _agent_id;
double _time;
std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution;
......
......@@ -72,7 +72,7 @@ void AgentsSourcesManager::Run()
//it might be better to use a timer
_isCompleted = false;
bool finished = false;
long updateFrequency = 1;
long updateFrequency = 1; //TODO parse this from inifile
do
{ //@todo: break if max simulation time is reached.
int current_time = (int)Pedestrian::GetGlobalTime();
......@@ -92,9 +92,11 @@ void AgentsSourcesManager::Run()
bool AgentsSourcesManager::ProcessAllSources() const
{
bool empty=true;
double current_time = Pedestrian::GetGlobalTime();
// std::cout << "\n -- current time: " << current_time << " number " << _building->GetAllPedestrians().size() << std::endl;
for (const auto& src : _sources)
{
if (src->GetPoolSize())
if (src->GetPoolSize() && (src->GetPlanTime() <= current_time) )// maybe diff<eps
{
vector<Pedestrian*> peds;
src->RemoveAgentsFromPool(peds,src->GetFrequency());
......@@ -104,9 +106,14 @@ bool AgentsSourcesManager::ProcessAllSources() const
//todo: here every pedestrian needs an exitline
if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building) )
Log->Write("WARNING:\tThere was no place for some pedestrians");
AgentsQueueIn::Add(peds);
empty = false;
//src->Dump();
}
if (src->GetPlanTime() > current_time) // for the case we still expect
// agents coming
empty = false;
//src->Dump();//exit(0);
}
return empty;
......
......@@ -198,6 +198,7 @@ bool PedDistributor::Distribute(Building *building) const {
N, roomID, allpos.size());
return false;
}
if (N==0) continue;
// Distributing
Log->Write("INFO: \tDistributing %d Agents in Room/Subrom [%d/%d]! Maximum allowed: %d", N, roomID, subroomID,
......@@ -588,8 +589,21 @@ vector<Point> PedDistributor::PossiblePositions(const SubRoom &r) {
* */
void PedDistributor::DistributeInSubRoom(int nAgents, vector<Point> &positions, int *pid,
StartDistribution *para, Building *building) const {
std::vector<int> reserved_ids;
for (const auto &source: _start_dis_sources) {
if(source->GetAgentId() >=0)
reserved_ids.push_back(source->GetAgentId());
}
// set the pedestrians
for (int i = 0; i < nAgents; ++i) {
// look for a not reserved id.
while( std::find(reserved_ids.begin(), reserved_ids.end(), *pid) != reserved_ids.end() ){
*pid += 1;
}
Pedestrian *ped = para->GenerateAgent(building, pid, 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