Commit b68f49a1 authored by Erik Andresen's avatar Erik Andresen

Manipulate CognitiveMapRouter by adding options in the ini(xml)-file.

(Selecting sensors and specifying the cognitive map (empty or complete))
parent c557f499
......@@ -228,7 +228,7 @@ bool ArgumentParser::ParseIniFile(string inifile)
Log->Write("WARNING:\t There is no header version. I am assuming %s",
JPS_VERSION);
}
else if (string(xMainNode->Attribute("version")) != JPS_VERSION && string(xMainNode->Attribute("version")) != JPS_OLD_VERSION)
else if (string(xMainNode->Attribute("version")) != JPS_VERSION)
{
Log->Write(
"ERROR:\t Wrong header version. Only version %s is supported.",
......@@ -269,8 +269,8 @@ bool ArgumentParser::ParseIniFile(string inifile)
max_cpus = omp_get_max_threads();
#endif
//max CPU
if(xMainNode->FirstChild("num_threads")) {
TiXmlNode* seedNode = xMainNode->FirstChild("num_threads")->FirstChild();
if(xMainNode->FirstChild("numCPU")) {
TiXmlNode* seedNode = xMainNode->FirstChild("numCPU")->FirstChild();
int n = 1;
if(seedNode){
const char* cpuValue = seedNode->Value();
......@@ -281,18 +281,18 @@ bool ArgumentParser::ParseIniFile(string inifile)
n = max_cpus;
}
pMaxOpenMPThreads = n;
Log->Write("INFO: \tnum_threads <%d>", pMaxOpenMPThreads);
Log->Write("INFO: \tnumCPU <%d>", pMaxOpenMPThreads);
#ifdef _OPENMP
if(n < omp_get_max_threads() )
omp_set_num_threads(pMaxOpenMPThreads);
#endif
}
else { // no num_threads tag
else { // no numCPU tag
pMaxOpenMPThreads = max_cpus;
#ifdef _OPENMP
omp_set_num_threads(pMaxOpenMPThreads);
#endif
Log->Write("INFO: \t Default num_threads <%d>", pMaxOpenMPThreads);
Log->Write("INFO: \t Default numCPU <%d>", pMaxOpenMPThreads);
}
//logfile
if (xMainNode->FirstChild("logfile"))
......@@ -369,7 +369,7 @@ bool ArgumentParser::ParseIniFile(string inifile)
//pick up which model to use
//get the wanted ped model id
pModel=xmltoi(xMainNode->FirstChildElement("agents")->Attribute("operational_model_id"),-1);
if( pModel==-1 /*|| ( (pModel!=MODEL_GFCM) && pModel!=MODEL_GOMPERTZ) */)
if( (pModel==-1) /*|| ( (pModel!=MODEL_GFCM) && pModel!=MODEL_GOMPERTZ) */)
{
Log->Write("ERROR: \tmissing operational_model_id attribute in the agent section. ");
Log->Write("ERROR: \tplease specify the model id to use");
......@@ -778,6 +778,10 @@ bool ArgumentParser::ParseRoutingStrategies(TiXmlNode *routingNode)
pRoutingStrategies.push_back(make_pair(id, ROUTING_COGNITIVEMAP));
Router *r = new CognitiveMapRouter(id, ROUTING_COGNITIVEMAP);
p_routingengine->AddRouter(r);
Log->Write("\nINFO: \tUsing CognitiveMapRouter");
if (ParseCogMapOpts(e))
return false;
}
else {
Log->Write("ERROR: \twrong value for routing strategy [%s]!!!\n",
......@@ -788,18 +792,59 @@ bool ArgumentParser::ParseRoutingStrategies(TiXmlNode *routingNode)
return true;
}
bool ArgumentParser::ParseStrategyNodeToObject(const TiXmlNode &strategyNode)
bool ArgumentParser::ParseCogMapOpts(TiXmlNode *routerNode)
{
string query="exit_crossing_strategy";
if( ! strategyNode.FirstChild(query.c_str()))
{
query="exitCrossingStrategy";
Log->Write("WARNING:\t exitCrossingStrategy is deprecated. Please consider using \"exit_crossing_strategy\" ");
}
if (strategyNode.FirstChild(query.c_str())) {
TiXmlNode* sensorNode=routerNode->FirstChild();
if (!sensorNode)
{
Log->Write("ERROR:\tNo sensors found.\n");
return false;
}
std::vector<std::string> sensorVec;
for (TiXmlElement* e = sensorNode->FirstChildElement("sensor"); e;
e = e->NextSiblingElement("sensor"))
{
string sensor = e->Attribute("description");
string status = e->Attribute("status");
//int id = atoi(e->Attribute("sensor_id"));
if (status=="activated")
{
sensorVec.push_back(sensor);
}
Log->Write("INFO: \tSensor "+ sensor + " added");
}
// static_cast to get access to the method 'addOption' of the CognitiveMapRouter
CognitiveMapRouter* r = static_cast<CognitiveMapRouter*>(p_routingengine->GetAvailableRouters().back());
r->addOption("Sensors",sensorVec);
TiXmlElement* cogMap=routerNode->FirstChildElement("cognitive_map");
if (!cogMap)
{
Log->Write("ERROR:\tCognitive Map not specified.\n");
return false;
}
std::vector<std::string> cogMapStatus;
cogMapStatus.push_back(cogMap->Attribute("status"));
Log->Write("INFO: \tAll pedestrian starting with a(n) "+cogMapStatus[0]+" cognitive map\n");
r->addOption("CognitiveMap",cogMapStatus);
return true;
}
bool ArgumentParser::ParseStrategyNodeToObject(const TiXmlNode &strategyNode)
{
if (strategyNode.FirstChild("exitCrossingStrategy")) {
const char *tmp =
strategyNode.FirstChild(query.c_str())->FirstChild()->Value();
strategyNode.FirstChild("exitCrossingStrategy")->FirstChild()->Value();
if (tmp)
{
pExitStrategy = atoi(tmp);
......@@ -819,7 +864,7 @@ bool ArgumentParser::ParseStrategyNodeToObject(const TiXmlNode &strategyNode)
break;
default:
p_exit_strategy = std::shared_ptr<DirectionStrategy>(new DirectionMinSeperationShorterLine());
Log->Write("ERROR:\t unknown exit_crossing_strategy < %d >", pExitStrategy);
Log->Write("ERROR:\t unknown exitCrossingStrategy < %d >", pExitStrategy);
Log->Write(" :\t the default < %d > will be used", 2);
return true;
break;
......@@ -829,7 +874,7 @@ bool ArgumentParser::ParseStrategyNodeToObject(const TiXmlNode &strategyNode)
{
return false;
}
Log->Write("INFO: \texit_crossing_strategy < %d >", pExitStrategy);
Log->Write("INFO: \texitCrossingStrategy < %d >", pExitStrategy);
}
return true;
}
......
......@@ -119,7 +119,7 @@ private:
void Usage(const std::string file);
/**
* @input a TiXmlNode with the first child "exit_crossing_strategy";
* @input a TiXmlNode with the first child "exitCrossingStrategy";
* sets pExitStrategy and p_exit_strategy
*/
bool ParseStrategyNodeToObject(const TiXmlNode &strategyNode);
......@@ -136,6 +136,8 @@ private:
*/
bool ParseRoutingStrategies(TiXmlNode* routingNode);
bool ParseCogMapOpts(TiXmlNode* routingNode);
bool ParseLinkedCells(const TiXmlNode &linkedCellNode);
bool ParseStepSize(TiXmlNode &stepNode);
......
<?xml version="1.0" encoding="UTF-8" ?>
<JuPedSim project="JPS-Project" version="0.5"
<JuPedSim project="JPS-Project" version="0.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
......@@ -27,7 +27,7 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
<!-- doors states are: close or open -->
<doors>
<door trans_id="1" caption="" state="open" />
<door trans_id="2" caption="" state="close" />
<door trans_id="2" caption="" state="open" />
</doors>
</traffic_constraints>
......@@ -74,7 +74,7 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exit_crossing_strategy>3</exit_crossing_strategy>
<exitCrossingStrategy>3</exitCrossingStrategy>
<linkedcells enabled="true" cell_size="2.2" />
<force_ped nu="0.3" dist_max="3" disteff_max="2" interpolation_width="0.1" />
<force_wall nu="0.2" dist_max="3" disteff_max="2" interpolation_width="0.1" />
......@@ -99,9 +99,14 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
</parameters>
</router>
<router router_id="7" description="cognitive_map">
<parameters>
<sensors>
<sensor sensor_id="1" description="Room2Corridor" status="activated"/>
<sensor sensor_id="2" description="Jam" status="activated"/>
</sensors>
<cognitive_map status="empty"/>
<!--parameters>
<navigation_lines file="routing.xml" />
</parameters>
</parameters-->
</router>
</route_choice_models>
......
......@@ -43,16 +43,17 @@
CognitiveMapRouter::CognitiveMapRouter()
{
building=NULL;
cm_storage=NULL;
sensor_manager=NULL;
building=nullptr;
cm_storage=nullptr;
sensor_manager=nullptr;
}
CognitiveMapRouter::CognitiveMapRouter(int id, RoutingStrategy s) : Router(id, s)
{
building=NULL;
cm_storage=NULL;
sensor_manager=NULL;
building=nullptr;
cm_storage=nullptr;
sensor_manager=nullptr;
}
CognitiveMapRouter::~CognitiveMapRouter()
......@@ -61,6 +62,10 @@ CognitiveMapRouter::~CognitiveMapRouter()
}
int CognitiveMapRouter::FindExit(Pedestrian * p)
{
//check for former goal.
......@@ -86,9 +91,9 @@ int CognitiveMapRouter::FindExit(Pedestrian * p)
int CognitiveMapRouter::FindDestination(Pedestrian * p)
{
//check if there is a way to the outside the pedestrian knows (in the cognitive map)
const GraphEdge * destination = NULL;
const GraphEdge * destination = nullptr;
destination = (*cm_storage)[p]->GetDestination();
if(destination == NULL) {
if(destination == nullptr) {
//no destination was found, now we could start the discovery!
//1. run the no_way sensors for room discovery.
sensor_manager->execute(p, SensorManager::NO_WAY);
......@@ -96,7 +101,7 @@ int CognitiveMapRouter::FindDestination(Pedestrian * p)
//check if this was enough for finding a global path to the exit
destination = (*cm_storage)[p]->GetDestination();
if(destination == NULL) {
if(destination == nullptr) {
//we still do not have a way. lets take the "best" local edge
//for this we don't calculate the cost to exit but calculte the cost for the edges at the actual vertex.
destination = (*cm_storage)[p]->GetLocalDestination();
......@@ -105,7 +110,7 @@ int CognitiveMapRouter::FindDestination(Pedestrian * p)
//if we still could not found any destination we are lost! Pedestrian will be deleted
//no destination should just appear in bug case or closed rooms.
if(destination == NULL) {
if(destination == nullptr) {
Log->Write("ERROR: \t One Pedestrian (ID: %i) was not able to find any destination", p->GetID());
return -1;
}
......@@ -126,11 +131,24 @@ bool CognitiveMapRouter::Init(Building * b)
Log->Write("INFO:\tInit the Cognitive Map Router Engine");
building = b;
//Init Cognitive Map Storage
cm_storage = new CognitiveMapStorage(building);
//Init Cognitive Map Storage, second parameter: decides whether cognitive Map is empty or complete
cm_storage = new CognitiveMapStorage(building,getOptions().at("CognitiveMap")[0]);
Log->Write("INFO:\tInitialized CognitiveMapStorage");
//Init Sensor Manager
sensor_manager = SensorManager::InitWithAllSensors(b, cm_storage);
//sensor_manager = SensorManager::InitWithAllSensors(b, cm_storage);
sensor_manager = SensorManager::InitWithCertainSensors(b, cm_storage, getOptions().at("Sensors"));
Log->Write("INFO:\tInitialized SensorManager");
return true;
}
const optStorage &CognitiveMapRouter::getOptions() const
{
return options;
}
void CognitiveMapRouter::addOption(const std::string &key, const std::vector<std::string> &value)
{
options.emplace(key,value);
}
......@@ -32,6 +32,7 @@
#include "Router.h"
#include <string>
#include <unordered_map>
class Building;
class Router;
......@@ -46,15 +47,30 @@ class NavLine;
*
*/
//c++11 alias: Container to store options for the router (i. a. sensors)
using optStorage = std::unordered_map<std::string,std::vector<std::string>>;
class CognitiveMapRouter: public Router {
public:
CognitiveMapRouter();
CognitiveMapRouter(int id, RoutingStrategy s);
virtual ~CognitiveMapRouter();
virtual int FindExit(Pedestrian* p);
virtual bool Init(Building* b);
/**
* @return options involved in the routing algorithm
*/
const optStorage &getOptions() const;
/**
* Adds further options (key,value) to the optionContainer
*/
void addOption(const std::string &key, const std::vector<std::string> &value);
protected:
int FindDestination(Pedestrian * );
......@@ -65,6 +81,9 @@ private:
CognitiveMapStorage * cm_storage;
SensorManager * sensor_manager;
/// Optional options which are supposed to be used
optStorage options;
};
#endif /* COGNITIVEMAPROUTER_H_ */
......@@ -36,10 +36,12 @@
#include "NavigationGraph.h"
CognitiveMapStorage::CognitiveMapStorage(const Building * const b)
CognitiveMapStorage::CognitiveMapStorage(const Building * const b, std::string cogMapStatus)
: building(b)
{
//creator = new EmptyCognitiveMapCreator(b);
if (cogMapStatus == "empty")
creator = new EmptyCognitiveMapCreator(b);
else
creator = new CompleteCognitiveMapCreator(b);
}
......
......@@ -52,7 +52,7 @@ typedef std::unordered_map<CMStorageKeyType, CMStorageValueType> CMStorageType;
*/
class CognitiveMapStorage {
public:
CognitiveMapStorage(const Building * const b);
CognitiveMapStorage(const Building * const b, std::string cogMapStatus);
virtual ~CognitiveMapStorage();
......
......@@ -77,5 +77,32 @@ SensorManager * SensorManager::InitWithAllSensors(const Building * b, CognitiveM
sensor_manager->Register(new LastDestinationsSensor(b), CHANGED_ROOM );
sensor_manager->Register(new JamSensor(b), PERIODIC | NO_WAY | CHANGED_ROOM );
return sensor_manager;
return sensor_manager;
}
SensorManager *SensorManager::InitWithCertainSensors(const Building * b, CognitiveMapStorage * cm_storage, std::vector<std::string> sensors)
{
SensorManager * sensor_manager = new SensorManager(b, cm_storage);
sensor_manager->Register(new DiscoverDoorsSensor(b), NO_WAY );
sensor_manager->Register(new LastDestinationsSensor(b), CHANGED_ROOM );
for (auto &it : sensors )
{
if (it =="Room2Corridor")
{
sensor_manager->Register(new RoomToFloorSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
}
else if (it == "Jam")
{
sensor_manager->Register(new JamSensor(b), PERIODIC | NO_WAY | CHANGED_ROOM );
}
else if (it == "Smoke")
{
sensor_manager->Register(new SmokeSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
}
}
return sensor_manager;
}
......@@ -38,6 +38,7 @@ class Pedestrian;
#include <vector>
#include <set>
#include <string>
class SensorManager {
public:
......@@ -62,6 +63,7 @@ public:
void execute(const Pedestrian *, EventType);
static SensorManager * InitWithAllSensors(const Building *, CognitiveMapStorage *);
static SensorManager * InitWithCertainSensors(const Building*, CognitiveMapStorage*, std::vector<std::string> sensors);
private:
const Building * const building;
......
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