0

I am working with sumo&rllib, and I want to get the data(car number of an intersection) to let rllib agent to learn, how to inspect the number and how to import that data into rllib.

toby
  • 21
  • 7
  • On sumo. I can run 'python randomTrip.py -n xxxxx.net.xml -r xxxx.net.xml -e 3000 -l' command. As the command said, the cars' routes are random. Now I want to create the same thing on flow. I checked the tutorial_8, and add my rou file(the 3000 vehicles, random route) in the template. There is error: KeyError:type'. How to fix that? And there is any method to ran random route for a big number of vehicles on flow.@nathanlct @Ashkan – toby Jul 16 '19 at 08:18
  • File "/home/dnl/flow/flow/scenarios/base_scenario.py", line 365, in __init__ veh, rou = self._vehicle_infos(net_params.template['rou']) File "/home/dnl/flow/flow/scenarios/base_scenario.py", line 720, in _vehicle_infos type_vehicle = vehicle.attrib['type'] File "src/lxml/etree.pyx", line 2457, in lxml.etree._Attrib.__getitem__ KeyError: 'type' – toby Jul 16 '19 at 14:52

1 Answers1

0

If you go in scenarios/base_scenario.py, in the docstring of specify_routes, you will see an example of how to specify stochastic routes:

      >>> def specify_routes(self, net_params):
      >>>     return {
      >>>         "top": [
      >>>             (["top", "left", "bottom", "right_0"], 0.9),
      >>>             (["top", "left", "bottom", "right_1"], 0.1)
      >>>         ],
      >>>         "left": [
      >>>             (["left", "bottom", "right_0", "top"], 0.3),
      >>>             (["left", "bottom", "right_1", "top"], 0.7)
      >>>         ],
      >>>         "bottom": [
      >>>             (["bottom", "right_0", "top", "left"], 0.5),
      >>>             (["bottom", "right_1", "top", "left"], 0.5)
      >>>         ]
      >>>     }

This way the vehicles will choose their routes in a non-deterministic way, you can make it as random as you want.

(this is a new feature, if you don't have this example in the docstring, make sure to pull from master)


To get the vehicles at the intersection in a grid, have a look at the function k_closest_to_intersection in envs/green_wave_env.py. You can then use this function in the get_state function of your environment to communicate with RLlib for instance.

math.husky
  • 193
  • 1
  • 8
  • Yeah, this function specify_routes can specify a stochastic route, but if there are many edges, so each vehicle has mang stochastic route to choose, should we enumerate every one? That's too troublesome. Can we combine the creation of stochastic routes with randomTrips.py(a SUMO program) in flow? – toby Jul 17 '19 at 01:01
  • And on k_closest_to_intersection, what is the meaning of k? It is the distance or like a radius of a circle which around that intersection? – toby Jul 17 '19 at 01:17
  • @toby Yes, I believe you must specify it manually. However it would be nice that the choice is uniformly random by default, I will think about implementing that. – math.husky Jul 17 '19 at 04:12
  • As for k, as mentioned in the docstring: `For each edge in edges, return the ids (veh_id) of the k vehicles in edge that are closest to an intersection (the intersection they are heading towards).`. I recommend you pass the 4 ids of the edges at an intersection one by one (4 calls to the function), and each will return a list of the k (or less if there are less vehicles on the edge) vehicles closest to the intersection. You can just try it and print the result to see what it returns! (or read the source code of the function, it is pretty short). – math.husky Jul 17 '19 at 04:14
  • So your meaning is: k is the number of cars. I cannot understand it. SoI try to test it. As for better simulation, I'd like to use grid scenario, but when i test my enviroment which follow the tutorial_9 and just change the scenario option from LoopScenario to SimpleGridScenario, and set the proper paramters of SimpleGridScenario.There is an error. About it , you can refer the my friend's question:" when test the grid scenario, there is an valueError".@nathanlct – toby Jul 17 '19 at 06:37
  • k is the number of cars in each edge, yes. To use the grid scenario, you can have a look at the `green_wave` example which uses the grid. A ValueError could be anything, so for that please post an other question with the entire error! – math.husky Jul 17 '19 at 07:19
  • Actually, I do not know how to get the output of k_closest_to_intersection function, on my get_state() function I insert that sentence 'vel = TrafficLightGridEnv.k_closest_to_intersection(self,edges="left3_0_0",k=1000)' and 'return vel' , on my run file, I wrote 'print(env.get_state())' There is no thing on the output – toby Jul 31 '19 at 13:07
  • On sumo examples, the env is not used. On rllib examples, you'd write `print(env.get_state())` in the env itself or in the simulation kernel most likely. – math.husky Aug 01 '19 at 04:22
  • Also look how classes and objects work in Python, you can't just write `TrafficLightGridEnv.k_closest_to_intersection`. – math.husky Aug 01 '19 at 04:22
  • On the get_state() function of green_wave_env.py , I wrote print(dist_to_intersec), when I ran green_wave.py, I cannot see any data of the print function. My aim is to check the data of dist_to_intersec, how to check it? @nathanlct – toby Aug 12 '19 at 15:30