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
20884fdf
Commit
20884fdf
authored
Aug 12, 2016
by
Mohcine Chraibi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ploting routine
parent
fcc18175
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
118 deletions
+67
-118
voronoi-boost/VoronoiPositionGenerator.cpp
voronoi-boost/VoronoiPositionGenerator.cpp
+65
-118
voronoi-boost/VoronoiPositionGenerator.h
voronoi-boost/VoronoiPositionGenerator.h
+2
-0
No files found.
voronoi-boost/VoronoiPositionGenerator.cpp
View file @
20884fdf
...
@@ -7,9 +7,7 @@
...
@@ -7,9 +7,7 @@
#define PLOT_VORONOI_DIAGRAM 0
#define PLOT_VORONOI_DIAGRAM 0
#if PLOT_VORONOI_DIAGRAM
static
int
global_count
=
0
;
static
int
global_count
=
0
;
#endif
...
@@ -89,7 +87,7 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius )
...
@@ -89,7 +87,7 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt, double radius )
bool
ComputeBestPositionVoronoiBoost
(
AgentsSource
*
src
,
std
::
vector
<
Pedestrian
*>&
peds
,
bool
ComputeBestPositionVoronoiBoost
(
AgentsSource
*
src
,
std
::
vector
<
Pedestrian
*>&
peds
,
Building
*
building
)
Building
*
building
)
{
{
bool
return_value
=
true
;
bool
return_value
=
true
;
auto
dist
=
src
->
GetStartDistribution
();
auto
dist
=
src
->
GetStartDistribution
();
int
roomID
=
dist
->
GetRoomId
();
int
roomID
=
dist
->
GetRoomId
();
...
@@ -203,7 +201,9 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
...
@@ -203,7 +201,9 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
//constructing the diagram
//constructing the diagram
voronoi_diagram
<
double
>
vd
;
voronoi_diagram
<
double
>
vd
;
construct_voronoi
(
discrete_positions
.
begin
(),
discrete_positions
.
end
(),
&
vd
);
construct_voronoi
(
discrete_positions
.
begin
(),
discrete_positions
.
end
(),
&
vd
);
#if PLOT_VORONOI_DIAGRAM
plotVoronoi
(
discrete_positions
,
vd
,
subroom
,
factor
);
#endif
voronoi_diagram
<
double
>::
const_vertex_iterator
chosen_it
=
vd
.
vertices
().
begin
();
voronoi_diagram
<
double
>::
const_vertex_iterator
chosen_it
=
vd
.
vertices
().
begin
();
double
dis
=
0
;
double
dis
=
0
;
//std::default_random_engine gen = dist->GetGenerator();
//std::default_random_engine gen = dist->GetGenerator();
...
@@ -212,7 +212,7 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
...
@@ -212,7 +212,7 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
else
else
VoronoiBestVertexGreedy
(
discrete_positions
,
vd
,
subroom
,
factor
,
chosen_it
,
dis
,
radius
);
VoronoiBestVertexGreedy
(
discrete_positions
,
vd
,
subroom
,
factor
,
chosen_it
,
dis
,
radius
);
if
(
dis
>
4
*
radius
*
radius
)
// be careful with the factor!! radius*factor, 2,3,4?
if
(
dis
>
4
*
radius
*
radius
)
{
{
Point
pos
(
chosen_it
->
x
()
/
factor
,
chosen_it
->
y
()
/
factor
);
//check!
Point
pos
(
chosen_it
->
x
()
/
factor
,
chosen_it
->
y
()
/
factor
);
//check!
ped
->
SetPos
(
pos
,
true
);
ped
->
SetPos
(
pos
,
true
);
...
@@ -231,21 +231,6 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
...
@@ -231,21 +231,6 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
iter_ped
=
peds
.
erase
(
iter_ped
);
// remove from the initial vector since it should only contain the pedestrians that could find a place
iter_ped
=
peds
.
erase
(
iter_ped
);
// remove from the initial vector since it should only contain the pedestrians that could find a place
}
}
/*else //try with the maximum distance, don't need this if already using the VoronoiBestVertexMax function
{
VoronoiBestVertexMax(discrete_positions, vd, subroom, factor, chosen_it, dis );
if( dis > radius*factor*radius*factor)// be careful with the factor!! radius*factor
{
Point pos( chosen_it->x()/factor, chosen_it->y()/factor ); //check!
ped->SetPos(pos , true);
VoronoiAdjustVelocityNeighbour( vd, chosen_it, ped, velocities_vector );
}
else
{
return_value = false;
//reject the pedestrian
}
}*/
}
// >0
}
// >0
...
@@ -255,7 +240,6 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
...
@@ -255,7 +240,6 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>
//maybe not all pedestrians could find a place, requeue them in the source
//maybe not all pedestrians could find a place, requeue them in the source
if
(
peds_without_place
.
size
()
>
0
)
if
(
peds_without_place
.
size
()
>
0
)
src
->
AddAgentsToPool
(
peds_without_place
);
src
->
AddAgentsToPool
(
peds_without_place
);
return
return_value
;
return
return_value
;
}
}
...
@@ -390,36 +374,6 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
...
@@ -390,36 +374,6 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
std
::
vector
<
voronoi_diagram
<
double
>::
const_vertex_iterator
>
possible_vertices
;
std
::
vector
<
voronoi_diagram
<
double
>::
const_vertex_iterator
>
possible_vertices
;
vector
<
double
>
partial_sums
;
vector
<
double
>
partial_sums
;
unsigned
long
size
=
0
;
unsigned
long
size
=
0
;
// double max_distance = std::numeric_limits<double>::epsilon();
// unsigned long imax=0;
#if PLOT_VORONOI_DIAGRAM
// =============== plot Voronoi Diagram =====================
char
name
[
50
];
sprintf
(
name
,
"log_%.3d.py"
,
global_count
);
FILE
*
f
;
f
=
fopen
(
name
,
"w"
);
fprintf
(
f
,
"# ------------------------------
\n
"
);
fprintf
(
f
,
"import matplotlib.pyplot as plt
\n
"
);
for
(
auto
pos
:
discrete_positions
)
{
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
or
\"
)
\n
"
,
pos
.
_x
/
factor
,
pos
.
_y
/
factor
);
}
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
const
voronoi_diagram
<
double
>::
vertex_type
&
vertex
=
*
it
;
const
voronoi_diagram
<
double
>::
edge_type
*
edge
=
vertex
.
incident_edge
();
do
{
if
(
edge
->
vertex0
()
&&
edge
->
vertex1
())
{
fprintf
(
f
,
"plt.plot([%f, %f], [%f, %f],
\"
bo-
\"
)
\n
"
,
edge
->
vertex0
()
->
x
()
/
factor
,
edge
->
vertex1
()
->
x
()
/
factor
,
edge
->
vertex0
()
->
y
()
/
factor
,
edge
->
vertex1
()
->
y
()
/
factor
);
}
edge
=
edge
->
next
();
}
while
(
edge
!=
vertex
.
incident_edge
());
}
// =============================================================
#endif
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
Point
vert_pos
=
Point
(
it
->
x
()
/
factor
,
it
->
y
()
/
factor
);
Point
vert_pos
=
Point
(
it
->
x
()
/
factor
,
it
->
y
()
/
factor
);
if
(
subroom
->
IsInSubRoom
(
vert_pos
)
)
if
(
subroom
->
IsInSubRoom
(
vert_pos
)
)
...
@@ -433,7 +387,7 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
...
@@ -433,7 +387,7 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
dis
=
(
p
.
_x
-
it
->
x
()
)
*
(
p
.
_x
-
it
->
x
()
)
+
(
p
.
_y
-
it
->
y
()
)
*
(
p
.
_y
-
it
->
y
()
)
;
dis
=
(
p
.
_x
-
it
->
x
()
)
*
(
p
.
_x
-
it
->
x
()
)
+
(
p
.
_y
-
it
->
y
()
)
*
(
p
.
_y
-
it
->
y
()
)
;
dis
=
dis
/
factor
/
factor
;
dis
=
dis
/
factor
/
factor
;
possible_vertices
.
push_back
(
it
);
possible_vertices
.
push_back
(
it
);
partial_sums
.
push_back
(
dis
);
// HERE
partial_sums
.
push_back
(
dis
);
size
=
partial_sums
.
size
();
size
=
partial_sums
.
size
();
if
(
size
>
1
)
if
(
size
>
1
)
...
@@ -465,27 +419,6 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
...
@@ -465,27 +419,6 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
dis
=
partial_sums
[
iposition
];
dis
=
partial_sums
[
iposition
];
if
(
iposition
>
1
)
if
(
iposition
>
1
)
dis
-=
partial_sums
[
iposition
-
1
];
dis
-=
partial_sums
[
iposition
-
1
];
// printf("\n================================================\n");
// printf("random number from %f to %f is: %f. Chosen is at position %d with dis=%f\n", lower_bound, upper_bound, a_random_double, iposition, dis);
// for(auto d : partial_sums)
// printf("d = %f\n", d);
#if PLOT_VORONOI_DIAGRAM
fprintf
(
f
,
"# ================================================
\n
"
);
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
go
\"
, ms=10)
\n
"
,
possible_vertices
[
iposition
]
->
x
()
/
factor
,
possible_vertices
[
iposition
]
->
y
()
/
factor
);
fprintf
(
f
,
"plt.xlim([50, 60])
\n
"
);
fprintf
(
f
,
"plt.ylim([98, 106])
\n
"
);
fprintf
(
f
,
"plt.title(
\"
d = %f
\"
)
\n
"
,
sqrt
(
dis
));
// geometry
fprintf
(
f
,
"plt.plot([50, 50], [98, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([60, 60], [98, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([50, 60], [98, 98],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([50, 60], [106, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.savefig(
\"
%.3d.png
\"
)
\n
"
,
global_count
++
);
fprintf
(
f
,
"# ------------------------------
\n
"
);
fclose
(
f
);
#endif
}
}
...
@@ -508,37 +441,10 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
...
@@ -508,37 +441,10 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
{
{
std
::
vector
<
voronoi_diagram
<
double
>::
const_vertex_iterator
>
possible_vertices
;
std
::
vector
<
voronoi_diagram
<
double
>::
const_vertex_iterator
>
possible_vertices
;
vector
<
double
>
distances
;
vector
<
double
>
distances
;
#if PLOT_VORONOI_DIAGRAM
// =============== plot Voronoi Diagram =====================
char
name
[
50
];
sprintf
(
name
,
"log_%.3d.py"
,
global_count
);
FILE
*
f
;
f
=
fopen
(
name
,
"w"
);
fprintf
(
f
,
"# ------------------------------
\n
"
);
fprintf
(
f
,
"import matplotlib.pyplot as plt
\n
"
);
for
(
auto
pos
:
discrete_positions
)
{
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
xr
\"
)
\n
"
,
pos
.
_x
/
factor
,
pos
.
_y
/
factor
);
}
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
const
voronoi_diagram
<
double
>::
vertex_type
&
vertex
=
*
it
;
const
voronoi_diagram
<
double
>::
edge_type
*
edge
=
vertex
.
incident_edge
();
do
{
if
(
edge
->
vertex0
()
&&
edge
->
vertex1
())
{
fprintf
(
f
,
"plt.plot([%f, %f], [%f, %f],
\"
bo-
\"
)
\n
"
,
edge
->
vertex0
()
->
x
()
/
factor
,
edge
->
vertex1
()
->
x
()
/
factor
,
edge
->
vertex0
()
->
y
()
/
factor
,
edge
->
vertex1
()
->
y
()
/
factor
);
}
edge
=
edge
->
next
();
}
while
(
edge
!=
vertex
.
incident_edge
());
}
// =============================================================
#endif
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
for
(
auto
it
=
vd
.
vertices
().
begin
();
it
!=
vd
.
vertices
().
end
();
++
it
){
Point
vert_pos
=
Point
(
it
->
x
()
/
factor
,
it
->
y
()
/
factor
);
Point
vert_pos
=
Point
(
it
->
x
()
/
factor
,
it
->
y
()
/
factor
);
if
(
subroom
->
IsInSubRoom
(
vert_pos
)
)
if
(
subroom
->
IsInSubRoom
(
vert_pos
)
)
if
(
IsEnoughInSubroom
(
subroom
,
vert_pos
,
radius
)
)
if
(
IsEnoughInSubroom
(
subroom
,
vert_pos
,
radius
)
)
{
{
const
voronoi_diagram
<
double
>::
vertex_type
&
vertex
=
*
it
;
const
voronoi_diagram
<
double
>::
vertex_type
&
vertex
=
*
it
;
const
voronoi_diagram
<
double
>::
edge_type
*
edge
=
vertex
.
incident_edge
();
const
voronoi_diagram
<
double
>::
edge_type
*
edge
=
vertex
.
incident_edge
();
...
@@ -557,22 +463,6 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
...
@@ -557,22 +463,6 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
int
iposition
=
biggest
-
distances
.
begin
();
// first biggest distance
int
iposition
=
biggest
-
distances
.
begin
();
// first biggest distance
chosen_it
=
possible_vertices
[
iposition
];
chosen_it
=
possible_vertices
[
iposition
];
dis
=
distances
[
iposition
];
dis
=
distances
[
iposition
];
#if PLOT_VORONOI_DIAGRAM
fprintf
(
f
,
"# ================================================
\n
"
);
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
go
\"
, ms=10)
\n
"
,
possible_vertices
[
iposition
]
->
x
()
/
factor
,
possible_vertices
[
iposition
]
->
y
()
/
factor
);
fprintf
(
f
,
"plt.xlim([48, 62])
\n
"
);
fprintf
(
f
,
"plt.ylim([96, 108])
\n
"
);
fprintf
(
f
,
"plt.title(
\"
d = %f
\"
)
\n
"
,
sqrt
(
dis
));
// geometry
fprintf
(
f
,
"plt.plot([50, 50], [98, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([60, 60], [98, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([50, 60], [98, 98],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.plot([50, 60], [106, 106],
\"
k-
\"
, lw=2)
\n
"
);
fprintf
(
f
,
"plt.savefig(
\"
%.3d.png
\"
)
\n
"
,
global_count
++
);
fprintf
(
f
,
"# ------------------------------
\n
"
);
fclose
(
f
);
#endif
}
}
...
@@ -611,3 +501,60 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
...
@@ -611,3 +501,60 @@ void VoronoiBestVertexGreedy (const std::vector<Point>& discrete_positions, cons
//}
//}
void
plotVoronoi
(
const
std
::
vector
<
Point
>&
discrete_positions
,
const
voronoi_diagram
<
double
>&
vd
,
SubRoom
*
subroom
,
double
factor
)
{
// =============== plot Voronoi Diagram =====================
char
name
[
50
];
sprintf
(
name
,
"log_%.3d.py"
,
global_count
);
FILE
*
f
;
f
=
fopen
(
name
,
"w"
);
// plot cells
fprintf
(
f
,
"# ------------------------------
\n
"
);
fprintf
(
f
,
"import matplotlib.pyplot as plt
\n
"
);
// plot seeds
for
(
auto
pos
:
discrete_positions
)
{
fprintf
(
f
,
"plt.plot([%f], [%f],
\"
or
\"
)
\n
"
,
pos
.
_x
/
factor
,
pos
.
_y
/
factor
);
}
// plot cells
for
(
auto
it
=
vd
.
cells
().
begin
();
it
!=
vd
.
cells
().
end
();
++
it
){
const
voronoi_diagram
<
double
>::
cell_type
&
cell
=
*
it
;
const
voronoi_diagram
<
double
>::
edge_type
*
edge
=
cell
.
incident_edge
();
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
);
}
edge
=
edge
->
next
();
}
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 gpointNext = *it;
if
(
gpoint
.
_x
>
max_x
)
max_x
=
gpoint
.
_x
;
if
(
gpoint
.
_y
>
max_y
)
max_y
=
gpoint
.
_y
;
if
(
gpoint
.
_x
<
min_x
)
min_x
=
gpoint
.
_x
;
if
(
gpoint
.
_y
<
max_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 );
break
;
}
}
double
eps
=
0.0
;
fprintf
(
f
,
"plt.xlim([%f, %f])
\n
"
,
min_x
-
eps
,
max_x
+
eps
);
fprintf
(
f
,
"plt.ylim([%f, %f])
\n
"
,
min_y
-
eps
,
max_y
+
eps
);
fprintf
(
f
,
"plt.savefig(
\"
%.3d.png
\"
)
\n
"
,
global_count
++
);
fclose
(
f
);
}
voronoi-boost/VoronoiPositionGenerator.h
View file @
20884fdf
...
@@ -71,6 +71,8 @@ void VoronoiBestVertexMax(const std::vector<Point>& discrete_positions, const vo
...
@@ -71,6 +71,8 @@ void VoronoiBestVertexMax(const std::vector<Point>& discrete_positions, const vo
voronoi_diagram
<
double
>::
const_vertex_iterator
&
max_it
,
double
&
max_dis
,
double
radius
);
voronoi_diagram
<
double
>::
const_vertex_iterator
&
max_it
,
double
&
max_dis
,
double
radius
);
void
VoronoiBestVertexGreedy
(
const
std
::
vector
<
Point
>&
discrete_positions
,
const
voronoi_diagram
<
double
>&
vd
,
SubRoom
*
subroom
,
double
factor
,
void
VoronoiBestVertexGreedy
(
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
);
voronoi_diagram
<
double
>::
const_vertex_iterator
&
max_it
,
double
&
max_dis
,
double
radius
);
void
plotVoronoi
(
const
std
::
vector
<
Point
>&
discrete_positions
,
const
voronoi_diagram
<
double
>&
vd
,
SubRoom
*
subroom
,
double
factor
);
/**
/**
* Position incoming pedestrian on a random vertex
* Position incoming pedestrian on a random vertex
* @param discrete_positions
* @param discrete_positions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment