Skip to content
Snippets Groups Projects
Commit 5f4253e5 authored by Aymeric berthoumieu's avatar Aymeric berthoumieu
Browse files

python plot file + correction of animal constructors

parent 7f55b3e4
Branches
No related tags found
1 merge request!22Aymeric
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()
......@@ -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;
......
......@@ -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);
......
......@@ -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;}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment