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

Now can read waiting area, which are stored as graphs. Next goal is calculated...

Now can read waiting area, which are stored as graphs. Next goal is calculated due to the given probability.
parent fa697110
......@@ -378,7 +378,7 @@ events/EventManager.cpp
events/Event.cpp
forms/jpscore.rc
math/KrauszModel.cpp)
math/KrauszModel.cpp IO/Trips.cpp IO/Trips.h)
set(THIRD_PARTY_SRC
tinyxml/tinystr.cpp
......
......@@ -24,6 +24,9 @@
#include "../geometry/SubRoom.h"
#include "../geometry/WaitingArea.h"
GeoFileParser::GeoFileParser(Configuration* configuration)
:_configuration(configuration)
{
......@@ -361,10 +364,13 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
return true; // no extra routing information
}
//load goals and routes
TiXmlNode* xGoalsNode = xRootNode->FirstChild("routing")->FirstChild("goals");
if (xGoalsNode) {
Trips trips;
for (TiXmlElement* e = xGoalsNode->FirstChildElement("goal"); e;
e = e->NextSiblingElement("goal")) {
......@@ -399,6 +405,8 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
building->AddGoal(goal);
_configuration->GetRoutingEngine()->AddFinalDestinationID(goal->GetId());
trips.addGoal(goal->GetId());
}
......@@ -425,20 +433,27 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
std::map<int, double> nextGoals;
trips.addGoal(wa->GetId());
//looking for next_wa
for (TiXmlElement* nextWa = e->FirstChildElement("next_wa"); nextWa;
nextWa = nextWa->NextSiblingElement("next_wa")) {
int nextWaId = xmltoi(nextWa->Attribute("id"));
double nextWaP = xmltof(nextWa->Attribute("p"));
std::cout << "nextWaID=" << nextWaId << ", nextWaP=" << nextWaP << std::endl;
EdgeProperty weight = EdgeProperty(-1, nextWaP);
trips.addGoal(nextWaId);
trips.addConnection(wa->GetId(), nextWaId, weight);
nextGoals.insert(std::pair<int, double>(nextWaId, nextWaP));
}
if (!waitingArea->setNextGoals(nextGoals)){
std::cout << "wa setNextGoals!";
return false;
};
//looking for polygons (walls)
for (TiXmlElement* xPolyVertices = e->FirstChildElement("polygon"); xPolyVertices;
xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {
......@@ -457,6 +472,7 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
}
if (!wa->ConvertLineToPoly()){
std::cout << "wa convertLineToPoly!";
return false;
}
......@@ -464,28 +480,10 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
_configuration->GetRoutingEngine()->AddFinalDestinationID(wa->GetId());
std::cout << waitingArea->toString() << std::endl;
}
// Save all saved goals in a vector
std::map<int, Goal*> allGoalsMap(building->GetAllGoals());
std::vector<Goal*> allGoals;
for(auto goal : allGoalsMap) {
allGoals.push_back(goal.second);
}
for (auto goal : allGoals){
// Check if current goal is a WaitingArea
if(WaitingArea* wa = dynamic_cast<WaitingArea*>(goal)) {
}
}
// for (auto const& goals : building->GetAllGoals()){
//
// }
std::cout << trips;
}
//load routes
......
......@@ -25,6 +25,7 @@
#include "../general/Configuration.h"
#include "../geometry/Building.h"
#include "../geometry/GeometryReader.h"
#include "Trips.h"
//TODO: the class name GeoFileParser is misleading as the ``geometry'' file contains among others also relations (transitions)
//TODO: between geometries/rooms. Probably, EnvironmentFileParser would be better, still parts of the environment are
......@@ -45,6 +46,10 @@ private:
bool LoadGeometry(Building* building);
bool LoadRoutingInfo(Building* filename);
bool ReadGoal();
bool ReadWaitingArea();
};
#endif //JPSCORE_GEOFILEPARSER_H
//
// Created by Tobias Schrödter on 23.11.18.
//
#include "Trips.h"
//#include <random>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
std::ostream& operator<<(std::ostream& os, const Trips& trips)
{
for (auto v : boost::make_iterator_range(boost::vertices(trips.trips))){
os << "Vertex " << v << " " << trips.trips[v] << "\n";
}
for (auto e : boost::make_iterator_range(boost::edges(trips.trips))){
os << "Edge " << e << " " << trips.trips[e] << "\n";
}
return os;
}
void Trips::addGoal(int id)
{
VertexItr vi, vi_end;
boost::tie(vi, vi_end) = boost::vertices(trips);
vi = getGoal(id);
// check if goal with id already exists
if (vi == vi_end) {
boost::add_vertex(VertexProperty{id}, trips);
return;
}
}
VertexItr Trips::getGoal(int id)
{
VertexItr vi, vi_end;
for (boost::tie(vi, vi_end) = boost::vertices(trips); vi != vi_end; ++vi) {
if(trips[*vi].getID() == id) return vi;
}
return vi_end;}
void Trips::addConnection(int sourceId, int destinationId, EdgeProperty& weight)
{
VertexItr vSource, vDestination, vEnd;
boost::tie(vSource, vEnd) = boost::vertices(trips);
// Check if vertex with sourceId exists, if not add it
vSource = getGoal(sourceId);
if (vSource == vEnd){
addGoal(sourceId);
}
// Check if vertex with destinationId exists, if not add it
boost::tie(vSource, vEnd) = boost::vertices(trips);
vDestination = getGoal(destinationId);
if (vDestination == vEnd){
addGoal(destinationId);
}
// Get updated iterator to source and destination, needed if one vertex had to be added
vSource = getGoal(sourceId);
vDestination = getGoal(destinationId);
// Finally add the edge
boost::add_edge(*vSource, *vDestination, weight, trips);
}
int Trips::getNextGoal(int id)
{
VertexItr vCurrent = getGoal(id);
VertexItr vEnd = boost::vertices(trips).second;
// Check if edge exists, if not there is no next goal (should never happen, check the ini file)
if (vCurrent == vEnd){
return -1;
}
// Create vector with possible targets and correspondig weights
std::vector<double> weights;
std::vector<long> targets;
for (auto e : boost::make_iterator_range(boost::out_edges(*vCurrent, trips))){
weights.push_back(trips[e].getProbabilty());
targets.push_back(e.m_target);
}
// Random number generator
// std::random_device rd;
// std::mt19937 gen(rd());
//
// std::default_random_engine generator;
// std::discrete_distribution<double> distribution (weights.begin(), weights.end());
boost::mt19937 gen;
boost::random::discrete_distribution<> dist(weights.begin(), weights.end());
// Map random number to target
return targets[(int)dist(gen)];
}
\ No newline at end of file
//
// Created by Tobias Schrödter on 23.11.18.
//
#ifndef JPSCORE_TRIPS_H
#define JPSCORE_TRIPS_H
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <ostream>
#include <vector>
class VertexProperty {
public:
VertexProperty(): id(-1){}
VertexProperty(int pId ) : id(pId) { }
std::string toString() const {
std::ostringstream oss;
oss << *this;
return oss.str();
}
int getID() { return id; }
private:
friend std::ostream& operator<<(std::ostream& os, VertexProperty const& v) {
return os << "id " << v.id;
}
int id;
};
class EdgeProperty {
public:
EdgeProperty(): distance(-1.), probability(-1.){}
EdgeProperty(double pDistance, double pProbability) : distance(pDistance), probability(pProbability) {
distance = pDistance;
probability = pProbability;
}
double getProbabilty() { return probability; }
double getDistance() { return distance; }
std::string toString() const {
std::ostringstream oss;
oss << *this;
return oss.str();
}
private:
friend std::ostream& operator<<(std::ostream& os, EdgeProperty const& e) {
return os << "distance " << e.distance << " probability=" << std::fixed << e.probability;
}
double distance;
double probability;
};
using DirectedGraph = boost::adjacency_list<
boost::vecS,
boost::vecS,
boost::directedS,
VertexProperty,
EdgeProperty> ;
using VertexItr = boost::graph_traits<DirectedGraph>::vertex_iterator; // Define Vertex iterator
using EdgeItr = boost::graph_traits<DirectedGraph>::edge_iterator; // Define Edge iterator
class Trips {
private:
DirectedGraph trips;
public:
void addGoal(int id);
friend std::ostream& operator<<(std::ostream& os, const Trips& trips);
void addConnection(int sourceId, int destinationId, EdgeProperty& weight);
VertexItr getGoal(int id);
std::vector<int>& getConnections(int id);
int getNextGoal(int id);
};
#endif //JPSCORE_TRIPS_H
\ No newline at end of file
......@@ -34,23 +34,11 @@
#include <vector>
#include "../general/Macros.h"
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include "../IO/Trips.h"
class Building;
class Pedestrian;
typedef boost::property<boost::edge_weight_t, double> EdgeWeightGoal;
/*
adjacency_list<OutEdgeList, VertexList, Directed,
VertexProperties, EdgeProperties,
GraphProperties, EdgeList>
*/
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeWeightGoal> Graph_Goal;
class Router {
/** @defgroup Router
* Collection of different router classes
......@@ -69,7 +57,7 @@ private:
protected:
/// Contain the ids of the intermediate destinations
Graph_Goal _trips;
Trips _trips;
/// All final destinations of the pedestrians
std::vector<int> _finalDestinations;
......
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