Commit 2ccc5948 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Refactoring the distribution class

parent c718c72d
/**
* \file StartDistribution
* \date Apr 15, 2015
* \version v0.6
* \copyright <2009-2015> 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
*
*
**/
#include "StartDistribution.h"
#include <cmath>
#include <cfloat>
#include "AgentsParameters.h"
#include "Pedestrian.h"
#include "../geometry/Building.h"
#include "../geometry/Point.h"
#include "../routing/RoutingEngine.h"
#include "../geometry/SubRoom.h"
using namespace std;
StartDistribution::StartDistribution(int seed)
{
_roomID = -1;
_subroomID=-1;
_nPeds = -1;
_groupID = -1;
_goalID = -1;
_routerID = -1;
_routeID = -1;
_age = -1;
_height = -1;
_startX = NAN;
_startY = NAN;
_startZ = NAN;
_gender = "male";
_patience=5;
_xMin=-FLT_MAX;
_xMax=FLT_MAX;
_yMin=-FLT_MAX;
_yMax=FLT_MAX;
_groupParameters=NULL;
_generator = std::default_random_engine(seed);
}
StartDistribution::~StartDistribution()
{
}
int StartDistribution::GetAgentsNumber() const
{
return _nPeds;
}
void StartDistribution::SetRoomID(int id)
{
_roomID = id;
}
int StartDistribution::GetAge() const
{
return _age;
}
void StartDistribution::SetAge(int age)
{
_age = age;
}
const std::string& StartDistribution::GetGender() const
{
return _gender;
}
void StartDistribution::SetGender(const std::string& gender)
{
_gender = gender;
}
int StartDistribution::GetGoalId() const
{
return _goalID;
}
void StartDistribution::SetGoalId(int goalId)
{
_goalID = goalId;
}
int StartDistribution::GetGroupId() const
{
return _groupID;
}
void StartDistribution::SetGroupId(int groupId)
{
_groupID = groupId;
}
int StartDistribution::GetHeight() const
{
return _height;
}
void StartDistribution::SetHeight(int height)
{
_height = height;
}
int StartDistribution::GetRoomId() const
{
return _roomID;
}
void StartDistribution::SetRoomId(int roomId)
{
_roomID = roomId;
}
int StartDistribution::GetSubroomID() const
{
return _subroomID;
}
void StartDistribution::SetSubroomID(int subroomId)
{
_subroomID = subroomId;
}
int StartDistribution::GetRouteId() const
{
return _routeID;
}
void StartDistribution::SetRouteId(int routeId)
{
_routeID = routeId;
}
int StartDistribution::GetRouterId() const
{
return _routerID;
}
void StartDistribution::SetRouterId(int routerId)
{
_routerID = routerId;
}
void StartDistribution::SetAgentsNumber(int N)
{
_nPeds = N;
}
Pedestrian* StartDistribution::GenerateAgent(Building* building, int* pid, vector<Point>& positions)
{
Pedestrian* ped = new Pedestrian();
// PedIndex
ped->SetID(*pid);
ped->SetAge(GetAge());
ped->SetGender(GetGender());
ped->SetHeight(GetHeight());
ped->SetFinalDestination(GetGoalId());
ped->SetGroup(GetGroupId());
ped->SetRouter(building->GetRoutingEngine()->GetRouter(_routerID));
ped->SetBuilding(building);
ped->SetRoomID(GetRoomId(),"");
ped->SetSubRoomID(GetSubroomID());
ped->SetPatienceTime(GetPatience());
ped->SetPremovementTime(GetPremovementTime());
ped->SetRiskTolerance(GetRiskTolerance());
//ped->SetTrip(); // not implemented
// a und b setzen muss vor v0 gesetzt werden,
// da sonst v0 mit Null überschrieben wird
JEllipse E = JEllipse();
E.SetAv(_groupParameters->GetAtau());
E.SetAmin(_groupParameters->GetAmin());
E.SetBmax(_groupParameters->GetBmax());
E.SetBmin(_groupParameters->GetBmin());
ped->SetEllipse(E);
ped->SetTau(_groupParameters->GetTau());
ped->SetV0Norm(_groupParameters->GetV0(),
_groupParameters->GetV0DownStairs(),
_groupParameters->GetV0UpStairs());
// first default Position
int index = -1;
//in the case a range was specified
for (unsigned int a=0;a<positions.size();a++)
{
Point pos=positions[a];
if((_xMin<=pos._x) &&
(pos._x <= _xMax)&&
(_yMin<=pos._y) &&
(pos._y < _yMax))
{
index=a;
break;
}
}
if(index==-1)
{
Log->Write("ERROR:\t Cannot distribute pedestrians in the mentioned area [%0.2f,%0.2f,%0.2f,%0.2f]",
_xMin,_xMax,_yMin,_yMax);
Log->Write("ERROR:\t Specifying a subroom_id might help");
}
else
{
Point pos = positions[index];
ped->SetPos(pos,true); //true for the initial position
positions.erase(positions.begin() + index);
const Point& start_pos = Point(_startX, _startY);
if ((std::isnan(start_pos._x) == 0) && (std::isnan(start_pos._y) == 0))
{
if (building->GetRoom(ped->GetRoomID())->GetSubRoom(ped->GetSubRoomID())->IsInSubRoom(
start_pos) == false)
{
Log->Write(
"ERROR: \t cannot distribute pedestrian %d in Room %d at fixed position %s",
*pid, GetRoomId(), start_pos.toString().c_str());
Log->Write(
"ERROR: \t Make sure that the position is inside the geometry and belongs to the specified room / subroom");
exit(EXIT_FAILURE);
}
ped->SetPos(start_pos, true); //true for the initial position
Log->Write("INFO: \t fixed position for ped %d in Room %d %s", *pid, GetRoomId(),
start_pos.toString().c_str());
}
}
(*pid)++;
return ped;
}
void StartDistribution::SetStartPosition(double x, double y, double z)
{
if(_nPeds!=1) {
Log->Write("INFO:\t you cannot specify the same start position for many agents");
Log->Write("INFO:\t Ignoring the start position");
return;
}
_startX=x;
_startY=y;
_startZ=z;
}
Point StartDistribution::GetStartPosition() const
{
return Point(_startX, _startY);
}
double StartDistribution::GetPatience() const
{
return _patience;
}
void StartDistribution::SetPatience(double patience)
{
_patience = patience;
}
AgentsParameters* StartDistribution::GetGroupParameters()
{
return _groupParameters;
}
void StartDistribution::SetGroupParameters(AgentsParameters* groupParameters)
{
_groupParameters = groupParameters;
}
void StartDistribution::Getbounds(double bounds[4])
{
bounds[0]=_xMin;
bounds[1]=_xMax;
bounds[2]=_yMin;
bounds[3]=_yMax;
}
void StartDistribution::Setbounds(double bounds[4])
{
_xMin=bounds[0];
_xMax=bounds[1];
_yMin=bounds[2];
_yMax=bounds[3];
}
void StartDistribution::InitPremovementTime(double mean, double stdv)
{
_premovementTime = std::normal_distribution<double>(mean,stdv);
}
double StartDistribution::GetPremovementTime()
{
return _premovementTime(_generator);
}
void StartDistribution::InitRiskTolerance(double mean, double stdv)
{
_riskTolerance = std::normal_distribution<double>(mean,stdv);
}
double StartDistribution::GetRiskTolerance()
{
return _riskTolerance(_generator);
}
/**
* \file StartDistribution.h
* \date Apr 15, 2015
* \version v0.6
* \copyright <2009-2015> 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
*
*
**/
#ifndef STARTDISTRIBUTION_H_
#define STARTDISTRIBUTION_H_
#include <vector>
#include <string>
#include <random>
//Forward declarations
class AgentsParameters;
class Pedestrian;
class Building;
class Point;
class StartDistribution
{
private:
int _roomID;
int _nPeds;
int _groupID;
int _goalID;
int _routerID;
int _routeID;
int _subroomID;
//demographic parameters
//TODO: should also follow a distribution, see _premovement
std::string _gender;
int _age;
int _height;
double _patience;
//force model parameters
AgentsParameters* _groupParameters;
//string motivation;// low, normal, high
double _startX; //only valid when _nPeds=1
double _startY; //only valid when _nPeds=1
double _startZ; //only valid when _nPeds=1
//bounds for distributing in a square
double _xMin;
double _xMax;
double _yMin;
double _yMax;
//pre movement time distribution
std::normal_distribution<double> _premovementTime;
//risk tolerance distribution
std::normal_distribution<double> _riskTolerance;
//random number generator engine
std::default_random_engine _generator;
public:
StartDistribution(int seed);
virtual ~StartDistribution();
int GetAgentsNumber() const;
void SetRoomID(int id);
void SetAgentsNumber(int N);
int GetAge() const;
void SetAge(int age);
const std::string& GetGender() const;
void SetGender(const std::string& gender);
int GetGoalId() const;
void SetGoalId(int goalId);
int GetGroupId() const;
void SetGroupId(int groupId);
int GetHeight() const;
void SetHeight(int height);
int GetRoomId() const;
void SetRoomId(int roomId);
int GetSubroomID() const;
void SetSubroomID(int subroomID);
int GetRouteId() const;
void SetRouteId(int routeId);
int GetRouterId() const;
void SetRouterId(int routerId);
void SetStartPosition(double x, double y, double z);
Point GetStartPosition() const;
double GetPatience() const;
void SetPatience(double patience);
void SetBounds(double xMin, double xMax, double yMin, double yMax);
void Getbounds(double bounds[4]);
void Setbounds(double bounds[4]);
AgentsParameters* GetGroupParameters();
void SetGroupParameters(AgentsParameters* groupParameters);
void InitPremovementTime(double mean, double stdv);
double GetPremovementTime();
void InitRiskTolerance(double mean, double stdv);
double GetRiskTolerance();
Pedestrian* GenerateAgent(Building* building, int* pid, std::vector<Point>& positions);
};
#endif /* STARTDISTRIBUTION_H_ */
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