I'm learning the FLOW project and doing their tutorial06 "Networks from OpenStreetMap". In this tutorial, one should be able to use the .osm file to run the simulation. However, there is an error raised, that the .xml of the network config files are missing.
The code in jupyter-notebook is as following:
# the TestEnv environment is used to simply simulate the network
from flow.envs import TestEnv
# the Experiment class is used for running simulations
from flow.core.experiment import Experiment
# all other imports are standard
from flow.core.params import VehicleParams
from flow.core.params import NetParams
from flow.core.params import InitialConfig
from flow.core.params import EnvParams
from flow.core.params import SumoParams
from flow.networks import Network
net_params = NetParams(
osm_path='networks/bay_bridge.osm'
)
# create the remainding parameters
env_params = EnvParams()
sim_params = SumoParams(render=True)
initial_config = InitialConfig()
vehicles = VehicleParams()
vehicles.add('human', num_vehicles=100)
flow_params = dict(
exp_tag='bay_bridge',
env_name=TestEnv,
network=Network,
simulator='traci',
sim=sim_params,
env=env_params,
net=net_params,
veh=vehicles,
initial=initial_config,
)
# number of time steps
flow_params['env'].horizon = 1000
exp = Experiment(flow_params)
# run the sumo simulation
_ = exp.run(1)
and I got the error:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-13-4a3adf64a06c> in <module>
13 # number of time steps
14 flow_params['env'].horizon = 1000
---> 15 exp = Experiment(flow_params)
16
17 # run the sumo simulation
~/Desktop/flow/flow/core/experiment.py in __init__(self, flow_params, custom_callables)
79
80 # Create the environment.
---> 81 self.env = create_env()
82
83 logging.info(" Starting experiment {} at {}".format(
~/Desktop/flow/flow/utils/registry.py in create_env(*_)
128 })
129
--> 130 return gym.envs.make(env_name)
131
132 return create_env, env_name
~/anaconda3/envs/flow/lib/python3.6/site-packages/gym/envs/registration.py in make(id, **kwargs)
154
155 def make(id, **kwargs):
--> 156 return registry.make(id, **kwargs)
157
158 def spec(id):
~/anaconda3/envs/flow/lib/python3.6/site-packages/gym/envs/registration.py in make(self, path, **kwargs)
99 logger.info('Making new env: %s', path)
100 spec = self.spec(path)
--> 101 env = spec.make(**kwargs)
102 # We used to have people override _reset/_step rather than
103 # reset/step. Set _gym_disable_underscore_compat = True on
~/anaconda3/envs/flow/lib/python3.6/site-packages/gym/envs/registration.py in make(self, **kwargs)
71 else:
72 cls = load(self.entry_point)
---> 73 env = cls(**_kwargs)
74
75 # Make the enviroment aware of which spec it came from.
~/Desktop/flow/flow/envs/base.py in __init__(self, env_params, sim_params, network, simulator, scenario)
162 # use the network class's network parameters to generate the necessary
163 # network components within the network kernel
--> 164 self.k.network.generate_network(self.network)
165
166 # initial the vehicles kernel using the VehicleParams object
~/Desktop/flow/flow/core/kernel/network/traci.py in generate_network(self, network)
125 elif self.network.net_params.osm_path is not None:
126 self._edges, self._connections = self.generate_net_from_osm(
--> 127 self.network.net_params)
128 else:
129 # combine all connections into a list
~/Desktop/flow/flow/core/kernel/network/traci.py in generate_net_from_osm(self, net_params)
577
578 # collect data from the generated network configuration file
--> 579 edges_dict, conn_dict = self._import_edges_from_net(net_params)
580
581 return edges_dict, conn_dict
~/Desktop/flow/flow/core/kernel/network/traci.py in _import_edges_from_net(self, net_params)
841 net_path = os.path.join(self.cfg_path, self.netfn) \
842 if net_params.template is None else self.netfn
--> 843 tree = ElementTree.parse(net_path, parser=parser)
844 root = tree.getroot()
845
~/anaconda3/envs/flow/lib/python3.6/xml/etree/ElementTree.py in parse(source, parser)
1194 """
1195 tree = ElementTree()
-> 1196 tree.parse(source, parser)
1197 return tree
1198
~/anaconda3/envs/flow/lib/python3.6/xml/etree/ElementTree.py in parse(self, source, parser)
584 close_source = False
585 if not hasattr(source, "read"):
--> 586 source = open(source, "rb")
587 close_source = True
588 try:
FileNotFoundError: [Errno 2] No such file or directory: '/home/anjie/Desktop/flow/flow/core/kernel/network/debug/cfg/bay_bridge_20200623-1345091592912709.4246037.net.xml'
I guess that, the in FLOW project, they try to use the 'netconvert' from SUMO to convert .xml files to the sumoconfig files. However, it fails at this step, that the .osm cannot be converted. But still, I cannot fix the error. BTW, the previous 5 tutorials can be run correctly.
I'm the author of this question. After investigating for hours, I found that the problem is the following command:
netconvert --osm bay_bridge.os
Error: Cannot import network data without PROJ-Library. Please install packages proj before building sumo
Quitting (on error).
Therefore, the problem is that the SUMO is not built with PROJ, and then I tried to re-build the SUMO with PROJ. However, I always encounter the problem with proj_api.h, which is not found by the ./configure command, but exists in /usr/local/includes/.
Thus, I looked into the config.log file from sumo source files, and it said:
configure:12501: checking proj_api.h usability
configure:12501: g++ -c -msse2 -mfpmath=sse -std=c++11 -O2 -DNDEBUG conftest.cpp >&5
In file included from conftest.cpp:59:
/usr/local/include/proj_api.h:37:2: error: #error 'To use the proj_api.h you must define the macro ACCEPT_USE_OF_DEPRECATED_PROJ_API_H'
37 | #error 'To use the proj_api.h you must define the macro ACCEPT_USE_OF_DEPRECATED_PROJ_API_H'
So I open the proj_api.h with root and edit the line as follows:
#ifndef ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
//#error 'To use the proj_api.h you must define the macro ACCEPT_USE_OF_DEPRECATED_PROJ_API_H'
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H 1
#endif
After all this, I successfully built the SUMO with the PROJ and everything works fine!