From f799698eb3329e38ee5647ddff5ac7852c73b2d6 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@gmail.com> Date: Fri, 25 Jul 2014 23:43:33 +0200 Subject: [PATCH] Bug in calculation of cutoff radius 1. Cutoff radius is only calculated for Gompertz not for GCFM 2. New trajectory format (xPos, yPos) --> (x,y). 3. move some python-functions to a separate module (utils.py) to avoid repetition --- Utest/test_1/master_ini.xml | 6 ++-- Utest/test_1/runtest_1.py | 55 +++---------------------------------- Utest/test_2/master_ini.xml | 4 +-- Utest/test_2/runtest_2.py | 55 +++---------------------------------- Utest/utils.py | 54 ++++++++++++++++++++++++++++++++++++ general/ArgumentParser.cpp | 14 ++++++---- 6 files changed, 75 insertions(+), 113 deletions(-) create mode 100644 Utest/utils.py diff --git a/Utest/test_1/master_ini.xml b/Utest/test_1/master_ini.xml index c7e7f681..e234ec45 100644 --- a/Utest/test_1/master_ini.xml +++ b/Utest/test_1/master_ini.xml @@ -82,12 +82,12 @@ <force_wall nu="10" b="0.70" c="3.0"/> </model_parameters> <agent_parameters agent_parameter_id="0"> - <v0 mu="1" sigma="0.0" /> + <v0 mu="1.0" sigma="0.0" /> <bmax mu="0.25" sigma="0.001" /> - <bmin mu="0.20" sigma="0.001" /> + <bmin mu="0.40" sigma="0.001" /> <amin mu="0.18" sigma="0.001" /> <tau mu="0.01" sigma="0.001" /> - <atau mu="0.5" sigma="0.001" /> + <atau mu="0.2" sigma="0.001" /> </agent_parameters> </model> </operational_models> diff --git a/Utest/test_1/runtest_1.py b/Utest/test_1/runtest_1.py index 0446f113..c7c70184 100755 --- a/Utest/test_1/runtest_1.py +++ b/Utest/test_1/runtest_1.py @@ -1,14 +1,15 @@ #! /usr/bin/env python import numpy as np -from xml.dom import minidom -import os, argparse, logging, time +import os, argparse, logging, time, sys from os import path, system from sys import argv ,exit import subprocess, glob import multiprocessing import matplotlib.pyplot as plt import re - +lib_path = os.path.abspath('..') +sys.path.append(lib_path) +from utils import * #========================= testnr = 1 #======================== @@ -29,54 +30,6 @@ DIR= os.path.dirname(os.path.realpath(argv[0])) CWD = os.getcwd() #-------------------------------------------------------- -def get_maxtime(filename): - """ - get max sim time - """ - logging.info("parsing <%s>"%filename) - try: - xmldoc = minidom.parse(filename) - except: - logging.critical('could not parse file. exit') - exit(FAILURE) - maxtime = float(xmldoc.getElementsByTagName('max_sim_time')[0].firstChild.nodeValue) - return maxtime - -def parse_file(filename): - """ - parse trajectories in Travisto-format and output results - in the following format: id frame x y - (no sorting of the data is performed) - returns - N: number of pedestrians - data: trajectories - """ - logging.info("parsing <%s>"%filename) - try: - xmldoc = minidom.parse(filename) - except: - logging.critical('could not parse file. exit') - exit(FAILURE) - N = int(xmldoc.getElementsByTagName('agents')[0].childNodes[0].data) - fps= xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data #type unicode - fps = float(fps) - fps = int(fps) - print "fps=", fps - #fps = int(xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data) - logging.info ("Npeds = %d, fps = %d"%(N, fps)) - frames = xmldoc.childNodes[0].getElementsByTagName('frame') - data = [] - for frame in frames: - frame_number = int(frame.attributes["ID"].value) - for agent in frame.getElementsByTagName("agent"): - agent_id = int(agent.attributes["ID"].value) - x = float(agent.attributes["xPos"].value) - y = float(agent.attributes["yPos"].value) - data += [agent_id, frame_number, x, y] - data = np.array(data).reshape((-1,4)) - return fps, N, data - - if __name__ == "__main__": if CWD != DIR: diff --git a/Utest/test_2/master_ini.xml b/Utest/test_2/master_ini.xml index 9e56f805..6096a8b4 100644 --- a/Utest/test_2/master_ini.xml +++ b/Utest/test_2/master_ini.xml @@ -86,10 +86,10 @@ <agent_parameters agent_parameter_id="0"> <v0 mu="1" sigma="0.0" /> <bmax mu="0.25" sigma="0.001" /> - <bmin mu="0.20" sigma="0.001" /> + <bmin mu="0.40" sigma="0.001" /> <amin mu="0.18" sigma="0.001" /> <tau mu="0.01" sigma="0.001" /> - <atau mu="0.5" sigma="0.001" /> + <atau mu="0.2" sigma="0.001" /> </agent_parameters> </model> </operational_models> diff --git a/Utest/test_2/runtest_2.py b/Utest/test_2/runtest_2.py index e6daef18..6eaca88c 100755 --- a/Utest/test_2/runtest_2.py +++ b/Utest/test_2/runtest_2.py @@ -7,8 +7,10 @@ from sys import argv ,exit import subprocess, glob import multiprocessing import matplotlib.pyplot as plt -import re - +import re, sys +lib_path = os.path.abspath('..') +sys.path.append(lib_path) +from utils import * #========================= testnr = 2 #======================== @@ -28,55 +30,6 @@ CWD = os.getcwd() DIR= os.path.dirname(os.path.realpath(argv[0])) #-------------------------------------------------------- -def get_maxtime(filename): - """ - get max sim time - """ - logging.info("parsing <%s>"%filename) - try: - xmldoc = minidom.parse(filename) - except: - logging.critical('could not parse file. exit') - exit(FAILURE) - maxtime = float(xmldoc.getElementsByTagName('max_sim_time')[0].firstChild.nodeValue) - return maxtime - -def parse_file(filename): - """ - parse trajectories in Travisto-format and output results - in the following format: id frame x y - (no sorting of the data is performed) - returns - N: number of pedestrians - data: trajectories - """ - logging.info("parsing <%s>"%filename) - try: - xmldoc = minidom.parse(filename) - except: - logging.critical('could not parse file. exit') - exit(FAILURE) - N = int(xmldoc.getElementsByTagName('agents')[0].childNodes[0].data) - fps= xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data #type unicode - fps = float(fps) - fps = int(fps) - print "fps=", fps - #fps = int(xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data) - logging.info ("Npeds = %d, fps = %d"%(N, fps)) - frames = xmldoc.childNodes[0].getElementsByTagName('frame') - data = [] - for frame in frames: - frame_number = int(frame.attributes["ID"].value) - for agent in frame.getElementsByTagName("agent"): - agent_id = int(agent.attributes["ID"].value) - x = float(agent.attributes["xPos"].value) - y = float(agent.attributes["yPos"].value) - data += [agent_id, frame_number, x, y] - data = np.array(data).reshape((-1,4)) - return fps, N, data - - - if __name__ == "__main__": if CWD != DIR: logging.info("working dir is %s. Change to %s"%(os.getcwd(), DIR)) diff --git a/Utest/utils.py b/Utest/utils.py new file mode 100644 index 00000000..88ae62a8 --- /dev/null +++ b/Utest/utils.py @@ -0,0 +1,54 @@ +from xml.dom import minidom +import logging +import numpy as np + +SUCCESS = 0 +FAILURE = 1 + +def get_maxtime(filename): + """ + get max sim time + """ + logging.info("parsing <%s>"%filename) + try: + xmldoc = minidom.parse(filename) + except: + logging.critical('could not parse file. exit') + exit(FAILURE) + maxtime = float(xmldoc.getElementsByTagName('max_sim_time')[0].firstChild.nodeValue) + return maxtime + + +def parse_file(filename): + """ + parse trajectories in Travisto-format and output results + in the following format: id frame x y + (no sorting of the data is performed) + returns + N: number of pedestrians + data: trajectories + """ + logging.info("parsing <%s>"%filename) + try: + xmldoc = minidom.parse(filename) + except: + logging.critical('could not parse file. exit') + exit(FAILURE) + N = int(xmldoc.getElementsByTagName('agents')[0].childNodes[0].data) + fps= xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data #type unicode + fps = float(fps) + fps = int(fps) + print "fps=", fps + #fps = int(xmldoc.getElementsByTagName('frameRate')[0].childNodes[0].data) + logging.info ("Npeds = %d, fps = %d"%(N, fps)) + frames = xmldoc.childNodes[0].getElementsByTagName('frame') + data = [] + for frame in frames: + frame_number = int(frame.attributes["ID"].value) + for agent in frame.getElementsByTagName("agent"): + agent_id = int(agent.attributes["ID"].value) + x = float(agent.attributes["x"].value) + y = float(agent.attributes["y"].value) + data += [agent_id, frame_number, x, y] + data = np.array(data).reshape((-1,4)) + return fps, N, data diff --git a/general/ArgumentParser.cpp b/general/ArgumentParser.cpp index aff7bc63..f831c091 100644 --- a/general/ArgumentParser.cpp +++ b/general/ArgumentParser.cpp @@ -1099,12 +1099,14 @@ void ArgumentParser::ParseAgentParameters(TiXmlElement* operativModel) agentParameters->InitAtau(mu,sigma); Log->Write("INFO: \ttAtau mu=%f , sigma=%f",mu,sigma); } - double beta_c = 2; /// @todo quick and dirty - double max_Ea = agentParameters->GetAmin() + agentParameters->GetAtau()*agentParameters->GetV0(); - double max_Eb = 0.5*(agentParameters->GetBmin() + 0.49) ; /// @todo hard-coded value should be the same as in pedestrians GetEB - double max_Ea_Eb = (max_Ea>max_Eb)?max_Ea:max_Eb; - pDistEffMaxPed = 2 * beta_c * max_Ea_Eb; - pDistEffMaxWall = pDistEffMaxPed; + if(pModel == 2) { // Gompertz + double beta_c = 2; /// @todo quick and dirty + double max_Ea = agentParameters->GetAmin() + agentParameters->GetAtau()*agentParameters->GetV0(); + double max_Eb = 0.5*(agentParameters->GetBmin() + 0.49) ; /// @todo hard-coded value should be the same as in pedestrians GetEB + double max_Ea_Eb = (max_Ea>max_Eb)?max_Ea:max_Eb; + pDistEffMaxPed = 2 * beta_c * max_Ea_Eb; + pDistEffMaxWall = pDistEffMaxPed; + } } } -- GitLab