Commit c65ee1fe authored by Ulrich Kemloh's avatar Ulrich Kemloh

Information sharing usable

Cleaning unused Graphrouter
parent 1f604271
......@@ -580,7 +580,7 @@ void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building)
char tmp1[CLENGTH] = "";
double color=ped->GetColor();
int color=ped->GetColor();
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
......
......@@ -45,13 +45,12 @@
#include "routing/QuickestPathRouter.h"
#include "routing/DirectionStrategy.h"
#include "routing/DummyRouter.h"
#include "routing/GraphRouter.h"
#include "routing/MeshRouter.h"
#include "routing/RoutingEngine.h"
#include "routing/SafestPathRouter.h"
#include "pedestrian/PedDistributor.h"
#include "routing/CognitiveMapRouter.h"
#include "events/EventManager.h" //neuer Header fuer die Events
#include "events/EventManager.h"
class Simulation
{
......
......@@ -36,6 +36,7 @@
#include <math.h>
#include <stdio.h>
#include "../pedestrian/Pedestrian.h"
#include "../pedestrian/Knowledge.h"
#include "../mpi/LCGrid.h"
#include "../geometry/Building.h"
#include "../geometry/SubRoom.h"
......@@ -45,10 +46,8 @@
#include "../IO/OutputHandler.h"
#include "../IO/IODispatcher.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
#include "../routing/GlobalRouter.h"
#include "../routing/QuickestPathRouter.h"
#include "../routing/GraphRouter.h"
#include "../routing/MeshRouter.h"
#include "../routing/DummyRouter.h"
#include "../routing/SafestPathRouter.h"
......@@ -193,7 +192,7 @@ void EventManager::ReadEventsTxt(double time)
bool EventManager::UpdateAgentKnowledge(Building* _b)
{
//#pragma omp parallel
#pragma omp parallel
for(auto&& ped:_b->GetAllPedestrians())
{
for (auto&& door: _b->GetAllTransitions())
......@@ -304,10 +303,9 @@ bool EventManager::UpdateRoute(Pedestrian* ped)
void EventManager::MergeKnowledge(Pedestrian* p1, Pedestrian* p2)
{
const map<int, NavLineState>& old_info1=p1->GetKnownledge();
const map<int, NavLineState>& old_info2=p2->GetKnownledge();
map<int, NavLineState> merge_info;
//map<int, double> merge_info;
auto const & old_info1=p1->GetKnownledge();
auto const & old_info2=p2->GetKnownledge();
map<int, Knowledge> merge_info;
//collect the most recent knowledge
for (auto&& info1 : old_info1)
......@@ -639,10 +637,6 @@ Router * EventManager::CreateRouter(const RoutingStrategy& strategy)
rout = new QuickestPathRouter(ROUTING_QUICKEST, ROUTING_QUICKEST);
break;
case ROUTING_DYNAMIC:
rout = new GraphRouter(ROUTING_DYNAMIC, ROUTING_DYNAMIC);
break;
case ROUTING_NAV_MESH:
rout = new MeshRouter(ROUTING_NAV_MESH, ROUTING_NAV_MESH);
break;
......
......@@ -51,7 +51,6 @@
#include "../pedestrian/AgentsParameters.h"
#include "../routing/GlobalRouter.h"
#include "../routing/QuickestPathRouter.h"
#include "../routing/GraphRouter.h"
#include "../routing/MeshRouter.h"
#include "../routing/DummyRouter.h"
#include "../routing/SafestPathRouter.h"
......@@ -760,11 +759,6 @@ bool ArgumentParser::ParseRoutingStrategies(TiXmlNode *routingNode)
Router *r = new QuickestPathRouter(id, ROUTING_QUICKEST);
p_routingengine->AddRouter(r);
}
else if (strategy == "dynamic") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_DYNAMIC));
Router *r = new GraphRouter(id, ROUTING_DYNAMIC);
p_routingengine->AddRouter(r);
}
else if (strategy == "nav_mesh") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_NAV_MESH));
Router *r = new MeshRouter(id, ROUTING_NAV_MESH);
......
......@@ -107,7 +107,6 @@ enum RoutingStrategy {
ROUTING_LOCAL_SHORTEST=1,
ROUTING_GLOBAL_SHORTEST,
ROUTING_QUICKEST,
ROUTING_DYNAMIC,
ROUTING_FROM_FILE,
ROUTING_NAV_MESH,
ROUTING_DUMMY,
......
......@@ -152,7 +152,7 @@ void LCGrid::ClearGrid()
void LCGrid::HighlightNeighborhood(int pedID, Building* building)
{
// force spotlight activation
Pedestrian::ActivateSpotlightSystem(true);
Pedestrian::SetColorMode(BY_SPOTLIGHT);
//darken all
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++){
......
/**
* \file RoutingGraphStorage.h
* \date Sep 10, 2012
* \file Knowledge.cpp
* \date Sep 18, 2012
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
......@@ -26,37 +26,45 @@
**/
#ifndef ROUTINGGRAPHSTORAGE_H_
#define ROUTINGGRAPHSTORAGE_H_
#include "Knowledge.h"
#include "../IO/OutputHandler.h"
extern OutputHandler* Log;
#include "RoutingGraph.h"
#include <map>
#include <set>
Knowledge::Knowledge()
{
_isClosed = false;
_time = 0;
_quality=1;
_id=-1;
}
Knowledge::~Knowledge()
{
}
class RoutingGraphStorage {
void Knowledge::Dump()
{
Log->Write("INFO: \tdoor [%d] state [%d] since [%f]",_id,_isClosed,_time);
}
public:
RoutingGraphStorage();
~RoutingGraphStorage();
void init(Building * b);
RoutingGraph * GetGraph(std::set<int> closed_doors);
void Knowledge::SetState(int id, bool is_closed, double time)
{
_isClosed=is_closed;
_time=time;
_id=id;
}
bool Knowledge::GetState() const
{
return _isClosed;
}
double Knowledge::GetQuality() const
{
return _quality;
}
private:
std::map<std::set<int>, RoutingGraph*> graphs;
std::set<int> empty_set;
// do not use this function now
std::set<int> GetBiggestSubSet(std::set<int> iset) const;
/**
* @param iset
* @param from
*/
void GenerateNewGraph(std::set<int> iset, std::set<int> from = std::set<int>());
};
#endif /* ROUTINGGRAPHSTORAGE_H_ */
double Knowledge::GetTime() const
{
return _time;
}
/**
* \file GraphRouter.h
* \date Aug 20, 2012
* \file Knowledge.h
* \date Sep 18, 2012
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
......@@ -25,29 +25,40 @@
*
**/
#ifndef KNOWLEDGE_H_
#define KNOWLEDGE_H_
#ifndef GRAPHROUTER_H_
#define GRAPHROUTER_H_
#include <iostream>
#include "Router.h"
#include "GlobalRouter.h"
#include "graph/RoutingGraphStorage.h"
#include "../geometry/Building.h"
class GraphRouter: public GlobalRouter {
class Knowledge
{
public:
GraphRouter();
GraphRouter(int id, RoutingStrategy s);
virtual ~GraphRouter();
/**
* Constructor
*/
Knowledge();
/**
* Destructor
*/
~Knowledge();
virtual int FindExit(Pedestrian* p);
virtual bool Init(Building* b);
void Dump();
void SetState(int id, bool is_closed, double time);
bool GetState() const;
double GetQuality() const;
double GetTime() const;
private:
RoutingGraphStorage g;
Building * _building;
const std::set<int> empty_set;
/// information quality in [0..1]. 1 is very reliable information
double _quality; //
/// last time the state was recorded.
double _time;
/// state 0=open, 1=close
bool _isClosed;
/// id of the door
int _id;
};
#endif /* KNOWLEDGE_H_ */
#endif /* GRAPHROUTER_H_ */
......@@ -26,20 +26,20 @@
**/
#include "Pedestrian.h"
#include <cassert>
#include "../geometry/Building.h"
#include "../geometry/NavLine.h"
#include "../routing/Router.h"
#include "../geometry/SubRoom.h"
#include "../IO/OutputHandler.h"
#include <cassert>
#include "Knowledge.h"
#include "Pedestrian.h"
using namespace std;
/// initialize the static variables
// initialize the static variables
double Pedestrian::_globalTime = 0.0;
AgentColorMode Pedestrian::_colorMode=BY_VELOCITY;
bool Pedestrian::_enableSpotlight = false;
Pedestrian::Pedestrian()
{
......@@ -58,7 +58,7 @@ Pedestrian::Pedestrian()
_updateRate = 0;
_turninAngle = 0.0;
_ellipse = JEllipse();
_navLine = new NavLine(); //FIXME this is not released
_navLine = new NavLine();
_router = NULL;
_building = NULL;
_reroutingThreshold = 0.0; // new orientation after 10 seconds, value is incremented
......@@ -296,38 +296,8 @@ void Pedestrian::ClearMentalMap()
void Pedestrian::AddKnownClosedDoor(int door, double time)
{
// 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
{
return _knownDoors.size();
}
set<int> Pedestrian::GetKnownClosedDoors()
{
map<int, NavLineState>::iterator it;
set<int> doors_closed;
for(it = _knownDoors.begin(); it != _knownDoors.end(); it++) {
if(it->second.closed()) {
doors_closed.insert(it->first);
}
}
return doors_closed;
}
//TODO: remove
map<int, NavLineState> * Pedestrian::GetKnownDoors()
{
return & _knownDoors;
_knownDoors[door].SetState(door,true,time);
}
void Pedestrian::ClearKnowledge()
......@@ -335,7 +305,7 @@ void Pedestrian::ClearKnowledge()
_knownDoors.clear();
}
const map<int, NavLineState>& Pedestrian::GetKnownledge() const
const map<int, Knowledge>& Pedestrian::GetKnownledge() const
{
return _knownDoors;
}
......@@ -354,25 +324,6 @@ const std::string Pedestrian::GetKnowledgeAsString() const
return key;
}
void Pedestrian::MergeKnownClosedDoors( map<int, NavLineState> * input)
{
map<int, NavLineState>::iterator it;
for(it = input->begin(); it != input->end(); it++) {
//it->second.print();
if(it->second.isShareable(GetGlobalTime())) {
if(_knownDoors.find(it->first) == _knownDoors.end()) {
_knownDoors[it->first] = NavLineState();
if(!_knownDoors[it->first].mergeDoor(it->second, GetGlobalTime())) {
_knownDoors.erase(it->first);
}
} else {
_knownDoors[it->first].mergeDoor(it->second, GetGlobalTime());
}
}
}
return;
}
const Point& Pedestrian::GetPos() const
{
return _ellipse.GetCenter();
......@@ -773,7 +724,7 @@ void Pedestrian::Dump(int ID, int pa)
break;
}
fflush(stdout);
//fflush(stdout);
// getc(stdin);
}
......@@ -857,15 +808,9 @@ void Pedestrian::SetSpotlight(bool spotlight)
_spotlight = spotlight;
}
bool Pedestrian::GetSpotlight()
{
return !_enableSpotlight || _spotlight;
}
void Pedestrian::ActivateSpotlightSystem(bool status)
void Pedestrian::SetColorMode(AgentColorMode mode)
{
_enableSpotlight = status;
_colorMode=mode;
}
int Pedestrian::GetColor()
......@@ -913,7 +858,3 @@ int Pedestrian::GetColor()
return color;
}
void Pedestrian::SetColorMode(AgentColorMode mode)
{
_colorMode=mode;
}
......@@ -35,15 +35,14 @@
#include <set>
#include <time.h>
#include "../pedestrian/Ellipse.h"
#include "Ellipse.h"
#include "../general/Macros.h"
#include "../routing/graph/NavLineState.h"
#include "../geometry/NavLine.h"
class Building;
class NavLine;
class Router;
class Knowledge;
class Pedestrian
{
......@@ -86,7 +85,7 @@ private:
int _lastCellPosition;
///state of doors with time stamps
std::map<int, NavLineState> _knownDoors;
std::map<int, Knowledge> _knownDoors;
/// distance to nearest obstacle that blocks the sight of ped.
double _distToBlockade;
......@@ -120,7 +119,6 @@ private:
// the current time in the simulation
static double _globalTime;
static bool _enableSpotlight;
static AgentColorMode _colorMode;
bool _spotlight;
......@@ -198,18 +196,13 @@ public:
void ClearMentalMap(); // erase the peds memory
// functions for known closed Doors (needed for the Graphrouting and Rerouting)
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;
void AddKnownClosedDoor(int door, double time);
// needed for information sharing
const std::map<int, NavLineState>& GetKnownledge() const;
const std::map<int, Knowledge>& GetKnownledge() const;
/**
* For convenience
* Return a string representation of the knowledge
* @return
* @return a string representation of the knowledge
*/
const std::string GetKnowledgeAsString() const;
......@@ -381,11 +374,6 @@ public:
static double GetGlobalTime();
static void SetGlobalTime(double time);
/**
* activate/deactivate the spotlight system
* @param status true for activating, false for deactivating
*/
static void ActivateSpotlightSystem(bool status);
/**
* Set the color mode for the pedestrians
......
/**
* \file GraphRouter.cpp
* \date Aug 20, 2012
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* JuPedSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* \section Description
*
*
**/
#include "GraphRouter.h"
#include "../pedestrian/Pedestrian.h"
#include "../geometry/SubRoom.h"
#define J_EPS_INFO_DIST 2.0 /// [m] abstand für Informationsaustausch (GraphRouter)
using namespace std;
/******************************
* GraphGrouter Methods
*****************************/
GraphRouter::GraphRouter()
{
_building=NULL;
}
GraphRouter::GraphRouter(int id, RoutingStrategy s) : GlobalRouter(id , s)
{
_building = NULL;
}
GraphRouter::~GraphRouter()
{
}
int GraphRouter::FindExit(Pedestrian* p)
{
set<int> closed_doors = p->GetKnownClosedDoors();
if(p->GetLastDestination() == -1) {
//this is needed for initialisation
p->ChangedSubRoom();
//Set Initial Route at the beginning
// get next destination for person in subroom (in the subroom not next to a crossing)
ExitDistance ed = g.GetGraph(closed_doors)->GetNextDestination(p);
if(!ed.GetDest()) {
// std::cout << "DELETE " << p->GetPedIndex() << std::endl;
// building->DeletePedFromSim(p);
return -1;
}
p->SetExitIndex(ed.GetDest()->id);
p->SetExitLine(ed.GetDest()->nav_line);
return 1;
} else {
//the pedestrian at least had a route, now check if he needs a new one
//if the pedestrian changed the subroom he needs a new route
if(p->ChangedSubRoom()) {
ExitDistance ed = g.GetGraph(closed_doors)->GetNextDestination(p->GetLastDestination(), p);
// check if the next destination is in the right subroom
// if the routing graph changes, it could happen, that the pedestrian has to turn.
if(ed.GetSubRoom()->GetRoomID() != p->GetRoomID() || ed.GetSubRoom()->GetSubRoomID() != p->GetSubRoomID()) {
p->SetExitIndex(p->GetLastDestination());
p->SetExitLine(ed.GetSrc()->nav_line);
return 1;
}
p->SetExitIndex(ed.GetDest()->id);
p->SetExitLine(ed.GetDest()->nav_line);
return 1;
}
if(p->GetNextDestination() != -1 && !g.GetGraph(closed_doors)->GetVertex(p->GetLastDestination())) {
ExitDistance ed = g.GetGraph(closed_doors)->GetNextDestination(p);
p->SetExitIndex(ed.GetDest()->id);
p->SetExitLine(ed.GetDest()->nav_line);
}
//check if the pedestrian reached an hline
Hline * hline = dynamic_cast<Hline*>(g.GetGraph(closed_doors)->GetVertex(p->GetNextDestination())->nav_line);
if(hline) {
// check if the pedestrian is near the Line or In LIne
if(g.GetGraph(closed_doors)->GetVertex(p->GetNextDestination())->nav_line->DistTo(p->GetPos()) < J_EPS*10 || g.GetGraph(closed_doors)->GetVertex(p->GetNextDestination())->nav_line->IsInLineSegment(p->GetPos())) {
//std::cout << "new route from HLINE" << std::endl;
ExitDistance ed = g.GetGraph(closed_doors)->GetNextDestination(p->GetLastDestination(),p);
p->SetExitIndex(ed.GetDest()->id);
p->SetExitLine(ed.GetDest()->nav_line);
return 1;
}
}
Transition * transition = dynamic_cast<Transition*>(g.GetGraph(closed_doors)->GetVertex(p->GetNextDestination())->nav_line);
if(transition) {
if(!transition->IsOpen() && transition->DistTo(p->GetPos()) < 0.5) {
p->AddKnownClosedDoor(transition->GetUniqueID());
ExitDistance ed = g.GetGraph(closed_doors)->GetNextDestination(p);
//std::cout << p->GetPedIndex() << " -- " << ed.GetDest()->id << std::endl;
p->SetExitIndex(ed.GetDest()->id);
p->SetExitLine(ed.GetDest()->nav_line);
}
}
// share Information about closed Doors
#pragma omp critical
if(p->DoorKnowledgeCount() != 0) {
vector<Pedestrian*> ps;
_building->GetPedestrians(p->GetRoomID(),p->GetSubRoomID(),ps);
for(unsigned int i = 0; i < ps.size(); i++) {
if((p->GetPos() - ps[i]->GetPos()).Norm() < J_EPS_INFO_DIST) {
if(ps[i]->GetKnownClosedDoors() != closed_doors) {
ps[i]->MergeKnownClosedDoors(p->GetKnownDoors());
//maybe the other pedestrian needs a new route
ExitDistance ed = g.GetGraph(ps[i]->GetKnownClosedDoors())->GetNextDestination(ps[i]);
if(!ed.GetDest()) {
std::cout << "DELETE " << ps[i]->GetID() << std::endl;
_building->DeletePedestrian(ps[i]);
} else {
// FIXME: ps[i] changedsubroom has to be called to avoid to give a new route twice!
// sometimes the outher pedestrian changed the subroom and gets a new route here. after this he is looking for a new route but there is no need for.
ps[i]->ChangedSubRoom();
ps[i]->SetExitIndex(ed.GetDest()->id);
ps[i]->SetExitLine(ed.GetDest()->nav_line);
}
}
}
}
}
return 1;
}
}
bool GraphRouter::Init(Building* b)
{
if(GlobalRouter::Init(b)==false)
return false;
Log->Write("ERROR: GRAPHROUTER is not ready to use yet.");
_building = b;
g.init(b);
//std::cout << b->GetTransition("200E Normal Exit E3")->IsOpen() << std::endl;
// b->GetTransition("200E Normal Exit E3")->Close();
//std::cout << b->GetTransition("200E Normal Exit E3")->IsOpen() << std::endl;
return true;
}
......@@ -132,7 +132,6 @@ public:
*/
virtual bool Init(Building* b) = 0;
};
#endif /* _ROUTING_H */
......
/**
* \file NAvLineState.cpp
* \date Sep 18, 2012
* \version v0.6
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* JuPedSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* \section Description
*
*
**/
#include "NavLineState.h"
NavLineState::NavLineState()
{
open = true;
timeOfInformation = 0;
timeFirstSeen = 0;
}
NavLineState::~NavLineState()
{
}
void NavLineState::close(double time)
{
open = false;
timeOfInformation = time;
timeFirstSeen = time;
}
bool NavLineState::closed()
{
return !open;
}
bool NavLineState::isShareable(double time)
{
if(!timeOfInformation) return true;
if(timeOfInformation+INFO_OFFSET < time) {
timeOfInformation = 0;
return true;
}
return false;
}
bool NavLineState::mergeDoor(NavLineState & orig, double time)
{
if(timeFirstSeen == 0 || orig.timeFirstSeen > timeFirstSeen) {
open = orig.open;
timeFirstSeen = orig.timeFirstSeen;
timeOfInformation = time;
return true;
}
return false;
}
void NavLineState::print()
{