Commit a339767d authored by tobias schroedter's avatar tobias schroedter

WIP First try of randomly distribute pedestrians inside waiting area

parent e17820fc
......@@ -1629,6 +1629,14 @@ bool IniFileParser::ParseStrategyNodeToObject(const TiXmlNode& strategyNode)
};
_config->set_dirSubLocal(dynamic_cast<DirectionSubLocalFloorfield*>(_exit_strategy.get()));
break;
case 10:
_exit_strategy = std::shared_ptr<DirectionStrategy>(new DirectionSubLocalFloorfieldTrips());
if(!ParseFfOpts(strategyNode)) {
return false;
};
_config->set_dirSubLocalTrips(dynamic_cast<DirectionSubLocalFloorfieldTrips*>(_exit_strategy.get()));
break;
default:
_exit_strategy = std::shared_ptr<DirectionStrategy>(new DirectionMinSeperationShorterLine());
Log->Write("ERROR:\t unknown exit_crossing_strategy <%d>", pExitStrategy);
......
......@@ -46,6 +46,7 @@
class AgentsParameters;
class DirectionSubLocalFloorfield;
class DirectionLocalFloorfield;
class DirectionSubLocalFloorfieldTrips;
#ifdef _JPS_AS_A_SERVICE
......@@ -287,12 +288,17 @@ public:
int get_exit_strat() const {return _exit_strat;}
void set_dirSubLocal(DirectionSubLocalFloorfield* dir) {_dirSubLocal = dir;}
void set_dirLocal(DirectionLocalFloorfield* dir) {_dirLocal = dir;}
DirectionSubLocalFloorfield* get_dirSubLocal() const {return _dirSubLocal;}
void set_dirLocal(DirectionLocalFloorfield* dir) {_dirLocal = dir;}
void set_dirSubLocalTrips(DirectionSubLocalFloorfieldTrips* dir) {_dirSubLocalTrips = dir;}
DirectionSubLocalFloorfield* get_dirSubLocal() const {return _dirSubLocal;}
DirectionLocalFloorfield* get_dirLocal() const {return _dirLocal;}
const std::string& GetHostname() const { return _hostname; };
DirectionSubLocalFloorfieldTrips* get_dirSubLocalTrips() const {return _dirSubLocalTrips;}
const std::string& GetHostname() const { return _hostname; };
void set_write_VTK_files_direction(bool write_VTK_files_direction) {_write_VTK_files_direction = write_VTK_files_direction;}
......@@ -410,8 +416,10 @@ private:
bool _write_VTK_files_direction;
int _exit_strat;
DirectionSubLocalFloorfield* _dirSubLocal;
DirectionLocalFloorfield* _dirLocal;
DirectionSubLocalFloorfieldTrips* _dirSubLocalTrips;
std::string _hostname;
std::string _trajectoriesFile;
......
......@@ -70,6 +70,8 @@ VelocityModel::~VelocityModel()
bool VelocityModel::Init (Building* building)
{
//FIXME really???
if(auto dirff = dynamic_cast<DirectionFloorfield*>(_direction.get())){
Log->Write("INFO:\t Init DirectionFloorfield starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
......@@ -97,6 +99,15 @@ bool VelocityModel::Init (Building* building)
Log->Write("INFO:\t Init DirectionSubLOCALFloorfield done");
}
if(auto dirsublocffTrips = dynamic_cast<DirectionSubLocalFloorfieldTrips*>(_direction.get())){
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTrips starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
dirsublocffTrips->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTrips done");
}
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
size_t peds_size = allPeds.size();
std::cout << "Building has " << peds_size << " peds\n";
......
......@@ -560,3 +560,137 @@ DirectionSubLocalFloorfield::~DirectionSubLocalFloorfield() {
delete pair.second;
}
}
///10
Point DirectionSubLocalFloorfieldTrips::GetTarget(Room* room, Pedestrian* ped) const
{
Goal* goal = ped->GetBuilding()->GetFinalGoal(ped->GetFinalDestination());
// Pedestrian is inside a waiting area
if (goal->IsInsideGoal(ped->GetPos())){
std::vector<Point> polygon(goal->GetPolygon());
std::set<Point> triangle;
int min=0, max;
// Get randomly 3 points of polygon (
// while (triangle.size() < 3){
// max = polygon.size();
// int index = min + (std::rand() % static_cast<int>(max - min + 1));
//
// triangle.insert(polygon.at(index));
// }
double r1, r2;
r1 = ((double) std::rand() / (RAND_MAX));
r2 = ((double) std::rand() / (RAND_MAX));
Point p1 = polygon[0] * (1. - sqrt(r1));
Point p2 = polygon[1] * (sqrt(r1) * (1 - r2));
Point p3 = polygon[2] * (sqrt(r1) * r2);
Point p = p1 + p2 + p3;
// UnivFFviaFM* floorfield = _locffviafm.at(ped->GetSubRoomUID());
// floorfield->getDirectionToUID(ped->GetExitIndex(), ped->GetPos(),p);
// return (p + ped->GetPos());
return p;
} else {
Point p;
UnivFFviaFM* floorfield = _locffviafm.at(ped->GetSubRoomUID());
floorfield->getDirectionToUID(ped->GetExitIndex(), ped->GetPos(),p);
return (p + ped->GetPos());
}
}
Point DirectionSubLocalFloorfieldTrips::GetDir2Wall(Pedestrian* ped) const
{
Point p;
int key = ped->GetSubRoomUID();
_locffviafm.at(key)->getDir2WallAt(ped->GetPos(), p);
return p;
}
double DirectionSubLocalFloorfieldTrips::GetDistance2Wall(Pedestrian* ped) const
{
return _locffviafm.at(ped->GetSubRoomUID())->getDistance2WallAt(ped->GetPos());
}
double DirectionSubLocalFloorfieldTrips::GetDistance2Target(Pedestrian* ped, int UID) {
int subroomUID = ped->GetSubRoomUID();
return _locffviafm.at(subroomUID)->getCostToDestination(UID, ped->GetPos());
}
void DirectionSubLocalFloorfieldTrips::Init(Building* buildingArg, double stepsize,
double threshold, bool useDistanceMap) {
_stepsize = stepsize;
_building = buildingArg;
_wallAvoidDistance = threshold;
_useDistancefield = useDistanceMap;
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
Log->Write("INFO: \tCalling Construtor of UnivFFviaFM(Subroom-scale)");
for (auto& roomPair : _building->GetAllRooms()) {
for (auto& subPair : roomPair.second->GetAllSubRooms()) {
int subUID = subPair.second->GetUID();
UnivFFviaFM* floorfield = new UnivFFviaFM(subPair.second.get(), _building, stepsize, _wallAvoidDistance, _useDistancefield);
_locffviafm[subUID] = floorfield;
floorfield->setUser(DISTANCE_AND_DIRECTIONS_USED);
floorfield->setMode(LINESEGMENT);
if (useDistanceMap) {
floorfield->setSpeedMode(FF_WALL_AVOID);
} else {
floorfield->setSpeedMode(FF_HOMO_SPEED);
}
floorfield->addAllTargetsParallel();
}
}
if (_building->GetConfig()->get_write_VTK_files_direction()) {
for (unsigned int i = 0; i < _locffviafm.size(); ++i) {
auto iter = _locffviafm.begin();
std::advance(iter, i);
int roomNr = iter->first;
iter->second->writeFF("direction" + std::to_string(roomNr) + ".vtk", iter->second->getKnownDoorUIDs());
}
}
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
Log->Write("INFO: \tTaken time: " + std::to_string(elapsed_seconds.count()));
_initDone = true;
//_locffviafm[0]->writeFF()
//write floorfields to file, one file per subroom //ar.graf: [SWITCH writevtk ON/OFF]
// for(unsigned int i = 0; i < subUIDs.size(); ++i) {
// std::vector<int> targets = {};
// targets.clear();
// int subroomUID = subUIDs[i];
// //if (subroomUID != 26) continue;
//
// for (auto pair : subAndTarget) {
// if (pair.first == subroomUID) {
// targets.emplace_back(pair.second);
// }
// }
// std::string filename1 = "floorfield" + std::to_string(subroomUID) + ".vtk";
// if (targets.size() > 0)
// _locffviafm[subroomUID]->writeFF(filename1, targets);
// }
}
DirectionSubLocalFloorfieldTrips::DirectionSubLocalFloorfieldTrips() {
_initDone = false;
}
DirectionSubLocalFloorfieldTrips::~DirectionSubLocalFloorfieldTrips() {
for (auto pair : _locffviafm) {
delete pair.second;
}
}
......@@ -135,5 +135,26 @@ protected:
std::string _filename;
};
class DirectionSubLocalFloorfieldTrips : public DirectionStrategy {
public:
DirectionSubLocalFloorfieldTrips();
void Init(Building* building, double stepsize, double threshold,
bool useDistanceMap);
~DirectionSubLocalFloorfieldTrips();
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
virtual Point GetDir2Wall(Pedestrian* ped) const;
virtual double GetDistance2Wall(Pedestrian* ped) const;
virtual double GetDistance2Target(Pedestrian* ped, int UID);
protected:
std::map<int, UnivFFviaFM*> _locffviafm;
bool _initDone;
Building* _building;
double _stepsize;
double _wallAvoidDistance;
bool _useDistancefield;
std::string _filename;
};
#endif /* _DIRECTIONSTRATEGY_H */
......@@ -625,11 +625,14 @@ int FFRouterTrips::FindExit1(Pedestrian* p)
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);
}
// if (_targetWithinSubroom) {
// locDistToDoor = _config->get_dirSubLocal()->GetDistance2Target(p, doorUID);
// } else {
// locDistToDoor = _config->get_dirLocal()->GetDistance2Target(p, doorUID);
// }
//
locDistToDoor = _config->get_dirSubLocalTrips()->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;
......
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