Commit 763139dc authored by Ulrich Kemloh's avatar Ulrich Kemloh

integrating a fire mesh

parent a6941fcd
......@@ -218,6 +218,8 @@ set ( source_files
routing/cognitive_map/sensor/JamSensor.cpp
routing/cognitive_map/sensor/LastDestinationsSensor.cpp
routing/cognitive_map/sensor/SmokeSensor.cpp
routing/cognitive_map/fire_mesh/firemesh.cpp
routing/cognitive_map/fire_mesh/knot.cpp
poly2tri/common/shapes.cpp
poly2tri/sweep/sweep_context.cpp
......
......@@ -2,13 +2,13 @@
<JuPedSim project="JPS-Project" version="0.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<max_sim_time>900</max_sim_time>
<max_sim_time>900</max_sim_time>
<!-- geometry file -->
<geometry>geo.xml</geometry>
<geometry>smokesensortest.xml</geometry>
<!-- trajectories file and format -->
<trajectories format="xml-plain" fps="8">
<file location="trajectories.xml" />
......@@ -21,49 +21,49 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- room states are: good or smoked -->
<!-- <rooms> -->
<!-- <room room_id="0" state="good" /> -->
<!-- </rooms> -->
<!-- <rooms> -->
<!-- <room room_id="0" state="good" /> -->
<!-- </rooms> -->
<!-- doors states are: close or open -->
<doors>
<door trans_id="1" caption="" state="open" />
<door trans_id="2" caption="" state="open" />
<!--door trans_id="1" caption="" state="open" />
<door trans_id="2" caption="" state="open" /-->
</doors>
</traffic_constraints>
<routing>
<goals>
<!--goals>
<goal id="0" final="false" caption="goal 1">
<polygon>
<vertex px="-1.0" py="5.0" />
<vertex px="-1.0" py="6.5" />
<vertex px="-2.0" py="6.5" />
<vertex px="-2.0" py="5.0" />
<vertex px="-1.0" py="5.0" />
</polygon>
<polygon>
<vertex px="-1.0" py="5.0" />
<vertex px="-1.0" py="6.5" />
<vertex px="-2.0" py="6.5" />
<vertex px="-2.0" py="5.0" />
<vertex px="-1.0" py="5.0" />
</polygon>
</goal>
<goal id="1" final="false" caption="goal 2">
<polygon>
<vertex px="24.0" py="6.5" />
<vertex px="23.0" py="6.5" />
<vertex px="23.0" py="5.0" />
<vertex px="24.0" py="5.0" />
<vertex px="24.0" py="6.5" />
</polygon>
<polygon>
<vertex px="24.0" py="6.5" />
<vertex px="23.0" py="6.5" />
<vertex px="23.0" py="5.0" />
<vertex px="24.0" py="5.0" />
<vertex px="24.0" py="6.5" />
</polygon>
</goal>
</goals>
</goals-->
<!-- in the form goal_id1:goal_id2:goal_id3:..:goal_idn -->
<!-- <routes> -->
<!-- <route id="1">0:1:0:1:0:1:2</route> -->
<!-- <route id="2">0:1:0:1:2</route> -->
<!-- </routes> -->
<!-- <routes> -->
<!-- <route id="1">0:1:0:1:0:1:2</route> -->
<!-- <route id="2">0:1:0:1:2</route> -->
<!-- </routes> -->
</routing>
<!--persons information and distribution -->
<agents operational_model_id="1">
<agents_distribution>
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="0" number="50" router_id="7" />
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="0" number="50" router_id="7" />
</agents_distribution>
</agents>
......@@ -71,22 +71,22 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!-- These parameters may be overwritten -->
<operational_models>
<model operational_model_id="1" description="gcfm">
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exit_crossing_strategy>3</exit_crossing_strategy>
<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" />
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exitCrossingStrategy>4</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" />
</model_parameters>
<agent_parameters agent_parameter_id="1">
<v0 mu="1.24" sigma="0.001" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
<agent_parameters agent_parameter_id="1">
<v0 mu="1.24" sigma="0.001" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
</model>
</operational_models>
......@@ -94,15 +94,18 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<route_choice_models>
<router router_id="1" description="global_shortest">
<parameters>
<navigation_lines file="routing.xml" />
</parameters>
</router>
<router router_id="7" description="cognitive_map">
<sensors>
<sensor sensor_id="1" description="Room2Corridor" status="activated" />
<sensor sensor_id="2" description="Jam" status="activated" />
</sensors>
<cognitive_map status="empty" />
<sensors>
<sensor sensor_id="1" description="Smoke" status="activated"/>
</sensors>
<cognitive_map status="complete"/>
<!--parameters>
<navigation_lines file="routing.xml" />
</parameters-->
</router>
</route_choice_models>
......
......@@ -84,6 +84,12 @@ int CognitiveMapRouter::FindExit(Pedestrian * p)
return status;
}
if (std::fmod(p->GetGlobalTime(),1)==0)
{
sensor_manager->execute(p, SensorManager::PERIODIC);
//std::cout << p->GetGlobalTime() << std::endl;
}
return 1;
}
......@@ -149,6 +155,6 @@ const optStorage &CognitiveMapRouter::getOptions() const
void CognitiveMapRouter::addOption(const std::string &key, const std::vector<std::string> &value)
{
options.insert(std::make_pair(key, value));
options.emplace(key,value);
}
/**
* \file firemesh.cpp
* \date Jan 1, 2015
* \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
* 2D-Mesh. Division of the geometry into a cartesian equidistant mesh
*
*
**/
#include "firemesh.h"
#include <cmath>
#include <fstream>
#include <iostream>
#include <sstream>
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
FireMesh::FireMesh()
{
//statHeaderRead=false;
statMesh=false;
}
FireMesh::FireMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize)
{
setUpMesh(xmin,ymin,xmax,ymax,cellsize);
//statHeaderRead=false;
statMesh=false;
}
FireMesh::FireMesh(const std::string &filename)
{
setKnotValuesFromFile(filename);
//statHeaderRead=false;
statMesh=false;
}
FireMesh::~FireMesh()
{
}
void FireMesh::setUpMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize)
{
_cellsize=cellsize;
/// as knot is the middle of a cell
_xmin=xmin+0.5*cellsize;
_xmax=xmax-0.5*cellsize;
_ymin=ymin+0.5*cellsize;
_ymax=ymax-0.5*cellsize;
int cols = (xmax - xmin) / cellsize+1;
int rows = (ymax - ymin) / cellsize+1;
/// set up matrix
_matrix.resize(rows);
for (auto &elem : _matrix)
{
elem.resize(cols);
}
for (int i=0; i<_matrix.size(); ++i)
{
for (int j=0; j<_matrix[0].size(); ++j)
{
knot k(xmin+i*cellsize, j*cellsize);
_matrix[i][j]=k;
}
}
}
const Matrix &FireMesh::getMesh() const
{
return _matrix;
}
double FireMesh::getKnotValue(const double &x, const double &y) const
{
double restx;
double resty;
int col;
int row;
/// Which knot is the nearest one to (x,y)?
///
if (x>_xmin && x<_xmax)
{
restx = fmod((x-_xmin),_cellsize);
col = (x-_xmin)/_cellsize;
if (restx>_cellsize/2.0)
{
++col;
}
}
else if (x>=_xmax)
{
restx=0;
col=_matrix.size()-1;
}
else
{
restx=0;
col=0;
}
if (y>_ymin && y<_ymax)
{
resty = fmod((y-_ymin),_cellsize);
row = (y-_ymin)/_cellsize;
if (resty>_cellsize/2.0)
{
++row;
}
}
else if (y>=_ymax)
{
resty=0;
row=_matrix[0].size()-1;
}
else
{
resty=0;
row=0;
}
return _matrix[row][col].getValue();
}
void FireMesh::setKnotValuesFromFile(const std::string &filename)
{
///open File (reading)
std::ifstream pFile(filename);
if (pFile)
{
std::vector<std::string> strVec;
std::string line;
///skip two lines
std::getline(pFile, line);
std::getline(pFile, line);
std::getline(pFile, line);
//std::cout << line << std::endl;
/// to avoid multiple reading of the header and mesh setting
//if (statHeaderRead==false)
//{
/// read header
strVec = split(line,',', strVec);
int cellsize = std::stoi(strVec[0]);
double xmin = std::stod(strVec[2]);
double xmax = std::stod(strVec[3]);
double ymin = std::stod(strVec[4]);
double ymax = std::stod(strVec[5]);
strVec.clear();
//std::cout << xmin << ymin << xmax << ymax << std::endl;
setUpMesh(xmin,ymin,xmax,ymax,cellsize);
//statHeaderRead=true;
//}
///Read matrix
///
int m = 0;
int n;
while (std::getline(pFile, line)) {
n = 0;
strVec = split(line, ',', strVec);
for (auto &elem : strVec)
{
//std::cout << elem << std::endl;
_matrix[m][n].setValue(std::stod(elem));
++n;
}
strVec.clear();
++m;
}
pFile.close();
statMesh=true;
}
else
std::cout << "Unable to open file";
}
bool FireMesh::statusMesh() const
{
return statMesh;
}
/**
* \file firemesh.h
* \date Jan 1, 2015
* \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
* 2D-Mesh. Division of the geometry into a cartesian equidistant mesh
*
*
**/
#ifndef FIREMESH_H
#define FIREMESH_H
#include <vector>
#include <string>
#include "knot.h"
//using Matrix = std::array<std::array<T, COL>, ROW>;
using Matrix = std::vector<std::vector<knot>>;
class FireMesh
{
public:
FireMesh();
FireMesh(const double &xmin, const double &ymin, const double &xmax, const double &ymax, const int &cellsize);
FireMesh(const std::string &filename);
~FireMesh();
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:
Matrix _matrix;
int _cellsize;
double _xmin;
double _xmax;
double _ymin;
double _ymax;
//bool statHeaderRead;
bool statMesh;
};
#endif // FIREMESH_H
#include "knot.h"
knot::knot()
{
}
knot::knot(const double &x, const double &y, const double &value)
{
_x=x;
_y=y;
_value=value;
}
knot::~knot()
{
}
void knot::setValue(const double &value)
{
_value=value;
}
const double &knot::getValue() const
{
return _value;
}
#ifndef KNOT_H
#define KNOT_H
class knot
{
public:
knot();
knot(const double &x, const double &y, const double &value=0);
~knot();
void setValue(const double &value);
const double &getValue() const;
private:
double _x;
double _y;
double _value;
};
#endif // KNOT_H
......@@ -52,10 +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)
: src(ge.src), dest(ge.dest), crossing(ge.crossing), approximate_distance(ge.approximate_distance), fireMesh(ge.fireMesh)
{
}
......@@ -149,7 +150,28 @@ const GraphVertex * GraphEdge::GetSrc() const
const Crossing * GraphEdge::GetCrossing() const
{
return crossing;
return crossing;
}
const FireMesh &GraphEdge::getFireMesh() const
{
return this->fireMesh;
}
void GraphEdge::setUpFireMesh()
{
std::string filename = "D:/JuPedSim/jpscore/inputfiles/cognitive_map/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
......
......@@ -31,6 +31,7 @@
#define GRAPHEDGE_H_
#include "../../../geometry/Line.h"
#include "../fire_mesh/firemesh.h"
#include <map>
class SubRoom;
......@@ -62,6 +63,12 @@ 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;
......@@ -84,6 +91,7 @@ private:
const GraphVertex * const src;
const GraphVertex * const dest;
const Crossing * const crossing;
FireMesh fireMesh;
/**
* Factor Bag
......
......@@ -100,7 +100,11 @@ SensorManager *SensorManager::InitWithCertainSensors(const Building * b, Cogniti
else if (it == "Smoke")
{
sensor_manager->Register(new SmokeSensor(b), INIT | PERIODIC | NO_WAY | CHANGED_ROOM );
}
}
......
......@@ -11,6 +11,7 @@
#include "../CognitiveMap.h"
#include "../../../pedestrian/Pedestrian.h"
#include "../../../geometry/SubRoom.h"
#include "../fire_mesh/firemesh.h"
#include <set>
SmokeSensor::~SmokeSensor()
......@@ -26,38 +27,45 @@ void SmokeSensor::execute(const Pedestrian * pedestrian, CognitiveMap * cognitiv