Commit 138e6066 authored by tobias schroedter's avatar tobias schroedter

WIP Commit, needs to clean up CMakeLists.txt

parent 5b35dc65
This diff is collapsed.
......@@ -482,34 +482,36 @@ bool GeoFileParser::LoadRoutingInfo(Building* building)
std::cout << waitingArea->toString() << std::endl;
}
// building->AddTrip(trips);
_configuration->GetRoutingEngine()->AddTrip(trips);
std::cout << trips;
}
//load routes
TiXmlNode* xTripsNode = xRootNode->FirstChild("routing")->FirstChild("routes");
if (xTripsNode)
for (TiXmlElement* trip = xTripsNode->FirstChildElement("route"); trip;
trip = trip->NextSiblingElement("route")) {
double id = xmltof(trip->Attribute("id"), -1);
if (id==-1) {
Log->Write("ERROR:\t id missing for trip");
return false;
}
std::string sTrip = trip->FirstChild()->ValueStr();
std::vector<std::string> vTrip;
vTrip.clear();
char* str = (char*) sTrip.c_str();
char* p = strtok(str, ":");
while (p) {
vTrip.push_back(xmltoa(p));
p = strtok(NULL, ":");
}
_configuration->GetRoutingEngine()->AddTrip(vTrip);
}
// TiXmlNode* xTripsNode = xRootNode->FirstChild("routing")->FirstChild("routes");
//
// if (xTripsNode)
// for (TiXmlElement* trip = xTripsNode->FirstChildElement("route"); trip;
// trip = trip->NextSiblingElement("route")) {
//
// double id = xmltof(trip->Attribute("id"), -1);
// if (id==-1) {
// Log->Write("ERROR:\t id missing for trip");
// return false;
// }
// std::string sTrip = trip->FirstChild()->ValueStr();
// std::vector<std::string> vTrip;
// vTrip.clear();
//
// char* str = (char*) sTrip.c_str();
// char* p = strtok(str, ":");
// while (p) {
// vTrip.push_back(xmltoa(p));
// p = strtok(NULL, ":");
// }
// _configuration->GetRoutingEngine()->AddTrip(vTrip);
// }
Log->Write("INFO:\tdone with loading extra routing information");
return true;
}
......
......@@ -25,7 +25,7 @@
#include "../general/Configuration.h"
#include "../geometry/Building.h"
#include "../geometry/GeometryReader.h"
#include "Trips.h"
#include "../geometry/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
......
......@@ -40,10 +40,13 @@
#include "../math/GradientModel.h"
#include "../math/VelocityModel.h"
#include "../routing/global_shortest/GlobalRouter.h"
#include "../routing/global_shortest_trips/GlobalRouterTrips.h"
#include "../routing/quickest/QuickestPathRouter.h"
#include "../routing/smoke_router/SmokeRouter.h"
#include "../routing/ai_router/AIRouter.h"
#include "../routing/ff_router/ffRouter.h"
#include "../routing/ff_router_trips/ffRouterTrips.h"
#include "../routing/trips_router/TripsRouter.h"
/* https://stackoverflow.com/questions/38530981/output-compiler-version-in-a-c-program#38531037 */
std::string ver_string(int a, int b, int c) {
......@@ -1134,6 +1137,13 @@ bool IniFileParser::ParseRoutingStrategies(TiXmlNode* routingNode, TiXmlNode* ag
Router *r = new GlobalRouter(id, ROUTING_GLOBAL_SHORTEST);
_config->GetRoutingEngine()->AddRouter(r);
}
else if ((strategy == "global_shortest_trips") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_GLOBAL_SHORTEST));
Router *r = new GlobalRouterTrips(id, ROUTING_GLOBAL_SHORTEST);
_config->GetRoutingEngine()->AddRouter(r);
}
else if ((strategy == "quickest") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_QUICKEST));
......@@ -1169,14 +1179,30 @@ bool IniFileParser::ParseRoutingStrategies(TiXmlNode* routingNode, TiXmlNode* ag
exit(EXIT_FAILURE);
#endif
}
else if ((strategy == "ff_global_shortest") &&
else if ((strategy == "AI_trips") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
#ifdef AIROUTER
Router *r = new AIRouterTrips(id, ROUTING_AI_TRIPS);
_config->GetRoutingEngine()->AddRouter(r);
Log->Write("\nINFO: \tUsing AIRouter Trips");
///Parsing additional options
if (!ParseAIOpts(e))
return false;
#else
std::cerr << "\nCan not use AI Router. Rerun cmake with option -DAIROUTER=true and recompile.\n";
exit(EXIT_FAILURE);
#endif
}
else if ((strategy == "ff_global_shortest_trips") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_FF_GLOBAL_SHORTEST));
Router *r = new FFRouter(id, ROUTING_FF_GLOBAL_SHORTEST, hasSpecificGoals, _config);
Router *r = new FFRouterTrips(id, ROUTING_FF_GLOBAL_SHORTEST, hasSpecificGoals, _config);
_config->GetRoutingEngine()->AddRouter(r);
if ((_exit_strat_number == 8) || (_exit_strat_number == 9)){
Log->Write("\nINFO: \tUsing FF Global Shortest Router");
Log->Write("\nINFO: \tUsing FF Global Shortest Router Trips");
}
else {
Log->Write("\nWARNING: \tExit Strategy Number is not 8 or 9!!!");
......@@ -1188,6 +1214,26 @@ bool IniFileParser::ParseRoutingStrategies(TiXmlNode* routingNode, TiXmlNode* ag
return false;
}
}
else if ((strategy == "ff_global_shortest") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_FF_GLOBAL_SHORTEST));
Router *r = new FFRouter(id, ROUTING_FF_GLOBAL_SHORTEST, hasSpecificGoals, _config);
_config->GetRoutingEngine()->AddRouter(r);
if ((_exit_strat_number == 8) || (_exit_strat_number == 9)){
Log->Write("\nINFO: \tUsing FF Global Shortest Router");
}
else {
Log->Write("\nWARNING: \tExit Strategy Number is not 8 or 9!!!");
// config object holds default values, so we omit any set operations
}
///Parsing additional options
if (!ParseFfRouterOps(e, ROUTING_FF_GLOBAL_SHORTEST)) {
return false;
}
}
else if ((strategy == "ff_local_shortest") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
//pRoutingStrategies.push_back(make_pair(id, ROUTING_FF_GLOBAL_SHORTEST));
......@@ -1221,6 +1267,12 @@ bool IniFileParser::ParseRoutingStrategies(TiXmlNode* routingNode, TiXmlNode* ag
return false;
}
}
else if ((strategy == "trips") &&
(std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) ) {
Router *r = new TripsRouter(id, ROUTING_TRIPS, _config);
_config->GetRoutingEngine()->AddRouter(r);
}
else if (std::find(usedRouter.begin(), usedRouter.end(), id) != usedRouter.end()) {
Log->Write("ERROR: \twrong value for routing strategy [%s]!!!\n",
strategy.c_str());
......
......@@ -299,6 +299,12 @@ void Simulation::UpdateRoutesAndLocations()
const map<int, Goal*>& goals = _building->GetAllGoals();
auto allRooms = _building->GetAllRooms();
// for (signed int p = 0; p < allPeds.size(); ++p) {
// Pedestrian* ped = allPeds[p];
//
// std::cout << "FinalDestination of [" << ped->GetID() << "] in (" << ped->GetRoomID() << ", " << ped->GetSubRoomID() << "/" << ped->GetSubRoomUID() << "): " << ped->GetFinalDestination() << std::endl;
// }
#pragma omp parallel for shared(pedsToRemove, allRooms)
for (signed int p = 0; p < allPeds.size(); ++p) {
auto ped = allPeds[p];
......@@ -307,8 +313,7 @@ void Simulation::UpdateRoutesAndLocations()
//set the new room if needed
if ((ped->GetFinalDestination() == FINAL_DEST_OUT)
&& (room->GetCaption() == "outside")) {
&& (room->GetCaption() == "outside")) { //TODO Hier aendern fuer inside goals?
#pragma omp critical(Simulation_Update_pedsToRemove)
pedsToRemove.insert(ped);
} else if ((ped->GetFinalDestination() != FINAL_DEST_OUT)
......
......@@ -41,6 +41,7 @@
#include "math/OperationalModel.h"
#include "math/ODESolver.h"
#include "routing/global_shortest/GlobalRouter.h"
#include "routing/global_shortest_trips/GlobalRouterTrips.h"
#include "routing/quickest/QuickestPathRouter.h"
#include "routing/DirectionStrategy.h"
#include "routing/RoutingEngine.h"
......
......@@ -43,6 +43,7 @@
#include "ArgumentParser.h"
#include "../pedestrian/AgentsParameters.h"
#include "../routing/global_shortest/GlobalRouter.h"
#include "../routing/global_shortest_trips/GlobalRouterTrips.h"
#include "../routing/quickest/QuickestPathRouter.h"
#include "../routing/smoke_router/SmokeRouter.h"
#include "../IO/IniFileParser.h"
......
......@@ -128,10 +128,12 @@ enum RoutingStrategy {
ROUTING_FROM_FILE,
ROUTING_SMOKE,
ROUTING_AI,
ROUTING_AI_TRIPS,
ROUTING_FLOORFIELD,
ROUTING_FF_GLOBAL_SHORTEST,
ROUTING_FF_LOCAL_SHORTEST,
ROUTING_FF_QUICKEST,
ROUTING_TRIPS,
ROUTING_UNDEFINED =-1
};
......
......@@ -3,7 +3,6 @@
//
#include "Trips.h"
//#include <random>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/discrete_distribution.hpp>
......@@ -39,7 +38,8 @@ VertexItr Trips::getGoal(int id)
for (boost::tie(vi, vi_end) = boost::vertices(trips); vi != vi_end; ++vi) {
if(trips[*vi].getID() == id) return vi;
}
return vi_end;}
return vi_end;
}
void Trips::addConnection(int sourceId, int destinationId, EdgeProperty& weight)
{
......@@ -87,12 +87,6 @@ int Trips::getNextGoal(int id)
}
// 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());
......
......@@ -94,3 +94,7 @@ RoutingStrategy Router::GetStrategy() const
return _strategy;
}
void Router::SetTrips(const Trips& trips){
_trips = trips;
std::cout << _trips << std::endl;
}
......@@ -34,7 +34,7 @@
#include <vector>
#include "../general/Macros.h"
#include "../IO/Trips.h"
#include "../geometry/Trips.h"
class Building;
class Pedestrian;
......@@ -140,6 +140,8 @@ public:
*/
virtual bool ParseAdditionalParameters(){return true;};
void SetTrips(const Trips& trips);
};
#endif /* _ROUTING_H */
......@@ -28,6 +28,7 @@
#include "RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
#include "../geometry/Trips.h"
using namespace std;
......@@ -68,19 +69,19 @@ void RoutingEngine::AddRouter(Router* router)
}
_routersCollection.push_back(router);
}
const vector<string>& RoutingEngine::GetTrip(int index) const
{
if ((index >= 0) && (index < (int) _tripsCollection.size()))
return _tripsCollection[index];
else {
char tmp[CLENGTH];
sprintf(tmp, "ERROR: \tWrong 'index' [%d] > [%d] in Routing::GetTrip()",
index, int(_tripsCollection.size()));
Log->Write(tmp);
exit(EXIT_FAILURE);
}
}
//
//const vector<string>& RoutingEngine::GetTrip(int index) const
//{
// if ((index >= 0) && (index < (int) _tripsCollection.size()))
// return _tripsCollection[index];
// else {
// char tmp[CLENGTH];
// sprintf(tmp, "ERROR: \tWrong 'index' [%d] > [%d] in Routing::GetTrip()",
// index, int(_tripsCollection.size()));
// Log->Write(tmp);
// exit(EXIT_FAILURE);
// }
//}
const std::vector<Router*> RoutingEngine::GetAvailableRouters() const
{
......@@ -110,9 +111,14 @@ Router* RoutingEngine::GetRouter(int id) const
return /*(Router*)*/ nullptr;
}
void RoutingEngine::AddTrip(vector<string> trip)
void RoutingEngine::AddTrip(Trips trip)
{
_tripsCollection.push_back(trip);
// _tripsCollection.push_back(trip);
// _tripsCollection = trip;
for(Router* router:_routersCollection)
{
router->SetTrips(trip);
}
}
bool RoutingEngine::Init(Building* building)
......
......@@ -36,6 +36,7 @@
class Pedestrian;
class Trips;
class RoutingEngine {
public:
......@@ -60,14 +61,14 @@ public:
* Add a new trip to the system. Individual pedestrian can be assigned a particular trip.
* @param trip
*/
void AddTrip(std::vector<std::string> trip);
void AddTrip(Trips trip);
/**
* Return a trip/route with the particular id
* @param id, the trip id
* @return the corresponding trip
*/
const std::vector<std::string>& GetTrip(int id) const;
// /**
// * Return a trip/route with the particular id
// * @param id, the trip id
// * @return the corresponding trip
// */
// const std::vector<std::string>& GetTrip(int id) const;
/**
* @return all available routers
......@@ -111,7 +112,7 @@ private:
/// collections of all routers used
std::vector<Router*> _routersCollection;
/// collection of all trips/routes
std::vector<std::vector<std::string> >_tripsCollection;
Trips _tripsCollection;
};
#endif /* ROUTINGENGINE_H_ */
/**
* \file CognitiveMapStorage.cpp
* \date Feb 1, 2014
* \version v0.7
* \copyright <2009-2015> 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
* Cognitive Map Storage
*
*
**/
#include "BrainStorage.h"
#include "cognitiveMap/internnavigationnetwork.h"
#include "../../tinyxml/tinyxml.h"
#include <memory>
#include "../../geometry/Building.h"
#include "../../pedestrian/Pedestrian.h"
//#include "NavigationGraph.h"
AIBrainStorage::AIBrainStorage(const Building * const b, const std::string &cogMapFiles, const std::string &signFiles)
: _building(b),_visibleEnv(VisibleEnvironment(b)),_cogMapFiles(cogMapFiles),_signFiles(signFiles)
{
//Set signs
ParseSigns();
}
Cortex* AIBrainStorage::operator[] (BStorageKeyType key)
{
BStorageType::iterator it = _corteces.find(key);
if(it == _corteces.end()) {
CreateCortex(key);
}
return _corteces[key].get();
}
void AIBrainStorage::ParseCogMap(BStorageKeyType ped)
{
_regions.clear();
//create filename
int groupId = ped->GetGroup();
if (_cogMapFiles=="")
return;
std::string cMFileName=_cogMapFiles;
cMFileName.replace(cMFileName.size()-4,4,std::to_string(groupId)+".xml");
std::string cogMapFilenameWithPath = _building->GetProjectRootDir() + cMFileName;
Log->Write(cogMapFilenameWithPath);
TiXmlDocument doccogMap(cogMapFilenameWithPath);
if (!doccogMap.LoadFile()) {
Log->Write("ERROR: \t%s", doccogMap.ErrorDesc());
Log->Write("\t could not parse the cognitive map file");
Log->Write("Cognitive map not specified");
return;
}
TiXmlElement* xRootNode = doccogMap.RootElement();
if( ! xRootNode ) {
Log->Write("ERROR:\tRoot element does not exist");
Log->Write("Cognitive map not specified");
return;
}
if( xRootNode->ValueStr () != "cognitiveMap" ) {
Log->Write("ERROR:\tRoot element value is not 'cognitiveMap'.");
Log->Write("Cognitive map not specified");
return;
}
if(xRootNode->Attribute("unit"))
if(std::string(xRootNode->Attribute("unit")) != "m") {
Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",xRootNode->Attribute("unit"));
Log->Write("Cognitive map not specified");
return;
}
double version = xmltof(xRootNode->Attribute("version"), -1);
if (version < std::stod(JPS_OLD_VERSION) ) {
Log->Write(" \tWrong geometry version!");
Log->Write(" \tOnly version >= %s supported",JPS_VERSION);
Log->Write(" \tPlease update the version of your geometry file to %s",JPS_VERSION);
Log->Write("Cognitive map not specified");
return;
}
//processing the regions node
TiXmlNode* xRegionsNode = xRootNode->FirstChild("regions");
if (!xRegionsNode) {
Log->Write("ERROR: \tCognitive map file without region definition!");
Log->Write("Cognitive map not specified");
return;
}
for(TiXmlElement* xRegion = xRegionsNode->FirstChildElement("region"); xRegion;
xRegion = xRegion->NextSiblingElement("region"))
{
std::string idR = xmltoa(xRegion->Attribute("id"), "-1");
std::string captionR = xmltoa(xRegion->Attribute("caption"));
std::string pxinmapR = xmltoa(xRegion->Attribute("px"),"-1");
std::string pyinmapR = xmltoa(xRegion->Attribute("py"),"-1");
std::string aR = xmltoa(xRegion->Attribute("a"),"-1");
std::string bR = xmltoa(xRegion->Attribute("b"),"-1");
AIRegion region (Point(std::stod(pxinmapR),std::stod(pyinmapR)));
region.SetId(std::stoi(idR));
region.SetCaption(captionR);
region.SetPosInMap(Point(std::stod(pxinmapR),std::stod(pyinmapR)));
region.SetA(std::stod(aR));
region.SetB(std::stod(bR));
//processing the landmarks node
TiXmlNode* xLandmarksNode = xRegion->FirstChild("landmarks");
if (!xLandmarksNode) {
Log->Write("ERROR: \tCognitive map file without landmark definition!");
Log->Write("No landmarks specified");
return;
}
for(TiXmlElement* xLandmark = xLandmarksNode->FirstChildElement("landmark"); xLandmark;
xLandmark = xLandmark->NextSiblingElement("landmark"))
{
std::string id = xmltoa(xLandmark->Attribute("id"), "-1");
std::string caption = xmltoa(xLandmark->Attribute("caption"));
std::string type = xmltoa(xLandmark->Attribute("type"),"-1");
std::string roomId = xmltoa(xLandmark->Attribute("subroom1_id"),"-1");
std::string pxreal = xmltoa(xLandmark->Attribute("pxreal"),"-1");
std::string pyreal = xmltoa(xLandmark->Attribute("pyreal"),"-1");
std::string pxinmap = xmltoa(xLandmark->Attribute("px"),"-1");
std::string pyinmap = xmltoa(xLandmark->Attribute("py"),"-1");
std::string a = xmltoa(xLandmark->Attribute("a"),"-1");
std::string b = xmltoa(xLandmark->Attribute("b"),"-1");
AILandmark landmark(Point(std::stod(pxreal),std::stod(pyreal)));
if (roomId=="NaN")
{
Log->Write("ERROR:\t Subroom Id is NaN!");
return;
}
landmark.SetId(std::stoi(id));
landmark.SetCaption(caption);
landmark.SetType(type);
landmark.SetRealPos(Point(std::stod(pxreal),std::stod(pyreal)));
landmark.SetPosInMap(Point(std::stod(pxinmap),std::stod(pyinmap)));
landmark.SetA(std::stod(a));
landmark.SetB(std::stod(b));
//landmark->SetRoom(_building->GetSubRoomByUID(std::stoi(roomId)));
//processing the rooms node
TiXmlNode* xAssociationsNode = xLandmark->FirstChild("associations");
if (!xAssociationsNode) {
Log->Write("Landmark with no association!");
continue;
}
for(TiXmlElement* xAsso = xAssociationsNode->FirstChildElement("association"); xAsso;
xAsso = xAsso->NextSiblingElement("association"))
{
std::string asso_id = xmltoa(xAsso->Attribute("id"), "-1");
std::string asso_caption = xmltoa(xAsso->Attribute("caption"), "0");
//std::string asso_type = xmltoa(xAsso->Attribute("type"),"-1");
std::string asso_x = xmltoa(xAsso->Attribute("px"),"-1");
std::string asso_y = xmltoa(xAsso->Attribute("py"),"-1");
std::string asso_a = xmltoa(xAsso->Attribute("a"),"-1");
std::string asso_b = xmltoa(xAsso->Attribute("b"),"-1");
int connection = std::stoi(xmltoa(xAsso->Attribute("connectedwith"),"-1"));
//std::string priority = xmltoa(xAsso->Attribute("priority"),"-1");
AILandmark assolandmark(Point(std::stod(asso_x),std::stod(asso_y)),
std::stod(asso_a),std::stod(asso_b));
assolandmark.SetId(std::stod(asso_id));
//std::cout << assolandmark.GetId() << std::endl;
assolandmark.SetCaption(asso_caption);
//assolandmark->AddConnection(std::stoi(connection));
//assolandmark->SetPriority(std::stod(priority));
bool connected=false;
if (connection==landmark.GetId())
connected=true;
landmark.AddAssociation(AIAssociation(&landmark,&assolandmark,connected));
region.AddLandmarkSubCs(assolandmark);
}
region.AddLandmark(landmark);
Log->Write("INFO:\tLandmark added!");
}
//processing the connections node
TiXmlNode* xConnectionsNode = xRegion->FirstChild("connections");