Commit ea46a982 authored by Arne Graf's avatar Arne Graf

ticks, subRoomUID-array, densitySpeed-array

parent a4979b57
......@@ -311,6 +311,7 @@ void Simulation::UpdateRoutesAndLocations()
for (int p = start; p<=end; ++p) {
Pedestrian* ped = allPeds[p];
ped->_ticksInThisRoom += 1;
Room* room = _building->GetRoom(ped->GetRoomID());
SubRoom* sub0 = room->GetSubRoom(ped->GetSubRoomID());
......@@ -330,8 +331,10 @@ void Simulation::UpdateRoutesAndLocations()
// reposition in the case the pedestrians "accidently left the room" not via the intended exit.
// That may happen if the forces are too high for instance
// the ped is removed from the simulation, if it could not be reassigned
//@todo: ar.graf: condition could be ff::subroom[grid->getKeyAt(ped->GetPosition())] != ped->GetSubRoomUID()
else if (!sub0->IsInSubRoom(ped)) {
bool assigned = false;
auto& allRooms = _building->GetAllRooms();
for (auto&& it_room : allRooms) {
......@@ -515,6 +518,9 @@ int Simulation::RunBody(double maxSimTime)
//update the events
_em->ProcessEvent();
//update doorticks
UpdateDoorticks();
//update the routes and locations
UpdateRoutesAndLocations();
......@@ -558,6 +564,21 @@ void Simulation::ProcessAgentsQueue()
}
}
void Simulation::UpdateDoorticks() const {
auto& allCross = _building->GetAllCrossings();
for (auto& crossPair : allCross) {
crossPair.second->_refresh1 += 1;
crossPair.second->_refresh2 += 1;
}
auto& allTrans = _building->GetAllTransitions();
for (auto& transPair : allTrans) {
transPair.second->_refresh1 += 1;
transPair.second->_refresh2 += 1;
}
};
void Simulation::UpdateFlowAtDoors(const Pedestrian& ped) const
{
if (_config->ShowStatistics()) {
......
......@@ -178,6 +178,13 @@ public:
* @param ped
*/
void UpdateFlowAtDoors(const Pedestrian& ped) const;
/**
* Update the refresh ticks for all doors. they count up and measure the age of the tickvalue (ffRouter, quickest)
*
*/
void UpdateDoorticks() const;
};
#endif /*SIMULATION_H_*/
......@@ -48,10 +48,10 @@ private:
public:
// last ped that passed was in room {1,2} that many ticks
int _lastTickTime1;
int _lastTickTime2;
int _refresh1;
int _refresh2;
int _lastTickTime1 = 0;
int _lastTickTime2 = 0;
int _refresh1 = 0;
int _refresh2 = 0;
/**
......
......@@ -47,7 +47,7 @@ using namespace std;
SubRoom
************************************************************/
int SubRoom::_static_uid=0;
int SubRoom::_static_uid=1; //must be positive (sideeffect for FloorfieldViaFM::isInside())
SubRoom::SubRoom()
{
......
......@@ -56,6 +56,7 @@ FloorfieldViaFM::~FloorfieldViaFM()
if (dist2Wall) delete[] dist2Wall;
if (speedInitial) delete[] speedInitial;
if (modifiedspeed) delete[] modifiedspeed;
if (densityspeed) delete[] densityspeed;
//if (cost) delete[] cost;
//if (neggrad) delete[] neggrad;
if (dirToWall) delete[] dirToWall;
......@@ -136,6 +137,9 @@ building(other.building)
modifiedspeed = new double[otherNumOfPoints];
std::copy(other.modifiedspeed, other.modifiedspeed + otherNumOfPoints, modifiedspeed);
densityspeed = new double[otherNumOfPoints];
std::copy(other.densityspeed, other.densityspeed + otherNumOfPoints, densityspeed);
cost = new double[otherNumOfPoints];
std::copy(other.cost, other.cost + otherNumOfPoints, cost);
......@@ -526,6 +530,11 @@ double FloorfieldViaFM::getDistance2WallAt(const Point& position) {
}
}
int FloorfieldViaFM::getSubroomUIDAt(const Point &position) {
long int key = grid->getKeyAtPoint(position);
return subroomUID[key];
}
/*!
* \brief Parsing geo-info but conflicts in multi-floor-buildings OBSOLETE
*
......@@ -657,6 +666,7 @@ void FloorfieldViaFM::parseBuilding(const Building* const buildingArg, const dou
grid->createGrid();
//create arrays
subroomUID = new int[grid->GetnPoints()];
gcode = new int[grid->GetnPoints()]; //gcode:
// enum GridCode { //used in floor fields
// WALL = 0,
......@@ -842,6 +852,7 @@ void FloorfieldViaFM::parseBuildingForExits(const Building* const buildingArg, c
//create arrays
gcode = new int[grid->GetnPoints()]; //see Macros.h: enum GridCode {...}
subroomUID = new int[grid->GetnPoints()];
dist2Wall = new double[grid->GetnPoints()];
speedInitial = new double[grid->GetnPoints()];
modifiedspeed = new double[grid->GetnPoints()];
......@@ -911,6 +922,7 @@ void FloorfieldViaFM::prepareForDistanceFieldCalculation(const bool onlyRoomsWit
speedInitial[i] = 1.;
cost[i] = -2.;
gcode[i] = INSIDE;
subroomUID[i] = isInside(i);
}
break;
} //switch
......@@ -1183,6 +1195,10 @@ void FloorfieldViaFM::setSpeed(bool useDistance2WallArg) {
}
void FloorfieldViaFM::calculateFloorfield(std::vector<Line>& targetlines, double* costarray, Point* neggradarray) {
calculateFloorfield(targetlines, costarray, neggradarray, modifiedspeed);
}
void FloorfieldViaFM::calculateFloorfield(std::vector<Line>& targetlines, double* costarray, Point* neggradarray, double* speedarray) {
Trial* smallest = nullptr;
Trial* biggest = nullptr;
......@@ -1201,7 +1217,7 @@ void FloorfieldViaFM::calculateFloorfield(std::vector<Line>& targetlines, double
trialfield[i].flag = flag + i;
trialfield[i].cost = costarray + i;
trialfield[i].neggrad = neggradarray + i;
trialfield[i].speed = modifiedspeed + i;
trialfield[i].speed = speedarray + i;
trialfield[i].father = nullptr;
trialfield[i].child = nullptr;
......@@ -1706,8 +1722,8 @@ void FloorfieldViaFM::writeFF(const std::string& filename, std::vector<int> targ
file.close();
}
bool FloorfieldViaFM::isInside(const long int key) {
bool temp = false;
int FloorfieldViaFM::isInside(const long int key) {
int temp = 0;
Point probe = grid->getPointFromKey(key);
const std::map<int, std::shared_ptr<Room>>& roomMap = building->GetAllRooms();
......@@ -1722,7 +1738,7 @@ bool FloorfieldViaFM::isInside(const long int key) {
SubRoom* subRoomPtr = subRoomPair.second.get();
if (subRoomPtr->IsInSubRoom(probe)) {
temp = true;
temp = subRoomPtr->GetUID();
}
}
}
......
......@@ -76,6 +76,8 @@ public:
void getDir2WallAt(const Point& position, Point& direction);
double getDistance2WallAt(const Point& position);
int getSubroomUIDAt(const Point& position);
void parseBuilding(const Building* const buildingArg, const double stepSizeX, const double stepSizeY);
void parseBuildingForExits(const Building* const buildingArg, const double stepSizeX, const double stepSizeY);
void prepareForDistanceFieldCalculation(const bool withExits);
......@@ -85,6 +87,7 @@ public:
void clearAndPrepareForFloorfieldReCalc(double* costarray);
void setNewGoalAfterTheClear(double* costarray, std::vector<Line>& GoalWallArg);
void calculateFloorfield(std::vector<Line>& wallArg, double* costarray, Point* neggradarray); //make private
void calculateFloorfield(std::vector<Line>& wallArg, double* costarray, Point* neggradarray, double* speedarray);
void calculateDistanceField(const double thresholdArg); //make private
void checkNeighborsAndAddToNarrowband(Trial* trialfield, Trial* &smallest, Trial* &biggest, int* flag, const long int key,
......@@ -100,7 +103,7 @@ public:
void testoutput(const char*, const char*, const double*);
void writeFF(const std::string&, std::vector<int> targetID);
virtual bool isInside(const long int key);
virtual int isInside(const long int key);
std::map<int, int> getGoalToLineUIDmap() const
{
......@@ -127,7 +130,7 @@ public:
#endif //TESTING
protected:
RectGrid* grid;
RectGrid* grid = nullptr;
std::vector<Line> wall;
std::vector<Line> exitsFromScope;
int numOfExits;
......@@ -140,14 +143,16 @@ protected:
//GridPoint Data in independant arrays (shared primary key)
// changed to threadsafe creation when needed: int* flag; //flag:( 0 = unknown, 1 = singel, 2 = double, 3 = final, 4 = added to trial but not calculated, -7 = outside)
int* gcode; //gridcode (see Macros.h)
double* dist2Wall;
double* speedInitial;
double* modifiedspeed;
double* cost;
int* gcode = nullptr; //gridcode (see Macros.h)
int* subroomUID = nullptr;
double* dist2Wall = nullptr;
double* speedInitial = nullptr;
double* modifiedspeed = nullptr;
double* densityspeed = nullptr;
double* cost = nullptr;
//long int* secKey; //secondary key to address ... not used yet
Point* neggrad; //gradients
Point* dirToWall;
Point* neggrad = nullptr; //gradients
Point* dirToWall = nullptr;
// changed to threadsafe creation when needed: Trial* trialfield;
std::map<int, double*> goalcostmap;
......
......@@ -144,6 +144,7 @@ void LocalFloorfieldViaFM::parseRoom(const Room* const roomArg,
//create arrays
//flag = new int[grid->GetnPoints()]; //flag:( 0 = unknown, 1 = singel, 2 = double, 3 = final, -7 = outside)
gcode = new int[grid->GetnPoints()];
subroomUID = new int[grid->GetnPoints()];
dist2Wall = new double[grid->GetnPoints()];
speedInitial = new double[grid->GetnPoints()];
modifiedspeed = new double[grid->GetnPoints()];
......@@ -407,8 +408,8 @@ void LocalFloorfieldViaFM::crossOutOutsideNeighbors(const long int key){
//// }
}
bool LocalFloorfieldViaFM::isInside(const long int key) {
bool temp = false;
int LocalFloorfieldViaFM::isInside(const long int key) {
int temp = 0;
Point probe = grid->getPointFromKey(key);
const std::map<int, std::shared_ptr<SubRoom>>& subRoomMap = room->GetAllSubRooms();
......@@ -418,7 +419,7 @@ bool LocalFloorfieldViaFM::isInside(const long int key) {
SubRoom* subRoomPtr = subRoomPair.second.get();
if (subRoomPtr->IsInSubRoom(probe)) {
temp = true;
temp = subRoomPtr->GetUID();
}
}
......@@ -575,6 +576,7 @@ void SubLocalFloorfieldViaFM::parseRoom(const SubRoom* const roomArg,
//create arrays
gcode = new int[grid->GetnPoints()]; //flag:( 0 = unknown, 1 = singel, 2 = double, 3 = final, -7 = outside)
subroomUID = new int[grid->GetnPoints()];
dist2Wall = new double[grid->GetnPoints()];
speedInitial = new double[grid->GetnPoints()];
modifiedspeed = new double[grid->GetnPoints()];
......@@ -600,7 +602,7 @@ void SubLocalFloorfieldViaFM::parseRoom(const SubRoom* const roomArg,
drawLinesOnGrid(exitsFromScope, gcode, OPEN_TRANSITION);
}
bool SubLocalFloorfieldViaFM::isInside(const long int key) {
int SubLocalFloorfieldViaFM::isInside(const long int key) {
Point probe = grid->getPointFromKey(key);
return subroom->IsInSubRoom(probe);
return subroom->IsInSubRoom(probe)?subroom->GetUID():0;
}
\ No newline at end of file
......@@ -49,7 +49,7 @@ public:
void getDirectionToGoalID(const int goalID);
void drawBlockerLines();
void crossOutOutsideNeighbors(const long int key);
virtual bool isInside(const long int key);
virtual int isInside(const long int key);
protected:
const Room* room;
};
......@@ -65,7 +65,7 @@ public:
void parseRoom(const SubRoom* const subroomArg, const double hxArg, const double hyArg);
void getDirectionToDestination (Pedestrian* ped, Point& direction);
void getDirectionToGoalID(const int goalID);
virtual bool isInside(const long int key);
virtual int isInside(const long int key);
protected:
const SubRoom* subroom;
};
......
......@@ -287,6 +287,20 @@ bool FFRouter::Init(Building* building)
int FFRouter::FindExit(Pedestrian* p)
{
if (_mode == quickest) {
//if needed: quickest-mechanic part 1 of 2
if ((_locffviafm.at(p->GetRoomID())->getGrid()->includesPoint(p->GetPos())) &&
(p->GetSubRoomUID() != _locffviafm.at(p->GetRoomID())->getSubroomUIDAt(p->GetPos()))) {
//pedestrian is still in the room, but changed subroom
notifyDoor(p);
}
//if needed: quickest-mechanic part 2 of 2
if (!(_locffviafm.at(p->GetRoomID())->getGrid()->includesPoint(p->GetPos()))) {
//pedestrian left the room and therefore changed subroom
notifyDoor(p);
}
}
double minDist = DBL_MAX;
int bestDoor = -1;
int bestGoal = -1;
......@@ -441,3 +455,30 @@ void FFRouter::SetMode(std::string s)
_mode = global_shortest;
return;
}
void FFRouter::notifyDoor(Pedestrian *const p) {
//find correct door
auto lastSubRoom = _building->GetSubRoomByUID(p->GetSubRoomUID());
auto doorsOfSubRoom = lastSubRoom->GetAllGoalIDs();
double minDist = _CroTrByUID.at(doorsOfSubRoom[0])->DistTo(p->GetPos());
double tmp = minDist;
Crossing* minCross = _CroTrByUID.at(doorsOfSubRoom[0]);
for(auto UID : doorsOfSubRoom) {
tmp = _CroTrByUID.at(UID)->DistTo(p->GetPos());
if (tmp < minDist) {
minCross = _CroTrByUID.at(UID);
minDist = tmp;
}
}
//find correct direction, where direction means: subRoom1 uses TickTime1, subRoom2 uses TickTime2; order in the Crossing::HLine is defining
if(minCross->GetSubRoom1()->IsInSubRoom(p)) { //p is in subRoom1, so he entered that from subRoom2
minCross->_lastTickTime2 = p->_ticksInThisRoom;
minCross->_refresh2 = 0;
}
if(minCross->GetSubRoom2()->IsInSubRoom(p)) {
minCross->_lastTickTime1 = p->_ticksInThisRoom;
minCross->_refresh1 = 0;
}
p->_ticksInThisRoom = 0;
}
......@@ -164,6 +164,11 @@ public:
*/
void SetMode(std::string s);
/*!
* \brief notify door about time spent in that room. needed for quickest mode
*/
void notifyDoor(Pedestrian* const p);
private:
protected:
......
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