Commit 5c9d5b77 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Cleaning the Event class.

Cleaning the event test simulation(inputfiles/events/ini.xml)
parent a3bcbaff
......@@ -243,9 +243,12 @@ bool Simulation::InitArgs(const ArgumentParser& args)
return false;
}
//read the events
//read and initialize events
_em = new EventManager(_building.get());
_em->ReadEventsXml();
if(_em->ReadEventsXml()==false)
{
Log->Write("ERROR: \tCould not initialize events handling");
}
_em->ListEvents();
//which hpc-architecture?
......
......@@ -36,6 +36,7 @@
#include "general/ArgumentParser.h"
#include "geometry/Building.h"
#include "geometry/SubRoom.h"
#include "IO/OutputHandler.h"
#include "IO/IODispatcher.h"
#include "math/OperationalModel.h"
......
/**
* \file EventManager.cpp
* \date Jul 4, 2014
* \version v0.6
* \copyright <2009-2014> 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
*
*
**/
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include "../geometry/Building.h"
#include "../geometry/SubRoom.h"
#include "../geometry/Transition.h"
#include "../geometry/Point.h"
#include "../tinyxml/tinyxml.h"
#include "../IO/OutputHandler.h"
#include "../IO/IODispatcher.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
#include "EventManager.h"
using namespace std;
/*******************
Konstruktoren
constructors
******************/
#define UPDATE_FREQUENCY 1 // in seconds
......@@ -33,9 +78,7 @@ EventManager::EventManager(Building *_b)
}
}
/*******************
Dateien einlesen
******************/
void EventManager::SetProjectFilename(const std::string &filename)
{
_projectFilename = filename;
......@@ -46,7 +89,7 @@ void EventManager::SetProjectRootDir(const std::string &filename)
_projectRootDir = filename;
}
void EventManager::ReadEventsXml()
bool EventManager::ReadEventsXml()
{
Log->Write("INFO: \tLooking for pre-defined events in other files");
//get the geometry filename from the project file
......@@ -54,7 +97,7 @@ void EventManager::ReadEventsXml()
if (!doc.LoadFile()) {
Log->Write("ERROR: \t%s", doc.ErrorDesc());
Log->Write("ERROR: \t could not parse the project file.");
exit(EXIT_FAILURE);
return false;
}
TiXmlElement* xMainNode = doc.RootElement();
......@@ -65,7 +108,7 @@ void EventManager::ReadEventsXml()
Log->Write("INFO: \tevents <" + eventfile + ">");
} else {
Log->Write("INFO: \tNo events found");
return;
return true;
}
Log->Write("INFO: \tParsing the event file");
......@@ -73,24 +116,24 @@ void EventManager::ReadEventsXml()
if (!docEvent.LoadFile()) {
Log->Write("ERROR: \t%s", docEvent.ErrorDesc());
Log->Write("ERROR: \t could not parse the event file.");
return;
return false;
}
TiXmlElement* xRootNode = docEvent.RootElement();
if (!xRootNode) {
Log->Write("ERROR:\tRoot element does not exist.");
exit(EXIT_FAILURE);
return false;
}
if (xRootNode->ValueStr() != "JPScore") {
Log->Write("ERROR:\tRoot element value is not 'JPScore'.");
exit(EXIT_FAILURE);
return false;
}
TiXmlNode* xEvents = xRootNode->FirstChild("events");
if (!xEvents) {
Log->Write("ERROR:\tNo events found.");
exit(EXIT_FAILURE);
return false;
}
for (TiXmlElement* e = xEvents->FirstChildElement("event"); e;
......@@ -100,7 +143,8 @@ void EventManager::ReadEventsXml()
_event_states.push_back(e->Attribute("state"));
_event_ids.push_back(atoi(e->Attribute("id")));
}
Log->Write("INFO: \tEvents were read\n");
Log->Write("INFO: \tEvents were initialized\n");
return true;
}
void EventManager::ListEvents()
......@@ -231,30 +275,32 @@ void EventManager::Update_Events(double time, double d)
/***************
Eventhandling
**************/
//close the door if it was open and relaunch the routing procedure
void EventManager::CloseDoor(int id)
{
//pruefen ob entsprechende Tuer schon zu ist, wenn nicht dann schliessen und neues Routing berechnen
Transition *t = _building->GetTransition(id);
if (t->IsOpen()) {
t->Close();
Log->Write("\tDoor %d closed.", id);
Log->Write("INFO:\tClosing door %d ", id);
ChangeRouting(id, "close");
} else {
Log->Write("Door %d is already close yet.", id);
Log->Write("WARNING: \tdoor %d is already close", id);
}
}
//open the door if it was open and relaunch the routing procedure
void EventManager::OpenDoor(int id)
{
//pruefen ob entsprechende Tuer schon offen ist, wenn nicht dann oeffnen und neues Routing berechnen
Transition *t = _building->GetTransition(id);
if (!t->IsOpen()) {
t->Open();
Log->Write("\tDoor %d opened.", id);
Log->Write("INFO:\tOpening door %d ", id);
ChangeRouting(id, "open");
} else {
Log->Write("Door %d is already open yet.", id);
Log->Write("WARNING: \tdoor %d is already open", id);
}
}
......@@ -328,7 +374,6 @@ void EventManager::GetEvent(char* c)
state += c[i];
}
}
}
if (state.compare("close") == 0) {
CloseDoor(atoi(id.c_str()));
......
......@@ -24,28 +24,16 @@
*
*
**/
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include "../geometry/Building.h"
#include "../geometry/SubRoom.h"
#include "../geometry/Transition.h"
#include "../geometry/Point.h"
#include "../tinyxml/tinyxml.h"
#include "../IO/OutputHandler.h"
#include "../IO/IODispatcher.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
#include <string>
class Building;
extern OutputHandler* Log;
class EventManager {
class EventManager
{
private:
std::vector<double> _event_times;
std::vector<std::string> _event_types;
......@@ -61,12 +49,11 @@ private:
long int _lastUpdateTime;
public:
//Konstruktor
//constructor
EventManager(Building *_b);
//Dateien einlesen
void SetProjectFilename(const std::string &filename) ;
void SetProjectFilename(const std::string &filename);
void SetProjectRootDir(const std::string &filename);
void ReadEventsXml();
bool ReadEventsXml();
void ListEvents();
void ReadEventsTxt(double time);
//Update
......
......@@ -71,6 +71,7 @@ Building::Building(const std::string& filename, const std::string& rootDir, Rout
_caption = "no_caption";
_rooms = vector<Room*>();
_savePathway = false;
_linkedCellGrid = nullptr;
//todo: what happens if any of these methods failed (return false)? throw exception ?
this->LoadGeometry();
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JPScore>
<events>
<event time="1" type="door" state="close" id="8" caption="left_exit" />
<event time="10" type="door" state="open" id="8" caption="left_exit" />
<event time="25" type="door" state="close" id="4" caption="main_exit" />
<event time="40" type="door" state="open" id="4" caption="main_exit" />
</events>
</JPScore>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<geometry version="0.5" caption="test" gridSizeX="20" gridSizeY="20" unit="m">
<rooms>
<room id="0" caption="rooms_up" zpos="0.00">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="2.0" py="6.0" />
<vertex px="0.0" py="6.0" />
<vertex px="0.0" py="10.0" />
<vertex px="5.0" py="10.0" />
<vertex px="5.0" py="6.0" />
<vertex px="3.0" py="6.0" />
</polygon>
</subroom>
<subroom id="1" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="7.0" py="6.0" />
<vertex px="5.0" py="6.0" />
<vertex px="5.0" py="10.0" />
<vertex px="10.0" py="10.0" />
<vertex px="10.0" py="6.0" />
<vertex px="8.0" py="6.0" />
</polygon>
</subroom>
<subroom id="2" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="11.0" py="6.0" />
<vertex px="10.0" py="6.0" />
<vertex px="10.0" py="10.0" />
<vertex px="13.0" py="10.0" />
<vertex px="13.0" py="6.0" />
<vertex px="12.0" py="6.0" />
</polygon>
</subroom>
<subroom id="3" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="15.0" py="6.0" />
<vertex px="13.0" py="6.0" />
<vertex px="13.0" py="10.0" />
<vertex px="18.0" py="10.0" />
<vertex px="18.0" py="6.0" />
<vertex px="16.0" py="6.0" />
</polygon>
</subroom>
</room>
<room id="1" caption="rooms_down" zpos="0.00">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="2.0" py="4.0" />
<vertex px="0.0" py="4.0" />
<vertex px="0.0" py="0.0" />
<vertex px="5.0" py="0.0" />
<vertex px="5.0" py="4.0" />
<vertex px="3.0" py="4.0" />
</polygon>
</subroom>
<subroom id="1" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="7.0" py="4.0" />
<vertex px="5.0" py="4.0" />
<vertex px="5.0" py="0.0" />
<vertex px="10.0" py="0.0" />
<vertex px="10.0" py="4.0" />
<vertex px="8.0" py="4.0" />
</polygon>
</subroom>
<subroom id="2" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="15.0" py="4.0" />
<vertex px="13.0" py="4.0" />
<vertex px="13.0" py="0.0" />
<vertex px="18.0" py="0.0" />
<vertex px="18.0" py="4.0" />
<vertex px="16.0" py="4.0" />
</polygon>
</subroom>
</room>
<room id="2" caption="hall" zpos="0.00">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="0.0" py="6.0" />
<vertex px="2.0" py="6.0" />
</polygon>
<polygon caption="wall">
<vertex px="3.0" py="6.0" />
<vertex px="7.0" py="6.0" />
</polygon>
<polygon caption="wall">
<vertex px="8.0" py="6.0" />
<vertex px="11.0" py="6.0" />
</polygon>
<polygon caption="wall">
<vertex px="12.0" py="6.0" />
<vertex px="15.0" py="6.0" />
</polygon>
<polygon caption="wall">
<vertex px="16.0" py="6.0" />
<vertex px="18.0" py="6.0" />
<vertex px="18.0" py="4.0" />
<vertex px="16.0" py="4.0" />
</polygon>
<polygon caption="wall">
<vertex px="15.0" py="4.0" />
<vertex px="13.0" py="4.0" />
<vertex px="13.0" py="-1.0" />
</polygon>
<polygon caption="wall">
<vertex px="10.0" py="-1.0" />
<vertex px="10.0" py="4.0" />
<vertex px="8.0" py="4.0" />
</polygon>
<polygon caption="wall">
<vertex px="7.0" py="4.0" />
<vertex px="3.0" py="4.0" />
</polygon>
<polygon caption="wall">
<vertex px="2.0" py="4.0" />
<vertex px="0.0" py="4.0" />
</polygon>
</subroom>
<crossings>
<crossing id="20" subroom1_id="0" subroom2_id="0">
<vertex px="13.0" py="4.0"/>
<vertex px="12.0" py="6.0"/>
</crossing>
<crossing id="21" subroom1_id="0" subroom2_id="0">
<vertex px="10.0" py="4.0"/>
<vertex px="11.0" py="6.0"/>
</crossing>
</crossings>
</room>
</rooms>
<transitions>
<transition id="0" caption="roomdoor0" type="normal"
room1_id="0" subroom1_id="0" room2_id="2" subroom2_id="0">
<vertex px="2.0" py="6.0" />
<vertex px="3.0" py="6.0" />
</transition>
<transition id="1" caption="roomdoor1" type="normal"
room1_id="0" subroom1_id="1" room2_id="2" subroom2_id="0">
<vertex px="7.0" py="6.0" />
<vertex px="8.0" py="6.0" />
</transition>
<transition id="2" caption="roomdoor2" type="normal"
room1_id="0" subroom1_id="2" room2_id="2" subroom2_id="0">
<vertex px="11.0" py="6.0" />
<vertex px="12.0" py="6.0" />
</transition>
<transition id="3" caption="roomdoor3" type="normal"
room1_id="0" subroom1_id="3" room2_id="2" subroom2_id="0">
<vertex px="15.0" py="6.0" />
<vertex px="16.0" py="6.0" />
</transition>
<transition id="4" caption="main_exit" type="emergency"
room1_id="2" subroom1_id="0" room2_id="-1" subroom2_id="-1">
<vertex px="10.0" py="-1.0" />
<vertex px="13.0" py="-1.0" />
</transition>
<transition id="5" caption="roomdoor5" type="normal"
room1_id="1" subroom1_id="0" room2_id="2" subroom2_id="0">
<vertex px="2.0" py="4.0" />
<vertex px="3.0" py="4.0" />
</transition>
<transition id="6" caption="roomdoor6" type="normal"
room1_id="1" subroom1_id="1" room2_id="2" subroom2_id="0">
<vertex px="7.0" py="4.0" />
<vertex px="8.0" py="4.0" />
</transition>
<transition id="7" caption="roomdoor7" type="normal"
room1_id="1" subroom1_id="2" room2_id="2" subroom2_id="0">
<vertex px="15.0" py="4.0" />
<vertex px="16.0" py="4.0" />
</transition>
<transition id="8" caption="left_exit" type="emergency"
room1_id="2" subroom1_id="0" room2_id="-1" subroom2_id="-1">
<vertex px="0.0" py="4.0" />
<vertex px="0.0" py="6.0" />
</transition>
</transitions>
</geometry>
<?xml version="1.0" encoding="UTF-8" ?>
<JuPedSim project="JPS-Project" version="0.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ini.xsd">
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<!-- geometry file -->
<geometry>geo.xml</geometry>
<max_sim_time>900</max_sim_time>
<events>events.xml</events>
<!-- trajectories file and format -->
<trajectories format="xml-plain" embed_mesh="false" fps="8">
<file location="testSchulTrajectories.xml" />
<!-- <socket hostname="127.0.0.1" port="8989"/> -->
</trajectories>
<!-- where to store the logs -->
<!--<logfile>outputfiles/log.txt</logfile> -->
<!-- traffic information: e.g closed doors or smoked rooms -->
<traffic_constraints>
<!-- room states are: good or smoked -->
<rooms>
<room room_id="0" state="good" />
<room room_id="1" state="good" />
<room room_id="2" state="good" />
</rooms>
<!-- doors states are: close or open -->
<doors>
<door trans_id="0" caption="roomdoor0" state="open" />
<door trans_id="1" caption="roomdoor1" state="open" />
<door trans_id="2" caption="roomdoor2" state="open" />
<door trans_id="3" caption="roomdoor3" state="open" />
<door trans_id="4" caption="main_exit" state="open" />
<door trans_id="5" caption="roomdoor5" state="open" />
<door trans_id="6" caption="roomdoor6" state="open" />
<door trans_id="7" caption="roomdoor7" state="open" />
<door trans_id="8" caption="left_exit" state="open" />
</doors>
</traffic_constraints>
<routing>
<goals>
<goal id="0" final="true" caption="goal1">
<polygon>
<vertex px="10.0" py="-2.0" />
<vertex px="10.0" py="-4.0" />
<vertex px="13.0" py="-4.0" />
<vertex px="13.0" py="-2.0" />
<vertex px="10.0" py="-2.0" />
</polygon>
</goal>
<goal id="1" final="true" caption="goal2">
<polygon>
<vertex px="0.0" py="4.0" />
<vertex px="-1.0" py="4.0" />
<vertex px="-1.0" py="6.0" />
<vertex px="0.0" py="6.0" />
<vertex px="0.0" py="4.0" />
</polygon>
</goal>
</goals>
<routes>
<route id="1">0</route>
<route id="2">1</route>
</routes>
</routing>
<!--persons information and distribution -->
<agents>
<agents_distribution>
<group group_id="0" room_id="0" subroom_id="0" number="20" router_id="1" />
<group group_id="1" room_id="0" subroom_id="1" number="20" router_id="1" />
<group group_id="2" room_id="0" subroom_id="2" number="4" router_id="1" />
<group group_id="3" room_id="0" subroom_id="3" number="20" router_id="1" />
<group group_id="4" room_id="1" subroom_id="0" number="20" router_id="1" />
<group group_id="5" room_id="1" subroom_id="1" number="20" router_id="1" />
<group group_id="6" room_id="1" subroom_id="2" number="20" router_id="1" />
</agents_distribution>
<agents_sources><!-- frequency in persons/minute -->
<source id="1" frequency="60" agents_max="150" router_id="1" goal_id="" route_id="" caption="source 1">
<polygon>
<vertex px="6.0" py="2.0" />
<vertex px="6.0" py="0.0" />
<vertex px="0.0" py="0.0" />
<vertex px="0.0" py="6.0" />
<vertex px="6.0" py="6.0" />
<vertex px="6.0" py="4.0" />
</polygon>
</source>
</agents_sources>
</agents>
<operational_models>
<model id="1" description="gcfm">
<parameters>
<solver>euler</solver>
<stepsize>0.001</stepsize>
<exitCrossingStrategy>3</exitCrossingStrategy>
<linkedcells enabled="true" cell_size="2.2" />
<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" />
<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" />
</parameters>
</model>
<model id="2" desciption="cdt">
<parameters></parameters>
</model>
</operational_models>
<route_choice_models>
<router router_id="1" description="global_shortest">
<parameters>
<!-- extra routing information -->
<navigation_lines file="routing.xml" />
</parameters>
</router>
</route_choice_models>
</JuPedSim>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<routing version="0.5">
<Hlines>
<Hline id="0" room_id="2" subroom_id="0">
<vertex px="13.0" py="4.0" />
<vertex px="12.0" py="6.0" />
</Hline>
<Hline id="1" room_id="2" subroom_id="0">
<vertex px="10.0" py="4.0" />
<vertex px="11.0" py="6.0" />
</Hline>
</Hlines>
</routing>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,8 +4,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../xsd/jps_events.xsd">
<events>
<event time="2" type="door" state="close" id="0"/>
<event time="10" type="door" state="close" id="1" caption="roomdoor" />
<event time="15" type="door" state="open" id="0" caption="exit" />
<event time="1" type="door" state="close" id="8" caption="left_exit" />
<event time="10" type="door" state="open" id="8" caption="left_exit" />
<event time="25" type="door" state="close" id="4" caption="main_exit" />
<event time="40" type="door" state="open" id="4" caption="main_exit" />
</events>
</JPScore>
</JPScore>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<geometry version="0.5" caption="test" gridSizeX="20" gridSizeY="20" unit="m">
<rooms>
<room id="0" caption="hall" zpos="0.00">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="6.0" py="2.0" />
<vertex px="6.0" py="0.0" />
<vertex px="0.0" py="0.0" />
<vertex px="0.0" py="6.0" />
<vertex px="6.0" py="6.0" />
<vertex px="6.0" py="4.0" />
</polygon>
</subroom>
</room>
</rooms>
<geometry version="0.5" caption="test" unit="m"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/jps_geometry.xsd">
<transitions>
<transition id="1" caption="exit" type="emergency"
room1_id="0" subroom1_id="0" room2_id="-1" subroom2_id="-1">
<vertex px="6.0" py="4.0" />
<vertex px="6.0" py="2.0" />
</transition>
</transitions>
<rooms>
<room id="0" caption="rooms_up">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="2.0" py="6.0" />
<vertex px="0.0" py="6.0" />
<vertex px="0.0" py="10.0" />
<vertex px="5.0" py="10.0" />
<vertex px="5.0" py="6.0" />
<vertex px="3.0" py="6.0" />
</polygon>
</subroom>
<subroom id="1" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="7.0" py="6.0" />
<vertex px="5.0" py="6.0" />
<vertex px="5.0" py="10.0" />
<vertex px="10.0" py="10.0" />
<vertex px="10.0" py="6.0" />
<vertex px="8.0" py="6.0" />
</polygon>
</subroom>
<subroom id="2" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="11.0" py="6.0" />
<vertex px="10.0" py="6.0" />
<vertex px="10.0" py="10.0" />
<vertex px="13.0" py="10.0" />
<vertex px="13.0" py="6.0" />
<vertex px="12.0" py="6.0" />
</polygon>
</subroom>
<subroom id="3" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="15.0" py="6.0" />
<vertex px="13.0" py="6.0" />
<vertex px="13.0" py="10.0" />
<vertex px="18.0" py="10.0" />
<vertex px="18.0" py="6.0" />
<vertex px="16.0" py="6.0" />
</polygon>
</subroom>
</room>
<room id="1" caption="rooms_down">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="2.0" py="4.0" />
<vertex px="0.0" py="4.0" />
<vertex px="0.0" py="0.0" />
<vertex px="5.0" py="0.0" />
<vertex px="5.0" py="4.0" />
<vertex px="3.0" py="4.0" />
</polygon>
</subroom>
<subroom id="1" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="7.0" py="4.0" />
<vertex px="5.0" py="4.0" />
<vertex px="5.0" py="0.0" />
<vertex px="10.0" py="0.0" />
<vertex px="10.0" py="4.0" />
<vertex px="8.0" py="4.0" />
</polygon>
</subroom>
<subroom id="2" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="15.0" py="4.0" />