Commit fd7f25d7 authored by Mohcine Chraibi's avatar Mohcine Chraibi

Merge branch 'v0.7' of cst.version.fz-juelich.de:jupedsim/jpscore into v0.7

parents 94979aff a1c6dd8e
......@@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file.
## v0.7.0 [Unreleased]
### Added
- Changelog file
- Rimea testcases
- Rimea testcases
- risk tolerance factor (value in [0 1]) for pedestrian. Pedestrians with high values are likely to take more risks.
### Changed
-
......
......@@ -2,6 +2,7 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../geometry/Point.h"
#include <cmath>
BOOST_AUTO_TEST_SUITE(PointTest)
......@@ -42,11 +43,182 @@ BOOST_AUTO_TEST_CASE(Point_Norm_Tests)
BOOST_CHECK(p1.Norm() == 1);
p1.SetY(3);
BOOST_CHECK(p1.Norm() == 3);
p1.SetX(3);
p1.SetY(4);
BOOST_CHECK(p1.Norm() == 5);
BOOST_TEST_MESSAGE("Leaving norm test");
}
BOOST_AUTO_TEST_CASE(POINT_TO_STRING_Test)
{
BOOST_TEST_MESSAGE("starting string conv test");
std::string xpt[] = {"0.25", "1.25", "2.25", "3.25"};
std::string ypt[] = {"10.25", "11.25", "12.25", "13.25"};
Point p1;
for (double i = 0.25; i < 4; ++i)
{
p1.SetX(i);
p1.SetY(i+10);
BOOST_CHECK( p1.toString() == "( " + xpt[int(i)] +
" : " + ypt[int(i)] + " )" );
}
Point p2(-2,-0.5);
BOOST_CHECK( p2.toString() == "( -2 : -0.5 )" );
BOOST_TEST_MESSAGE("Leaving string conv test");
}
BOOST_AUTO_TEST_CASE(POINT_NORM_MOLIFIED_TEST)
{
BOOST_TEST_MESSAGE("starting NormMolified test");
Point p;
for (double i = 0, j = 0.5; i < 10; ++i, ++j)
{
p.SetX(i);
p.SetY(j);
BOOST_CHECK( p.NormMolified() == sqrt(pow(i,2) + pow(j,2) + 0.1) );
}
BOOST_TEST_MESSAGE("Leaving NormMolified test");
}
BOOST_AUTO_TEST_CASE(POINT_NORM_SQUARE_TEST)
{
BOOST_TEST_MESSAGE("starting NormSquare test");
Point p;
for (double i = -5, j = 0.6; i < 5; ++i, ++j)
{
p.SetX(i);
p.SetY(j);
BOOST_CHECK( p.NormSquare() == pow(i,2) + pow(j,2) );
}
BOOST_TEST_MESSAGE("Leaving NormMSquare test");
}
BOOST_AUTO_TEST_CASE(POINT_NORMALIZE_TEST)
{
BOOST_MESSAGE("starting Normalize test");
Point p1(0.0001,0.0001);
Point p2(10,10);
p2 = p1.Normalized();
BOOST_MESSAGE(" check for norm < J_EPS ");
BOOST_REQUIRE( p2.GetX() == 0.0 && p2.GetY() == 0.0 );
for (double i = 0, j = -10; i < 5; ++i, ++j)
{
p1.SetX(i);
p1.SetY(j);
p2 = p1.Normalized();
BOOST_MESSAGE(" check for norm > J_EPS ");
BOOST_REQUIRE( p2.GetX() == i / p1.Norm() &&
p2.GetY() == j / p1.Norm() );
p2 = p1.NormalizedMolified();
BOOST_MESSAGE(" check for norm > J_EPS_GOAL ");
BOOST_REQUIRE( p2.GetX() == i / p1.NormMolified() &&
p2.GetY() == j / p1.NormMolified() );
}
BOOST_MESSAGE("Leaving normalize test");
}
BOOST_AUTO_TEST_CASE(POINT_DET_TEST)
{
BOOST_MESSAGE("starting determinant test");
const double PI = 3.14159265358979323846;
Point p1(10,5);
Point p2;
for (int i = 1; i < 5; ++i)
{
p2.SetX( cos(PI / -i) );
p2.SetY( sin(PI / i) );
BOOST_CHECK( p1.Det(p2) == 10 * sin(PI/i) - 5 * cos(PI/i));
//BOOST_CHECK( p1.Det(p2) == p1.CrossP(p2));
}
BOOST_MESSAGE("Leaving determinant test");
}
BOOST_AUTO_TEST_CASE(POINT_SCALARPRODUCT_TEST)
{
BOOST_MESSAGE("starting scalar product test");
const double PI = 3.14159265358979323846;
Point p1(10,5);
Point p2;
for (int i = 1; i < 5; ++i)
{
p2.SetX( cos(PI / i) );
p2.SetY( sin(PI / -i) );
BOOST_CHECK( p1.ScalarP(p2) == 10 * p2.GetX() + 5 * p2.GetY() );
}
BOOST_MESSAGE("Leaving scalar product test");
}
BOOST_AUTO_TEST_CASE(POINT_OPEROVERLOADING_TEST)
{
BOOST_MESSAGE("starting operator overload test");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 10; ++i)
{
Point p1(i, -i*10);
Point p2( cos(PI/i), sin(PI/i) );
Point sum = p1 + p2;
BOOST_REQUIRE( sum.GetX() == i + cos(PI/i) &&
sum.GetY() == -i*10 + sin(PI/i) );
Point sub = p1 - p2;
BOOST_REQUIRE( sub.GetX() == i - cos(PI/i) &&
sub.GetY() == -i*10 - sin(PI/i) );
Point mul = p2 * i;
BOOST_REQUIRE( mul.GetX() == i * cos(PI/i) &&
mul.GetY() == i * sin(PI/i) );
Point pluseq(i, i);
pluseq += p1;
BOOST_REQUIRE( pluseq.GetX() == i + i &&
pluseq.GetY() == -i*10 + i );
Point div = p2 / 1E-7;
BOOST_REQUIRE( div.GetX() == p2.GetX() &&
div.GetY() == p2.GetY() );
div = p2 / 2;
BOOST_REQUIRE( div.GetX() == p2.GetX() / 2 &&
div.GetY() == p2.GetY() / 2 );
BOOST_CHECK( p1 != p2 );
p1.SetX( p2.GetX() );
p1.SetY( p2.GetY() );
BOOST_CHECK( p1 == p2 );
}
BOOST_MESSAGE("Leaving operator overload test");
}
BOOST_AUTO_TEST_CASE(POINT_COORDTRANS_TO_ELLIPSE_TEST)
{
BOOST_MESSAGE("starting coord transform to ellipse");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 5; ++i)
{
Point p1(i*10, i/10);
Point center(i, -i);
Point check = (p1 - center).Rotate( cos(PI/i), -sin(PI/i) );
Point transform = p1.CoordTransToEllipse( center, cos(PI/i), sin(PI/i) );
BOOST_CHECK( transform == check );
}
BOOST_MESSAGE("Leaving coord transform to ellipse");
}
BOOST_AUTO_TEST_CASE(POINT_COORDTRANS_TO_CART_TEST)
{
BOOST_MESSAGE("starting coord transform to cartesian");
const double PI = 3.14159265358979323846;
for (int i = 1; i < 5; ++i)
{
Point p1(i*10, i/10);
Point center(-i, i);
Point transform = p1.CoordTransToCart( center, cos(PI/i), sin(PI/i) );
Point check = p1.Rotate( cos(PI/i), sin(PI/i) );
BOOST_REQUIRE( transform.GetX() == check.GetX() - i &&
transform.GetY() == check.GetY() + i );
}
BOOST_MESSAGE("starting coord transform to cartesian");
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
......@@ -136,7 +136,8 @@ enum AgentColorMode {
BY_VELOCITY=1,
BY_KNOWLEDGE,
BY_ROUTE,
BY_SPOTLIGHT
BY_SPOTLIGHT,
//BY_GROUP
};
//global functions for convenience
......
......@@ -12,7 +12,7 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!-- trajectories file and format -->
<trajectories format="xml-plain" fps="8">
<file location="big_room_trrajectories.xml" />
<!--<socket hostname="127.0.0.1" port="8989"/> -->
<socket hostname="127.0.0.1" port="8989"/>
</trajectories>
<!-- where to store the logs -->
<!--<logfile>outputfiles/log.txt</logfile> -->
......@@ -70,7 +70,8 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!--persons information and distribution -->
<agents operational_model_id="2">
<agents_distribution>
<group group_id="0" room_id="0" subroom_id="0" number="500" router_id="1" agent_parameter_id="1" />
<group group_id="0" room_id="0" subroom_id="0" number="50" router_id="1" agent_parameter_id="1"
risk_tolerance_mean="0.8" risk_tolerance_sigma="0.01"/>
</agents_distribution>
</agents>
......
......@@ -12,7 +12,7 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!-- trajectories file and format -->
<trajectories format="xml-plain" fps="8">
<file location="testSchulTrajectories.xml" />
<!-- <socket hostname="127.0.0.1" port="8989"/> -->
<socket hostname="127.0.0.1" port="8989"/>
</trajectories>
<!-- where to store the logs -->
<!--<logfile>outputfiles/log.txt</logfile> -->
......
......@@ -257,6 +257,8 @@ bool PedDistributor::InitDistributor(const string& fileName, const std::map<int,
double patience= xmltof(e->Attribute("patience"), 5);
double premovement_mean= xmltof(e->Attribute("pre_movement_mean"), 0);
double premovement_sigma= xmltof(e->Attribute("pre_movement_sigma"), 0);
double risk_tolerance_mean= xmltof(e->Attribute("risk_tolerance_mean"), 0);
double risk_tolerance_sigma= xmltof(e->Attribute("risk_tolerance_sigma"), 0);
double x_min=xmltof(e->Attribute("x_min"), -FLT_MAX);
double x_max=xmltof(e->Attribute("x_max"), FLT_MAX);
......@@ -292,6 +294,7 @@ bool PedDistributor::InitDistributor(const string& fileName, const std::map<int,
dis->SetHeight(height);
dis->SetPatience(patience);
dis->InitPremovementTime(premovement_mean,premovement_sigma);
dis->InitRiskTolerance(risk_tolerance_mean,risk_tolerance_sigma);
if(agentPars.count(agent_para_id)==0)
{
......@@ -759,6 +762,7 @@ void PedDistributor::DistributeInSubRoom(SubRoom* r,int nAgents , vector<Point>&
ped->SetSubRoomID(r->GetSubRoomID());
ped->SetPatienceTime(para->GetPatience());
ped->SetPremovementTime(para->GetPremovementTime());
ped->SetRiskTolerance(para->GetRiskTolerance());
const Point& start_pos = para->GetStartPosition();
......@@ -844,3 +848,13 @@ double StartDistributionRoom::GetPremovementTime()
{
return _premovementTime(_generator);
}
void StartDistributionRoom::InitRiskTolerance(double mean, double stdv)
{
_riskTolerance = std::normal_distribution<double>(mean,stdv);
}
double StartDistributionRoom::GetRiskTolerance()
{
return _riskTolerance(_generator);
}
......@@ -74,6 +74,11 @@ private:
//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;
......@@ -109,8 +114,10 @@ public:
void Setbounds(double bounds[4]);
AgentsParameters* GetGroupParameters();
void SetGroupParameters(AgentsParameters* groupParameters);
void InitPremovementTime(double mean, double stv);
void InitPremovementTime(double mean, double stdv);
double GetPremovementTime();
void InitRiskTolerance(double mean, double stdv);
double GetRiskTolerance();
};
//TODO merge the two classes and set the _subRoomID=-1
......
......@@ -793,6 +793,18 @@ double Pedestrian::GetPremovementTime()
return _premovement;
}
void Pedestrian::SetRiskTolerance(double tol)
{
if (tol>1) tol=1;
if(tol<0) tol=0;
_riskTolerance=tol;
}
double Pedestrian::GetRiskTolerance() const
{
return _riskTolerance;
}
const Building* Pedestrian::GetBuilding()
{
return _building;
......
......@@ -55,6 +55,7 @@ private:
double _height;
double _age;
double _premovement = 0;
double _riskTolerance=0;
std::string _gender;
//gcfm specific parameters
......@@ -128,7 +129,7 @@ private:
Building * _building;
public:
// Konstruktoren
// constructors
Pedestrian();
virtual ~Pedestrian();
......@@ -325,6 +326,20 @@ public:
*/
double GetPremovementTime();
/**
* Set/Get the risk tolerance of a pedestrians.
* The value should be in the interval [0 1].
* It will be truncated accordingly if not in that interval.
*/
void SetRiskTolerance(double tol);
/**
* Set/Get the risk tolerance of a pedestrians.
* The value should be in the interval [0 1].
* It will be truncated accordingly if not in that interval.
*/
double GetRiskTolerance() const;
/**
* return the pedestrian color used for visualiation.
* Default mode is coded by velocity.
......
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