Commit 0e5c688f authored by Ulrich Kemloh's avatar Ulrich Kemloh

Refactoring events manager and part merging of the information sharing.

parent 5c9d5b77
......@@ -26,7 +26,7 @@ the implied warranties of merchantability and fitness for a particular purpose.
The software and accompanying documentation, if any, provided hereunder is
provided “as is”. JuPedSim has no obligation to provide maintenance, support,
updates, enhancements, or modifications.
Forschungszentrum J ̈ulich GmbH makes no warranty, expressed or implied,
Forschungszentrum Julich GmbH makes no warranty, expressed or implied,
to users of JuPedSim, and accepts no responsibility for its use. Users of JuPedSim
assume sole responsibility for determining the appropriateness of its use; and for
any actions taken or not taken as a result of analyses performed using this tool.
......
......@@ -292,15 +292,15 @@ int Simulation::RunSimulation()
// update the positions
_operationalModel->ComputeNextTimeStep(t, _deltaT, _building.get());
// update the routes and locations
//Update();
//update the routes and locations
UpdateRoutesAndLocations();
//update the events
_em->Update_Events(t, _deltaT);
_em->Update_Events(t);
//_em->ProcessEvent();
//other updates
//someone might have leave the building
//someone might have left the building
_nPeds = _building->GetAllPedestrians().size();
//update the linked cells
......
This diff is collapsed.
......@@ -29,6 +29,10 @@
#include <string>
class Building;
class Router;
class GlobalRouter;
class QuickestPathRouter;
class RoutingEngine;
extern OutputHandler* Log;
......@@ -42,22 +46,83 @@ private:
std::string _projectFilename;
std::string _projectRootDir;
Building *_building;
double _deltaT;
FILE *_file;
bool _dynamic;
int _eventCounter;
long int _lastUpdateTime;
//save the router corresponding to the actual state of the building
std::map<std::string, RoutingEngine*> _eventEngineStorage;
//save the available routers defined in the simulation
std::vector<RoutingStrategy> _availableRouters;
private:
/**
* collect the close doors and generate a new graph
* @param _building
*/
bool CreateRoutingEngine(Building* _b, int first_engine=false);
/**
* Create a router corresponding to the given strategy
* @param strategy
* @return a router/NULL for invalid strategies
*/
Router * CreateRouter(const RoutingStrategy& strategy);
/**
* Update the knowledge about closed doors.
* Each pedestrian who is xx metres from a closed door,
* will save that information
* @param _b, the building object
*/
bool UpdateAgentKnowledge(Building* _b);
/**
* Merge the knowledge of the two pedestrians.
* The information with the newest timestamp
* is always accepted with a probability of one.
* @param p1, first pedestrian
* @param p2, second pedestrian
*/
void MergeKnowledge(Pedestrian* p1, Pedestrian* p2);
/**
* Update the pedestrian route based on the new information
* @param p1
* @return
*/
bool UpdateRoute(Pedestrian* p1);
public:
//constructor
///constructor
EventManager(Building *_b);
void SetProjectFilename(const std::string &filename);
void SetProjectRootDir(const std::string &filename);
/**
* Read and parse the events
* @return false if an error occured
*/
bool ReadEventsXml();
/**
* Print the parsed events
*/
void ListEvents();
/**
* Read and parse events from a text file
* @param time
*/
void ReadEventsTxt(double time);
//Update
void Update_Events(double time, double d);
/**
* Process the events at runtime
* @param time
*/
void Update_Events(double time);
//process the event using the current time stamp
//from the pedestrian class
void ProcessEvent();
//Eventhandling
void CloseDoor(int id);
void OpenDoor(int id);
......
......@@ -699,7 +699,7 @@ void Building::AddHline(Hline* line)
// check if the lines are identical
Hline* ori= _hLines[line->GetID()];
if(ori->operator ==(*line)) {
Log->Write("INFO: Skipping identical hlines with ID [%d]",line->GetID());
Log->Write("INFO: \tSkipping identical hlines with ID [%d]",line->GetID());
return;
} else {
Log->Write(
......@@ -869,7 +869,7 @@ bool Building::IsVisible(Line* l1, Line* l2, bool considerHlines)
return true;
}
bool Building::ped_is_visible(const Point& p1, const Point& p2, bool considerHlines)
bool Building::IsVisible(const Point& p1, const Point& p2, bool considerHlines)
{
for (unsigned int i = 0; i < _rooms.size(); i++) {
Room* room = _rooms[i];
......
......@@ -133,7 +133,7 @@ public:
* Alls walls and transitions and crossings are used in this check.
* The use of hlines is optional, because they are not real, can be considered transparent
*/
bool ped_is_visible(const Point& p1, const Point& p2, bool considerHlines=false);
bool IsVisible(const Point& p1, const Point& p2, bool considerHlines=false);
/**
* @return a crossing or a transition matching the given caption.
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JPScore project="JPS-Project" version="0.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../xsd/jps_events.xsd">
<events>
<event time="1" type="door" state="close" id="8" caption="left_exit" />
<event time="10" type="door" state="open" id="8" caption="left_exit" />
<event time="25" type="door" state="close" id="4" caption="main_exit" />
<event time="40" type="door" state="open" id="4" caption="main_exit" />
</events>
<JPScore project="JPS-Project" version="0.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/jps_events.xsd">
<events>
<event time="1" type="door" state="close" id="8" caption="left_exit" />
<event time="10" type="door" state="open" id="8" caption="left_exit" />
<event time="25" type="door" state="close" id="4" caption="main_exit" />
<event time="40" type="door" state="open" id="4" caption="main_exit" />
<event time="70" type="door" state="close" id="8" caption="main_exit" />
</events>
</JPScore>
\ No newline at end of file
......@@ -163,7 +163,7 @@ void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* bui
Pedestrian* ped1 = neighbours[i];
Point p1 = ped->GetPos();
Point p2 = ped1->GetPos();
bool ped_is_visible = building->ped_is_visible(p1, p2, false);
bool ped_is_visible = building->IsVisible(p1, p2, false);
if (!ped_is_visible)
continue;
// if(debugPed == ped->GetID())
......
......@@ -201,7 +201,7 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building*
//if they are in the same subroom
Point p1 = ped->GetPos();
Point p2 = ped1->GetPos();
bool isVisible = building->ped_is_visible(p1, p2, false);
bool isVisible = building->IsVisible(p1, p2, false);
if (!isVisible)
continue;
// if(debugPed == ped->GetID())
......
......@@ -73,8 +73,9 @@ Pedestrian::Pedestrian()
_lastPosition = Point(0,0);
_lastCellPosition = -1;
_recordingTime = 20; //seconds
_knownDoors = map<int, NavLineState>();
_height = 160;
// _knownDoors = map<int, NavLineState>();
_knownDoors.clear();
_height = 170;
_age = 30;
_gender = "male";
_trip = vector<int> ();
......@@ -82,7 +83,8 @@ Pedestrian::Pedestrian()
_spotlight = false;
_V0UpStairs=0.0;
_V0DownStairs=0.0;
_DistToBlockade=0.0;
_distToBlockade=0.0;
_routingStrategy=ROUTING_GLOBAL_SHORTEST;
}
......@@ -243,6 +245,11 @@ int Pedestrian::GetUniqueRoomID() const
return _roomID * 1000 + _subRoomID;
}
RoutingStrategy Pedestrian::GetRoutingStrategy() const
{
return _routingStrategy;
}
// returns the exit Id corresponding to the
// unique subroom identifier
......@@ -286,12 +293,14 @@ void Pedestrian::ClearMentalMap()
_exitIndex = -1;
}
void Pedestrian::AddKnownClosedDoor(int door)
void Pedestrian::AddKnownClosedDoor(int door, double time)
{
if(_knownDoors.find(door) == _knownDoors.end()) {
_knownDoors[door].close(GetGlobalTime());
}
return;
// if(_knownDoors.find(door) == _knownDoors.end()) {
// _knownDoors[door].close(GetGlobalTime());
// }
// return;
if(time==0) time=_globalTime;
_knownDoors[door].SetState(true,time);
}
int Pedestrian::DoorKnowledgeCount() const
......@@ -314,11 +323,22 @@ set<int> Pedestrian::GetKnownClosedDoors()
return doors_closed;
}
//TODO: remove
map<int, NavLineState> * Pedestrian::GetKnownDoors()
{
return & _knownDoors;
}
void Pedestrian::ClearKnowledge()
{
_knownDoors.clear();
}
const map<int, NavLineState>& Pedestrian::GetKnownledge() const
{
return _knownDoors;
}
void Pedestrian::MergeKnownClosedDoors( map<int, NavLineState> * input)
{
map<int, NavLineState>::iterator it;
......@@ -444,7 +464,7 @@ const Point& Pedestrian::GetV0(const Point& target)
//new_v0 = delta.NormalizedMolified();
new_v0 = delta.Normalized();
// -------------------------------------- Handover new target
t = _newOrientationDelay++ *_deltaT/(1.0+1000* _DistToBlockade);
t = _newOrientationDelay++ *_deltaT/(1.0+1000* _distToBlockade);
_V0 = _V0 + (new_v0 - _V0)*( 1 - exp(-t/_tau) );
#if DEBUG
......@@ -452,7 +472,7 @@ const Point& Pedestrian::GetV0(const Point& target)
printf("Goal Line=[%f, %f]-[%f, %f]\n", _navLine->GetPoint1().GetX(), _navLine->GetPoint1().GetY(), _navLine->GetPoint2().GetX(), _navLine->GetPoint2().GetY());
printf("Ped=%d, sub=%d, room=%d pos=[%f, %f], target=[%f, %f]\n", _id, _subRoomID, _roomID, pos.GetX(), pos.GetY(), target.GetX(), target.GetY());
printf("Ped=%d : BEFORE new_v0=%f %f norm = %f\n", _id, new_v0.GetX(), new_v0.GetY(), new_v0.Norm());
printf("ped=%d: t=%f, _newOrientationFlag=%d, neworientationDelay=%d, _DistToBlockade=%f\n", _id,t, _newOrientationFlag, _newOrientationDelay, _DistToBlockade);
printf("ped=%d: t=%f, _newOrientationFlag=%d, neworientationDelay=%d, _DistToBlockade=%f\n", _id,t, _newOrientationFlag, _newOrientationDelay, _distToBlockade);
printf("_v0=[%f, %f] norm = %f\n", _V0.GetX(), _V0.GetY(), _V0.Norm());
}
// getc(stdin);
......@@ -485,7 +505,7 @@ double Pedestrian::GetTimeInJam() const
void Pedestrian::SetSmoothTurning()
{
_newOrientationDelay = 0;
_newOrientationDelay = 0;
}
......@@ -536,42 +556,42 @@ bool Pedestrian::IsReadyForRerouting()
double Pedestrian::GetReroutingTime()
{
return _timeBeforeRerouting;
return _timeBeforeRerouting;
}
bool Pedestrian::GetNewEventFlag()
{
return _newEventFlag;
return _newEventFlag;
}
bool Pedestrian::GetNewOrientationFlag()
{
return _newOrientationFlag;
return _newOrientationFlag;
}
void Pedestrian::SetDistToBlockade(double dist)
{
_DistToBlockade = dist;
_distToBlockade = dist;
}
double Pedestrian::GetDistToBlockade()
{
return _DistToBlockade;
return _distToBlockade;
}
void Pedestrian::SetNewOrientationFlag(bool flag)
{
_newOrientationFlag=flag;
_newOrientationFlag=flag;
}
void Pedestrian::SetNewEventFlag(bool flag)
{
_newEventFlag=flag;
_newEventFlag=flag;
}
double Pedestrian::GetAge() const
{
return _age;
return _age;
}
void Pedestrian::SetAge(double age)
......@@ -626,9 +646,9 @@ double Pedestrian::GetRecordingTime() const
}
double Pedestrian::GetMeanVelOverRecTime() const {
//just few position were saved
if (_lastPositions.size()<2) return _ellipse.GetV().Norm();
return fabs ( (_lastPositions.back()-_lastPositions.front()).Norm() / _recordingTime );
//just few position were saved
if (_lastPositions.size()<2) return _ellipse.GetV().Norm();
return fabs ( (_lastPositions.back()-_lastPositions.front()).Norm() / _recordingTime );
}
double Pedestrian::GetDistanceToNextTarget() const
......@@ -684,7 +704,7 @@ void Pedestrian::Dump(int ID, int pa)
switch (pa) {
case 0: {
case 0:
printf(">> Room/Subroom [%d / %d]\n", _roomID, _subRoomID);
printf(">> Destination [ %d ]\n", _exitIndex);
printf(">> Final Destination [ %d ]\n", _desiredFinalDestination);
......@@ -693,17 +713,14 @@ void Pedestrian::Dump(int ID, int pa)
printf(">> Velocity [%0.2f, %0.2f] Norm = [%0.2f]\n", GetV().GetX(), GetV().GetY(), GetV().Norm());
if(GetExitLine()) {
printf(">> ExitLine: (%0.2f, %0.2f) -- (%0.2f, %0.2f)\n", GetExitLine()->GetPoint1().GetX(), GetExitLine()->GetPoint1().GetY(),
GetExitLine()->GetPoint2().GetX(), GetExitLine()->GetPoint2().GetY());
GetExitLine()->GetPoint2().GetX(), GetExitLine()->GetPoint2().GetY());
printf(">> dist: %f\n", GetExitLine()->DistTo(GetPos()));
}
printf(">> smooth rotating: %s \n", (_newOrientationDelay > 0) ? "yes" : "no");
printf(">> mental map");
map<int, int>::iterator iter;
for (iter = _mentalMap.begin(); iter != _mentalMap.end(); iter++) {
printf("\t room / destination [%d, %d]\n", iter->first, iter->second);
}
}
break;
for(auto&& item: _mentalMap)
printf("\t room / destination [%d, %d]\n", item.first, item.second);
break;
case 1:
printf(">> Position [%f, %f]\n", GetPos().GetX(), GetPos().GetY());
......@@ -724,14 +741,20 @@ void Pedestrian::Dump(int ID, int pa)
case 5:
printf(">> Destination [ %d ]\n", _exitIndex);
break;
case 6: { //Mental Map
case 6: //Mental Map
printf(">> mental map");
map<int, int>::iterator iter;
for (iter = _mentalMap.begin(); iter != _mentalMap.end(); iter++) {
printf("\t room / destination [%d, %d]", iter->first, iter->second);
}
}
break;
for(auto&& item: _mentalMap)
printf("\t room / destination [%d, %d]", item.first, item.second);
break;
case 7:
for(auto&& item:_knownDoors)
printf("\t door [%d] closed since [%lf] sec\n", item.first, item.second.GetTime());
break;
default:
break;
}
fflush(stdout);
......@@ -756,6 +779,7 @@ double Pedestrian::GetGlobalTime()
void Pedestrian::SetRouter(Router* router)
{
_router=router;
_routingStrategy=router->GetStrategy();
}
Router* Pedestrian::GetRouter() const
......
......@@ -45,9 +45,9 @@ class NavLine;
class Router;
class Pedestrian {
class Pedestrian
{
private:
//generic parameters, independent from models
int _id; //starting with 1
int _exitIndex; // current exit
......@@ -85,15 +85,11 @@ private:
Point _lastPosition;
int _lastCellPosition;
/**
* A set with UniqueIDs of closed crossings,
* transitions or hlines (hlines doesnt make that much sense,
* just that they are removed from the routing graph)
*/
///state of doors with time stamps
std::map<int, NavLineState> _knownDoors;
double _DistToBlockade=0; // distance to nearest obstacle that blocks the sight of ped.
/// distance to nearest obstacle that blocks the sight of ped.
double _distToBlockade;
//routing parameters
/// new orientation after 10 seconds
double _reroutingThreshold;
......@@ -109,6 +105,8 @@ private:
std::queue <Point> _lastPositions;
/// store the last velocities
std::queue <Point> _lastVelocites;
/// routing strategy followed
RoutingStrategy _routingStrategy;
int _newOrientationDelay; //2 seconds, in steps
......@@ -183,6 +181,7 @@ public:
const Point& GetV0() const;
const Point& GetV0(const Point& target);
void InitV0(const Point& target);
/**
* the desired speed is the projection of the speed on the horizontal plane.
* @return the norm of the desired speed.
......@@ -198,12 +197,20 @@ public:
void ClearMentalMap(); // erase the peds memory
// functions for known closed Doors (needed for the Graphrouting and Rerouting)
void AddKnownClosedDoor(int door);
void AddKnownClosedDoor(int door, double time=0);//TODo: refactor and remove =0
std::set<int> GetKnownClosedDoors();
void MergeKnownClosedDoors(std::map<int, NavLineState> * input);
std::map<int, NavLineState> * GetKnownDoors();
int DoorKnowledgeCount() const;
// needed for information sharing
const std::map<int, NavLineState>& GetKnownledge() const;
/**
* clear all information related to the knowledge about closed doors
*/
void ClearKnowledge();
RoutingStrategy GetRoutingStrategy() const;
int GetUniqueRoomID() const;
int GetNextDestination();
int GetLastDestination();
......
......@@ -296,7 +296,7 @@ bool GlobalRouter::Init(Building* building)
if (nav1->operator ==(*nav2))
continue;
if (building->ped_is_visible(nav1->GetCentre(), nav2->GetCentre(), true)) {
if (building->IsVisible(nav1->GetCentre(), nav2->GetCentre(), true)) {
int to_door = _map_id_to_index[nav2->GetUniqueID()];
_distMatrix[from_door][to_door] = penalty*(nav1->GetCentre()
- nav2->GetCentre()).Norm();
......
......@@ -69,7 +69,7 @@ void RoutingEngine::AddRouter(Router* router)
_routersCollection.push_back(router);
}
const vector<string> RoutingEngine::GetTrip(int index) const
const vector<string>& RoutingEngine::GetTrip(int index) const
{
if ((index >= 0) && (index < (int) _tripsCollection.size()))
return _tripsCollection[index];
......@@ -82,23 +82,31 @@ const vector<string> RoutingEngine::GetTrip(int index) const
}
}
const std::vector<Router*> RoutingEngine::GetAvailableRouters() const
{
return _routersCollection;
}
Router* RoutingEngine::GetRouter(RoutingStrategy strategy) const
{
for(unsigned int r=0; r<_routersCollection.size(); r++) {
if(_routersCollection[r]->GetStrategy()==strategy)
return _routersCollection[r];
for(Router* router:_routersCollection)
{
if(router->GetStrategy()==strategy)
return router;
}
//Log->Write("ERROR: \t Could not Find any router with ID: [%d].",strategy);
//exit(EXIT_FAILURE);
Log->Write("ERROR: \t Could not Find any router with Strategy: [%d].",strategy);
return (Router*) NULL;
}
Router* RoutingEngine::GetRouter(int id) const
{
for(unsigned int r=0; r<_routersCollection.size(); r++) {
if(_routersCollection[r]->GetID()==id)
return _routersCollection[r];
for(Router* router:_routersCollection)
{
if(router->GetID()==id)
return router;
}
Log->Write("ERROR: \t Could not Find any router with ID: [%d].",id);
return (Router*) NULL;
}
......
......@@ -64,11 +64,16 @@ public:
/**
* Return a trip/route with the particular id
* FIXME referenz?
* @param id
* @return
* @param id, the trip id
* @return the corresponding trip
*/
const std::vector<std::string>& GetTrip(int id) const;
/**
* @return all available routers
*
*/
const std::vector<std::string> GetTrip(int id) const;
const std::vector<Router*> GetAvailableRouters() const;
/**
* Find the next destination using the appropriate router from
......@@ -89,6 +94,8 @@ public:
/**
* Return the router with the specified id
* TODO: Remove this method
* Should prefer etRouter(RoutingStrategy strategy)
*/
Router* GetRouter(int id) const;
......
......@@ -82,3 +82,24 @@ void NavLineState::print()
{
std::cout << open << " - "<< timeFirstSeen << " - " << timeOfInformation << std::endl;
}
void NavLineState::SetState(bool is_closed, double time)
{
_isClosed=is_closed;
_time=time;
}
bool NavLineState::GetState() const
{
return _isClosed;
}
int NavLineState::GetQuality() const
{
return _quality;
}
int NavLineState::GetTime() const
{
return _time;
}
......@@ -25,18 +25,17 @@
*
**/
#ifndef NAVLINESTATE_H_
#define NAVLINESTATE_H_
#include <time.h>
#include <iostream>
//time between a pedestrian got the information and uses the information
#define INFO_OFFSET 1.5
class NavLineState {
class NavLineState
{
public:
NavLineState();
......@@ -48,11 +47,23 @@ public:
bool mergeDoor(NavLineState & orig, double time);
void print();
void SetState(bool is_closed, double time);
bool GetState() const;
int GetQuality() const;
int GetTime() const;
private:
bool open; // aka state
int timeFirstSeen; // number of clocks till the door was seen changed the first time
int timeOfInformation; // number of clocks when i got the information. should be set to zero after a period of time is over (to
// information quality in [0..1]. 1 is very reliable information
int _quality; //
// last time the state was recorded.
int _time;
// state 0=open, 1=close
bool _isClosed;
};
#endif /* ROUTINGGRAPHSTORAGE_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