Commit 311f63fa authored by Mohcine Chraibi's avatar Mohcine Chraibi

Merge branch '158' into 'develop'

Issue 158

See merge request !21
parents 60b744d8 2d1fb525
Pipeline #9289 failed with stages
in 5 minutes and 7 seconds
......@@ -54,7 +54,8 @@ make-linux:
- cd build
- make -j$nproc
- echo "compile | ${CI_PROJECT_DIR}"
tags:
- linux
#============== unit_test ============
test:
dependencies:
......
......@@ -35,7 +35,7 @@
#include "math/GompertzModel.h"
#include "math/GradientModel.h"
#include "pedestrian/AgentsQueue.h"
#include "pedestrian/AgentsSourcesManager.h"
#ifdef _OPENMP
#else
......@@ -61,6 +61,7 @@ Simulation::Simulation(Configuration* args)
_fps = 1;
_em = nullptr;
_gotSources = false;
_maxSimTime = 100;
// _config = args;
}
......@@ -201,6 +202,7 @@ bool Simulation::InitArgs()
sprintf(tmp, "\tt_max: %f\n", _config->GetTmax());
s.append(tmp);
_deltaT = _config->Getdt();
_maxSimTime = _config->GetTmax();
sprintf(tmp, "\tdt: %f\n", _deltaT);
_periodic = _config->IsPeriodic();
sprintf(tmp, "\t periodic: %d\n", _periodic);
......@@ -214,10 +216,11 @@ bool Simulation::InitArgs()
_routingEngine = _config->GetRoutingEngine();
auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_config));
// IMPORTANT: do not change the order in the following..
_building = std::unique_ptr<Building>(new Building(_config, *distributor));
_building = std::shared_ptr<Building>(new Building(_config, *distributor));
// Initialize the agents sources that have been collected in the pedestrians distributor
_agentSrcManager.SetBuilding(_building.get());
_agentSrcManager.SetMaxSimTime(GetMaxSimTime());
_gotSources = (bool) distributor->GetAgentsSources().size(); // did we have any sources? false if no sources
for (const auto& src: distributor->GetAgentsSources()) {
_agentSrcManager.AddSource(src);
......@@ -529,12 +532,31 @@ void Simulation::RunFooter()
void Simulation::ProcessAgentsQueue()
{
/* std::cout << "Call Simulation::ProcessAgentsQueue() at: " << Pedestrian::GetGlobalTime() << std::endl; */
/* std::cout << KRED << " SIMULATION building " << _building << " size " << _building->GetAllPedestrians().size() << "\n" << RESET; */
/* for(auto pp: _building->GetAllPedestrians()) */
/* std::cout<< KBLU << "BUL: Simulation: " << pp->GetPos()._x << ", " << pp->GetPos()._y << RESET << std::endl; */
//incoming pedestrians
vector<Pedestrian*> peds;
// std::cout << ">>> peds " << peds.size() << RESET<< std::endl;
AgentsQueueIn::GetandClear(peds);
//std::cout << "SIMULATION BEFORE BOOL = " << _agentSrcManager.IsBuildingUpdated() << " peds size " << peds.size() << "\n" ;
//_agentSrcManager.SetBuildingUpdated(true);
/* std::cout << "SIMULATION AFTER BOOL = " << _agentSrcManager.IsBuildingUpdated() << "\n" ; */
for (auto&& ped: peds) {
/* std::cout << "Add to building : " << ped->GetPos()._x << ", " << ped->GetPos()._y << " t: "<< Pedestrian::GetGlobalTime() << std::endl; */
_building->AddPedestrian(ped);
}
// for(auto pp: _building->GetAllPedestrians())
// std::cout<< KBLU << "BUL: Simulation: " << pp->GetPos()._x << ", " << pp->GetPos()._y << " t: "<< Pedestrian::GetGlobalTime() <<RESET << std::endl;
/* std::cout << "LEAVE Simulation::ProcessAgentsQueue() with " << " size " << _building->GetAllPedestrians().size() << "\n" << RESET; */
}
void Simulation::UpdateDoorticks() const {
......@@ -619,3 +641,7 @@ Building* Simulation::GetBuilding()
{
return _building.get();
}
int Simulation::GetMaxSimTime() const{
return _maxSimTime;
}
......@@ -67,7 +67,7 @@ private:
///seed using for the random number generator
unsigned int _seed;
/// building object
std::unique_ptr<Building> _building;
std::shared_ptr<Building> _building;
/// Force model to use
std::shared_ptr<OperationalModel> _operationalModel;
/// Manage all route choices algorithms
......@@ -85,6 +85,8 @@ private:
/// hybrid simulation manager
//HybridSimulationManager
int _periodic;
int _maxSimTime;
bool _gotSources; // is true if we got some sources. Otherwise, false.
// bool _printPB; // print progressbar
public:
......@@ -182,6 +184,8 @@ public:
*
*/
void UpdateDoorticks() const;
int GetMaxSimTime() const;
};
......
......@@ -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
......@@ -86,7 +86,11 @@ int main(int argc, char** argv)
//Start the thread for managing the sources of agents if any
//std::thread t1(sim.GetAgentSrcManager());
double simMaxTime = configuration->GetTmax();
std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());//@todo pass simMaxTime to Run
std::thread t1(&AgentsSourcesManager::Run, &sim.GetAgentSrcManager());
while(!sim.GetAgentSrcManager().IsRunning())
{
// std::cout << "waiting...\n";
}
//main thread for the simulation
evacTime = sim.RunStandardSimulation(simMaxTime);
//Join the main thread
......@@ -111,7 +115,6 @@ int main(int argc, char** argv)
}
double execTime = difftime(endtime, starttime);
std::stringstream summary;
summary << std::setprecision(2) << std::fixed;
summary << "\nExec Time [s] : " << execTime << std::endl;
......
......@@ -358,7 +358,8 @@ my_pair VelocityModel::GetSpacing(Pedestrian* ped1, Pedestrian* ped2, Point ei,
//printf("ERROR: \tin VelocityModel::forcePedPed() ep12 can not be calculated!!!\n");
Log->Write("WARNING: \tin VelocityModel::GetSPacing() ep12 can not be calculated!!!\n");
Log->Write("\t\t Pedestrians are too near to each other (%f).", Distance);
exit(EXIT_FAILURE);
my_pair(FLT_MAX, ped2->GetID());
exit(EXIT_FAILURE); //TODO
}
double condition1 = ei.ScalarProduct(ep12); // < e_i , e_ij > should be positive
......@@ -399,7 +400,9 @@ Point VelocityModel::ForceRepPed(Pedestrian* ped1, Pedestrian* ped2, int periodi
Log->Write("\t\t Maybe the value of <a> in force_ped should be increased. Going to exit.\n");
printf("ped1 %d ped2 %d\n", ped1->GetID(), ped2->GetID());
printf("ped1 at (%f, %f), ped2 at (%f, %f)\n", ped1->GetPos()._x, ped1->GetPos()._y, ped2->GetPos()._x, ped2->GetPos()._y);
exit(EXIT_FAILURE);
exit(EXIT_FAILURE); //TODO: quick and dirty fix for issue #158
// (sometimes sources create peds on the same location)
}
Point ei = ped1->GetV().Normalized();
if(ped1->GetV().NormSquare()<0.01){
......
This diff is collapsed.
......@@ -84,6 +84,7 @@ public:
* Set the building object
*/
void SetBuilding(Building* building);
void SetRunning(bool running);
/**
* @return true if all agents have been generated
......@@ -91,6 +92,14 @@ public:
*/
bool IsCompleted() const;
/**
* @return true if the building is updated
*
*/
bool IsBuildingUpdated() const;
void SetBuildingUpdated(bool update);
/**
* Return a pointer to the building object
*/
......@@ -111,10 +120,13 @@ public:
/**
* Return the total number of agents that will be generated.
* used by visualisation to allocate space
*
*/
long GetMaxAgentNumber() const;
int GetMaxSimTime() const;
void SetMaxSimTime(int t);
bool IsRunning() const;
private:
/**
......@@ -165,11 +177,16 @@ private:
std::vector<std::shared_ptr<AgentsSource> > _sources;
///to control the trigger of the events
long int _lastUpdateTime = 0;
int maxSimTime = 0;
/// building object
Building* _building=nullptr;
/// whether all agents have been dispatched
static bool _isCompleted;
//std::atomic<bool>_isCompleted=false;
// std::atomic<bool>_buildingUpdated=false;
bool _buildingUpdated;
bool _isRunning = false;
};
#endif /* AGENTSSOURCESMANAGER_H_ */
......@@ -198,7 +198,9 @@ void Pedestrian::SetID(int i)
_id = i;
if(i<=0)
{
cout<<"invalid ID"<<i<<endl;exit(0);
cerr<<">> Invalid pedestrians ID " << i<< endl;
cerr<<">> Pedestrian ID should be > 0. Exit." << endl;
exit(0);
}
}
......@@ -1225,6 +1227,3 @@ bool Pedestrian::Relocate(std::function<void(const Pedestrian&)> flowupdater) {
}
return status;
}
......@@ -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,7 @@ 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
......@@ -120,11 +121,11 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
}
std::vector<Pedestrian*>::iterator iter_ped;
std::srand(0);
for (iter_ped = peds.begin(); iter_ped != peds.end(); )
{
Pedestrian* ped = *iter_ped;
radius = ped->GetEllipse().GetBmax(); //max radius of the current pedestrian
if(existing_peds.size() == 0 )
{
const Point& center_pos = subroom->GetCentroid();
......@@ -156,10 +157,10 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
double speed = ped->GetEllipse().GetV0(); //@todo: some peds do not have a navline. This should not be accepted.
v=v*speed;
ped->SetV(v);
existing_peds.push_back(ped);
}//0
else //more than one pedestrian
{
//it would be better to maybe have a mapping between discrete_positions and pointers to the pedestrians
......@@ -216,11 +217,9 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
Point pos( chosen_it->x()/factor, chosen_it->y()/factor ); //check!
ped->SetPos(pos , true);
VoronoiAdjustVelocityNeighbour(chosen_it, ped, velocities_vector, goal_vector);
// proceed to the next pedestrian
existing_peds.push_back(ped);
++iter_ped;
}
else
{
......@@ -239,6 +238,8 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
//maybe not all pedestrians could find a place, requeue them in the source
if(peds_without_place.size()>0)
src->AddAgentsToPool(peds_without_place);
return return_value;
}
......@@ -401,7 +402,8 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
double lower_bound = 0;
double upper_bound = partial_sums[size-1];
std::random_device rd;
std::mt19937 gen(rd()); //@todo use seed instead of rd(). Generator should not be here
//std::mt19937 gen(rd()); //@todo use seed instead of rd(). Generator should not be here
std::mt19937 gen(1); //@todo use seed instead of rd(). Generator should not be here
std::uniform_real_distribution<double> distribution(lower_bound, upper_bound); //std::nextafter(upper_bound, DBL_MAX));
vector<double> random_numbers;
for(unsigned int r=0; r<size;r++)
......
......@@ -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