我正在学习 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。但是,我仍然无法修复错误。BTW,前面5个教程都可以正常运行。