Commit 14de8c48 authored by tobias schroedter's avatar tobias schroedter

Realtime event reader improved

parent 8e2d1dd6
......@@ -61,15 +61,6 @@ EventManager::EventManager(Building *_b, unsigned int seed)
_updateFrequency =1 ;//seconds
_updateRadius =2;//meters
_file = fopen("../events/events.txt", "r");
if (!_file) {
Log->Write("INFO:\tFiles 'events.txt' missing. "
"Realtime interaction with the simulation not possible.");
} else {
Log->Write("INFO:\tFile 'events.txt' will be monitored for new events.");
_dynamic = true;
}
//generate random number between 0 and 1 uniformly distributed
_rdDistribution = std::uniform_real_distribution<double> (0,1);
//std::random_device rd;
......@@ -103,6 +94,23 @@ bool EventManager::ReadEventsXml()
}
TiXmlElement* xMainNode = doc.RootElement();
string realtimefile;
if (xMainNode->FirstChild("event_realtime")) {
realtimefile = _projectRootDir
+ xMainNode->FirstChild("event_realtime")->FirstChild()->Value();
_file = fopen(realtimefile.c_str(), "r");
if (!_file) {
Log->Write("INFO:\tFiles '"+ realtimefile+ "' missing. "
"Realtime interaction with the simulation not possible.");
} else {
Log->Write("INFO:\tFile '"+ realtimefile+ "' will be monitored for new events.");
_dynamic = true;
}
} else {
Log->Write("INFO: \tNo realtime events found");
}
string eventfile = "";
if (xMainNode->FirstChild("events_file")) {
eventfile = _projectRootDir
......@@ -113,6 +121,7 @@ bool EventManager::ReadEventsXml()
return true;
}
Log->Write("INFO: \tParsing the event file");
TiXmlDocument docEvent(eventfile);
if (!docEvent.LoadFile()) {
......@@ -174,8 +183,8 @@ void EventManager::ReadEventsTxt(double time)
char cstring[256];
int lines = 0;
do {
if (fgets(cstring, 30, _file) == NULL) {
Log->Write("WARNING: \tCould not read the event file");
if (fgets(cstring, 30, _file) == nullptr) {
// Log->Write("WARNING: \tCould not read the event file");
return;
}
if (cstring[0] != '#') {// skip comments
......@@ -525,6 +534,7 @@ void EventManager::ProcessEvent()
void EventManager::CloseDoor(int id)
{
Transition *t = _building->GetTransition(id);
if (t->IsOpen())
{
t->Close();
......
......@@ -366,6 +366,10 @@ bool Building::InitGeometry()
InitInsideGoals();
Log->Write("INFO: \tInit Geometry successful!!!\n");
for (auto& transItr : _transitions){
Transition* trans = transItr.second;
std::cout << trans->GetID() << " is open " << trans->IsOpen() << std::endl;
}
return true;
}
......@@ -419,6 +423,8 @@ bool Building::InitInsideGoals()
found = false;
}
Log->Write("INFO: \tInitInsideGoals successful!!!\n");
return true;
}
bool Building::correct() const {
......@@ -954,10 +960,10 @@ Transition* Building::GetTransition(int ID) const //ar.graf: added const 2015-12
}
}
Crossing* Building::GetCrossing(int ID)
Crossing* Building::GetCrossing(int ID) const
{
if (_crossings.count(ID)==1) {
return _crossings[ID];
return _crossings.at(ID);
}
else {
if (ID==-1)
......
......@@ -130,7 +130,7 @@ public:
* @param ID of Crossing: int
* @return Pointer of Crossing
*/
Crossing* GetCrossing(int ID);
Crossing* GetCrossing(int ID) const;
/**
* Not implemented
......
......@@ -331,7 +331,7 @@ void FloorfieldViaFMTrips::createMapEntryInLineToGoalID(const int goalID, bool i
&& (b._y>=yMin) && (b._y<=yMax)
) {
localline.emplace_back(Line((Line) iwall));
std::cout << "(Line) iwall : " << ((Line) iwall).toString() << std::endl;
// std::cout << "(Line) iwall : " << ((Line) iwall).toString() << std::endl;
}
else {
......
......@@ -53,7 +53,6 @@ UnivFFviaFMTrips::UnivFFviaFMTrips(Room* r, Configuration* const conf, double hx
UnivFFviaFMTrips::UnivFFviaFMTrips(Room* roomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors, std::map<int, Goal*> goals) {
//build the vector with walls(wall or obstacle), the map with <UID, Door(Cross or Trans)>, the vector with targets(UIDs)
//then call other constructor including the mode
Log->Write("UnivFFviaFMTrips::UnivFFviaFMTrips(Room* roomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors)\n");
_configuration = confArg;
_scope = FF_ROOM_SCALE;
_room = roomArg->GetID();
......@@ -170,8 +169,6 @@ UnivFFviaFMTrips::UnivFFviaFMTrips(SubRoom* subRoomArg, Configuration* const con
//build the vector with walls(wall or obstacle), the map with <UID, Door(Cross or Trans)>, the vector with targets(UIDs)
//then call other constructor including the mode
Log->Write("UnivFFviaFMTrips::UnivFFviaFMTrips(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors))");
_configuration = confArg;
_scope = FF_SUBROOM_SCALE;
_room = subRoomArg->GetRoomID();
......
......@@ -108,8 +108,11 @@ bool FFRouterTrips::Init(Building* building)
for (auto &itrGoal : building->GetAllGoals()) {
if(WaitingArea* wa = dynamic_cast<WaitingArea*>(itrGoal.second)) {
_globalFF->createMapEntryInLineToGoalID(itrGoal.first, true);
std::cout << "Added " << itrGoal.first << " to goalIDs " << wa->getTransitionID() << std::endl;
}else{
_globalFF->createMapEntryInLineToGoalID(itrGoal.first, false);
std::cout << "Added " << itrGoal.first << " to goalIDs " << std::endl;
}
goalIDs.emplace_back(itrGoal.first);
}
......@@ -132,6 +135,7 @@ bool FFRouterTrips::Init(Building* building)
std::vector<std::pair<int, int>> roomAndCroTrVector;
roomAndCroTrVector.clear();
for (auto& pair:allTrans) {
if (pair.second->IsOpen()) {
_allDoorUIDs.emplace_back(pair.second->GetUniqueID());
......@@ -145,6 +149,7 @@ bool FFRouterTrips::Init(Building* building)
if (room2) roomAndCroTrVector.emplace_back(std::make_pair(room2->GetID(), pair.second->GetUniqueID()));
}
}
for (auto& pair:allCross) {
if (pair.second->IsOpen()) {
_allDoorUIDs.emplace_back(pair.second->GetUniqueID());
......@@ -153,39 +158,16 @@ bool FFRouterTrips::Init(Building* building)
if (room1) roomAndCroTrVector.emplace_back(std::make_pair(room1->GetID(), pair.second->GetUniqueID()));
}
}
// for (auto& goalMap : allGoals) {
// Goal* goal = goalMap.second;
// if (WaitingArea* wa = dynamic_cast<WaitingArea*>(goal)) {
// if (wa->isOpen()){
// int roomID;
// for (auto& room : _building->GetAllRooms()){
// for (auto& subroom : room.second->GetAllSubRooms()){
// if (subroom.second->IsInSubRoom(wa->GetCentroid())){
// roomID = room.second->GetID();
// }
// }
// }
//
// for (const Wall wall : wa->GetAllWalls()) {
// int uid = wall.GetUniqueID();
// if (std::find(_allDoorUIDs.begin(), _allDoorUIDs.end(), uid) == _allDoorUIDs.end()) {
// _allDoorUIDs.emplace_back(uid);
// Crossing cross;
// cross.SetPoint1(wall.GetPoint1());
// cross.SetPoint2(wall.GetPoint2());
// cross.SetCaption(wa->GetCaption());
// _CroTrByUID.insert(std::make_pair(uid, &cross));
// roomAndCroTrVector.emplace_back(roomID, uid);
// }
// }
// }
// }
// }
//make unique
std::sort(_allDoorUIDs.begin(), _allDoorUIDs.end());
_allDoorUIDs.erase( std::unique(_allDoorUIDs.begin(),_allDoorUIDs.end()), _allDoorUIDs.end());
// for (auto& door : _allDoorUIDs){
// std::cout << "Door: " << door << std::endl;
// }
//cleanse maps
_distMatrix.clear();
_pathsMatrix.clear();
......@@ -200,6 +182,8 @@ bool FFRouterTrips::Init(Building* building)
_distMatrix.insert(std::make_pair( key , value));
//pathsMatrix[i][j] = i or j ? (follow wiki:path_reconstruction, it should be j)
_pathsMatrix.insert(std::make_pair( key , id2 ));
// std::cout << "_pathsMatrix added ( " << key.first << " " << key.second << " | " << id2 << ")" << std::endl;
//_subroomMatrix.insert(std::make_pair(key, nullptr));
}
}
......@@ -593,21 +577,15 @@ int FFRouterTrips::FindExit1(Pedestrian* p)
}
}
int bestFinalDoor = -1; // to silence the compiler
for(int finalDoor : validFinalDoor) {
//with UIDs, we can ask for shortest path
for (int doorUID : DoorUIDsOfRoom) {
//double locDistToDoor = _locffviafm[p->GetRoomID()]->getCostToDestination(doorUID, p->GetPos(), _mode);
double locDistToDoor = 0.;
// if (_targetWithinSubroom) {
// locDistToDoor = _config->get_dirSubLocal()->GetDistance2Target(p, doorUID);
// } else {
// locDistToDoor = _config->get_dirLocal()->GetDistance2Target(p, doorUID);
// }
//
locDistToDoor = _config->get_dirStrategy()->GetDistance2Target(p, doorUID);
if (locDistToDoor < -J_EPS) { //for old ff: //this can happen, if the point is not reachable and therefore has init val -7
continue;
}
......@@ -615,6 +593,12 @@ int FFRouterTrips::FindExit1(Pedestrian* p)
//auto subroomDoors = _building->GetSubRoomByUID(p->GetSubRoomUID())->GetAllGoalIDs();
//only consider, if paths exists
if (_pathsMatrix.count(key)==0) {
Crossing* cross1 = _building->GetCrossing(key.first);
Crossing* cross2 = _building->GetCrossing(key.second);
Transition* trans1 = _building->GetTransition(key.first);
Transition* trans2 = _building->GetTransition(key.first);
Log->Write("no key for %d %d", key.first, key.second);
continue;
}
......
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