Commit d4e52325 authored by Arne Graf's avatar Arne Graf

ctor wip

parent de41f9a8
Pipeline #2383 failed with stages
in 31 seconds
......@@ -290,6 +290,7 @@ set(source_files
routing/ff_router/LocalFloorfieldViaFM.cpp
routing/ff_router/FloorfieldViaFM.cpp
#routing/ff_router/FFKit.cpp
routing/ff_router/UnivFFviaFM.cpp
#global_shortest
routing/global_shortest/AccessPoint.cpp
......@@ -355,6 +356,7 @@ set(header_files
routing/ff_router/LocalFloorfieldViaFM.h
routing/ff_router/FloorfieldViaFM.h
#routing/ff_router/FFKit.h
routing/ff_router/UnivFFviaFM.h
#general
routing/DirectionStrategy.h
......
......@@ -249,10 +249,6 @@ bool Simulation::InitArgs()
// This should be done after the initialization of the operationalModel
// because then, invalid pedestrians have been deleted and FindExit()
// has been called.
Log->Write("INFO:\t PreSim of DirectionStrategy starting ...");
if (!_operationalModel->GetDirection()->PreSim(_building.get()))
return false;
Log->Write("INFO:\t PreSim of DirectionStrategy done");
//other initializations
for (auto&& ped: _building->GetAllPedestrians()) {
......@@ -509,11 +505,11 @@ double Simulation::RunBody(double maxSimTime)
if (0==frameNr%writeInterval) {
_iod->WriteFrame(frameNr/writeInterval, _building.get());
}
if(!_gotSources && !_periodic /*&& _printPB*/) // @todo: option for print progressbar
// Log->ProgressBar(initialnPeds, initialnPeds-_nPeds, t);
//bar->Progressed(initialnPeds-_nPeds);
else
printf("time: %.2f | %.2f\n", t , maxSimTime);
// if(!_gotSources && !_periodic /*&& _printPB*/) // @todo: option for print progressbar
// // Log->ProgressBar(initialnPeds, initialnPeds-_nPeds, t);
// bar->Progressed(initialnPeds-_nPeds);
// else
// printf("time: %.2f | %.2f\n", t , maxSimTime);
// needed to control the execution time PART 2
// time(&endtime);
......
......@@ -162,13 +162,14 @@ enum FFRouterMode {
};
enum GridCode { //used in floor fields
WALL = 0,
INSIDE,
OUTSIDE,
OPEN_CROSSING,
OPEN_TRANSITION,
CLOSED_CROSSING, //closed crossings and transitions are marked as walls in "parseBuilding"
CLOSED_TRANSITION
WALL = -10,
INSIDE = -11,
OUTSIDE = -12,
//instead of constants, GridCode stores UID of doors
OPEN_CROSSING = -13,
OPEN_TRANSITION = -14,
CLOSED_CROSSING = -15, //closed crossings and transitions are marked as walls in "parseBuilding"
CLOSED_TRANSITION = -16
};
enum FastMarchingFlags {
......@@ -181,6 +182,37 @@ enum FastMarchingFlags {
FM_OUTSIDE = -7
};
enum FloorfieldMode {
FF_CENTRALPOINT,
FF_FULL_LINE,
FF_WALL_AVOID,
FF_HOMO_SPEED
};
enum MagicNumbers{
UNKNOWN_DISTANCE,
UNKNOWN_COST,
WALL_ON_COSTARRAY,
TARGET_REGION
};
constexpr double magicnum(int i) {
return (i == UNKNOWN_DISTANCE) ? -3.0 : (i == UNKNOWN_COST) ? -2.0 : (i == WALL_ON_COSTARRAY) ? -7.0 : (i == TARGET_REGION) ? 0.0 : NAN;
Please register or sign in to reply
// switch (i) {
// case UNKNOWN_DISTANCE:
// return -3.0;
// case UNKNOWN_COST:
// return -2.0;
// case WALL_ON_COSTARRAY:
// return -7.0;
// case TARGET_REGION:
// return 0.0;
// default:
// std::cerr << "ERROR: \tunknown magic number " << i << std::endl;
// return NAN;
// }
}
//global functions for convenience
inline char xmltob(const char * t, char v = 0)
......
......@@ -147,7 +147,6 @@ Pedestrian::Pedestrian(const StartDistribution& agentsParameters, Building& buil
_tmpFirstOrientation = true;
_turninAngle = 0.0;
_ellipse = JEllipse();
//_navLine = new NavLine(); //FIXME? argraf : rather nullptr and Setter includes correct uid (done below)
_navLine = nullptr;
_router = NULL;
_building = NULL;
......@@ -254,16 +253,11 @@ void Pedestrian::SetExitIndex(int i)
void Pedestrian::SetExitLine(const NavLine* l) //FIXME? argraf : _navLine = new NavLine(*l); this would have a navLine with consistent uid (done below)
{
//_navLine = l;
//_navLine->SetPoint1(l->GetPoint1());
//_navLine->SetPoint2(l->GetPoint2());
if(l) {
_navLine = std::unique_ptr<NavLine>(new NavLine(*l));
}
/*else if(l && _navLine && *l != *_navLine && l->GetUniqueID() != _navLine->GetUniqueID()){
if(_navLine)
delete _navLine;
if(l) {
_navLine = new NavLine(*l);
}*/
}
}
void Pedestrian::SetPos(const Point& pos, bool initial)
......@@ -392,7 +386,7 @@ int Pedestrian::GetExitIndex() const
NavLine* Pedestrian::GetExitLine() const
{
return _navLine.get();
return _navLine;
}
const vector<int>& Pedestrian::GetTrip() const
......
......@@ -91,7 +91,7 @@ private:
int _oldSubRoomID;
Point _lastE0;
std::unique_ptr<NavLine> _navLine; // current exit line
NavLine* _navLine; // current exit line
std::map<int, int>_mentalMap; // map the actual room to a destination
std::vector<int> _destHistory;
std::vector<int> _trip;
......
......@@ -410,48 +410,7 @@ void DirectionLocalFloorfield::Init(Building* buildingArg, double stepsize,
_initDone = true;
}
bool DirectionLocalFloorfield::PreSim(Building* building) {
std::map<int, std::vector<int>> doorsInRoom;
doorsInRoom.clear();
Log->Write("INFO: \tDirectionLocalFloorfield::PreSim");
std::set<std::pair<int, int>> roomsDoorsSet;
roomsDoorsSet.clear();
auto allPeds = building->GetAllPedestrians();
#pragma omp parallel
{
#pragma omp for
for (size_t i = 0; i < allPeds.size(); ++i) {
auto ped = allPeds.begin();
std::advance(ped, i);
if (auto router = dynamic_cast<FFRouter*>((*ped)->GetRouter())) {
auto pedSubroomsDoorSet = router->GetPresumableExitRoute(*ped);
#pragma omp critical(roomsDoorsSet)
for (auto it : pedSubroomsDoorSet) {
roomsDoorsSet.insert(std::make_pair(it.first->GetRoomID(), it.second));
}
}
}
#pragma omp for
for (size_t i = 0; i < roomsDoorsSet.size(); ++i) {
auto rdIt = roomsDoorsSet.begin();
// suboptimal, because a set doesn't provide random-access iterators
std::advance(rdIt, i);
CalcFloorfield(rdIt->first, rdIt->second);
#pragma omp critical(doorsInRoom)
doorsInRoom[rdIt->first].push_back(rdIt->second);
}
}
for (size_t i = 0; i < doorsInRoom.size(); ++i) {
auto roomIt = doorsInRoom.begin();
std::advance(roomIt, i);
//@todo: ar.graf: plz make switch in ini file and dependand on ini write yes/no (issue 208)
//writeFF(roomIt->first, roomIt->second);
}
return true;
}
void DirectionLocalFloorfield::CalcFloorfield(int room, int destUID) {
Point dummy;
......
......@@ -46,41 +46,33 @@ public:
DirectionStrategy();
virtual ~DirectionStrategy();
// Allow the DirectionStrategy to perform some pre-simulation calculation, with all pedestrians
// already set and a valid _exitIndex. Returns true if the initialization was successful.
virtual bool PreSim(Building* building) = 0;
virtual Point GetTarget(Room* room, Pedestrian* ped) const = 0;
};
class DirectionMiddlePoint : public DirectionStrategy {
public:
virtual bool PreSim(Building* building) {(void) building; return true;};
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
};
class DirectionMinSeperation : public DirectionStrategy {
public:
virtual bool PreSim(Building* building) {(void) building; return true;};
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
};
class DirectionMinSeperationShorterLine : public DirectionStrategy {
public:
virtual bool PreSim(Building* building) {(void) building; return true;};
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
};
class DirectionInRangeBottleneck : public DirectionStrategy {
public:
virtual bool PreSim(Building* building) {(void) building; return true;};
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
};
class DirectionGeneral : public DirectionStrategy {
public:
virtual bool PreSim(Building* building) {(void) building; return true;};
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
};
......@@ -88,7 +80,6 @@ class DirectionFloorfield : public DirectionStrategy {
public:
DirectionFloorfield();
void Init(Building* building, double stepsize, double threshold, bool useDistancMap);
virtual bool PreSim(Building* building) {(void) building; return true;};
~DirectionFloorfield();
//void Init();
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
......@@ -105,7 +96,6 @@ public:
DirectionLocalFloorfield();
void Init(Building* building, double stepsize, double threshold,
bool useDistancMap);
virtual bool PreSim(Building* building);
~DirectionLocalFloorfield();
//void Init();
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
......@@ -132,7 +122,6 @@ public:
DirectionSubLocalFloorfield();
void Init(Building* building, double stepsize, double threshold,
bool useDistancMap);
virtual bool PreSim(Building* building) {(void) building; return true;};
~DirectionSubLocalFloorfield();
//void Init();
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
......
This diff is collapsed.
//
// Created by arne on 5/9/17.
//
/**
* \file UnivFFviaFM.h
* \date May 09, 2017
* \version N/A (v0.8.x)
* \copyright <2017-2020> Forschungszentrum Jülich GmbH. All rights reserved.
*
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* JuPedSim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* \section Description
* Implementation of classes for a reworked floorfield. A floorfield in general
* yields a cost field to a specific goal and a correlated vectorfield for the
* optimal path in terms of the cost value.
*
* Rework focused on a cleaner structure and less inheritance (no diamond) and
* less workarounds.
*
*
**/
#ifndef JPSCORE_UNIVFFVIAFM_H
#define JPSCORE_UNIVFFVIAFM_H
#include <string>
#include <vector>
#include <map>
#include <float.h>
class Room;
class SubRoom;
class Building;
class Configuration;
class Point;
class RectGrid;
class Line;
enum SPEEDFIELD { //this enum is used as index in _speedFieldSelector
INITIAL_SPEED=0, //homogen speed in walkable area, nealy zero in walls
REDU_WALL_SPEED=1, //reduced wall speed
PED_SPEED=2 //standing agents reduce speed, so that jams will be considered in ff
};
enum TARGETMODE {
LINESEGMENT=0,
CENTERPOINT
};
enum USERMODE {
DISTANCE_MEASUREMENTS_ONLY,
DISTANCE_AND_DIRECTIONS_USED
};
class CompareCost { //this class is used in std::priority_queue in UnivFFviaFM::calcFF
public:
CompareCost(double* costarray) : _costarray(costarray) {}
bool operator() (const int a, const int b) const {
return _costarray[a] > _costarray[b];
}
private:
double* _costarray = nullptr;
};
class UnivFFviaFM {
public:
UnivFFviaFM(Room* a, Building* b, double c, double d, double e, bool f);
UnivFFviaFM(SubRoom* a, Building* b, double c, double d, double e, bool f);
UnivFFviaFM(Room *a, const Configuration *b, double c, double d, double e, bool f);
UnivFFviaFM(SubRoom *a, const Configuration *b, double c, double d, double e, bool f);
UnivFFviaFM(std::vector<Line>& walls, std::map<int, Line>& doors, std::vector<int> targetUIDs, int mode, double spacing);
UnivFFviaFM() {};
UnivFFviaFM(UnivFFviaFM&){};
~UnivFFviaFM(){};
void addTarget(const int uid, Line* door);
std::vector<int> getKnownDoorUIDs();
double getCostToDestination(const int destID, const Point& position, int mode) {return 0.;};
double getCostToDestination(const int destID, const Point& position) {return 0.;};
RectGrid* getGrid(){return nullptr;};
virtual void getDirectionToUID(int destID, const long int key, Point& direction, int mode){};
void getDirectionToUID(int destID, const long int key, Point& direction){};
void writeFF(const std::string&, std::vector<int> targetID);
void createRectGrid(std::vector<Line>& walls, std::map<int, Line>& doors, double spacing);
void processGeometry(std::vector<Line>&walls, std::map<int, Line>& doors);
void drawLinesOnGrid(std::map<int, Line>& doors, int *const grid);
template <typename T>
void drawLinesOnGrid(std::vector<Line>& wallArg, T* const target, const T value);
template <typename T>
void drawLinesOnGrid(Line& line, T* const target, const T value);
void calcFF(double*, Point*, const double* const);
void calcCost(const long int key, double* cost, Point* dir, const double* const speed);
inline double onesidedCalc(double xy, double hDivF);
inline double twosidedCalc(double x, double y, double hDivF);
private:
Building* _building = nullptr;
Configuration* _configuration = nullptr;
int _mode = LINESEGMENT; //default
int _user = DISTANCE_AND_DIRECTIONS_USED; //default
RectGrid* _grid = nullptr;
long int _nPoints = 0;
std::vector<double*> _speedFieldSelector;
int* _gridCode = nullptr;
double _wallAvoidDistance = 0.;
bool _useWallAvoidance = false;
//the following maps are responsible for dealloc the arrays
std::map<int, double*> _costFieldWithKey;
std::map<int, Point*> _directionFieldWithKey;
std::vector<int> _uids;
std::map<int, Line> _doors;
};
#endif //JPSCORE_UNIVFFVIAFM_H
This diff is collapsed.
......@@ -64,6 +64,7 @@
#include "../../general/Macros.h"
#include "../../geometry/Building.h"
#include "LocalFloorfieldViaFM.h"
#include "UnivFFviaFM.h"
class Building;
class Pedestrian;
......@@ -181,13 +182,6 @@ public:
*/
void SetMode(std::string s);
/*!
* \brief Get the route the pedestrian p wants to take (according to _pathsMatrix)
* @param p The pedestrian in question
* @return A set containing (subroom*, doorUID) pairs. The floorfields needed are inside the subroom, originating from the door.
*/
std::set<std::pair<SubRoom*, int>> GetPresumableExitRoute(Pedestrian* p);
private:
protected:
......@@ -198,7 +192,7 @@ protected:
std::vector<int> _allDoorUIDs;
std::vector<int> _localShortestSafedPeds;
const Building* _building;
std::map<int, LocalFloorfieldViaFM*> _locffviafm; // the actual type might be CentrePointLocalFFViaFM
std::map<int, UnivFFviaFM*> _locffviafm; // the actual type might be CentrePointLocalFFViaFM
FloorfieldViaFM* _globalFF;
std::map<int, Transition*> _TransByUID;
std::map<int, Transition*> _ExitsByUID;
......
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