Commit 67a25c24 authored by Arne Graf's avatar Arne Graf

ff_quickest prototype implemented, room sanity enabled

parent 65faf57d
Pipeline #3993 failed with stages
in 4 minutes and 14 seconds
......@@ -476,8 +476,6 @@ double Simulation::RunBody(double maxSimTime)
ProcessAgentsQueue();
if (t>Pedestrian::GetMinPremovementTime()) {
//@todo: @ar.graf: here we could place router-tasks (calc new maps) that can use multiple cores AND we have 't'
//update the linked cells
_building->UpdateGrid();
......@@ -487,8 +485,15 @@ double Simulation::RunBody(double maxSimTime)
//update the events
_em->ProcessEvent();
//update doorticks
//UpdateDoorticks();
//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)) {
FFRouter* ffrouter = dynamic_cast<FFRouter*>(_routingEngine.get()->GetRouter(ROUTING_FF_QUICKEST));
if (ffrouter->MustReInit()) {
ffrouter->ReInit();
ffrouter->SetRecalc(t);
}
}
//update the routes and locations
UpdateRoutesAndLocations();
......
......@@ -187,6 +187,7 @@ enum FloorfieldMode {
FF_FULL_LINE,
FF_WALL_AVOID,
FF_HOMO_SPEED,
FF_PED_SPEED,
FF_ROOM_SCALE,
FF_SUBROOM_SCALE
};
......
......@@ -706,12 +706,9 @@ std::vector<Point> Building::GetBoundaryVertices() const
bool Building::SanityCheck()
{
Log->Write("INFO: \tChecking the geometry for artifacts");
Log->Write("INFO: \tChecking the geometry for artifacts: (Ignore Warnings, if ff_[...] router is used!)");
bool status = true;
//only for ffRouter
return status;
for(auto&& itr_room: _rooms)
{
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
......
......@@ -981,7 +981,7 @@ Router* Pedestrian::GetRouter() const
int Pedestrian::FindRoute()
{
if( ! _router) {
Log->Write("ERROR:\t one or more routers does not exit! Check your router_ids");
Log->Write("ERROR:\t one or more routers does not exist! Check your router_ids");
return -1;
}
//bool isinsub = (_building->GetAllRooms().at(this->GetRoomID())->GetSubRoom(this->GetSubRoomID())->IsInSubRoom(this));
......
......@@ -95,7 +95,7 @@ Router* RoutingEngine::GetRouter(RoutingStrategy strategy) const
if(router->GetStrategy()==strategy)
return router;
}
Log->Write("ERROR: \t Could not Find any router with Strategy: [%d].",strategy);
//Log->Write("ERROR: \t Could not Find any router with Strategy: [%d].",strategy);
return /*(Router*)*/ nullptr;
}
......
This diff is collapsed.
......@@ -42,6 +42,7 @@
#include <float.h>
#include "../../general/Macros.h"
class Pedestrian;
class Room;
class SubRoom;
class Building;
......@@ -87,6 +88,7 @@ public:
UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors);
void create(std::vector<Line>& walls, std::map<int, Line>& doors, std::vector<int> targetUIDs, int mode,
double spacing, double wallAvoidDist, bool useWallDistances);
void recreateAllForQuickest();
UnivFFviaFM() {};
UnivFFviaFM(UnivFFviaFM&){};
virtual ~UnivFFviaFM();
......@@ -95,6 +97,7 @@ public:
void addTarget(const int uid, double* costarray = nullptr, Point* gradarray = nullptr);
void addAllTargets();
void addAllTargetsParallel();
void addTargetsParallel(std::vector<int> wantedDoors);
std::vector<int> getKnownDoorUIDs();
void setUser(int userArg);
void setMode(int modeArg);
......@@ -118,6 +121,7 @@ public:
void processGeometry(std::vector<Line>&walls, std::map<int, Line>& doors);
void markSubroom(const Point& insidePoint, SubRoom* const value);
void createReduWallSpeed(double* reduWallSpeed);
void createPedSpeed(Pedestrian* const * pedsArg, int nsize, int modechoice, double radius);
void drawLinesOnGrid(std::map<int, Line>& doors, int *const grid);
template <typename T>
......
......@@ -185,7 +185,7 @@ bool FFRouter::Init(Building* building)
// } else {
// locffptr = new LocalFloorfieldViaFM(pairRoomIt->second.get(), building, 0.125, 0.125, 0.0, false);
// }
locffptr->setUser(DISTANCE_AND_DIRECTIONS_USED);
locffptr->setUser(DISTANCE_MEASUREMENTS_ONLY);
locffptr->setMode(CENTERPOINT);
locffptr->setSpeedMode(FF_HOMO_SPEED);
locffptr->addAllTargetsParallel();
......@@ -198,6 +198,10 @@ bool FFRouter::Init(Building* building)
// nowait, because the parallel region ends directly afterwards
//#pragma omp for nowait
//@todo: @ar.graf: it would be easier to browse thru doors of each field directly after "addAllTargetsParallel" as
// we do only want doors of same subroom anyway. BUT the router would have to switch from room-scope
// to subroom-scope. Nevertheless, we could omit the room info (used to acces correct field), if we
// do it like in "ReInit()".
for (unsigned int i = 0; i < roomAndCroTrVector.size(); ++i) {
auto rctIt = roomAndCroTrVector.begin();
std::advance(rctIt, i);
......@@ -337,7 +341,68 @@ bool FFRouter::Init(Building* building)
bool FFRouter::ReInit()
{
return false;
//cleanse maps
_distMatrix.clear();
_pathsMatrix.clear();
//init, yet no distances, only create map entries
for(auto& id1 : _allDoorUIDs) {
for(auto& id2 : _allDoorUIDs){
std::pair<int, int> key = std::make_pair(id1, id2);
double value = (id1 == id2)? 0.0 : DBL_MAX;
//distMatrix[i][j] = 0, if i==j
//distMatrix[i][j] = max, else
_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 ));
_subroomMatrix.insert(std::make_pair(key, nullptr));
}
}
for (auto floorfield : _locffviafm) {
floorfield.second->setSpeedMode(FF_PED_SPEED);
//@todo: ar.graf: create a list of local ped-ptr instead of giving all peds-ptr
floorfield.second->createPedSpeed(_building->GetAllPedestrians().data(), _building->GetAllPedestrians().size(), _mode, 1.);
floorfield.second->recreateAllForQuickest();
std::vector<int> allDoors(floorfield.second->getKnownDoorUIDs());
for (auto firstDoor : allDoors) {
for (auto secondDoor : allDoors) {
if (secondDoor <= firstDoor) continue; // calculate every path only once
// if the two doors are not within the same subroom, do not consider (ar.graf)
// should fix problems of oscillation caused by doorgaps in the distancegraph
int thisUID1 = (_CroTrByUID.at(firstDoor)->GetSubRoom1()) ? _CroTrByUID.at(firstDoor)->GetSubRoom1()->GetUID() : -1 ;
int thisUID2 = (_CroTrByUID.at(firstDoor)->GetSubRoom2()) ? _CroTrByUID.at(firstDoor)->GetSubRoom2()->GetUID() : -2 ;
int otherUID1 = (_CroTrByUID.at(secondDoor)->GetSubRoom1()) ? _CroTrByUID.at(secondDoor)->GetSubRoom1()->GetUID() : -3 ;
int otherUID2 = (_CroTrByUID.at(secondDoor)->GetSubRoom2()) ? _CroTrByUID.at(secondDoor)->GetSubRoom2()->GetUID() : -4 ;
if (
(thisUID1 != otherUID1) &&
(thisUID1 != otherUID2) &&
(thisUID2 != otherUID1) &&
(thisUID2 != otherUID2) ) {
continue;
}
double tempDistance = floorfield.second->getCostToDestination(firstDoor, _CroTrByUID.at(secondDoor)->GetCentre());
if (tempDistance < floorfield.second->getGrid()->Gethx()) {
//Log->Write("WARNING:\tDistance of doors %d and %d is too small: %f",*otherDoor, *innerPtr, tempDistance);
//Log->Write("^^^^^^^^\tIf there are scattered subrooms, which are not connected, this is ok.");
continue;
}
std::pair<int, int> key_ij = std::make_pair(secondDoor, firstDoor);
std::pair<int, int> key_ji = std::make_pair(firstDoor, secondDoor);
if (_distMatrix.at(key_ij) > tempDistance) {
_distMatrix.erase(key_ij);
_distMatrix.erase(key_ji);
_distMatrix.insert(std::make_pair(key_ij, tempDistance));
_distMatrix.insert(std::make_pair(key_ji, tempDistance));
}
} //secondDoor(s)
} //firstDoor(s)
} //allRooms
FloydWarshall();
_plzReInit = false;
return true;
}
......@@ -359,13 +424,8 @@ int FFRouter::FindExit(Pedestrian* p)
// }
if (_mode == quickest) {
//new version: recalc densityspeed every x seconds
if (p->GetGlobalTime() > _timeToRecalc) {
_timeToRecalc += _recalc_interval; //@todo: ar.graf: change "5" to value of config file/classmember
// for (auto localfield : _locffviafm) { //@todo: ar.graf: create a list of local ped-ptr instead of giving all peds-ptr
// localfield.second->setSpeedThruPeds(_building->GetAllPedestrians().data(), _building->GetAllPedestrians().size(), _mode, 1.);
// localfield.second->deleteAllFFs();
// }
ReInit();
if ((p->GetGlobalTime() > _timeToRecalc) && (p->GetGlobalTime() > Pedestrian::GetMinPremovementTime() + _recalc_interval)) {
_plzReInit = true;
}
}
double minDist = DBL_MAX;
......@@ -649,4 +709,12 @@ void FFRouter::SetMode(std::string s)
_mode = global_shortest;
return;
}
bool FFRouter::MustReInit() {
return _plzReInit;
}
void FFRouter::SetRecalc(double t) {
_timeToRecalc = t + _recalc_interval;
}
\ No newline at end of file
......@@ -137,12 +137,11 @@ public:
virtual bool Init(Building* building);
/*!
* \brief ReInit the router (must be called after each event (open/close change)
* \brief ReInit the router if quickest router is used. Current position of agents is considered.
*
* ReInit() will reconstruct the graph (nodes = doors, edges = costs) and
* find shortest paths via Floyd-Warshall. It will reconstruct the floorfield to
* evaluate the best doors to certain goals as they could change. Further on it
* will take the information of former floorfields, if useful.
* evaluate the best doors to certain goals as they could change.
*
*
* \param[in] [name of input parameter] [its description]
......@@ -181,6 +180,8 @@ public:
* \brief set mode (shortest, quickest, ...)
*/
void SetMode(std::string s);
bool MustReInit();
void SetRecalc(double t);
private:
......@@ -206,6 +207,7 @@ protected:
int _mode;
double _timeToRecalc = 0.;
double _recalc_interval;
bool _plzReInit = false;
bool _hasSpecificGoals;
bool _targetWithinSubroom;
// If we use CentrePointDistance (i.e. CentrePointLocalFFViaFM), some algorithms can maybe be simplified
......
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