Regulate open/close of doors according to max flow

- Debug messages here..
parent 60718706
Pipeline #16428 passed with stages
in 17 minutes and 20 seconds
......@@ -158,3 +158,14 @@ Win32/
*.dir/
*.user
packages/
/jpscore.srctrlbm
/jpscore.srctrldb
/jpscore.srctrlprj
/jpscore2.srctrlbm
/jpscore2.srctrldb
/jpscore2.srctrlprj
/test.py
/threads.cpp
/geometry.png
/run.py
/Utest/Validation/7test_BO/jpsreport_ini.xml
......@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
## v0.8.4 [TBD]
### Added
- Add new properties to doors #299, #295
- Add new properties to sources !41 #298
- Added homebrew [packages](https://github.com/JuPedSim/homebrew-jps/blob/master/README.md)
- added function `correct` to fix sloppily drawn geometries !36
- use cmake option `-D JPSFIRE=true` (default false) !33
......
......@@ -413,28 +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("\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");
}
......@@ -562,7 +562,24 @@ double Simulation::RunBody(double maxSimTime)
}
}
#endif
}
// here open transition that should be closed
for (auto& itr: _building->GetAllTransitions())
{
Transition* Trans = itr.second;
if(Trans->isTemporaryClosed())
{
Trans->UpdateClosingTime( _deltaT);
if(Trans->GetClosingTime() <= _deltaT)
{
std::cout << KRED << " In simulation:" << Pedestrian::GetGlobalTime() << RESET << "\n";
Trans->changeTemporaryState();
}
}
}
}// while time
return t;
}
......@@ -671,10 +688,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());
}
Crossing* cross = _building->GetCrossingByUID(ped.GetExitIndex());
if (cross) {
cross->IncreaseDoorUsage(1, ped.GetGlobalTime());
}
}
}
......
......@@ -36,6 +36,8 @@ Crossing::Crossing()
{
_id = -1;
_isOpen=true;
_temporaryClosed=false; // some doors have to be closed and opened again
// depending on _outflowRate.
_doorUsage = 0;
_maxDoorUsage = std::numeric_limits<int>::max();
_outflowRate = std::numeric_limits<double>::max();
......@@ -179,12 +181,39 @@ int Crossing::CommonSubroomWith(Crossing* other, SubRoom* &subroom) {
void Crossing::IncreaseDoorUsage(int number, double time)
{
double oldTime = _lastPassingTime;
_doorUsage += number;
_lastPassingTime = time;
_flowAtExit += to_string(time) + " " + to_string(_doorUsage) + "\n";
double deltaTime = _lastPassingTime - oldTime;
double flow = number/deltaTime;
if(flow > _outflowRate)
{
// _outflowRate > flow (=number/deltaTime)
// _outflowRate = number/(deltaTime + t1)
// --> [1]
_closingTime = number / _outflowRate - deltaTime; //[1]
_temporaryClosed = true;
this->Close();
std::cout << KGRN << "Closing transition " << GetID() << ". Closing time " << _closingTime <<"\n";
std::cout << "time: " << time << "\n";
std::cout << "last passing time " << oldTime << "\n";
std::cout << "delta time " << deltaTime << "\n";
std::cout << "door usage " << _doorUsage << std::endl;
std::cout << "\n ---> J = " << number/ deltaTime << std::endl ;
std::cout << "Max J " << _outflowRate << "\n" << RESET;
}
// close the door is mdu is reached
if(_doorUsage >= _maxDoorUsage)
{
std::cout << KGRN << "Closing door " << GetID() << "\n"<< RESET;
Log-> Write("INFO:\tClosing door %d. DoorUsage = %d (>= %d). Time=%.2f", GetID(), GetDoorUsage(), GetMaxDoorUsage(), time);
this->Close();
}
......@@ -226,3 +255,27 @@ void Crossing::SetMaxDoorUsage(int mdu)
{
_maxDoorUsage = mdu;
}
double Crossing::GetClosingTime() const
{
return _closingTime;
}
void Crossing::UpdateClosingTime(double dt)
{
_closingTime -= dt;
}
bool Crossing::isTemporaryClosed()
{
return _temporaryClosed;
}
void Crossing::changeTemporaryState()
{
_temporaryClosed = false;
_closingTime = 0;
this->Open();
std::cout << KRED<< ">> Open door for trans "<< GetID() << "\n" << RESET;
}
......@@ -45,10 +45,13 @@ private:
//SubRoom* _subRoom1;
//SubRoom* _subRoom2;
bool _isOpen;
bool _temporaryClosed;
int _doorUsage;
double _lastPassingTime;
double _outflowRate;
double _outflowRate; // pedestrians / second
int _maxDoorUsage;
double _closingTime; // time to wait until door is reopened
std::string _flowAtExit;
public:
......@@ -189,6 +192,26 @@ public:
* @return the last time this crossing was crossed
*/
double GetLastPassingTime() const;
/**
* @return the time we should wait until the door is reopened
*
*/
double GetClosingTime() const;
/**
* @param dt: time to decrease the waiting time until door is reopened
*/
void UpdateClosingTime(double dt);
bool isTemporaryClosed();
/**
* changes two private variables
* _temporaryClosed is false
* and _closingTime is 0
*/
void changeTemporaryState();
};
#endif /* _CROSSING_H */
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