Commit 55db3180 authored by Ulrich Kemloh's avatar Ulrich Kemloh

splitting the simulation logic and the geometry.

Pedestrians are now stored in a single vector.
parent f7fe6e7a
......@@ -303,26 +303,24 @@ void TrajectoriesJPSV04::WriteFrame(int frameNr, Building* building)
if( building->GetAllPedestrians().size() == 0)
return;
sprintf(tmp, "<frame ID=\"%d\">\n", frameNr);
data.append(tmp);
for (int roomindex = 0; roomindex < building->GetNumberOfRooms(); roomindex++) {
Room* r = building->GetRoom(roomindex);
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++)
{
Pedestrian* ped = allPeds[p];
Room* r = building->GetRoom(ped->GetRoomID());
string caption = r->GetCaption();
if ((rooms_to_plot.empty() == false)
&& (IsElementInVector(rooms_to_plot, caption) == false)) {
continue;
}
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k);
for (int i = 0; i < s->GetNumberOfPedestrians(); ++i) {
Pedestrian* ped = s->GetPedestrian(i);
data.append(WritePed(ped));
}
}
&& (IsElementInVector(rooms_to_plot, caption) == false)) {
continue;
}
data.append(WritePed(ped));
}
data.append("</frame>\n");
Write(data);
}
......@@ -365,21 +363,16 @@ void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building)
{
char tmp[CLENGTH] = "";
for (int roomindex = 0; roomindex < building->GetNumberOfRooms(); roomindex++) {
Room* r = building->GetRoom(roomindex);
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k);
for (int i = 0; i < s->GetNumberOfPedestrians(); ++i) {
Pedestrian* ped = s->GetPedestrian(i);
double x = ped->GetPos().GetX();
double y = ped->GetPos().GetY();
double z = ped->GetElevation();
sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x,
y,z);
Write(tmp);
}
}
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++){
Pedestrian* ped = allPeds[p];
double x = ped->GetPos().GetX();
double y = ped->GetPos().GetY();
double z = ped->GetElevation();
sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x, y,z);
Write(tmp);
}
}
void TrajectoriesFLAT::WriteFooter()
......@@ -574,8 +567,12 @@ void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building)
sprintf(tmp, "<frame ID=\"%d\">\n", frameNr);
data.append(tmp);
for (int roomindex = 0; roomindex < building->GetNumberOfRooms(); roomindex++) {
Room* r = building->GetRoom(roomindex);
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++)
{
Pedestrian* ped = allPeds[p];
Room* r = building->GetRoom(ped->GetRoomID());
string caption = r->GetCaption();
if ((rooms_to_plot.empty() == false)
......@@ -583,37 +580,31 @@ void TrajectoriesJPSV06::WriteFrame(int frameNr, Building* building)
continue;
}
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k);
for (int i = 0; i < s->GetNumberOfPedestrians(); ++i)
{
char tmp[CLENGTH] = "";
Pedestrian* ped = s->GetPedestrian(i);
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"x=\"%.2f\"\ty=\"%.2f\"\t"
"z=\"%.2f\"\t"
"rA=\"%.2f\"\trB=\"%.2f\"\t"
"eO=\"%.2f\" eC=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
data.append(tmp);
}
char tmp[CLENGTH] = "";
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"x=\"%.2f\"\ty=\"%.2f\"\t"
"z=\"%.2f\"\t"
"rA=\"%.2f\"\trB=\"%.2f\"\t"
"eO=\"%.2f\" eC=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
data.append(tmp);
}
data.append("</frame>\n");
Write(data);
}
......@@ -707,42 +698,39 @@ void TrajectoriesJPSV05::WriteFrame(int frameNr, Building* building)
sprintf(tmp, "<frame ID=\"%d\">\n", frameNr);
data.append(tmp);
for (int roomindex = 0; roomindex < building->GetNumberOfRooms(); roomindex++) {
Room* r = building->GetRoom(roomindex);
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++)
{
Pedestrian* ped = allPeds[p];
Room* r = building->GetRoom(ped->GetRoomID());
string caption = r->GetCaption();
char tmp[CLENGTH] = "";
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k);
for (int i = 0; i < s->GetNumberOfPedestrians(); ++i)
{
char tmp[CLENGTH] = "";
Pedestrian* ped = s->GetPedestrian(i);
double v0 = ped->GetV0Norm();
int color=1; // red= very low velocity
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"x=\"%.2f\"\ty=\"%.2f\"\t"
"z=\"%.2f\"\t"
"rA=\"%.2f\"\trB=\"%.2f\"\t"
"eO=\"%.2f\" eC=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
data.append(tmp);
}
if (v0 != 0.0) {
double v = ped->GetV().Norm();
color = (int) (v / v0 * 255);
}
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"x=\"%.2f\"\ty=\"%.2f\"\t"
"z=\"%.2f\"\t"
"rA=\"%.2f\"\trB=\"%.2f\"\t"
"eO=\"%.2f\" eC=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
data.append(tmp);
}
data.append("</frame>\n");
_outputHandler->Write(data);
}
......
......@@ -53,6 +53,8 @@ Simulation::Simulation()
_fps=1;
_em=NULL;
_argsParser=NULL;
_hpc=-1;
_profiling=false;
}
Simulation::~Simulation()
......@@ -509,7 +511,7 @@ int Simulation::RunSimulation()
void Simulation::Update()
{
//_building->Update();
_building->UpdateVerySlow();
_building->Update();
//someone might have leave the building
_nPeds=_building->GetAllPedestrians().size();
// update the global time
......
......@@ -20,6 +20,7 @@ EventManager::EventManager(Building *_b){
_dynamic=false;
_file = fopen("../events/events.txt","r");
_lastUpdateTime=0;
_deltaT=0;
if(!_file){
Log->Write("INFO:\tDatei events.txt nicht gefunden. Dynamisches Eventhandling nicht moeglich.");
}
......@@ -140,32 +141,38 @@ void EventManager::Update_Events(double time, double d){
// neues Routing) ansonsten fertig
_deltaT=d;
vector<Pedestrian*> _allPedestrians=_building->GetAllPedestrians();
int nSize = _allPedestrians.size();
vector<Pedestrian*> _allPeds=_building->GetAllPedestrians();
//zuerst muss geprueft werden, ob die Peds, die die neuen Infos schon haben sie an andere Peds weiter-
//leiten muessen (wenn diese sich in der naechsten Umgebung befinden)
int currentTime = _allPedestrians[0]->GetGlobalTime();
int currentTime = _allPeds[0]->GetGlobalTime();
if(currentTime!=_lastUpdateTime)
if((currentTime%UPDATE_FREQUENCY)==0) {
for(int p=0;p<nSize;p++){
if(_allPedestrians[p]->GetNewEventFlag()){
int rID = _allPedestrians[p]->GetRoomID();
int srID = _allPedestrians[p]->GetSubRoomID();
Room* room = _building->GetRoom(rID);
SubRoom* sub = room->GetSubRoom(srID);//Nur Infos an Leute im gleichen Raum weitergeben
for (int k = 0; k < sub->GetNumberOfPedestrians(); k++) {
Pedestrian* ped = sub->GetPedestrian(k);
if(!ped->GetNewEventFlag()&&ped->GetReroutingTime()>2.0){
//wenn der Pedestrian die neuen Infos noch nicht hat und eine Reroutingtime von > 2 Sekunden hat, pruefen ob er nah genug ist
Point pos1 = _allPedestrians[p]->GetPos();
Point pos2 = ped->GetPos();
double distX = pos1.GetX()-pos2.GetX();
double distY = pos1.GetY()-pos2.GetY();
double dist = sqrt(distX*distX+distY*distY);
if(dist<=J_EPS_INFO_DIST){// wenn er nah genug (weniger als 2m) ist, Info weitergeben (Reroutetime auf 2 Sek)
//ped->RerouteIn(2.0);
ped->RerouteIn(0.0);
for(unsigned int p1=0;p1<_allPeds.size();p1++)
{
Pedestrian* ped1 = _allPeds[p1];
if(ped1->GetNewEventFlag()){
int rID = ped1->GetRoomID();
int srID = ped1->GetSubRoomID();
for(unsigned int p2=0;p2<_allPeds.size();p2++)
{
Pedestrian* ped2 = _allPeds[p2];
//same room and subroom
if(rID==ped2->GetRoomID() && srID==ped2->GetSubRoomID())
{
if(!ped2->GetNewEventFlag()&&ped2->GetReroutingTime()>2.0){
//wenn der Pedestrian die neuen Infos noch nicht hat und eine Reroutingtime von > 2 Sekunden hat, pruefen ob er nah genug ist
Point pos1 = ped1->GetPos();
Point pos2 = ped2->GetPos();
double distX = pos1.GetX()-pos2.GetX();
double distY = pos1.GetY()-pos2.GetY();
double dist = sqrt(distX*distX+distY*distY);
if(dist<=J_EPS_INFO_DIST){// wenn er nah genug (weniger als 2m) ist, Info weitergeben (Reroutetime auf 2 Sek)
//ped->RerouteIn(2.0);
ped2->RerouteIn(0.0);
}
}
}
}
......@@ -176,15 +183,15 @@ void EventManager::Update_Events(double time, double d){
}
//dann muss die Reroutingzeit der Peds, die die neuen Infos noch nicht haben, aktualisiert werden:
for(int p=0;p<nSize;p++){
//if(!_allPedestrians[p]->GetNewEventFlag()){
_allPedestrians[p]->UpdateReroutingTime();
if(_allPedestrians[p]->IsReadyForRerouting()){
_allPedestrians[p]->ClearMentalMap();
_allPedestrians[p]->ResetRerouting();
_allPedestrians[p]->SetNewEventFlag(true);
for(unsigned int p1=0;p1<_allPeds.size();p1++)
{
Pedestrian* ped1 = _allPeds[p1];
ped1->UpdateReroutingTime();
if(ped1->IsReadyForRerouting()){
ped1->ClearMentalMap();
ped1->ResetRerouting();
ped1->SetNewEventFlag(true);
}
//}
}
//Events finden
......@@ -287,7 +294,7 @@ void EventManager::getTheEvent(char* c){
string id = "";
string state = "";
for(int i=0;i<20;i++){
if(c[i]==NULL){
if(!c[i]){
break;
}
else if(c[i]==' '){
......
This diff is collapsed.
......@@ -80,11 +80,12 @@ public:
void SetCaption(const std::string& s);
void SetRoutingEngine(RoutingEngine* r);
void SetRoom(Room* room, int index);
/// delete the ped from the ped vector
void DeletePedestrian(Pedestrian* &ped);
/// delete the ped from the simulation
void DeletePedFromSim(Pedestrian* &ped);
void AddPedestrian(Pedestrian* ped);
void GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds);
std::string GetCaption() const;
......@@ -170,10 +171,8 @@ public:
void InitSavePedPathway(const std::string &filename);
void AddRoom(Room* room);
void Update();
void UpdateVerySlow();
void UpdateGrid();
void AddSurroundingRoom(); // add a final room (outside or world), that encompasses the complete geometry
void DumpSubRoomInRoom(int roomID, int subID);
const std::map<int, Crossing*>& GetAllCrossings() const;
const std::map<int, Transition*>& GetAllTransitions() const;
......
......@@ -143,15 +143,6 @@ SubRoom* Room::GetSubRoom(int index) const
#ifdef _SIMULATOR
int Room::GetNumberOfPedestrians() const
{
int sum = 0;
for (int i = 0; i < GetNumberOfSubRooms(); i++) {
sum += GetSubRoom(i)->GetNumberOfPedestrians();
}
return sum;
}
#endif // _SIMULATOR
RoomState Room::GetState() const
......
......@@ -124,11 +124,6 @@ public:
*/
SubRoom* GetSubRoom(int index) const;
/**
* @return the number of pedestrians in the rooms (all subrooms)
*/
int GetNumberOfPedestrians() const;
/**
* @return the state for this room
*/
......@@ -149,7 +144,6 @@ public:
*/
void AddTransitionID(int ID);
/**
* Debug output for this class
*/
......
......@@ -70,28 +70,6 @@ SubRoom::SubRoom()
_area = 0.0;
_closed=false;
_uid = _static_uid++;
#ifdef _SIMULATOR
_peds = vector<Pedestrian* > ();
#endif //_SIMULATOR
}
SubRoom::SubRoom(const SubRoom& orig)
{
_id = orig.GetSubRoomID();
_walls = orig.GetAllWalls();
_poly = orig.GetPolygon();
_goalIDs = orig.GetAllGoalIDs();
_area = orig.GetArea();
_closed=orig.GetClosed();
_roomID=orig.GetRoomID();
_uid = orig.GetUID();
_cosAngleWithHorizontalPlane=orig.GetCosAngleWithHorizontal();
#ifdef _SIMULATOR
_peds = orig.GetAllPedestrians();
#endif //_SIMULATOR
}
SubRoom::~SubRoom()
......@@ -102,13 +80,6 @@ SubRoom::~SubRoom()
delete _obstacles[i];
}
_obstacles.clear();
#ifdef _SIMULATOR
for (unsigned int i = 0; i < _peds.size(); i++) {
delete _peds[i];
}
#endif //_SIMULATOR
}
// Setter -Funktionen
......@@ -577,10 +548,6 @@ NormalSubRoom::NormalSubRoom() : SubRoom()
}
NormalSubRoom::NormalSubRoom(const NormalSubRoom& orig) : SubRoom(orig)
{
}
NormalSubRoom::~NormalSubRoom()
{
......@@ -781,11 +748,6 @@ Stair::Stair() : NormalSubRoom()
pDown = Point();
}
Stair::Stair(const Stair & orig) : NormalSubRoom(orig)
{
pUp = orig.GetUp();
pDown = orig.GetDown();
}
Stair::~Stair()
{
......@@ -890,7 +852,6 @@ void Stair::WriteToErrorLog() const
* */
const Point* Stair::CheckCorner(const Point** otherPoint, const Point** aktPoint, const Point* nextPoint)
{
Point l1 = **otherPoint - **aktPoint;
Point l2 = *nextPoint - **aktPoint;
const Point* rueck = NULL;
......@@ -1029,21 +990,6 @@ const std::string& SubRoom::GetType() const
#ifdef _SIMULATOR
void SubRoom::SetAllPedestrians(const vector<Pedestrian*>& peds)
{
_peds = peds;
}
void SubRoom::SetPedestrian(Pedestrian* ped, int index)
{
if ((index >= 0) && (index < GetNumberOfPedestrians())) {
_peds[index] = ped;
} else {
Log->Write("ERROR: Wrong Index in SubRoom::SetPedestrian()");
exit(0);
}
}
bool SubRoom::IsInSubRoom(Pedestrian* ped) const
{
const Point& pos = ped->GetPos();
......@@ -1054,51 +1000,4 @@ bool SubRoom::IsInSubRoom(Pedestrian* ped) const
}
int SubRoom::GetNumberOfPedestrians() const
{
return _peds.size();
}
const vector<Pedestrian*>& SubRoom::GetAllPedestrians() const
{
return _peds;
}
Pedestrian* SubRoom::GetPedestrian(int index) const
{
if ((index >= 0) && (index < (int) GetNumberOfPedestrians()))
return _peds[index];
else {
Log->Write("ERROR: Wrong 'index' in SubRoom::GetPedestrian()");
exit(0);
}
}
void SubRoom::AddPedestrian(Pedestrian* ped)
{
_peds.push_back(ped);
}
void SubRoom::DeletePedestrian(int index)
{
if ((index >= 0) && (index < (int) GetNumberOfPedestrians())) {
_peds.erase(_peds.begin() + index);
} else {
Log->Write("ERROR: Wrong Index in SubRoom::DeletePedestrian()");
exit(0);
}
}
void SubRoom::ClearAllPedestrians()
{
for(unsigned int p=0; p<_peds.size(); p++) {
delete _peds[p];
}
_peds.clear();
}
#endif // _SIMULATOR
......@@ -80,11 +80,6 @@ private:
/// storing and incrementing the total number of subrooms
static int _static_uid;
#ifdef _SIMULATOR
std::vector<Pedestrian*> _peds; // pedestrians container
#endif
protected:
std::vector<Wall> _walls;
std::vector<Point> _poly; // Polygonal representation of the subroom
......@@ -93,7 +88,6 @@ public:
// constructors
SubRoom();
SubRoom(const SubRoom& orig);
virtual ~SubRoom();
/**
......@@ -257,7 +251,6 @@ public:
const Transition* GetTransition(int i) const;
const Hline* GetHline(int i) const;
/**
* Add a wall to the subroom
*/
......@@ -269,11 +262,6 @@ public:
*/
void AddObstacle(Obstacle* obs);
/**
* Remove the pedestrian from the subroom.
* @param index, the index of the peds in the vector (NOT THE ID !)
*/
void DeletePedestrian(int index);
void AddGoalID(int ID);
void RemoveGoalID(int ID);
......@@ -308,22 +296,12 @@ public:
///check whether the pedestrians is still in the subroom
virtual bool IsInSubRoom(const Point& ped) const = 0;
// MPI:
void ClearAllPedestrians();
#ifdef _SIMULATOR
/**
* @return the number of pedestrians in this subroom
*/
int GetNumberOfPedestrians() const;
void AddPedestrian(Pedestrian* ped);
virtual bool IsInSubRoom(Pedestrian* ped) const;
void SetAllPedestrians(const std::vector<Pedestrian*>& peds);
void SetPedestrian(Pedestrian* ped, int index);
const std::vector<Pedestrian*>& GetAllPedestrians() const;
Pedestrian* GetPedestrian(int index) const;
#endif
......
......@@ -30,7 +30,7 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
<!--persons information and distribution -->
<agents operational_model_id="1">
<agents_distribution>
<group group_id="0" agent_parameter_id="1" room_id="0" subroom_id="0" number="10000" goal_id="-1" router_id="1" />
<group group_id="0" agent_parameter_id="1" room_id="0" subroom_id="0" number="10" goal_id="-1" router_id="1" />
</agents_distribution>
</agents>
......
......@@ -516,13 +516,7 @@ void GCFMModel::CalculateForce(double time, double tip1, Building* building) con
"is bigger than desired velocity (%f) at time: %fs\n",
sqrt(normVi), ped->GetID(), ped->GetV0Norm(), time);
// remove the pedestrian and abort
for(int p=0; p<subroom->GetNumberOfPedestrians(); p++) {
if (subroom->GetPedestrian(p)->GetID()==ped->GetID()) {
subroom->DeletePedestrian(p);
break;
}
}
building->DeletePedFromSim(ped);
building->DeletePedestrian(ped);
Log->Write("\tERROR: one ped was removed due to high velocity");
exit(EXIT_FAILURE);
}
......
......@@ -886,15 +886,8 @@ void GPU_GCFMModel::CalculateForce(double time, double tip1, Building* building)
sqrt(normVi), ped->GetID(), ped->GetV0Norm(), time);////time statt t
// remove the pedestrian and abort
for(int p=0;p<subroom->GetNumberOfPedestrians();p++){
if (subroom->GetPedestrian(p)->GetID()==ped->GetID()){