Commit 5f0a498d authored by tobias schroedter's avatar tobias schroedter

State (open/close) depending of the number of Pedestrians inside is changed...

State (open/close) depending of the number of Pedestrians inside is changed and considered from the other waiting areas.
parent 9bd82776
Pipeline #17127 failed with stages
in 12 seconds
......@@ -163,9 +163,8 @@ if (GIT_SCM AND GITDIR)
else()
message(STATUS "Not in a git repo")
endif()
string(REGEX REPLACE "\#"
"" GIT_COMMIT_SUBJECT
${GIT_COMMIT_SUBJECT})
# string(REGEX REPLACE "\#" "" GIT_COMMIT_SUBJECT ${GIT_COMMIT_SUBJECT})
# even if not in a git repository we need to define these
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_SHA1}\"")
......@@ -402,7 +401,7 @@ geometry/Trips.cpp
routing/trips_router/TripsRouter.cpp
forms/jpscore.rc
math/KrauszModel.cpp)
math/KrauszModel.cpp geometry/GoalManager.cpp geometry/GoalManager.h)
set(THIRD_PARTY_SRC
tinyxml/tinystr.cpp
......
//
// Created by Tobias Schrödter on 2019-02-17.
//
#include "GoalManager.h"
#include "../pedestrian/Pedestrian.h"
#include "WaitingArea.h"
void GoalManager::SetGoals(std::map<int, Goal*> goals)
{
_allGoals = goals;
}
void GoalManager::ProcessPedPosition(Pedestrian* ped)
{
// Goal* goal = _allGoals[ped->GetFinalDestination()];
//
// if (goal!=nullptr){
// if (WaitingArea* wa = dynamic_cast<WaitingArea*>(goal)) {
// bool pedInside = wa->IsInsideGoal(ped->GetPos());
//
// if (pedInside) {
// wa->addPed(ped->GetID());
//
// if (!wa->isOpen()) {
// for (auto& goalItr : _allGoals) {
// if (WaitingArea* goal = dynamic_cast<WaitingArea*>(goalItr.second)) {
// goal->updateProbabilities(false, wa->GetId());
// }
// }
// }
//
// }
// else {
//
//
// // if just has left goal
// // decrease numPed in previous goal
// // if numPed <= maxPed
// // open Goal
// // update for goal where next goal has goal id
// }
// }
// }
// Ped is in current waiting area
if (CheckInsideWaitingArea(ped, ped->GetFinalDestination())){
WaitingArea* wa = dynamic_cast<WaitingArea*>(_allGoals[ped->GetFinalDestination()]);
wa->addPed(ped->GetID());
ped->EnterGoal();
if (!wa->isOpen()) {
SetState(wa->GetId(), false);
}
}
if ((ped->GetLastGoalID() != -1 ) && (ped->GetFinalDestination() != ped->GetLastGoalID())){
if (!CheckInsideWaitingArea(ped, ped->GetLastGoalID())){
WaitingArea* wa = dynamic_cast<WaitingArea*>(_allGoals[ped->GetLastGoalID()]);
if (wa != nullptr){
wa->removePed(ped->GetID());
ped->LeaveGoal();
if (wa->isOpen()) {
SetState(wa->GetId(), true);
}
}
}
}
}
bool GoalManager::CheckInside(Pedestrian* ped, int goalID)
{
Goal* goal = _allGoals[goalID];
if (goal!=nullptr){
return goal->IsInsideGoal(ped->GetPos());
}
return false;
}
bool GoalManager::CheckInsideWaitingArea(Pedestrian* ped, int goalID)
{
Goal* goal = _allGoals[goalID];
if (goal!=nullptr){
if (WaitingArea* wa = dynamic_cast<WaitingArea*>(goal)) {
return goal->IsInsideGoal(ped->GetPos());
}
}
return false;
}
void GoalManager::SetState(int goalID, bool state)
{
for (auto& goalItr : _allGoals) {
if (WaitingArea* goal = dynamic_cast<WaitingArea*>(goalItr.second)) {
goal->updateProbabilities(state, goalID);
}
}
}
\ No newline at end of file
//
// Created by Tobias Schrödter on 2019-02-17.
//
#ifndef JPSCORE_GOALMANAGER_H
#define JPSCORE_GOALMANAGER_H
#include <map>
class Goal;
class Pedestrian;
class GoalManager {
private:
std::map<int, Goal*> _allGoals;
public:
void SetGoals(std::map<int, Goal*> goals);
void ProcessPedPosition(Pedestrian* ped);
private:
bool CheckInside(Pedestrian* ped, int goalID);
bool CheckInsideWaitingArea(Pedestrian* ped, int goalID);
void SetState(int goalID, bool state);
};
#endif //JPSCORE_GOALMANAGER_H
......@@ -54,6 +54,13 @@ const std::map<int, double>& WaitingArea::getNextGoals() const
bool WaitingArea::setNextGoals(const std::map<int, double>& nextGoals)
{
WaitingArea::nextGoals = nextGoals;
nextGoalsOpen.clear();
for (auto& goalItr : nextGoals){
nextGoalsOpen[goalItr.first] = true;
}
return checkProbabilities();
}
......@@ -72,6 +79,15 @@ void WaitingArea::updateProbabilities()
}
// Open or closes goal with id
void WaitingArea::updateProbabilities(bool isOpen, int id)
{
if ( nextGoalsOpen.find(id) != nextGoalsOpen.end() ) {
nextGoalsOpen[id] = isOpen;
}
}
std::string WaitingArea::toString()
{
std::string out;
......@@ -118,16 +134,17 @@ int WaitingArea::GetNextGoal()
for (auto& nextGoal : nextGoals){
cumProb += nextGoal.second;
if (random <= cumProb ){
if ((nextGoalsOpen[nextGoal.first]) && (random <= cumProb)){
return nextGoal.first;
}
}
return this->_id;
}
void WaitingArea::addPed(int ped)
{
pedInside.insert(ped);
if (pedInside.size() > maxNumPed){
if (pedInside.size() >= maxNumPed){
open = false;
}
}
......@@ -135,9 +152,14 @@ void WaitingArea::addPed(int ped)
void WaitingArea::removePed(int ped)
{
pedInside.erase(ped);
if (pedInside.size() <= maxNumPed){
if (pedInside.size() < maxNumPed){
open = true;
}
if (pedInside.size() < minNumPed){
startTime = -1.;
}
}
......@@ -164,7 +186,7 @@ bool WaitingArea::isWaiting(double time, const Building* building)
return false;
}
}else{
if ((time > startTime + waitingTime) && (startTime > 0. )){
if ((time > startTime + waitingTime) && (startTime >= 0. )){
return false;
}
}
......
......@@ -52,6 +52,11 @@ protected:
*/
std::map<int, double> nextGoals;
/**
* Map of possible next goals/waiting areas (id) with corresponding state
*/
std::map<int, bool> nextGoalsOpen;
/**
* Set of pedestrians who are currently in waiting area
*/
......@@ -95,6 +100,8 @@ public:
int getNumPed();
bool isWaiting(double time, const Building* building);
void updateProbabilities(bool isOpen, int id);
private:
void updateProbabilities();
bool checkProbabilities();
......
......@@ -1247,3 +1247,24 @@ bool Pedestrian::Relocate(std::function<void(const Pedestrian&)> flowupdater) {
}
return status;
}
int Pedestrian::GetLastGoalID() const
{
return _lastGoalID;
}
bool Pedestrian::IsInsideGoal() const
{
return _insideGoal;
}
void Pedestrian::EnterGoal()
{
_insideGoal = true;
_lastGoalID = _desiredFinalDestination;
}
void Pedestrian::LeaveGoal()
{
_insideGoal = false;
}
......@@ -152,6 +152,9 @@ private:
std::shared_ptr<WalkingSpeed> _WalkingSpeed = nullptr;
std::shared_ptr<ToxicityAnalysis> _ToxicityAnalysis = nullptr;
int _lastGoalID = -1;
bool _insideGoal =false;
public:
// public member
......@@ -496,6 +499,15 @@ public:
double GetSwayAmpB() const;
const std::shared_ptr<ToxicityAnalysis> &getToxicityAnalysis();
void EnterGoal();
void LeaveGoal();
int GetLastGoalID() const;
bool IsInsideGoal() const;
};
#endif /* _PEDESTRIAN_H */
......@@ -52,6 +52,7 @@
#include "UnivFFviaFMTrips.h"
//#include "../../geometry/Building.h"
#include "../../geometry/WaitingArea.h"
#include "../../geometry/GoalManager.h"
int FFRouterTrips::_cnt = 0;
......@@ -340,6 +341,8 @@ bool FFRouterTrips::Init(Building* building)
// std::cout << dist.first.first << "->" << dist.first.second << ": " << dist.second << std::endl;
// }
goalManager.SetGoals(_building->GetAllGoals());
Log->Write("INFO: \tFF Router Init done.");
return true;
}
......@@ -443,6 +446,8 @@ bool FFRouterTrips::ReInit()
}
FloydWarshall();
goalManager.SetGoals(_building->GetAllGoals());
_plzReInit = false;
return true;
}
......@@ -462,13 +467,13 @@ int FFRouterTrips::FindExit(Pedestrian* ped)
// Check if current position is already waiting area
// yes: set next goal and return findExit(p)
goalManager.ProcessPedPosition(ped);
if ((goal!=nullptr) && (goal->IsInsideGoal(ped->GetPos()))){
if(WaitingArea* wa = dynamic_cast<WaitingArea*>(goal)) {
//take the current time from the pedestrian
double t = Pedestrian::GetGlobalTime();
wa->addPed(ped->GetID());
if (!wa->isWaiting(t, _building)){
ped->SetFinalDestination(wa->GetNextGoal());
}
......
......@@ -65,6 +65,7 @@
#include "../../geometry/Building.h"
#include "./FloorfieldViaFMTrips.h"
#include "./UnivFFviaFMTrips.h"
#include "../../geometry/GoalManager.h"
class Building;
class Pedestrian;
......@@ -227,6 +228,8 @@ protected:
bool _useCentrePointDistance = true;
//output filename counter: cnt
static int _cnt;
GoalManager goalManager;
};
#endif /* FFROUTER_H_ */
......@@ -431,6 +431,14 @@ void VoronoiBestVertexRandMax (AgentsSource* src, const std::vector<Point>& disc
// partial_sums: [d_0^2, d_0^2 + d_1^2, d_0^2 + d_1^2 + d_2^2, ..., \sum_i^{n-1} d_i^3]
//now we have the vector of possible vertices and weights and we can choose one randomly
if(partial_sums.empty())
{
Log->Write("Warning: No possible vertices. Maybe BB too small for %d agents?", src->GetChunkAgents());
// exit(EXIT_FAILURE); // maybe not exit, just ignore
// dis = 0;
return;
}
double lower_bound = 0;
double upper_bound = partial_sums[size-1];
std::random_device rd;
......
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