flow-project / flow

Computational framework for reinforcement learning in traffic control
MIT License
1.06k stars 375 forks source link

Error in flow/flow/core/kernel/vehicle/traci.py line 908 - Why are we passing 1e-3 for the duration? #723

Closed mtgibson2014 closed 5 years ago

mtgibson2014 commented 5 years ago

I'm trying to simply run "python examples/sumo/sugiyama.py" and I'm getting an issue with something related to a function in the kernel. It seems like in "apply_acceleration" we are passing in a decimal -- 1e-3 , when the traci code is expecting an integer. Was I suppose to install/update something within the last months or is this an error in Flow?

Code Snippet

`def apply_acceleration(self, veh_ids, acc): """See parent class."""

to hand the case of a single vehicle

    if type(veh_ids) == str:
        veh_ids = [veh_ids]
        acc = [acc]

    for i, vid in enumerate(veh_ids):
        if acc[i] is not None and vid in self.get_ids():
            this_vel = self.get_speed(vid)
            next_vel = max([this_vel + acc[i] * self.sim_step, 0])
            self.kernel_api.vehicle.slowDown(vid, next_vel, 1e-3)`

The last line: self.kernel_api.vehicle.slowDown(vid, next_vel, 1e-3)

is giving me an error because 1e-3 is not an integer.


The traci code for this function has: `def slowDown(self, vehID, speed, duration): """slowDown(string, double, int) -> None

    Changes the speed smoothly to the given value over the given amount
    of time in ms (can also be used to increase speed).
    """
    self._connection._beginMessage(
        tc.CMD_SET_VEHICLE_VARIABLE, tc.CMD_SLOWDOWN, vehID, 1 + 4 + 1 + 8 + 1 + 4)
    ####### DEBUGGING #######
    import ipdb; ipdb.set_trace()
    #########################
    self._connection._string += struct.pack(
        "!BiBdBi", tc.TYPE_COMPOUND, 2, tc.TYPE_DOUBLE, speed, tc.TYPE_INTEGER, duration)
    self._connection._sendExact()`

And I'm assuming that for: self._connection._string += struct.pack( "!BiBdBi", tc.TYPE_COMPOUND, 2, tc.TYPE_DOUBLE, speed, tc.TYPE_INTEGER, duration)

it expects that duration is an integer.

Output log:

Screen Shot 2019-09-17 at 5 57 41 PM
AboudyKreidieh commented 5 years ago

Sumo changed the third input of slowDown in version 1.0.0 to required as input seconds instead of milliseconds, and since then we have replaced the 1 values with a 1e-3. You are probably still using sumo-0.31. I recommend you remove any sumo binaries you have on your laptop and reinstall them following our setup instructions

mtgibson2014 commented 5 years ago

Thank you! It's fixed now.