Commit 32858daa authored by tobias schroedter's avatar tobias schroedter

First try to get Events working with new door states

parent 2a988781
......@@ -349,9 +349,10 @@ void Simulation::UpdateRoutesAndLocations()
if(_gotSources)
ped->FindRoute();
//finally actualize the route
if ( !_gotSources && ped->FindRoute() == -1) {
if ( !_gotSources && ped->FindRoute() == -1 ) {
//a destination could not be found for that pedestrian
Log->Write("ERROR: \tCould not find a route for pedestrian %d",ped->GetID());
Log->Write("ERROR: \tCould not find a route for pedestrian %d in room %d and subroom %d",
ped->GetID(), ped->GetRoomID(), ped->GetSubRoomID());
//ped->FindRoute(); //debug only, plz remove
std::function<void(const Pedestrian&)> f = std::bind(&Simulation::UpdateFlowAtDoors, this, std::placeholders::_1);
ped->Relocate(f);
......
......@@ -13,7 +13,7 @@ Event::Event(int id, double time, const std::string& type,
_id=id;
_time=time;
_type=type;
_state=state;
_state= StringToDoorState(state);
}
Event::~Event()
......@@ -25,7 +25,7 @@ int Event::GetId() const
return _id;
}
const std::string& Event::GetState() const
const DoorState Event::GetState() const
{
return _state;
}
......@@ -43,6 +43,21 @@ const std::string& Event::GetType() const
const std::string Event::GetDescription() const
{
char tmp[1024];
sprintf(tmp,"After %.2f sec, %s door %d", _time,_state.c_str(), _id);
std::string state;
switch (_state){
case DoorState::OPEN:
state = "open";
break;
case DoorState::CLOSE:
state = "close";
break;
case DoorState::TEMP_CLOSE:
state = "temp_close";
break;
default:
state = "error";
break;
}
sprintf(tmp,"After %.2f sec, %s door %d", _time, state.c_str(), _id);
return std::string(tmp);
}
......@@ -9,6 +9,7 @@
#define EVENTS_EVENT_H_
#include <string>
#include "../general/Macros.h"
class Event
{
......@@ -37,7 +38,7 @@ public:
/**
* @return the state (open, close) of the event
*/
const std::string& GetState() const;
const DoorState GetState() const;
/**
* @return the time at which the event was recorded
......@@ -58,7 +59,7 @@ private:
double _time;
int _id;
std::string _type;
std::string _state;
DoorState _state;
};
#endif /* EVENTS_EVENT_H_ */
......@@ -258,24 +258,25 @@ bool EventManager::DisseminateKnowledge(Building* _b)
}
//TODO Was passiert hier?
//update the routers based on the configurations
//#pragma omp parallel
for(auto&& ped:_b->GetAllPedestrians())
{
if(UpdateRoute(ped)==false)
{
//Clear the memory and attempt to reroute
//this can happen if all doors are known to be closed
ped->ClearKnowledge();
Log->Write("ERROR: \t clearing ped knowledge");
//ped->Dump(ped->GetID());
if(UpdateRoute(ped)==false)
{
Log->Write("ERROR: \t cannot reroute the pedestrian. unknown problem");
//return false;
exit(EXIT_FAILURE);
}
}
// if(UpdateRoute(ped)==false)
// {
// //Clear the memory and attempt to reroute
// //this can happen if all doors are known to be closed
// ped->ClearKnowledge();
// Log->Write("ERROR: \t clearing ped knowledge");
// //ped->Dump(ped->GetID());
// if(UpdateRoute(ped)==false)
// {
// Log->Write("ERROR: \t cannot reroute the pedestrian. unknown problem");
// //return false;
// exit(EXIT_FAILURE);
// }
// }
}
return true;
}
......@@ -516,10 +517,17 @@ void EventManager::ProcessEvent()
if (fabs(event.GetTime() - current_time_d) < J_EPS_EVENT) {
//Event with current time stamp detected
Log->Write("INFO:\tEvent: after %.2f sec: ", current_time_d);
if (event.GetState().compare("close") == 0) {
CloseDoor(event.GetId());
} else {
switch (event.GetState()){
case DoorState::OPEN:
OpenDoor(event.GetId());
break;
case DoorState::CLOSE:
CloseDoor(event.GetId());
break;
case DoorState::TEMP_CLOSE:
TempCloseDoor(event.GetId());
break;
}
}
......@@ -534,7 +542,7 @@ void EventManager::CloseDoor(int id)
{
Transition *t = _building->GetTransition(id);
if (t->IsOpen())
if (!t->IsClose())
{
t->Close();
Log->Write("INFO:\tClosing door %d ", id);
......@@ -549,6 +557,26 @@ void EventManager::CloseDoor(int id)
}
void EventManager::TempCloseDoor(int id)
{
Transition *t = _building->GetTransition(id);
if (!t->IsTempClose())
{
t->TempClose();
Log->Write("INFO:\tClosing door %d ", id);
//Create and save a graph corresponding to the actual state of the building.
if(CreateRoutingEngine(_building)==false)
{
Log->Write("ERROR: \tcannot create a routing engine with the new event");
}
} else {
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)
{
......
......@@ -74,6 +74,7 @@ public:
void ProcessEvent();
//Eventhandling
void CloseDoor(int id);
void TempCloseDoor(int id);
void OpenDoor(int id);
//void ChangeRouting(int id, const std::string& state);
void GetEvent(char* c);
......
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