Commit 2e886f46 authored by arno gay-bauer's avatar arno gay-bauer
Browse files

The console prints the danger line coordinates, and the exposition formula is reviewed.

Exposition happens every second instead of every step, and the console
prints danger lines coordinates in a sequence of
time x1 y1 x2 y2
parent 8fcad754
Pipeline #10842 passed with stages
in 7 minutes and 14 seconds
......@@ -517,7 +517,8 @@ double Simulation::RunBody(double maxSimTime)
if ((!_gotSources) &&
((frameNr < 100 && frameNr % 10 == 0) ||
(frameNr > 100 && frameNr % 100 == 0)))
printf("time: %6.2f (%4.0f) | Agents: %6ld / %d [%4.1f%%]\n", t , maxSimTime, _nPeds, initialnPeds, (double)(initialnPeds-_nPeds)/initialnPeds*100);
2+2;
//printf("time: %6.2f (%4.0f) | Agents: %6ld / %d [%4.1f%%]\n", t , maxSimTime, _nPeds, initialnPeds, (double)(initialnPeds-_nPeds)/initialnPeds*100);
// needed to control the execution time PART 2
......
......@@ -149,6 +149,9 @@ Building::~Building()
iter!=_goals.end(); ++iter) {
delete iter->second;
}
for (unsigned int p = 0; p<_dangerLines.size(); p++) {
delete _dangerLines[p];
}
}
Configuration* Building::GetConfig() const {
......
......@@ -33,6 +33,7 @@
#include "../pedestrian/Pedestrian.h"
#include "Line.h"
#include "Wall.h"
#include "../IO/OutputHandler.cpp"
using namespace std;
......@@ -50,6 +51,8 @@ DangerLine::DangerLine() : Line()
_x_speed = 0;
_y_speed = 0;
_lastTimeUpdate = 0;
_lastTimeExposure = 0;
_expositionReady = true;
}
......@@ -69,13 +72,23 @@ void DangerLine::setParameters(double fatalDistance, double startDistance, doubl
}
void DangerLine::expose(Pedestrian* ped) const
void DangerLine::expose(Pedestrian* ped)
{
Point p = ped->GetPos();
double fatality = abs(getFatalProbability(&p));
double fate = rand() % 100;
if( fate < fatality ){
ped->SetV0Norm(0,0,0,0,0,0,0);
//We don't want to expose every step, but every second
if(_expositionReady) {
//std::cout<<"OK++ EXPOSE: "<<_lastTimeUpdate<<" "<<_lastTimeExposure<<std::endl;
_lastTimeExposure = _lastTimeUpdate;
Point p = ped->GetPos();
double fatality = abs(getFatalProbability(&p));
double fate = rand() % 100;
if (fate < fatality) {
//we "kill" the pedestrian by making it not moving
//TODO improve this part by making the pedestrian able to be walked over
ped->SetV0Norm(0, 0, 0, 0, 0, 0, 0);
}
}else{
//std::cout<<"KO---- EXPOSE: "<<_lastTimeUpdate<<" "<<_lastTimeExposure<<std::endl;
}
}
......@@ -99,6 +112,16 @@ void DangerLine::update(double time)
if(_lastTimeUpdate == 0) //first time calling
_lastTimeUpdate = time;
if(_lastTimeExposure == 0)
_lastTimeExposure = time;
if(_expositionReady){
_expositionReady = false;
}else if(time - _lastTimeExposure > 1){
_expositionReady = true;
}
double new_x1 = this->GetPoint1()._x + (time-_lastTimeUpdate)*_x_speed;
double new_y1 = this->GetPoint1()._y + (time-_lastTimeUpdate)*_y_speed;
double new_x2 = this->GetPoint2()._x + (time-_lastTimeUpdate)*_x_speed;
......@@ -107,5 +130,17 @@ void DangerLine::update(double time)
this->SetPoint1(Point(new_x1,new_y1));
this->SetPoint2(Point(new_x2,new_y2));
this->_lastTimeUpdate = time;
//For the moment, danger line trajectories are written in the console
this->print();
}
void DangerLine::print()
{
std::cout<<_lastTimeUpdate<<" "
<<this->GetPoint1()._x<<" "
<<this->GetPoint1()._y<<" "
<<this->GetPoint2()._x<<" "
<<this->GetPoint2()._y<<std::endl;
}
......@@ -53,6 +53,8 @@ private:
double _x_speed;
double _y_speed;
double _lastTimeUpdate;
double _lastTimeExposure;
bool _expositionReady;
/**
* @param p a point close to the line
......@@ -75,7 +77,7 @@ public:
* with a random chance bigger the closer to the line
* @param ped the pedestrian to expose
*/
void expose(Pedestrian *ped) const;
void expose(Pedestrian *ped);
/**
* set the characteristics of the line
......@@ -93,6 +95,9 @@ public:
* @param time simulation time
*/
void update(double time);
void print();
};
#endif /* _DANGERLINE_H */
......
Supports Markdown
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