Commit 8a4f8ba2 authored by Ulrich Kemloh's avatar Ulrich Kemloh

refactoring the events

parent 1a74d107
......@@ -239,6 +239,7 @@ set ( source_files
poly2tri/sweep/sweep.cpp
poly2tri/sweep/cdt.cpp
events/EventManager.cpp
events/Event.cpp
)
set ( header_files
......@@ -327,6 +328,7 @@ set ( header_files
poly2tri/sweep/advancing_front.h
poly2tri/sweep/sweep.h
events/EventManager.h
events/Event.h
)
......
/*
* Event.cpp
*
* Created on: Jul 21, 2015
* Author: piccolo
*/
#include "Event.h"
Event::Event(int id, double time, const std::string& type,
const std::string& state)
{
_id=id;
_time=time;
_type=type;
_state=state;
}
Event::~Event()
{
}
int Event::GetId() const
{
return _id;
}
const std::string& Event::GetState() const
{
return _state;
}
double Event::GetTime() const
{
return _time;
}
const std::string& Event::GetType() const
{
return _type;
}
const std::string Event::GetDescription() const
{
char tmp[1024];
sprintf(tmp,"After %.2f sec, %s door %d", _time,_state.c_str(), _id);
return std::string(tmp);
}
/*
* Event.h
*
* Created on: Jul 21, 2015
* Author: piccolo
*/
#ifndef EVENTS_EVENT_H_
#define EVENTS_EVENT_H_
#include <string>
class Event
{
public:
/**
* Constructor
* @param id
* @param time
* @param type
* @param state
*/
Event(int id, double time, const std::string& type,
const std::string& state);
/**
* Destructor
*/
virtual ~Event();
/**
* @return the id of the event
*/
int GetId() const;
/**
* @return the state (open, close) of the event
*/
const std::string& GetState() const;
/**
* @return the time at which the event was recorded
*/
double GetTime() const;
/**
* @return the type of the event (room, door)
*/
const std::string& GetType() const;
/**
* return a description of the event
*/
const std::string GetDescription() const;
private:
double _time;
int _id;
std::string _type;
std::string _state;
};
#endif /* EVENTS_EVENT_H_ */
This diff is collapsed.
......@@ -33,31 +33,50 @@ class Router;
class GlobalRouter;
class QuickestPathRouter;
class RoutingEngine;
class Event;
extern OutputHandler* Log;
class EventManager
{
private:
std::vector<double> _event_times;
std::vector<std::string> _event_types;
std::vector<std::string> _event_states;
std::vector<int> _event_ids;
std::string _projectFilename;
std::string _projectRootDir;
Building *_building;
FILE *_file;
bool _dynamic;
int _eventCounter;
long int _lastUpdateTime;
//information propagation time in seconds
int _updateFrequency;
//information propagation range in meters
int _updateRadius;
//save the router corresponding to the actual state of the building
std::map<std::string, RoutingEngine*> _eventEngineStorage;
//save the available routers defined in the simulation
std::vector<RoutingStrategy> _availableRouters;
public:
/**
* Constructor
*/
EventManager(Building *_b);
/**
* destructor
*/
~EventManager();
/**
* Read and parse the events
* @return false if an error occured
*/
bool ReadEventsXml();
/**
* Print the parsed events
*/
void ListEvents();
/**
* Read and parse events from a text file
* @param time
*/
void ReadEventsTxt(double time);
//process the event using the current time stamp
//from the pedestrian class
void ProcessEvent();
//Eventhandling
void CloseDoor(int id);
void OpenDoor(int id);
//void ChangeRouting(int id, const std::string& state);
void GetEvent(char* c);
private:
/**
......@@ -97,45 +116,24 @@ private:
*/
bool UpdateRoute(Pedestrian* p1);
public:
///constructor
EventManager(Building *_b);
/**
*
* destructor
*/
~EventManager();
/**
* Read and parse the events
* @return false if an error occured
*/
bool ReadEventsXml();
/**
* Print the parsed events
*/
void ListEvents();
/**
* Read and parse events from a text file
* @param time
*/
void ReadEventsTxt(double time);
private:
/**
* Process the events at runtime
* @param time
*/
void Update_Events(double time);
std::vector<Event> _events;
std::string _projectFilename;
std::string _projectRootDir;
Building *_building;
FILE *_file;
bool _dynamic;
int _eventCounter;
long int _lastUpdateTime;
//information propagation time in seconds
int _updateFrequency;
//information propagation range in meters
int _updateRadius;
//save the router corresponding to the actual state of the building
std::map<std::string, RoutingEngine*> _eventEngineStorage;
//save the available routers defined in the simulation
std::vector<RoutingStrategy> _availableRouters;
//process the event using the current time stamp
//from the pedestrian class
void ProcessEvent();
//Eventhandling
void CloseDoor(int id);
void OpenDoor(int id);
void ChangeRouting(int id, const std::string& state);
void GetEvent(char* c);
};
......@@ -3,7 +3,7 @@
<JPScore project="JPS-Project" version="0.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_events.xsd">
<events update_frequency="2" update_radius="1" agents_color_by_knowledge="true">
<events update_frequency="2" update_radius="1">
<event time="15" type="door" state="close" id="8" caption="left_exit" />
<event time="50" type="door" state="open" id="8" caption="left_exit" />
<event time="51" type="door" state="close" id="4" caption="main_exit" />
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JPScore project="JPS-Project" version="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_events.xsd">
<JPScore project="JPS-Project" version="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_events.xsd">
<events update_frequency="2" update_radius="1" agents_color_by_knowledge="true">
<event time="10" type="door" state="close" id="2" caption="exit" />
<event time="30" type="door" state="close" id="3" caption="exit" />
......
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<JuPedSim project="JPS-Project" version="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.7/jps_ini_core.xsd">
<!-- seed used for initialising random generator -->
<seed>12542</seed>
......@@ -11,7 +11,7 @@
<!-- trajectories file and format -->
<trajectories format="xml-plain" fps="8">
<file location="big_room_trrajectories.xml" />
<file location="big_room_trajectories.xml" />
<socket hostname="127.0.0.1" port="8989" />
</trajectories>
......
<?xml version="1.0" encoding="UTF-8" ?>
<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://xsd.jupedsim.org/0.7/jps_ini_core.xsd">
<!-- seed used for initialising random generator -->
<seed>12542</seed>
......@@ -61,16 +61,16 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<agents_distribution>
<group group_id="0" agent_parameter_id="1" room_id="0" subroom_id="0" number="20" router_id="1" />
<group group_id="1" agent_parameter_id="1" room_id="0" subroom_id="1" number="20" router_id="1" />
<group group_id="2" agent_parameter_id="1" room_id="0" subroom_id="2" number="4" router_id="1" />
<group group_id="2" agent_parameter_id="1" room_id="0" subroom_id="2" number="10" router_id="1" />
<group group_id="3" agent_parameter_id="1" room_id="0" subroom_id="3" number="20" router_id="1" />
<group group_id="4" agent_parameter_id="1" room_id="1" subroom_id="0" number="20" router_id="1" />
<group group_id="5" agent_parameter_id="1" room_id="1" subroom_id="1" number="20" router_id="1" />
<group group_id="6" agent_parameter_id="1" room_id="1" subroom_id="2" number="20" router_id="1" />
</agents_distribution>
<agents_sources><!-- frequency in persons/second -->
<source0 id="1" group_id="0" frequency="0" agents_max="150" router_id="1" goal_id="" route_id="" caption="source 1"/>
</agents_sources>
<!-- <agents_sources>frequency in persons/second -->
<!-- <source0 id="1" group_id="0" frequency="0" agents_max="150" router_id="1" goal_id="" route_id="" caption="source 1"/> -->
<!-- </agents_sources> -->
</agents>
<operational_models>
......
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