运行 来自 FLOW 项目的 tutorial06 "Networks from OpenStreetMap" 时出现文件错误

File error while running the tutorial06 "Networks from OpenStreetMap" from FLOW project

我正在学习 FLOW 项目并完成他们的教程 06“来自 OpenStreetMap 的网络”。在本教程中,应该能够使用 .osm 文件来 运行 模拟。但是,出现错误,网络配置文件的 .xml 丢失。

jupyter-notebook中的代码如下:

# 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)

我得到了错误:

---------------------------------------------------------------------------
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'

我猜想,在 FLOW 项目中,他们尝试使用 SUMO 中的 'netconvert' 将 .xml 文件转换为 sumoconfig 文件。但是,此步骤失败,无法转换 .osm。但是,我仍然无法修复错误。顺便说一句,前面的 5 个教程可以 运行 正确。

我是这个问题的作者。经过几个小时的调查,我发现问题出在以下命令:

netconvert --osm bay_bridge.os

Error: Cannot import network data without PROJ-Library. Please install packages proj before building sumo
Quitting (on error).

因此,问题是SUMO不是用PROJ构建的,然后我尝试用PROJ重新构建SUMO。但是我总是遇到proj_api.h的问题,./configure命令找不到,但是存在于/usr/local/includes/.

因此,我查看了 sumo 源文件中的 config.log 文件,它说:

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'

所以我用 root 打开 proj_api.h 并编辑如下行:

#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

经过这一切,我成功地用 PROJ 构建了 SUMO,一切正常!