Commit a0757617 authored by Erik Andresen's avatar Erik Andresen

minor changes

parent 7a42d1a1
......@@ -228,6 +228,7 @@ set ( source_files
routing/cognitive_map/fire_mesh/FireMesh.cpp
routing/cognitive_map/fire_mesh/Knot.cpp
routing/cognitive_map/fire_mesh/FireMeshStorage.cpp
routing/cognitive_map/map_knowlegde/routeknowlegde.cpp
poly2tri/common/shapes.cpp
poly2tri/sweep/sweep_context.cpp
......@@ -270,6 +271,7 @@ set ( header_files
routing/cognitive_map/fire_mesh/FireMesh.h
routing/cognitive_map/fire_mesh/Knot.h
routing/cognitive_map/fire_mesh/FireMeshStorage.h
routing/cognitive_map/map_knowlegde/routeknowlegde.h
pedestrian/Pedestrian.h
pedestrian/PedDistributor.h
......
......@@ -62,10 +62,6 @@ CognitiveMapRouter::~CognitiveMapRouter()
}
int CognitiveMapRouter::FindExit(Pedestrian * p)
{
//check for former goal.
......@@ -83,8 +79,6 @@ int CognitiveMapRouter::FindExit(Pedestrian * p)
(*cm_storage)[p]->UpdateSubRoom();
return status;
}
//std::cout << p->GetGlobalTime() << std::endl;
......
......@@ -39,6 +39,8 @@
using namespace std;
/**
* Constructors & Destructors
*/
......@@ -47,6 +49,10 @@ CognitiveMap::CognitiveMap(const Building * building, const Pedestrian * pedestr
: building(building), pedestrian(pedestrian)
{
navigation_graph = new NavigationGraph(building);
}
CognitiveMap::~CognitiveMap()
......@@ -82,6 +88,24 @@ NavigationGraph * CognitiveMap::GetNavigationGraph() const
const GraphEdge * CognitiveMap::GetDestination()
{
SubRoom * sub_room = building->GetRoom(pedestrian->GetRoomID())->GetSubRoom(pedestrian->GetSubRoomID());
///Route Knowlegde
if (!_RKnowlegde.GetRememberedRooms().empty())
{
///Room seems to be familiar?
if (!_RKnowlegde.RoomIsFamiliar((*navigation_graph)[sub_room]))
{
/// not familiar (go back or use other tactics)
return nullptr;
}
else
{
return _RKnowlegde.NextDoorOnRoute((*navigation_graph)[sub_room]);
}
}
return nullptr;
return (*navigation_graph)[sub_room]->GetCheapestDestinationByEdges(pedestrian->GetPos());
}
......@@ -108,6 +132,15 @@ std::vector<const GraphEdge *>& CognitiveMap::GetDestinations()
return destinations;
}
void CognitiveMap::CreateRouteKnowlegde(const Pedestrian *pedestrian)
{
SubRoom * sub_room = building->GetRoom(pedestrian->GetRoomID())->GetSubRoom(pedestrian->GetSubRoomID());
NextDoorKnowlegde ndknowlegde = (*navigation_graph)[sub_room]->GetShortestPathFromHere(pedestrian->GetPos());
_RKnowlegde = RouteKnowlegde(ndknowlegde);
}
bool CognitiveMap::ChangedSubRoom() const
{
return current_subroom != building->GetRoom(pedestrian->GetRoomID())->GetSubRoom(pedestrian->GetSubRoomID());
......
......@@ -31,6 +31,7 @@
#define COGNITIVEMAP_H_
#include "NavigationGraph.h"
#include "./map_knowlegde/routeknowlegde.h"
#include <vector>
class SubRoom;
......@@ -73,6 +74,8 @@ public:
bool HadNoDestination() const;
void AddDestination(const GraphEdge *);
std::vector<const GraphEdge *> & GetDestinations();
/// Route knowlegde will be created using memory (depending on probabilites) of shortest path
void CreateRouteKnowlegde(const Pedestrian * pedestrian);
bool ChangedSubRoom() const;
void UpdateSubRoom();
......@@ -83,6 +86,8 @@ private:
const Pedestrian * const pedestrian;
const SubRoom * current_subroom = NULL;
std::vector<const GraphEdge *> destinations;
RouteKnowlegde _RKnowlegde;
};
......
......@@ -64,7 +64,6 @@ void CognitiveMapStorage::CreateCognitiveMap(CMStorageKeyType ped)
{
//todo: the possibility to have more then one creator.
cognitive_maps.insert(std::make_pair(ped, creator->CreateCognitiveMap(ped)));
//debug
//cognitive_maps[ped]->GetNavigationGraph()->WriteToDotFile(building->GetProjectRootDir());
......
......@@ -71,5 +71,9 @@ CognitiveMap * CompleteCognitiveMapCreator::CreateCognitiveMap(const Pedestrian
cm->Add(itr_trans.second);
}
}
///RouteKnowlegde
/// Remembered routes and assoziations between rooms and doors
cm->CreateRouteKnowlegde(ped);
return cm;
}
#include "FireMeshStorage.h"
#include "../../../geometry/Building.h"
FireMeshStorage::FireMeshStorage(const Building * const b, const std::string &filepath, const double &updateintervall, const double &finalTime)
{
_building=b;
......
......@@ -2,12 +2,16 @@
#define FIREMESHSTORAGE_H
#include <unordered_map>
#include <vector>
#include "FireMesh.h"
#include "../../../geometry/Building.h"
class Building;
class Point;
class Crossing;
// Container to store all fireMeshs. Sorted first by coordinates of the corresponding door, secondly by simulation's global time
using fireMeshContainer = std::unordered_map<std::string,FireMesh>;
using fireMeshContainer = std::unordered_map<std::string, FireMesh>;
class FireMeshStorage
{
......
......@@ -153,33 +153,6 @@ const Crossing * GraphEdge::GetCrossing() const
return _crossing;
}
//const FireMesh *GraphEdge::GetFireMesh() const
//{
// return _fireMesh;
//}
//void GraphEdge::SetUpFireMesh()
//{
// //TODO: read this prefix from the ini file
// // std::string filename = "D:/workspace/JuPedSim/jpscore/inputfiles/cognitive_map";
// std::string prefix = "D:/workspace/JPS/JPScore/inputfiles/cognitive_map";
// std::string filename = prefix + "/Door_X_" + std::to_string(_crossing->GetCentre().GetX())
// + "_Y_" + std::to_string(_crossing->GetCentre().GetY()) + ".csv";
// _fireMesh.SetKnotValuesFromFile(filename);
//}
//double GraphEdge::GetSmokeFactor(const Point &pointPed) const
//{ //std::cout << pointPed.GetX() << " " << pointPed.GetY() << std::endl;
// if (_fireMesh.statusMesh()==true)
// return _fireMesh.GetKnotValue(pointPed.GetX(),pointPed.GetY());
// else
// return 1.0;
//}
bool GraphEdge::IsExit() const
{
return _crossing->IsExit();
......
......@@ -62,11 +62,6 @@ public:
const GraphVertex * GetSrc() const;
const Crossing * GetCrossing() const;
///FireMesh
//const FireMesh * GetFireMesh() const;
//void SetUpFireMesh();
//double GetSmokeFactor(const Point &pointPed) const;
double GetApproximateDistance() const;
double GetApproximateDistance(const Point &) const;
void SetFactor(double factor, std::string name);
......@@ -80,7 +75,6 @@ private:
const GraphVertex * const _src;
const GraphVertex * const _dest;
const Crossing * const _crossing;
//FireMesh * _fireMesh;
/**
* Factor Bag
......
......@@ -209,6 +209,7 @@ const GraphEdge * GraphVertex::GetCheapestDestinationByEdges(const Point & posit
//did we found an exits?
if(exit_edge != NULL) {
const GraphEdge * act_edge = destinations[exit_edge].first;
if(act_edge == NULL) {
return exit_edge;
} else {
......@@ -256,5 +257,86 @@ const GraphEdge * GraphVertex::GetLocalCheapestDestination(const Point & positio
return act_edge;
}
}
NextDoorKnowlegde GraphVertex::GetShortestPathFromHere(const Point &position) const
{
std::set<const GraphEdge *> visited;
// map with GrapEdges and their predecessors and distances
std::map<const GraphEdge *, std::pair<const GraphEdge *, double> > destinations;
// priority queue with discovered Edges and their distance.
std::priority_queue<
std::pair<double, const GraphEdge *>,
vector<std::pair<double, const GraphEdge *> >,
std::greater<std::pair<double, const GraphEdge *> >
> queue;
const GraphEdge * exit_edge = nullptr;
// add all out edges from this vertex to priority queue and destinations.
for(EdgesContainer::const_iterator it = this->GetAllOutEdges()->begin(); it != this->GetAllOutEdges()->end(); ++it) {
double new_distance = (*it)->GetWeight(position);
destinations[(*it)] = std::make_pair((const GraphEdge*) nullptr, new_distance);
queue.push(std::make_pair(new_distance, (*it)));
}
while(!queue.empty()) {
const GraphEdge * act_edge = queue.top().second;
double act_distance = queue.top().first;
queue.pop();
//if we discovered an exit edge we are finished (queue is distance ordered)
if(act_edge->IsExit()) {
exit_edge = act_edge;
break;
}
//discover new edges or shorter paths to old edges
const EdgesContainer * new_edges = act_edge->GetDest()->GetAllOutEdges();
for(EdgesContainer::const_iterator it = new_edges->begin(); it != new_edges->end(); ++it) {
// if the destination edges was visited we already have the shortest path to this destination.
if(visited.find((*it)) != visited.end() || (*it)->GetDest() == act_edge->GetSrc()) continue;
double new_distance = act_distance + (*it)->GetWeight(act_edge->GetCrossing()->GetCentre());
//check if the destination edge was discovered before.
if(destinations.find((*it)) == destinations.end()) {
//initialize the new discovered vertex with distance inifity and push it to the queue
destinations[(*it)] = std::make_pair<const GraphEdge*, double>(nullptr, INFINITY);
queue.push(std::make_pair(new_distance, (*it)));
}
//check if we found a shorter path to the dest vertex
if(destinations[(*it)].second > new_distance) {
destinations[(*it)].second = new_distance;
destinations[(*it)].first = act_edge;
}
}
visited.insert(act_edge);
}
//did we found an exits?
NextDoorKnowlegde rknowlegde;
if(exit_edge != nullptr) {
rknowlegde.emplace(exit_edge->GetSrc(),exit_edge);
const GraphEdge * act_edge = destinations[exit_edge].first;
if(act_edge == nullptr) {
return rknowlegde;
} else {
while(this != act_edge->GetSrc()) {
rknowlegde.emplace(act_edge->GetSrc(),act_edge);
act_edge = destinations[act_edge].first;
}
return rknowlegde;
}
} else {
return rknowlegde;
}
}
......@@ -42,6 +42,10 @@ class NavLine;
class Crossing;
class Transition;
class GraphEdge;
class GraphVertex;
using NextDoorKnowlegde = std::unordered_map<const GraphVertex *,const GraphEdge *>;
/**
* @brief Graph Vertex.
......@@ -51,6 +55,7 @@ class GraphVertex {
public:
typedef std::set<GraphEdge *> EdgesContainer;
/****************************
* Constructors & Destructors
****************************/
......@@ -80,6 +85,9 @@ public:
const GraphEdge * GetCheapestDestinationByEdges(const Point & position) const;
const GraphEdge * GetLocalCheapestDestination(const Point & position) const;
NextDoorKnowlegde GetShortestPathFromHere(const Point & position) const;
private:
// edges wich are "known" from this vertex
......
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