Commit f2066beb authored by Mohcine Chraibi's avatar Mohcine Chraibi

Changed to ReInit router

geometries may change during simulation
parent 268285f1
......@@ -352,7 +352,7 @@ void Simulation::UpdateRoutesAndLocations()
//set the new room if needed
if ((ped->GetFinalDestination() == FINAL_DEST_OUT)
&& (room->GetCaption() == "outside")) { //TODO Hier aendern fuer inside goals?
&& (room->GetCaption() == "outside")) { //TODO Hier aendern fuer inside goals?
#pragma omp critical(Simulation_Update_pedsToRemove)
pedsToRemove.insert(ped);
} else if ((ped->GetFinalDestination() != FINAL_DEST_OUT)
......@@ -575,43 +575,37 @@ double Simulation::RunBody(double maxSimTime)
//here we could place router-tasks (calc new maps) that can use multiple cores AND we have 't'
//update quickestRouter
if (_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST)) {
if(geometryChanged)
{
FFRouter* ffrouter2 = dynamic_cast<FFRouter*>(_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST));
ffrouter2->Init(_building.get());
// debug
fs::path f("tmp_"+std::to_string(t)+"_"+_config->GetGeometryFile());
std::string filename = f.string();
std::cout << "\nUpdate geometry. New geometry --> " << filename.c_str() << "\n";
std::cout<< KGRN << "Enter correctGeometry: Building Has " << _building->GetAllTransitions().size() << " Transitions\n" << RESET;
_building->SaveGeometry(filename);
//
double _deltaH = _building->GetConfig()->get_deltaH();
double _wallAvoidDistance = _building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = _building->GetConfig()->get_use_wall_avoidance();
if(auto dirlocff = dynamic_cast<DirectionLocalFloorfield*>(_building->GetConfig()->get_dirStrategy())){
Log->Write("INFO:\t Init DirectionLOCALFloorfield starting ...");
dirlocff->Init(_building.get(), _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionLOCALFloorfield done");
}
std::cout << KBLU << " Init router in simulation\n" << RESET;
}
else{
FFRouter* ffrouter = dynamic_cast<FFRouter*>(_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST));
if (ffrouter->MustReInit()) {
ffrouter->ReInit();
ffrouter->SetRecalc(t);
}
if(geometryChanged)
{
// debug
fs::path f("tmp_"+std::to_string(t)+"_"+_config->GetGeometryFile());
std::string filename = f.string();
std::cout << "\nUpdate geometry. New geometry --> " << filename.c_str() << "\n";
std::cout<< KGRN << "Enter correctGeometry: Building Has " << _building->GetAllTransitions().size() << " Transitions\n" << RESET;
_building->SaveGeometry(filename);
//
double _deltaH = _building->GetConfig()->get_deltaH();
double _wallAvoidDistance = _building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = _building->GetConfig()->get_use_wall_avoidance();
if(auto dirlocff = dynamic_cast<DirectionLocalFloorfield*>(_building->GetConfig()->get_dirStrategy())){
Log->Write("INFO:\t Init DirectionLOCALFloorfield starting ...");
dirlocff->Init(_building.get(), _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionLOCALFloorfield done");
}
}
else{ // quickest needs update even if NeedsUpdate() is false
FFRouter* ffrouter = dynamic_cast<FFRouter*>(_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST));
if (ffrouter->MustReInit()) {
ffrouter->ReInit();
ffrouter->SetRecalc(t);
}
}
// here the used routers are update, when needed due to external changes
if (_routingEngine->NeedsUpdate()){
std::cout << KBLU << " Init router in simulation\n" << RESET;
_routingEngine->UpdateRouter();
}
......
......@@ -322,6 +322,44 @@ bool FFRouter::ReInit()
_distMatrix.clear();
_pathsMatrix.clear();
// Geommetry may change dure to trains or whatever happens in the future
//get all door UIDs
_allDoorUIDs.clear();
_TransByUID.clear();
_ExitsByUID.clear();
_CroTrByUID.clear();
auto& allTrans = _building->GetAllTransitions();
auto& allCross = _building->GetAllCrossings();
std::vector<std::pair<int, int>> roomAndCroTrVector;
roomAndCroTrVector.clear();
for (auto& pair:allTrans) {
//TODO if (pair.second->IsOpen()) {
if (!pair.second->IsClose()) {
_allDoorUIDs.emplace_back(pair.second->GetUniqueID());
_CroTrByUID.insert(std::make_pair(pair.second->GetUniqueID(), pair.second));
if (pair.second->IsExit()) {
_ExitsByUID.insert(std::make_pair(pair.second->GetUniqueID(), pair.second));
}
Room* room1 = pair.second->GetRoom1();
if (room1) roomAndCroTrVector.emplace_back(std::make_pair(room1->GetID(), pair.second->GetUniqueID()));
Room* room2 = pair.second->GetRoom2();
if (room2) roomAndCroTrVector.emplace_back(std::make_pair(room2->GetID(), pair.second->GetUniqueID()));
}
}
for (auto& pair:allCross) {
//TODO if (pair.second->IsOpen()) {
if (!pair.second->IsClose()) {
_allDoorUIDs.emplace_back(pair.second->GetUniqueID());
_CroTrByUID.insert(std::make_pair(pair.second->GetUniqueID(), pair.second));
Room* room1 = pair.second->GetRoom1();
if (room1) roomAndCroTrVector.emplace_back(std::make_pair(room1->GetID(), pair.second->GetUniqueID()));
}
}
//make unique
std::sort(_allDoorUIDs.begin(), _allDoorUIDs.end());
_allDoorUIDs.erase( std::unique(_allDoorUIDs.begin(),_allDoorUIDs.end()), _allDoorUIDs.end());
// alldoorUIDs reinit
//init, yet no distances, only create map entries
for(auto& id1 : _allDoorUIDs) {
for(auto& id2 : _allDoorUIDs){
......
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