Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CPP Ecosystem Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RIVOAL Samuel
CPP Ecosystem Project
Commits
5f4253e5
Commit
5f4253e5
authored
4 years ago
by
Aymeric berthoumieu
Browse files
Options
Downloads
Patches
Plain Diff
python plot file + correction of animal constructors
parent
7f55b3e4
Branches
Branches containing commit
No related tags found
1 merge request
!22
Aymeric
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
plotPopulationEvolution.py
+59
-38
59 additions, 38 deletions
plotPopulationEvolution.py
src/Animal.cpp
+5
-0
5 additions, 0 deletions
src/Animal.cpp
src/Environment.cpp
+1
-1
1 addition, 1 deletion
src/Environment.cpp
src/Statistics.cpp
+1
-0
1 addition, 0 deletions
src/Statistics.cpp
with
66 additions
and
39 deletions
plotPopulationEvolution.py
+
59
−
38
View file @
5f4253e5
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
os
import
listdir
stats
=
pd
.
read_csv
(
"
report.csv
"
)
columns
=
stats
.
columns
print
(
columns
)
def
find_csv_filenames
(
path_to_dir
,
suffix
=
"
.csv
"
):
"""
:param path_to_dir: path to the directory where you are looking fore files
:param suffix: file type
:return:
list of names of files of type suffix in directory at path_to_dir
"""
filenames
=
listdir
(
path_to_dir
)
return
[
filename
for
filename
in
filenames
if
filename
.
endswith
(
suffix
)]
csvFiles
=
find_csv_filenames
(
'
./
'
)
# All .csv files in the current directory
# Plot for each .csv file (or simulation)
for
i
in
range
(
len
(
csvFiles
)):
stats
=
pd
.
read_csv
(
csvFiles
[
i
])
# read file
columns
=
stats
.
columns
# take headers
behaviour_stack
=
[]
behaviour_headers
=
[]
...
...
@@ -13,30 +29,35 @@ AccessoriesAndCaptors_headers = []
for
c
in
columns
:
if
c
[:
2
]
==
"
b_
"
:
behaviour_headers
.
append
(
c
)
behaviour_stack
.
append
(
stats
[
c
].
values
.
tolist
())
behaviour_headers
.
append
(
c
)
# behaviours' headers
behaviour_stack
.
append
(
stats
[
c
].
values
.
tolist
())
# behaviours' data
elif
(
c
[:
2
]
==
"
a_
"
)
or
(
c
[:
2
]
==
"
c_
"
):
AccessoriesAndCaptors_headers
.
append
(
c
)
AccessoriesAndCaptors_stack
.
append
(
stats
[
c
].
values
.
tolist
())
AccessoriesAndCaptors_headers
.
append
(
c
)
# accessories and captors' headers
AccessoriesAndCaptors_stack
.
append
(
stats
[
c
].
values
.
tolist
())
# accessories and captors' data
behaviour_stack
=
np
.
vstack
(
behaviour_stack
)
# AccessoriesAndCaptors_stack = np.vstack(AccessoriesAndCaptors_stack)
# First plot
# First plot
(behaviour and full population)
fig
,
ax
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
45
,
50
))
ax
=
plt
.
gca
()
ax
.
stackplot
(
range
(
1
,
len
(
stats
)
+
1
),
behaviour_stack
,
labels
=
behaviour_headers
,
alpha
=
0.7
)
ax
.
set_title
(
"
Evolution of population with behaviour distinction.
"
,
fontsize
=
18
)
ax
.
legend
(
fontsize
=
10
,
ncol
=
4
)
title
=
"
Evolution of population with behaviour distinction. (simulation
"
+
str
(
i
+
1
)
+
"
/
"
+
str
(
len
(
csvFiles
))
+
"
)
"
ax
.
set_title
(
title
,
fontsize
=
18
)
ax
.
legend
(
fontsize
=
10
)
plt
.
xlabel
(
"
Number of steps.
"
)
plt
.
ylabel
(
"
Number of Animals.
"
)
# Second plot
# Second plot (accesories and captors)
"""
fig, ax = plt.subplots(1, 1, figsize=(45, 50))
ax = plt.gca()
ax
.
stackplot
(
range
(
1
,
len
(
stats
)
+
1
),
behaviour_stack
,
labels
=
behaviour_headers
,
alpha
=
0.7
)
ax
.
set_title
(
"
Evolution of accessories and captors population.
"
,
fontsize
=
18
)
ax
.
legend
(
fontsize
=
10
,
ncol
=
4
)
ax.stackplot(range(1, len(stats) + 1), AccessoriesAndCaptors_stack, labels=AccessoriesAndCaptors_headers, alpha=0.7)
title =
"
Evolution of accessories and captors population.(simulation
"
+ str(i + 1) +
"
/
"
+ str(len(csvFiles)) +
"
)
"
ax.set_title(title, fontsize=18)
ax.legend(fontsize=10)
plt.xlabel(
"
Number of steps.
"
)
plt.ylabel(
"
Number of accessories and captors.
"
)
"""
plt
.
show
()
This diff is collapsed.
Click to expand it.
src/Animal.cpp
+
5
−
0
View file @
5f4253e5
...
...
@@ -32,6 +32,7 @@ Animal::Animal() {
color
=
new
T
[
3
];
behaviour
=
FearfulBehaviour
::
getBehaviourInstance
();
isMultiple
=
false
;
}
Animal
::
Animal
(
const
Animal
&
a
){
...
...
@@ -77,6 +78,8 @@ Animal& Animal::operator=(Animal&& p) noexcept
x
=
p
.
x
;
y
=
p
.
y
;
behaviour
=
p
.
behaviour
;
isMultiple
=
p
.
isMultiple
;
cumulX
=
cumulY
=
0.
;
orientation
=
p
.
orientation
;
speed
=
p
.
speed
;
...
...
@@ -99,6 +102,8 @@ Animal& Animal::operator=(const Animal& p) noexcept
x
=
p
.
x
;
y
=
p
.
y
;
behaviour
=
p
.
behaviour
;
isMultiple
=
p
.
isMultiple
;
cumulX
=
cumulY
=
0.
;
orientation
=
p
.
orientation
;
speed
=
p
.
speed
;
...
...
This diff is collapsed.
Click to expand it.
src/Environment.cpp
+
1
−
1
View file @
5f4253e5
...
...
@@ -85,12 +85,12 @@ std::vector<Animal *> Environment::detectedNeighbors(Animal* a){
void
Environment
::
die
()
{
// kill animal in the ecosystem at the end of the step
cout
<<
"size = "
<<
animals
.
size
()
<<
endl
;
// first we update Statistics
for
(
std
::
vector
<
Animal
*>::
iterator
iter
=
animals
.
begin
();
iter
!=
animals
.
end
();
++
iter
)
{
// All animal at the end of the vector at this step are going to die
// Behaviours
if
((
*
iter
)
->
getLife
()
<=
0
){
cout
<<
"in"
<<
endl
;
if
((
*
iter
)
->
getIsMultiple
())
{
cout
<<
" decrement multiple "
<<
endl
;
statistics
.
modifyData
(
multiple
,
false
);
...
...
This diff is collapsed.
Click to expand it.
src/Statistics.cpp
+
1
−
0
View file @
5f4253e5
...
...
@@ -75,6 +75,7 @@ Statistics::Statistics(vector<string> behaviorAccessoriesCaptorsNames){
void
Statistics
::
modifyData
(
string
key
,
bool
increment
){
// modify the data contained in header with the key "key". If increment is at true the data takes +1,
// else the data takes -1
cout
<<
key
<<
":"
<<
increment
<<
endl
;
if
(
increment
){
data
[
key
]
=
data
[
key
]
+
1
;}
else
{
data
[
key
]
=
data
[
key
]
-
1
;}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment