Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
JPScore
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
92
Issues
92
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JuPedSim
JPScore
Commits
311f63fa
Commit
311f63fa
authored
May 03, 2018
by
Mohcine Chraibi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '158' into 'develop'
Issue 158 See merge request
!21
parents
60b744d8
2d1fb525
Pipeline
#9289
failed with stages
in 5 minutes and 7 seconds
Changes
11
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
434 additions
and
312 deletions
+434
-312
.gitlab-ci.yml
.gitlab-ci.yml
+9
-8
Simulation.cpp
Simulation.cpp
+28
-2
Simulation.h
Simulation.h
+5
-1
geometry/Building.cpp
geometry/Building.cpp
+1
-3
main.cpp
main.cpp
+7
-4
math/VelocityModel.cpp
math/VelocityModel.cpp
+6
-3
pedestrian/AgentsSourcesManager.cpp
pedestrian/AgentsSourcesManager.cpp
+258
-189
pedestrian/AgentsSourcesManager.h
pedestrian/AgentsSourcesManager.h
+18
-1
pedestrian/Pedestrian.cpp
pedestrian/Pedestrian.cpp
+6
-7
voronoi-boost/VoronoiPositionGenerator.cpp
voronoi-boost/VoronoiPositionGenerator.cpp
+43
-41
voronoi-boost/VoronoiPositionGenerator.h
voronoi-boost/VoronoiPositionGenerator.h
+53
-53
No files found.
.gitlab-ci.yml
View file @
311f63fa
...
...
@@ -6,8 +6,8 @@ before_script:
-
nproc=`grep -c '^processor' /proc/cpuinfo`
-
echo "nproc = $nproc"
-
export LD_LIBRARY_PATH=$HOME/boost_1_61_0/stage/lib/:$LD_LIBRARY_PATH
#========== Pipeline ==================
stages
:
-
configure
...
...
@@ -46,7 +46,7 @@ make-linux:
-
lib
-
lib/Debug
-
bin
stage
:
compile
tags
:
-
linux
...
...
@@ -54,13 +54,14 @@ make-linux:
-
cd build
-
make -j$nproc
-
echo "compile | ${CI_PROJECT_DIR}"
tags
:
-
linux
#============== unit_test ============
test
:
dependencies
:
-
make-linux
stage
:
unit_test
stage
:
unit_test
script
:
-
cd build
-
ctest -R Boost
...
...
@@ -75,7 +76,7 @@ verification:
script
:
-
cd build
-
ctest -R juelich
only
:
only
:
-
develop
tags
:
-
linux
...
...
@@ -90,7 +91,7 @@ verification:
# script:
# - cd build
# - ctest -R rimea
# only:
# only:
# - develop
# tags:
# - linux
...
...
@@ -105,7 +106,7 @@ verification:
# script:
# - cd build
# - ctest -R validation
# only:
# only:
# - develop
# tags:
# - linux
...
...
Simulation.cpp
View file @
311f63fa
...
...
@@ -35,7 +35,7 @@
#include "math/GompertzModel.h"
#include "math/GradientModel.h"
#include "pedestrian/AgentsQueue.h"
#include "pedestrian/AgentsSourcesManager.h"
#ifdef _OPENMP
#else
...
...
@@ -61,6 +61,7 @@ Simulation::Simulation(Configuration* args)
_fps
=
1
;
_em
=
nullptr
;
_gotSources
=
false
;
_maxSimTime
=
100
;
// _config = args;
}
...
...
@@ -201,6 +202,7 @@ bool Simulation::InitArgs()
sprintf
(
tmp
,
"
\t
t_max: %f
\n
"
,
_config
->
GetTmax
());
s
.
append
(
tmp
);
_deltaT
=
_config
->
Getdt
();
_maxSimTime
=
_config
->
GetTmax
();
sprintf
(
tmp
,
"
\t
dt: %f
\n
"
,
_deltaT
);
_periodic
=
_config
->
IsPeriodic
();
sprintf
(
tmp
,
"
\t
periodic: %d
\n
"
,
_periodic
);
...
...
@@ -214,10 +216,11 @@ bool Simulation::InitArgs()
_routingEngine
=
_config
->
GetRoutingEngine
();
auto
distributor
=
std
::
unique_ptr
<
PedDistributor
>
(
new
PedDistributor
(
_config
));
// IMPORTANT: do not change the order in the following..
_building
=
std
::
unique
_ptr
<
Building
>
(
new
Building
(
_config
,
*
distributor
));
_building
=
std
::
shared
_ptr
<
Building
>
(
new
Building
(
_config
,
*
distributor
));
// Initialize the agents sources that have been collected in the pedestrians distributor
_agentSrcManager
.
SetBuilding
(
_building
.
get
());
_agentSrcManager
.
SetMaxSimTime
(
GetMaxSimTime
());
_gotSources
=
(
bool
)
distributor
->
GetAgentsSources
().
size
();
// did we have any sources? false if no sources
for
(
const
auto
&
src
:
distributor
->
GetAgentsSources
())
{
_agentSrcManager
.
AddSource
(
src
);
...
...
@@ -529,12 +532,31 @@ void Simulation::RunFooter()
void
Simulation
::
ProcessAgentsQueue
()
{
/* std::cout << "Call Simulation::ProcessAgentsQueue() at: " << Pedestrian::GetGlobalTime() << std::endl; */
/* std::cout << KRED << " SIMULATION building " << _building << " size " << _building->GetAllPedestrians().size() << "\n" << RESET; */
/* for(auto pp: _building->GetAllPedestrians()) */
/* std::cout<< KBLU << "BUL: Simulation: " << pp->GetPos()._x << ", " << pp->GetPos()._y << RESET << std::endl; */
//incoming pedestrians
vector
<
Pedestrian
*>
peds
;
// std::cout << ">>> peds " << peds.size() << RESET<< std::endl;
AgentsQueueIn
::
GetandClear
(
peds
);
//std::cout << "SIMULATION BEFORE BOOL = " << _agentSrcManager.IsBuildingUpdated() << " peds size " << peds.size() << "\n" ;
//_agentSrcManager.SetBuildingUpdated(true);
/* std::cout << "SIMULATION AFTER BOOL = " << _agentSrcManager.IsBuildingUpdated() << "\n" ; */
for
(
auto
&&
ped
:
peds
)
{
/* std::cout << "Add to building : " << ped->GetPos()._x << ", " << ped->GetPos()._y << " t: "<< Pedestrian::GetGlobalTime() << std::endl; */
_building
->
AddPedestrian
(
ped
);
}
// for(auto pp: _building->GetAllPedestrians())
// std::cout<< KBLU << "BUL: Simulation: " << pp->GetPos()._x << ", " << pp->GetPos()._y << " t: "<< Pedestrian::GetGlobalTime() <<RESET << std::endl;
/* std::cout << "LEAVE Simulation::ProcessAgentsQueue() with " << " size " << _building->GetAllPedestrians().size() << "\n" << RESET; */
}
void
Simulation
::
UpdateDoorticks
()
const
{
...
...
@@ -619,3 +641,7 @@ Building* Simulation::GetBuilding()
{
return
_building
.
get
();
}
int
Simulation
::
GetMaxSimTime
()
const
{
return
_maxSimTime
;
}
Simulation.h
View file @
311f63fa
...
...
@@ -67,7 +67,7 @@ private:
///seed using for the random number generator
unsigned
int
_seed
;
/// building object
std
::
unique
_ptr
<
Building
>
_building
;
std
::
shared
_ptr
<
Building
>
_building
;
/// Force model to use
std
::
shared_ptr
<
OperationalModel
>
_operationalModel
;
/// Manage all route choices algorithms
...
...
@@ -85,6 +85,8 @@ private:
/// hybrid simulation manager
//HybridSimulationManager
int
_periodic
;
int
_maxSimTime
;
bool
_gotSources
;
// is true if we got some sources. Otherwise, false.
// bool _printPB; // print progressbar
public:
...
...
@@ -182,6 +184,8 @@ public:
*
*/
void
UpdateDoorticks
()
const
;
int
GetMaxSimTime
()
const
;
};
...
...
geometry/Building.cpp
View file @
311f63fa
...
...
@@ -841,7 +841,7 @@ void Building::AddPedestrian(Pedestrian* ped)
for
(
unsigned
int
p
=
0
;
p
<
_allPedestians
.
size
();
p
++
)
{
Pedestrian
*
ped1
=
_allPedestians
[
p
];
if
(
ped
->
GetID
()
==
ped1
->
GetID
())
{
cout
<<
"Pedestrian
already in the room ??? "
<<
ped
->
GetID
()
<<
endl
;
cout
<<
"Pedestrian
"
<<
ped
->
GetID
()
<<
" already in the room."
<<
endl
;
return
;
}
}
...
...
@@ -1047,5 +1047,3 @@ Transition* Building::GetTransitionByUID(int uid) const
//}
#endif // _SIMULATOR
main.cpp
View file @
311f63fa
...
...
@@ -49,7 +49,7 @@ int main(int argc, char** argv)
Configuration
*
configuration
=
new
Configuration
();
// Parsing the arguments
bool
status
=
false
;
{
{
//ArgumentParser* p = new ArgumentParser(configuration); //Memory Leak
std
::
unique_ptr
<
ArgumentParser
>
p
(
new
ArgumentParser
(
configuration
));
status
=
p
->
ParseArgs
(
argc
,
argv
);
...
...
@@ -86,8 +86,12 @@ int main(int argc, char** argv)
//Start the thread for managing the sources of agents if any
//std::thread t1(sim.GetAgentSrcManager());
double
simMaxTime
=
configuration
->
GetTmax
();
std
::
thread
t1
(
&
AgentsSourcesManager
::
Run
,
&
sim
.
GetAgentSrcManager
());
//@todo pass simMaxTime to Run
//main thread for the simulation
std
::
thread
t1
(
&
AgentsSourcesManager
::
Run
,
&
sim
.
GetAgentSrcManager
());
while
(
!
sim
.
GetAgentSrcManager
().
IsRunning
())
{
// std::cout << "waiting...\n";
}
//main thread for the simulation
evacTime
=
sim
.
RunStandardSimulation
(
simMaxTime
);
//Join the main thread
t1
.
join
();
...
...
@@ -111,7 +115,6 @@ int main(int argc, char** argv)
}
double
execTime
=
difftime
(
endtime
,
starttime
);
std
::
stringstream
summary
;
summary
<<
std
::
setprecision
(
2
)
<<
std
::
fixed
;
summary
<<
"
\n
Exec Time [s] : "
<<
execTime
<<
std
::
endl
;
...
...
math/VelocityModel.cpp
View file @
311f63fa
...
...
@@ -242,7 +242,7 @@ void VelocityModel::ComputeNextTimeStep(double current, double deltaT, Building*
//double winkel = spacings[0].second;
//Point tmp;
Point
speed
=
direction
.
Normalized
()
*
OptimalSpeed
(
ped
,
spacing
);
result_acc
.
push_back
(
speed
);
result_acc
.
push_back
(
speed
);
spacings
.
clear
();
//clear for ped p
...
...
@@ -358,7 +358,8 @@ my_pair VelocityModel::GetSpacing(Pedestrian* ped1, Pedestrian* ped2, Point ei,
//printf("ERROR: \tin VelocityModel::forcePedPed() ep12 can not be calculated!!!\n");
Log
->
Write
(
"WARNING:
\t
in VelocityModel::GetSPacing() ep12 can not be calculated!!!
\n
"
);
Log
->
Write
(
"
\t\t
Pedestrians are too near to each other (%f)."
,
Distance
);
exit
(
EXIT_FAILURE
);
my_pair
(
FLT_MAX
,
ped2
->
GetID
());
exit
(
EXIT_FAILURE
);
//TODO
}
double
condition1
=
ei
.
ScalarProduct
(
ep12
);
// < e_i , e_ij > should be positive
...
...
@@ -399,7 +400,9 @@ Point VelocityModel::ForceRepPed(Pedestrian* ped1, Pedestrian* ped2, int periodi
Log
->
Write
(
"
\t\t
Maybe the value of <a> in force_ped should be increased. Going to exit.
\n
"
);
printf
(
"ped1 %d ped2 %d
\n
"
,
ped1
->
GetID
(),
ped2
->
GetID
());
printf
(
"ped1 at (%f, %f), ped2 at (%f, %f)
\n
"
,
ped1
->
GetPos
().
_x
,
ped1
->
GetPos
().
_y
,
ped2
->
GetPos
().
_x
,
ped2
->
GetPos
().
_y
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
//TODO: quick and dirty fix for issue #158
// (sometimes sources create peds on the same location)
}
Point
ei
=
ped1
->
GetV
().
Normalized
();
if
(
ped1
->
GetV
().
NormSquare
()
<
0.01
){
...
...
pedestrian/AgentsSourcesManager.cpp
View file @
311f63fa
This diff is collapsed.
Click to expand it.
pedestrian/AgentsSourcesManager.h
View file @
311f63fa
...
...
@@ -84,6 +84,7 @@ public:
* Set the building object
*/
void
SetBuilding
(
Building
*
building
);
void
SetRunning
(
bool
running
);
/**
* @return true if all agents have been generated
...
...
@@ -91,6 +92,14 @@ public:
*/
bool
IsCompleted
()
const
;
/**
* @return true if the building is updated
*
*/
bool
IsBuildingUpdated
()
const
;
void
SetBuildingUpdated
(
bool
update
);
/**
* Return a pointer to the building object
*/
...
...
@@ -111,10 +120,13 @@ public:
/**
* Return the total number of agents that will be generated.
* used by visualisation to allocate space
*
*/
long
GetMaxAgentNumber
()
const
;
int
GetMaxSimTime
()
const
;
void
SetMaxSimTime
(
int
t
);
bool
IsRunning
()
const
;
private:
/**
...
...
@@ -165,11 +177,16 @@ private:
std
::
vector
<
std
::
shared_ptr
<
AgentsSource
>
>
_sources
;
///to control the trigger of the events
long
int
_lastUpdateTime
=
0
;
int
maxSimTime
=
0
;
/// building object
Building
*
_building
=
nullptr
;
/// whether all agents have been dispatched
static
bool
_isCompleted
;
//std::atomic<bool>_isCompleted=false;
// std::atomic<bool>_buildingUpdated=false;
bool
_buildingUpdated
;
bool
_isRunning
=
false
;
};
#endif
/* AGENTSSOURCESMANAGER_H_ */
pedestrian/Pedestrian.cpp
View file @
311f63fa
...
...
@@ -198,7 +198,9 @@ void Pedestrian::SetID(int i)
_id
=
i
;
if
(
i
<=
0
)
{
cout
<<
"invalid ID"
<<
i
<<
endl
;
exit
(
0
);
cerr
<<
">> Invalid pedestrians ID "
<<
i
<<
endl
;
cerr
<<
">> Pedestrian ID should be > 0. Exit."
<<
endl
;
exit
(
0
);
}
}
...
...
@@ -597,7 +599,7 @@ double Pedestrian::GetV0Norm() const
// // getc(stdin);
walking_speed
=
(
1
-
f
*
g
)
*
_ellipse
.
GetV0
()
+
f
*
g
*
speed_down
;
// printf("%f DOWN max_e=%f, z=%f, f=%f, v0=%f, v0d=%f, ret=%f\n", _globalTime, maxSubElevation, ped_elevation, f, _ellipse.GetV0(), _V0DownStairs, (1-f*g)*_ellipse.GetV0() + f*g*speed_down);
}
...
...
@@ -630,7 +632,7 @@ double Pedestrian::GetV0Norm() const
walking_speed
=
(
1
-
f
*
g
)
*
_ellipse
.
GetV0
()
+
f
*
g
*
speed_up
;
}
}
}
//IF execution of WalkingInSmoke depending on JPSfire section in INI file
if
(
_WalkingSpeed
&&
_WalkingSpeed
->
ReduceWalkingSpeed
())
{
...
...
@@ -641,7 +643,7 @@ double Pedestrian::GetV0Norm() const
//WHERE should the call to that routine be placed properly?
//only executed every 3 seconds
// fprintf(stderr, "%f\n", walking_speed);
return
walking_speed
;
// orthogonal projection on the stair
//return _ellipse.GetV0()*_building->GetRoom(_roomID)->GetSubRoom(_subRoomID)->GetCosAngleWithHorizontal();
...
...
@@ -1225,6 +1227,3 @@ bool Pedestrian::Relocate(std::function<void(const Pedestrian&)> flowupdater) {
}
return
status
;
}
voronoi-boost/VoronoiPositionGenerator.cpp
View file @
311f63fa
...
...
@@ -74,18 +74,18 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius )
return
false
;
for
(
const
auto
&
trans
:
subroom
->
GetAllTransitions
()
)
if
(
trans
->
DistTo
(
pt
)
<
radius
+
0.1
)
return
false
;
if
(
trans
->
DistTo
(
pt
)
<
radius
+
0.1
)
return
false
;
for
(
const
auto
&
cross
:
subroom
->
GetAllCrossings
()
)
if
(
cross
->
DistTo
(
pt
)
<
radius
+
0.1
)
return
false
;
if
(
cross
->
DistTo
(
pt
)
<
radius
+
0.1
)
return
false
;
return
true
;
}
bool
ComputeBestPositionVoronoiBoost
(
AgentsSource
*
src
,
std
::
vector
<
Pedestrian
*>&
peds
,
Building
*
building
)
Building
*
building
,
std
::
vector
<
Pedestrian
*>&
peds_queue
)
{
bool
return_value
=
true
;
auto
dist
=
src
->
GetStartDistribution
();
...
...
@@ -96,6 +96,7 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
std
::
vector
<
Pedestrian
*>
existing_peds
;
std
::
vector
<
Pedestrian
*>
peds_without_place
;
building
->
GetPedestrians
(
roomID
,
subroomID
,
existing_peds
);
existing_peds
.
insert
(
existing_peds
.
end
(),
peds_queue
.
begin
(),
peds_queue
.
end
());
double
radius
=
0.3
;
//radius of a person, 0.3 is just some number(needed for the fake_peds bellow), will be changed afterwards
...
...
@@ -120,11 +121,11 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
}
std
::
vector
<
Pedestrian
*>::
iterator
iter_ped
;
std
::
srand
(
0
);
for
(
iter_ped
=
peds
.
begin
();
iter_ped
!=
peds
.
end
();
)
{
Pedestrian
*
ped
=
*
iter_ped
;
radius
=
ped
->
GetEllipse
().
GetBmax
();
//max radius of the current pedestrian
if
(
existing_peds
.
size
()
==
0
)
{
const
Point
&
center_pos
=
subroom
->
GetCentroid
();
...
...
@@ -145,7 +146,7 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
{
ped
->
SetPos
(
center_pos
,
true
);
}
Point
v
;
if
(
ped
->
GetExitLine
())
{
v
=
(
ped
->
GetExitLine
()
->
ShortestPoint
(
ped
->
GetPos
())
-
ped
->
GetPos
()).
Normalized
();
...
...
@@ -156,14 +157,14 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
double
speed
=
ped
->
GetEllipse
().
GetV0
();
//@todo: some peds do not have a navline. This should not be accepted.
v
=
v
*
speed
;
ped
->
SetV
(
v
);
existing_peds
.
push_back
(
ped
);
}
//0
else
//more than one pedestrian
{
//it would be better to maybe have a mapping between discrete_positions and pointers to the pedestrians
//then there would be no need to remember the velocities_vector and goal_vector
//it would be better to maybe have a mapping between discrete_positions and pointers to the pedestrians
//then there would be no need to remember the velocities_vector and goal_vector
std
::
vector
<
Point
>
discrete_positions
;
std
::
vector
<
Point
>
velocities_vector
;
std
::
vector
<
int
>
goal_vector
;
...
...
@@ -210,17 +211,15 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
VoronoiBestVertexRandMax
(
discrete_positions
,
vd
,
subroom
,
factor
,
chosen_it
,
dis
,
radius
);
else
VoronoiBestVertexGreedy
(
discrete_positions
,
vd
,
subroom
,
factor
,
chosen_it
,
dis
,
radius
);
if
(
dis
>
4
*
radius
*
radius
)
{
Point
pos
(
chosen_it
->
x
()
/
factor
,
chosen_it
->
y
()
/
factor
);
//check!
ped
->
SetPos
(
pos
,
true
);
VoronoiAdjustVelocityNeighbour
(
chosen_it
,
ped
,
velocities_vector
,
goal_vector
);
// proceed to the next pedestrian
existing_peds
.
push_back
(
ped
);
++
iter_ped
;
}
else
{
...
...
@@ -239,6 +238,8 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
//maybe not all pedestrians could find a place, requeue them in the source
if
(
peds_without_place
.
size
()
>
0
)
src
->
AddAgentsToPool
(
peds_without_place
);
return
return_value
;
}
...
...
@@ -266,21 +267,21 @@ void VoronoiAdjustVelocityNeighbour(voronoi_diagram<double>::const_vertex_iterat
std
::
size_t
index
=
(
edge
->
cell
()
)
->
source_index
();
if
(
ped
->
GetFinalDestination
()
==
goal_vector
[
index
]
)
{
no1
++
;
speed
+=
velocities_vector
[
index
].
Norm
();
no1
++
;
speed
+=
velocities_vector
[
index
].
Norm
();
}
else
{
no2
++
;
backup_speed
+=
velocities_vector
[
index
].
Norm
();
no2
++
;
backup_speed
+=
velocities_vector
[
index
].
Norm
();
}
edge
=
edge
->
rot_next
();
}
while
(
edge
!=
vertex
.
incident_edge
());
if
(
no1
)
speed
=
speed
/
no1
;
speed
=
speed
/
no1
;
else
speed
=
backup_speed
/
(
no2
*
3.0
);
//just some small speed
speed
=
backup_speed
/
(
no2
*
3.0
);
//just some small speed
v
=
v
*
speed
;
ped
->
SetV
(
v
);
...
...
@@ -324,26 +325,26 @@ void VoronoiAdjustVelocityNeighbour(voronoi_diagram<double>::const_vertex_iterat
//
// do
// {
//
//do something
//
if( goal_vector[index]!=-3 && goal_vector[index]!=ped->GetFinalDestination() ) //
//
if( check_line.IntersectionWithCircle(p,1.0) ) //0.7 because the radius is around 0.3
//
{
//
score -= 100;
//
break;
//
}
//
//do something
//
if( goal_vector[index]!=-3 && goal_vector[index]!=ped->GetFinalDestination() ) //
//
if( check_line.IntersectionWithCircle(p,1.0) ) //0.7 because the radius is around 0.3
//
{
//
score -= 100;
//
break;
//
}
//
//
//
//change edge
//
edge = edge->rot_next();
//
index = ( edge->cell() )->source_index();
//
p = discrete_positions[index]/factor;
//
//change edge
//
edge = edge->rot_next();
//
index = ( edge->cell() )->source_index();
//
p = discrete_positions[index]/factor;
//
// } while( edge != vertex.incident_edge() );
//*/
// if(score > max_score)
// {
// max_score =score;
//
max_dis = dis;
//
max_dis = dis;
// max_it = it;
// }
// }
...
...
@@ -401,7 +402,8 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
double
lower_bound
=
0
;
double
upper_bound
=
partial_sums
[
size
-
1
];
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
//@todo use seed instead of rd(). Generator should not be here
//std::mt19937 gen(rd()); //@todo use seed instead of rd(). Generator should not be here
std
::
mt19937
gen
(
1
);
//@todo use seed instead of rd(). Generator should not be here
std
::
uniform_real_distribution
<
double
>
distribution
(
lower_bound
,
upper_bound
);
//std::nextafter(upper_bound, DBL_MAX));
vector
<
double
>
random_numbers
;
for
(
unsigned
int
r
=
0
;
r
<
size
;
r
++
)
...
...
@@ -409,7 +411,7 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
shuffle
(
random_numbers
.
begin
(),
random_numbers
.
end
(),
gen
);
double
a_random_double
=
random_numbers
[
0
];
//the first element in the range [first, last) that is not less than a_random_double
auto
lower
=
std
::
lower_bound
(
partial_sums
.
begin
(),
partial_sums
.
end
(),
a_random_double
);
int
iposition
=
lower
-
partial_sums
.
begin
();
...
...
@@ -505,13 +507,13 @@ void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_dia
{
// =============== plot Voronoi Diagram =====================
char
name
[
50
];
sprintf
(
name
,
"log_%.3d.py"
,
global_count
);
sprintf
(
name
,
"log_%.3d.py"
,
global_count
);
FILE
*
f
;
f
=
fopen
(
name
,
"w"
);
// plot cells
// plot cells
fprintf
(
f
,
"# ------------------------------
\n
"
);
fprintf
(
f
,
"import matplotlib.pyplot as plt
\n
"
);
// plot seeds
// plot seeds
for
(
auto
pos
:
discrete_positions
)
{
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
or
\"
)
\n
"
,
pos
.
_x
/
factor
,
pos
.
_y
/
factor
);
...
...
@@ -523,18 +525,18 @@ void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_dia
do
{
if
(
edge
->
vertex0
()
&&
edge
->
vertex1
())
{
fprintf
(
f
,
"plt.plot([%f, %f], [%f, %f],
\"
bo-
\"
, lw=2)
\n
"
,
edge
->
vertex0
()
->
x
()
/
factor
,
edge
->
vertex1
()
->
x
()
/
factor
,
edge
->
vertex0
()
->
y
()
/
factor
,
edge
->
vertex1
()
->
y
()
/
factor
);
fprintf
(
f
,
"plt.plot([%f, %f], [%f, %f],
\"
bo-
\"
, lw=2)
\n
"
,
edge
->
vertex0
()
->
x
()
/
factor
,
edge
->
vertex1
()
->
x
()
/
factor
,
edge
->
vertex0
()
->
y
()
/
factor
,
edge
->
vertex1
()
->
y
()
/
factor
);
}
edge
=
edge
->
next
();
}
while
(
edge
!=
cell
.
incident_edge
());
}
while
(
edge
!=
cell
.
incident_edge
());
}
// plot geometry
double
max_x
=
std
::
numeric_limits
<
double
>::
min
(),
min_x
=
std
::
numeric_limits
<
double
>::
max
();
double
max_y
=
std
::
numeric_limits
<
double
>::
min
(),
min_y
=
std
::
numeric_limits
<
double
>::
max
();
const
vector
<
Point
>
polygon
=
subroom
->
GetPolygon
();
for
(
auto
it
=
polygon
.
begin
();
it
!=
polygon
.
end
();
)
{
Point
gpoint
=
*
(
it
++
);
Point
gpoint
=
*
(
it
++
);
// Point gpointNext = *it;
if
(
gpoint
.
_x
>
max_x
)
max_x
=
gpoint
.
_x
;
...
...
@@ -544,7 +546,7 @@ void plotVoronoi(const std::vector<Point>& discrete_positions, const voronoi_dia
min_x
=
gpoint
.
_x
;
if
(
gpoint
.
_y
<
min_y
)
min_y
=
gpoint
.
_y
;
// fprintf(f, "plt.plot([%f, %f], [%f, %f], \"k-\", lw=2)\n", gpoint._x, gpointNext._x, gpoint._y, gpointNext._y);
if
(
it
==
polygon
.
end
()){
// fprintf(f, "plt.plot([%f, %f], [%f, %f], \"k-\", lw=2)\n", gpointNext._x, polygon.begin()->_x, gpointNext._y, polygon.begin()->_y );
...
...
voronoi-boost/VoronoiPositionGenerator.h
View file @
311f63fa
...
...
@@ -30,67 +30,67 @@ class Point;
// TODO: bool IsSpace(SubRoom* subroom, Point& pt,Point& v1);
/**
* Calculates if a point (which is inside the subroom) is far enough from the walls, transitions, crossings ( > radius of a person)
* @param subroom
* @param pt
*/
bool
IsEnoughInSubroom
(
SubRoom
*
subroom
,
Point
&
pt
,
double
radius
);
/**
* Position incoming pedestrian using voronoi from boost library
* @param src
* @param peds
*/
bool
ComputeBestPositionVoronoiBoost
(
AgentsSource
*
src
,
std
::
vector
<
Pedestrian
*>&
peds
,
Building
*
_building
);
/**
* Position incoming pedestrian on the vertex with the greatest distance
* @param discrete_positions, positions of existing pedestrians + fake pedestrians (but multiplied with the factor)
* @param vd
* @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person
*/
/**
* Calculates if a point (which is inside the subroom) is far enough from the walls, transitions, crossings ( > radius of a person)
* @param subroom
* @param pt
*/
bool
IsEnoughInSubroom
(
SubRoom
*
subroom
,
Point
&
pt
,
double
radius
);
/**
* Position incoming pedestrian using voronoi from boost library
* @param src
* @param peds
*/
bool
ComputeBestPositionVoronoiBoost
(
AgentsSource
*
src
,
std
::
vector
<
Pedestrian
*>&
peds
,
Building
*
_building
,
std
::
vector
<
Pedestrian
*>&
peds_queue
);
/**
* Position incoming pedestrian on the vertex with the greatest distance
* @param discrete_positions, positions of existing pedestrians + fake pedestrians (but multiplied with the factor)
* @param vd
* @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person
*/
void
VoronoiBestVertexMax
(
const
std
::
vector
<
Point
>&
discrete_positions
,
const
voronoi_diagram
<
double
>&
vd
,
SubRoom
*
subroom
,
double
factor
,
voronoi_diagram
<
double
>::
const_vertex_iterator
&
max_it
,
double
&
max_dis
,
double
radius
);
/**
* Position incoming pedestrian on the vertex with greater probability for greater distances
* @param discrete_positions
* @param vd
* @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex
* @param max_dis, after calling the function this will be the (distance*factor)^2 where distance is the distance to the chosen vertex
* @param radius, radius of a person
*/
void
VoronoiBestVertexRandMax
(
const
std
::
vector
<
Point
>&
discrete_positions
,
const
voronoi_diagram
<
double
>&
vd
,
SubRoom
*
subroom
,
double
factor
,
/**
* Position incoming pedestrian on the vertex with greater probability for greater distances
* @param discrete_positions
* @param vd
* @param subroom
* @param max_it, after calling the function this will be the iterator of the best vertex