Commit cb57630a authored by Erik Andresen's avatar Erik Andresen

Dynamic adaption of FireMeshes almost working

parent 46626dbc
......@@ -800,18 +800,32 @@ bool ArgumentParser::ParseCogMapOpts(TiXmlNode *routerNode)
Log->Write("ERROR:\tNo sensors found.\n");
return false;
}
/// static_cast to get access to the method 'addOption' of the CognitiveMapRouter
CognitiveMapRouter* r = static_cast<CognitiveMapRouter*>(p_routingengine->GetAvailableRouters().back());
std::vector<std::string> sensorVec;
for (TiXmlElement* e = sensorNode->FirstChildElement("sensor"); e;
e = e->NextSiblingElement("sensor"))
{
string sensor = e->Attribute("description");
///adding Smoke Sensor specific parameters
if (sensor=="Smoke")
{
std::vector<std::string> smokeOptVec;
smokeOptVec.push_back(e->Attribute("p_field_path"));
smokeOptVec.push_back(e->Attribute("update_time"));
smokeOptVec.push_back(e->Attribute("final_time"));
r->addOption("smokeOptions",smokeOptVec);
}
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");
......
......@@ -99,7 +99,8 @@
</router>
<router router_id="7" description="cognitive_map">
<sensors>
<sensor sensor_id="1" description="Smoke" status="activated" potentialfile="./"/>
<!--sensor sensor_id="2" description="Room2Corridor"/-->
<sensor sensor_id="1" description="Smoke" p_field_path="D:\JuPedSim\jpscore\inputfiles\cognitive_map\pFields\" update_time="30" final_time="90"/>
</sensors>
<cognitive_map status="complete" />
<!--parameters>
......
......@@ -54,7 +54,7 @@
<agents operational_model_id="2">
<agents_distribution>
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="0" number="50" router_id="7" pre_movement_mean="15" pre_movement_sigma="15"/>
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="0" number="100" router_id="7" pre_movement_mean="60" pre_movement_sigma="60"/>
<!--group group_id="2" agent_parameter_id="1" room_id="0" subroom_id="1" number="10" router_id="7" pre_movement_mean="30" pre_movement_sigma="30"/>/
<group group_id="3" agent_parameter_id="1" room_id="0" subroom_id="2" number="10" router_id="7" pre_movement_mean="30" pre_movement_sigma="30"/-->
</agents_distribution>
......@@ -96,9 +96,8 @@
<router router_id="7" description="cognitive_map">
<sensors>
<sensor sensor_id="1" description="Room2Corridor" status="activated"/>
<sensor sensor_id="2" description="LastDestination" status="activated"/>
<sensor sensor_id="3" description="Smoke" potentialfile="./"/>
<!--sensor sensor_id="1" description="Room2Corridor"/-->
<sensor sensor_id="2" description="Smoke" p_field_path="D:\JuPedSim\jpscore\inputfiles\cognitive_map\pFields\" update_time="30" final_time="90"/>
</sensors>
<cognitive_map status="complete" />
<!--parameters>
......
This diff is collapsed.
......@@ -86,10 +86,10 @@ int CognitiveMapRouter::FindExit(Pedestrian * p)
}
if (std::fmod(p->GetGlobalTime(),10)==0)
if (std::fmod(p->GetGlobalTime(),30)==0.0)
{
sensor_manager->execute(p, SensorManager::PERIODIC);
//std::cout << p->GetGlobalTime() << std::endl;
}
return 1;
}
......@@ -142,7 +142,7 @@ bool CognitiveMapRouter::Init(Building * b)
Log->Write("INFO:\tInitialized CognitiveMapStorage");
//Init Sensor Manager
//sensor_manager = SensorManager::InitWithAllSensors(b, cm_storage);
sensor_manager = SensorManager::InitWithCertainSensors(b, cm_storage, getOptions().at("Sensors"));
sensor_manager = SensorManager::InitWithCertainSensors(b, cm_storage, getOptions());
Log->Write("INFO:\tInitialized SensorManager");
return true;
}
......
......@@ -49,7 +49,7 @@ 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> >;
using optStorage = std::unordered_map<std::string,std::vector<std::string>>;
class CognitiveMapRouter: public Router {
public:
......
......@@ -52,7 +52,7 @@ FireMesh::FireMesh()
FireMesh::FireMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize)
{
GetUpMesh(xmin,ymin,xmax,ymax,cellsize);
SetUpMesh(xmin,ymin,xmax,ymax,cellsize);
//statHeaderRead=false;
_statMesh=false;
}
......@@ -70,7 +70,7 @@ FireMesh::~FireMesh()
}
void FireMesh::GetUpMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize)
void FireMesh::SetUpMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize)
{
_cellsize=cellsize;
......@@ -195,7 +195,7 @@ void FireMesh::SetKnotValuesFromFile(const std::string &filename)
strVec.clear();
//std::cout << xmin << ymin << xmax << ymax << std::endl;
GetUpMesh(xmin,ymin,xmax,ymax,cellsize);
SetUpMesh(xmin,ymin,xmax,ymax,cellsize);
//statHeaderRead=true;
//}
......
......@@ -48,12 +48,13 @@ public:
FireMesh(const std::string &filename);
~FireMesh();
void GetUpMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize);
void SetUpMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize);
const Matrix &GetMesh() const;
double GetKnotValue(const double &x, const double &y) const;
void SetKnotValuesFromFile(const std::string &filename);
bool statusMesh() const;
private:
......
......@@ -4,6 +4,7 @@ FireMeshStorage::FireMeshStorage(const Building * const b, const std::string &fi
{
_building=b;
_filepath=filepath;
_updateIntervall=updateintervall;
CreateTimeList(updateintervall,finalTime);
IdentifyDoors();
......@@ -23,39 +24,59 @@ void FireMeshStorage::CreateTimeList(const double &updateIntervall, const double
{
_timelist.push_back(i);
i+=updateIntervall;
}
}
void FireMeshStorage::IdentifyDoors()
{
const std::map<int,std::unique_ptr<Door>> doors = _building->GetAllRooms();
const std::map<int,Crossing*> doors = _building->GetAllCrossings();
for (auto it=doors.begin(); it!= doors.end(); ++it)
{
_doors.push_back(it.second);
_doors.push_back(*it->second);
}
const std::map<int,Transition*> exits = _building->GetAllTransitions();
for (auto it=exits.begin(); it!= exits.end(); ++it)
{
_doors.push_back(*it->second);
}
}
void FireMeshStorage::CreateFireMeshes()
{
_fMContainer.clear();
for (auto &door:_doors)
{
for (auto &i:_timelist)
{
std::string filename = _filepath + "/Door_X_" + std::to_string(door->GetCentre().GetX())
+ "_Y_" + std::to_string(door->GetCentre().GetY()) + "/t_"+std::to_string(i)+".csv";
FireMesh mesh(filename);
_fMContainer.emplace(std::make_pair(door->GetCentre(),i),mesh);
std::string suffix = "Door_X_" + std::to_string(door.GetCentre().GetX())
+ "_Y_" + std::to_string(door.GetCentre().GetY()) + "\\t_"+std::to_string(i)+".csv";
FireMesh mesh(_filepath+suffix);
std::string str = "Door_X_"+ std::to_string(door.GetCentre().GetX())
+ "_Y_" + std::to_string(door.GetCentre().GetY()) + "_t_"+std::to_string(i);
}
_fMContainer.emplace(str,mesh);
}
}
}
const FireMesh &FireMeshStorage::get_FireMesh(const Point &doorCentre, const double &simTime)
const FireMesh &FireMeshStorage::get_FireMesh(const Point &doorCentre, const double &simTime) const
{
return _fMContainer.at(std::make_pair(doorCentre,simTime));
int simT=simTime/_updateIntervall;
simT*=_updateIntervall;
//std::cout << simT << std::endl;
std::string str = "Door_X_"+ std::to_string(doorCentre.GetX())
+ "_Y_" + std::to_string(doorCentre.GetY()) + "_t_"+std::to_string(simT)+".000000";
//std::cout << str << std::endl;
return _fMContainer.at(str);
}
......@@ -7,7 +7,7 @@
// 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::pair<Point,double>,FireMesh>;
using fireMeshContainer = std::unordered_map<std::string,FireMesh>;
class FireMeshStorage
{
......@@ -17,14 +17,15 @@ public:
void CreateTimeList(const double &updateIntervall, const double &finalTime, const double &startTime=0);
void IdentifyDoors();
void CreateFireMeshes();
const FireMesh& get_FireMesh(const Point &doorCentre, const double &simTime);
const FireMesh& get_FireMesh(const Point &doorCentre, const double &simTime) const;
private:
Building *_building;
const Building *_building;
fireMeshContainer _fMContainer;
std::string _filepath;
double _updateIntervall;
std::vector<double> _timelist;
std::vector<Door> _doors;
std::vector<Crossing> _doors;
};
......
......@@ -52,11 +52,11 @@ GraphEdge::GraphEdge(const GraphVertex * const s, const GraphVertex * const d,
: _src(s), _dest(d), _crossing(crossing)
{
CalcApproximateDistance();
SetUpFireMesh();
}
GraphEdge::GraphEdge(GraphEdge const &ge)
: _src(ge._src), _dest(ge._dest), _crossing(ge._crossing), _approximate_distance(ge._approximate_distance), _fireMesh(ge._fireMesh)
: _src(ge._src), _dest(ge._dest), _crossing(ge._crossing), _approximate_distance(ge._approximate_distance)
{
}
......
......@@ -72,7 +72,7 @@ SensorManager * SensorManager::InitWithAllSensors(const Building * b, CognitiveM
//Init and register Sensors
sensor_manager->Register(new DiscoverDoorsSensor(b), NO_WAY );
sensor_manager->Register(new RoomToFloorSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
sensor_manager->Register(new SmokeSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
//sensor_manager->Register(new SmokeSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
sensor_manager->Register(new LastDestinationsSensor(b), CHANGED_ROOM );
sensor_manager->Register(new JamSensor(b), PERIODIC | NO_WAY | CHANGED_ROOM );
......@@ -80,13 +80,14 @@ SensorManager * SensorManager::InitWithAllSensors(const Building * b, CognitiveM
return sensor_manager;
}
SensorManager *SensorManager::InitWithCertainSensors(const Building * b, CognitiveMapStorage * cm_storage, std::vector<std::string> sensors)
SensorManager *SensorManager::InitWithCertainSensors(const Building * b, CognitiveMapStorage * cm_storage, const optStorage& optSto)
{
SensorManager * sensor_manager = new SensorManager(b, cm_storage);
sensor_manager->Register(new DiscoverDoorsSensor(b), NO_WAY );
sensor_manager->Register(new LastDestinationsSensor(b), CHANGED_ROOM );
std::vector<std::string> sensors = optSto.at("Sensors");
for (auto &it : sensors )
{
if (it =="Room2Corridor")
......@@ -99,9 +100,10 @@ SensorManager *SensorManager::InitWithCertainSensors(const Building * b, Cogniti
}
else if (it == "Smoke")
{
sensor_manager->Register(new SmokeSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
std::string smokeFilepath = optSto.at("smokeOptions").at(0);
double updatet = std::stod(optSto.at("smokeOptions").at(1));
double finalt = std::stod(optSto.at("smokeOptions").at(2));
sensor_manager->Register(new SmokeSensor(b,smokeFilepath,updatet,finalt), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
}
......
......@@ -35,6 +35,10 @@ class CognitiveMapStorage;
class AbstractSensor;
class Pedestrian;
#include<unordered_map>
#include<vector>
//c++11 alias: Container to store options for the router (i. a. sensors)
using optStorage = std::unordered_map<std::string,std::vector<std::string>>;
#include <vector>
#include <set>
......@@ -63,7 +67,7 @@ public:
void execute(const Pedestrian *, EventType);
static SensorManager * InitWithAllSensors(const Building *, CognitiveMapStorage *);
static SensorManager * InitWithCertainSensors(const Building*, CognitiveMapStorage*, std::vector<std::string> sensors);
static SensorManager * InitWithCertainSensors(const Building*, CognitiveMapStorage*, const optStorage& optSto);
private:
const Building * const building;
......
......@@ -15,10 +15,13 @@
#include "../fire_mesh/FireMeshStorage.h"
#include <set>
SmokeSensor::SmokeSensor(const Building *b, const &filepath, const &updateintervall, const &finalTime) : AbstractSensor(b)
SmokeSensor::SmokeSensor(const Building *b, const std::string &filepath, const double &updateintervall, const double &finalTime) : AbstractSensor(b)
{
_FMStorage= new FireMeshStorage(b,filepath,updateintervall,finalTime);
std::shared_ptr<FireMeshStorage> FMS(new FireMeshStorage(b,filepath,updateintervall,finalTime));
Log->Write("INFO:\tInitialized FireMeshStorage (Smoke Sensor)");
_FMStorage=FMS;
}
SmokeSensor::~SmokeSensor()
......@@ -38,8 +41,12 @@ void SmokeSensor::execute(const Pedestrian * pedestrian, CognitiveMap * cognitiv
for (auto &item : *edges)
{
double smokeFactor = item->GetSmokeFactor(pedestrian->GetPos());
//std::cout << smokeFactor << std::endl;
/// first: find Mesh corresponding to current edge and current simTime. Secondly get knotvalue from that mesh depending
/// on the current position of the pedestrian
double smokeFactor = _FMStorage->get_FireMesh(item->GetCrossing()->GetCentre(),
pedestrian->GetGlobalTime()).GetKnotValue(pedestrian->GetPos().GetX(),
pedestrian->GetPos().GetY());
std::cout << smokeFactor << std::endl;
item->SetFactor(smokeFactor,GetName());
//std::cout << item->GetFactor() << std::endl;
}
......@@ -75,13 +82,13 @@ void SmokeSensor::execute(const Pedestrian * pedestrian, CognitiveMap * cognitiv
}
void SmokeSensor::set_FMStorage(const&fmStorage)
void SmokeSensor::set_FMStorage(const std::shared_ptr<FireMeshStorage> fmStorage)
{
_FMStorage=fmStorage;
}
const FireMeshStorage *SmokeSensor::get_FMStorage()
const std::shared_ptr<FireMeshStorage> SmokeSensor::get_FMStorage()
{
return _FMStorage;
......
......@@ -10,6 +10,7 @@
#define SMOKESENSOR_H 1
#include "AbstractSensor.h"
#include <memory>
class Point;
class FireMeshStorage;
......@@ -18,15 +19,15 @@ class SmokeSensor : public AbstractSensor
{
public:
SmokeSensor(const Building * b, const&filepath, const&updateintervall, const&finalTime);
SmokeSensor(const Building * b, const std::string &filepath, const double &updateintervall, const double &finalTime);
virtual ~SmokeSensor();
std::string GetName() const;
void execute(const Pedestrian *, CognitiveMap *) const;
void set_FMStorage(const &fmStorage);
const FireMeshStorage* get_FMStorage();
void set_FMStorage(const std::shared_ptr<FireMeshStorage> fmStorage);
const std::shared_ptr<FireMeshStorage> get_FMStorage();
private:
......
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