diff --git a/IO/GeoFileParser.cpp b/IO/GeoFileParser.cpp index acba6362660a13046e5fccc982ef1e067a3a5236..c73c37e550501068178d80329df415a8c921dd31 100644 --- a/IO/GeoFileParser.cpp +++ b/IO/GeoFileParser.cpp @@ -419,6 +419,8 @@ bool GeoFileParser::LoadRoutingInfo(Building* building) int min_peds = xmltoi(e->Attribute("min_peds"), -1); int max_peds = xmltoi(e->Attribute("max_peds"), -1); int waiting_time = xmltoi(e->Attribute("waiting_time"), -1); + int transition_id = xmltoi(e->Attribute("transition_id"), -1); + std::string caption = xmltoa(e->Attribute("caption"), "-1"); Goal* wa = new WaitingArea(); @@ -430,7 +432,7 @@ bool GeoFileParser::LoadRoutingInfo(Building* building) waitingArea->setMinNumPed(min_peds); waitingArea->setMaxNumPed(max_peds); waitingArea->setWaitingTime(waiting_time); - + waitingArea->setTransitionID(transition_id); std::map<int, double> nextGoals; trips.addGoal(wa->GetId()); diff --git a/geometry/Building.cpp b/geometry/Building.cpp index ecc219f1bb538559c716a121f77923de5ab6a9d5..9c778d81de6587ba9211f1c5e66da03692728dea 100644 --- a/geometry/Building.cpp +++ b/geometry/Building.cpp @@ -821,7 +821,7 @@ Room* Building::GetRoom(string caption) const bool Building::AddCrossing(Crossing* line) { int IDRoom = line->GetRoom1()->GetID(); - int IDLine = line->GetID(); + int IDLine = line->GetUniqueID(); int IDCrossing = 1000 * IDRoom + IDLine; if (_crossings.count(IDCrossing) != 0) { diff --git a/geometry/Crossing.cpp b/geometry/Crossing.cpp index 601611175df83ded2ca8ada16cef483d7602fde5..436d9703e9ffad647eaba3c30925de2d16d716e4 100644 --- a/geometry/Crossing.cpp +++ b/geometry/Crossing.cpp @@ -42,10 +42,10 @@ Crossing::~Crossing() { } -void Crossing::SetID(int ID) -{ - _id = ID; -} +//void Crossing::SetID(int ID) +//{ +// _id = ID; +//} //void Crossing::SetSubRoom2(SubRoom* r2) //{ @@ -54,10 +54,10 @@ void Crossing::SetID(int ID) // Getter-Funktionen -int Crossing::GetID() const -{ - return _id; -} +//int Crossing::GetID() const +//{ +// return _id; +//} //SubRoom* Crossing::GetSubRoom2() const //{ diff --git a/geometry/Crossing.h b/geometry/Crossing.h index d758528cfe0975d9f605ff3e4d5102b9cc0cb14c..4f9702f63b7729ea2017e757362cfbc122512ee2 100644 --- a/geometry/Crossing.h +++ b/geometry/Crossing.h @@ -38,8 +38,8 @@ class SubRoom; class Crossing : public Hline { private: - /// TODO ? unique between crossings and transitions ? - int _id; +// /// TODO ? unique between crossings and transitions ? +// int _id; /// only one room needed, since a crossing only separates 2 subrooms //Room* _room1; //SubRoom* _subRoom1; @@ -64,17 +64,17 @@ public: */ virtual ~Crossing(); - /** - * Set/Get the Id of the crossing - * TODO: do you really want to shadow ? - */ - void SetID(int ID); - - /** - * Set/Get the Id of the crossing - * TODO: do you really want to shadow ? - */ - int GetID () const; +// /** +// * Set/Get the Id of the crossing +// * TODO: do you really want to shadow ? +// */ +// void SetID(int ID); +// +// /** +// * Set/Get the Id of the crossing +// * TODO: do you really want to shadow ? +// */ +// int GetID () const; /** * Set/Get the second subroom diff --git a/geometry/Goal.cpp b/geometry/Goal.cpp index d31216e1d2d868ca066e73ebecb1384ac5777617..8d31a9e532b4563a1994a1e6663ddf31f9382220 100644 --- a/geometry/Goal.cpp +++ b/geometry/Goal.cpp @@ -41,7 +41,7 @@ Goal::Goal() _isFinalGoal=0; _walls = vector<Wall > (); _poly = vector<Point > (); - _crossing = Crossing(); +// _crossing = Crossing(); } Goal::~Goal() @@ -72,6 +72,7 @@ int Goal::GetId() const void Goal::SetId(int id) { _id = id; + _crossing.SetID(id); } const vector<Point>& Goal::GetPolygon() const diff --git a/geometry/Hline.h b/geometry/Hline.h index 500361032691c3ea7bbfa83ec4c1799f66e1bad4..b764ca5d96d4833093515a738886efcf5ac8307a 100644 --- a/geometry/Hline.h +++ b/geometry/Hline.h @@ -38,7 +38,7 @@ class Room; class Hline: public NavLine { -private: +protected: int _id; std::string _caption; diff --git a/geometry/WaitingArea.cpp b/geometry/WaitingArea.cpp index 8bb312e0d6ca04bd9b0ed4eda24850bfc3f4d4d8..47f15a15d741130775f810c8586132bd03e45d29 100644 --- a/geometry/WaitingArea.cpp +++ b/geometry/WaitingArea.cpp @@ -3,6 +3,7 @@ // #include "WaitingArea.h" +#include "Building.h" int WaitingArea::getMaxNumPed() const { @@ -99,13 +100,10 @@ void WaitingArea::setWaitingTime(double waitingTime) WaitingArea::waitingTime = waitingTime; } -std::vector<Line> WaitingArea::getAllLines() -{ -} - int WaitingArea::GetNextGoal() { - double random = std::rand()/RAND_MAX; + std::srand( (unsigned)time( NULL ) ); + double random = ((double) std::rand() / (RAND_MAX)); double cumProb = 0.; for (auto& nextGoal : nextGoals){ @@ -114,17 +112,16 @@ int WaitingArea::GetNextGoal() return nextGoal.first; } } - } -void WaitingArea::addPed() +void WaitingArea::addPed(int ped) { - numPed++; + pedInside.insert(ped); } -void WaitingArea::removePed() +void WaitingArea::removePed(int ped) { - numPed--; + pedInside.erase(ped); } void WaitingArea::startTimer(double time) @@ -133,22 +130,41 @@ void WaitingArea::startTimer(double time) std::cout << "Timer started at " << startTime << std::endl; } -bool WaitingArea::isWaiting(double time) +bool WaitingArea::isWaiting(double time, const Building* building) { - if ((numPed >= minNumPed) && (startTime < 0. )){ + Transition* trans; + if (transitionID >= 0){ + trans = building->GetTransition(transitionID); + } + + if ((pedInside.size() >= minNumPed) && (startTime < 0. )){ startTimer(time); } - if ((time < startTime + waitingTime) || (startTime < 0. )){ - std::cout << "Waiting ..." << std::endl; - return true; - }else{ - std::cout << "Waiting over!" << std::endl; + if ((time > startTime + waitingTime) && (startTime > 0. ) && (transitionID < 0)){ + return false; + } + + if ((startTime > 0. ) && (time > startTime + waitingTime) && (trans->IsOpen())){ + std::cout << "Waiting ended" << std::endl; return false; } + + std::cout << "Waiting ..." << std::endl; + return true; } int WaitingArea::getNumPed() { - return numPed; + return pedInside.size(); +} + +int WaitingArea::getTransitionID() const +{ + return transitionID; +} + +void WaitingArea::setTransitionID(int transitionID) +{ + WaitingArea::transitionID = transitionID; } diff --git a/geometry/WaitingArea.h b/geometry/WaitingArea.h index a584c4eb38ef392144878c06c034db8570a86ee0..255b93ae6ba128d99f065d0a49ae9e53e8d10358 100644 --- a/geometry/WaitingArea.h +++ b/geometry/WaitingArea.h @@ -12,6 +12,7 @@ #include <map> #include <stdio.h> +class Building; class WaitingArea : public Goal{ protected: @@ -30,7 +31,12 @@ protected: double startTime = -1; - int numPed = 0; + int transitionID = -1; +public: + int getTransitionID() const; + + void setTransitionID(int transitionID); + protected: /** @@ -43,6 +49,11 @@ protected: */ std::map<int, double> nextGoals; + /** + * Set of pedestrians who are currently in waiting area + */ + std::set<int> pedInside; + public: int getMaxNumPed() const; @@ -71,11 +82,11 @@ public: int GetNextGoal(); - void addPed(); - void removePed(); + void addPed(int ped); + void removePed(int ped); void startTimer(double time); int getNumPed(); - bool isWaiting(double time); + bool isWaiting(double time, const Building* building); private: void updateProbabilities(); diff --git a/routing/ff_router_trips/ffRouterTrips.cpp b/routing/ff_router_trips/ffRouterTrips.cpp index d09a1c595f7623903790d33952663bdc5879293c..853d5295c1355b26a0e1326f0ef3828ce6669b69 100644 --- a/routing/ff_router_trips/ffRouterTrips.cpp +++ b/routing/ff_router_trips/ffRouterTrips.cpp @@ -497,9 +497,9 @@ int FFRouterTrips::FindExit(Pedestrian* ped) //take the current time from the pedestrian double t = Pedestrian::GetGlobalTime(); - wa->addPed(); + wa->addPed(ped->GetID()); - if (!wa->isWaiting(t)){ + if (!wa->isWaiting(t, _building)){ ped->SetFinalDestination(wa->GetNextGoal()); } }