-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmake_fd.py
80 lines (73 loc) · 2.67 KB
/
make_fd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Generation of the fundamental diagram by calling some model defined in this repository
# Copyright (C) 2014-2015 Mohcine Chraibi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# contact: [email protected]
import subprocess
import matplotlib.pyplot as plt
import os
from sys import argv
if len(argv) ==1: # no input is provided
program = "asep_fast.py" # default program to use
else:
program = argv[1]
print("%s starts with %s" % (argv[0], program))
# ----------------------------------------
num_runs = 10
max_pedestrians = 120
sim_steps = 1000
pedestrians = range(1, max_pedestrians)
filename = open("stdout.txt", "w")
# ----------------------------------------
for n in pedestrians:
print("run %s with num_peds %3.3d num_runs %3.3d steps % 3.4d" % (program, n, num_runs, sim_steps))
subprocess.call(["python", program, "-n" "%d" % n, "-N", "%d" % num_runs, "-m", "%d" % sim_steps],
stdout=filename)
# ----------------------------------------
filename.close()
velocities = []
densities = []
# the line should be something like this
# N 1 mean_velocity 1.20 [m/s] density 0.10 [1/m]
filename = open("stdout.txt", "r")
for line in filename:
if line.startswith("N"):
line = line.split()
velocities.append(float(line[3]))
densities.append(float(line[6]))
filename.close()
# -------- plot FD ----------
# rho vs v
fig = plt.figure()
ax = fig.add_subplot(111)
ax.cla()
plt.subplot(211)
plt.plot(densities, velocities, lw=2)
plt.ylim([0, max(velocities)+0.05])
plt.ylabel(r"$v\, [m/s]$", size=20)
plt.xlabel(r"$\rho\, [m^{-1}]$", size=20)
# rho vs J (J=rho*v)
J = [r * v for (r, v) in zip(densities, velocities)]
plt.subplot(212)
plt.plot(densities, J, lw=2)
plt.xlabel(r"$\rho\, [m^{-1}]$", size=20)
plt.ylabel(r"$J\, [s^{-1}]$", size=20)
fig.tight_layout()
print("\n")
for end in ["pdf", "png", "eps"]:
figure_name = os.path.join("figs", "asep_fd.%s" % end)
print("result written in %s" % figure_name)
plt.savefig(figure_name)