Commit b862d46e authored by Mohcine Chraibi's avatar Mohcine Chraibi

Resolve "Show statistics of crossings"

parent 796ad04a
......@@ -605,7 +605,8 @@ set_property(TARGET core PROPERTY CXX_STANDARD_REQUIRED ON)
if(CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(core thirdParty stdc++fs) # link to lib filesystem
else()
message(WARNING "I don't know how to link filesystem with ${CMAKE_CXX_COMPILER_ID}")
target_link_libraries(core thirdParty)
#message(WARNING "I don't know how to link filesystem with ${CMAKE_CXX_COMPILER_ID}")
endif()
......
......@@ -413,6 +413,28 @@ void Simulation::PrintStatistics()
output->Write(goal->GetFlowCurve());
}
}
Log->Write("\nUsage of Crossings");
Log->Write("==========");
for (const auto& itr : _building->GetAllCrossings()) {
Crossing* goal = itr.second;
if (goal->GetDoorUsage()) {
Log->Write(
"\nCrossing ID [%d] in Room ID [%d] used by [%d] pedestrians. Last passing time [%0.2f] s",
goal->GetID(), itr.first/1000, goal->GetDoorUsage(),
goal->GetLastPassingTime());
string statsfile = _config->GetTrajectoriesFile() + "_flow_crossing_id_"
+ to_string(itr.first/1000) + "_" + to_string(itr.first % 1000) +".dat";
Log->Write("More Information in the file: %s", statsfile.c_str());
auto output = new FileHandler(statsfile.c_str());
output->Write("#Flow at crossing " + goal->GetCaption() + "( ID " + to_string(goal->GetID())
+ " ) in Room ( ID "+ to_string(itr.first / 1000) + " )");
output->Write("#Time (s) cummulative number of agents \n");
output->Write(goal->GetFlowCurve());
}
}
Log->Write("\n");
}
......@@ -649,6 +671,10 @@ void Simulation::UpdateFlowAtDoors(const Pedestrian& ped) const
//#pragma omp critical
trans->IncreaseDoorUsage(1, ped.GetGlobalTime());
}
Crossing* cross = _building->GetCrossingByUID(ped.GetExitIndex());
if (cross) {
cross->IncreaseDoorUsage(1, ped.GetGlobalTime());
}
}
}
......
......@@ -1302,6 +1302,16 @@ Transition* Building::GetTransitionByUID(int uid) const
return nullptr;
}
Crossing* Building::GetCrossingByUID(int uid) const
{
for (auto&& cross : _crossings) {
if (cross.second->GetUniqueID() == uid)
return cross.second;
}
return nullptr;
}
bool Building::SaveGeometry(const std::string& filename) const
{
std::stringstream geometry;
......
......@@ -173,6 +173,8 @@ public:
*/
Transition* GetTransitionByUID(int uid) const;
Crossing* GetCrossingByUID(int uid) const;
//TOD0: rename later to GetGoal
Goal* GetFinalGoal(int id) const;
......
......@@ -36,6 +36,8 @@ Crossing::Crossing()
{
_id = -1;
_isOpen=true;
_doorUsage = 0;
_lastPassingTime = 0;
}
Crossing::~Crossing()
......@@ -172,3 +174,25 @@ int Crossing::CommonSubroomWith(Crossing* other, SubRoom* &subroom) {
}
return result;
}
void Crossing::IncreaseDoorUsage(int number, double time)
{
_doorUsage += number;
_lastPassingTime = time;
_flowAtExit += to_string(time) + " " + to_string(_doorUsage) + "\n";
}
int Crossing::GetDoorUsage() const
{
return _doorUsage;
}
double Crossing::GetLastPassingTime() const
{
return _lastPassingTime;
}
const std::string & Crossing::GetFlowCurve() const
{
return _flowAtExit;
}
\ No newline at end of file
......@@ -45,6 +45,9 @@ private:
//SubRoom* _subRoom1;
//SubRoom* _subRoom2;
bool _isOpen;
int _doorUsage;
double _lastPassingTime;
std::string _flowAtExit;
public:
// last ped that passed was in room {1,2} that many ticks
......@@ -139,6 +142,29 @@ public:
* @param subroom returns one of the common subrooms
*/
virtual int CommonSubroomWith(Crossing* other, SubRoom* &subroom);
/**
* Increment the number of persons that used that crossing
* @param number, how many person have passed the crossing
* @param time, at which time
*/
void IncreaseDoorUsage(int number, double time);
/**
* @return the number of pedestrians that used that crossing.
*/
int GetDoorUsage() const;
/**
* @return the flow curve for this crossing
*/
const std::string & GetFlowCurve() const;
/**
* @return the last time this crossing was crossed
*/
double GetLastPassingTime() const;
};
#endif /* _CROSSING_H */
......
......@@ -38,8 +38,6 @@ using namespace std;
Transition::Transition() : Crossing()
{
_isOpen = true;
_doorUsage=0;
_lastPassingTime=0;
_room2 = nullptr;
// _lastTickTime1 = 0;
// _lastTickTime2 = 0;
......@@ -190,24 +188,3 @@ string Transition::GetDescription() const
return geometry;
}
void Transition::IncreaseDoorUsage(int number, double time)
{
_doorUsage+=number;
_lastPassingTime=time;
_flowAtExit+=to_string(time)+" "+to_string(_doorUsage)+"\n";
}
int Transition::GetDoorUsage() const
{
return _doorUsage;
}
double Transition::GetLastPassingTime() const
{
return _lastPassingTime;
}
const std::string & Transition::GetFlowCurve() const
{
return _flowAtExit;
}
......@@ -40,10 +40,7 @@ private:
bool _isOpen;
std::string _type;
// number of agents that passed that exit
int _doorUsage;
double _lastPassingTime;
std::string _flowAtExit;
public:
/**
* Cosntructor
......@@ -65,30 +62,7 @@ public:
* The first one is set in the crossing class.
*/
void SetRoom2(Room* ID);
/**
* Increment the number of persons that used that exit
* @param number, how many person have passed the door
* @param time, at which time
*/
void IncreaseDoorUsage(int number, double time);
/**
* @return the number of pedestrians that used that exit.
*/
int GetDoorUsage() const;
/**
* @return the flow curve for this exit
*/
const std::string & GetFlowCurve() const;
/**
* @return the last time this door was crossed
*/
double GetLastPassingTime() const;
/**
* Set/Get the type of the transition
*/
......
......@@ -121,8 +121,8 @@ bool PedDistributor::Distribute(Building *building) const {
{
if(fs::is_regular_file(p))
{
std::string basename = p.stem(); //
std::string extention = p.extension();
std::string basename = p.stem().string(); //
std::string extention = p.extension().string();
auto tmpPositions = GetPositionsFromFile(p.string(), dist->GetAgentsNumber(), unit);
//check if positions are
//empty. May happen if file
......
......@@ -1239,7 +1239,7 @@ bool Pedestrian::Relocate(std::function<void(const Pedestrian&)> flowupdater) {
//the agent left the old room
//actualize the egress time for that room
#pragma omp critical(SetEgressTime)
allRooms.at(GetRoomID())->SetEgressTime(GetGlobalTime()); //set Egresstime to old room //@todo: ar.graf : GetRoomID() yields NEW room
allRooms.at(oldRoomID)->SetEgressTime(GetGlobalTime()); //set Egresstime to old room //@todo: ar.graf : GetRoomID() yields NEW room
}
status = true;
break;
......
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