Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup fixes for producing human traffic jams #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/agent_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import config as defaults

# changeFasterLane = changeFasterLaneBuilder()
changeFasterLane = changeFasterLaneBuilder(likelihood_mult=0.5, speedThreshold=2)
changeFasterLane = changeFasterLaneBuilder(likelihood_mult=0.5, speedThreshold=2, bias=1)
basicHumanParams = {
"name" : "human",
"shape" : "passenger",
Expand All @@ -20,6 +20,7 @@
"speedDev" : 0.5,
"sigma" : 0.75,
"tau" : 3, # http://www.croberts.com/respon.htm
# "carFollowModel" : "Wiedemann", # "PWagner2009",
# "laneChangeModel": 'LC2013',
}

Expand Down
5 changes: 3 additions & 2 deletions python/carfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def randomChangeLaneFn((idx, car), sim, step):

def changeFasterLaneBuilder(speedThreshold = 5, likelihood_mult = 0.5,
dxBack = 0, dxForward = 60,
gapBack = 10, gapForward = 5):
gapBack = 10, gapForward = 5, bias=0):
"""
Intelligent lane changer
:param speedThreshold: minimum speed increase required
Expand All @@ -21,6 +21,7 @@ def changeFasterLaneBuilder(speedThreshold = 5, likelihood_mult = 0.5,
:param dxForward: Farthest distance forward car can see
:param gapBack: Minimum required clearance behind car
:param gapForward: Minimum required clearance in front car
:param bias: additive speed bias term (m/s)
:return: carFn to input to a carParams
"""
def carFn((idx, car), sim, step):
Expand All @@ -32,7 +33,7 @@ def carFn((idx, car), sim, step):
continue
cars = sim.getCars(idx, dxBack=dxBack, dxForward=dxForward, lane=lane)
if len(cars) > 0:
v[lane] = mean([c["v"] for c in cars])
v[lane] = mean([c["v"] for c in cars]) + bias
else:
v[lane] = traci.vehicle.getMaxSpeed(car["id"])
maxv = max(v)
Expand Down
54 changes: 36 additions & 18 deletions python/icra.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
import copy

import config as defaults
from loopsim import LoopSim
Expand All @@ -10,27 +11,41 @@


if __name__ == "__main__":
vTypeParams = humanParams
vTypeParams["laneSpread"] = 0
vTypeParams["tau"] = 0.5
vTypeParams["speedDev"] = 0.1
vTypeParams["speedFactor"] = 1
globalLaneSpread = 0

hParams = humanParams
hParams["laneSpread"] = globalLaneSpread
hParams["tau"] = 2
hParams["speedDev"] = 0.2
hParams["speedFactor"] = 1.1
hParams["minGap"] = 1

hParams1 = copy.copy(humanParams)
hParams1["name"] = "human1"
hParams1["laneSpread"] = 1
hParams1["tau"] = 2
hParams1["speedDev"] = 0.4
hParams1["speedFactor"] = 1.2
hParams1["count"] = 0

mParams = midpointParams
mParams["laneSpread"] = 0
mParams["laneSpread"] = globalLaneSpread
# mParams["tau"] = 0.1

gParams = fillGapMidpointParams
gParams["laneSpread"] = 0
gParams["laneSpread"] = globalLaneSpread
# gParams["tau"] = 0.1

aParams = ACCParams
aParams["laneSpread"] = 0
aParams["laneSpread"] = globalLaneSpread
# aParams["tau"] = 0.1

###############
# Option ranges
###############

numLanes = 2
totVehicles = 22
numLanes = 1
totVehicles = 11

'''
sigmaValues = [0.5, 0.9]
Expand All @@ -39,12 +54,14 @@
robotTypes = (mParams, gParams, aParams)
'''

sigmaValues = [0.9]
sigmaValues = [0.5]
numRobotsValues = [0, 1]
numRuns = 1
robotTypes = [gParams]

fps = 24
# WARNING SUMO can't really handle more than 2 fps, probably due to limitations of underlying car following models
# TODO(cathywu) develop our own high resolution car following models?
fps = 2
simStepLength = 1./fps
simTime = 100
simSteps = int(simTime/simStepLength)
Expand All @@ -53,17 +70,17 @@
for sigma in sigmaValues:
for numRobots in numRobotsValues:
for rParams in robotTypes:
vTypeParams["sigma"] = sigma
vTypeParams["count"] = (totVehicles-numRobots)
rParams["count"] = numRobots
hParams["sigma"] = sigma
hParams["count"] = (totVehicles-numRobots)
rParams["count"] = numRobots

if defaults.RANDOM_SEED:
print ">>> Setting random seed to ", defaults.RANDOM_SEED
random.seed(defaults.RANDOM_SEED)

for run in range(numRuns):
opts = {
"paramsList" : [vTypeParams, rParams],
"paramsList" : [hParams, hParams1, rParams],
"simSteps" : simSteps,
"tag" : "Sugiyama-sigma=%03f-run=%d" % (sigma, run),
}
Expand All @@ -72,8 +89,9 @@
print "sigma =", sigma, "numRobots = ", numRobots,
print "robot type =", rParams["name"], "run = ", run
print "***"
speedRange = (0,30)
sim.simulate(opts, sumo='sumo-gui', speedRange=speedRange, sublane=False)
speedRange = (0, 30)
sim.simulate(opts, sumo='sumo', speedRange=speedRange, sublane=False)
# sim.simulate(opts, sumo='sumo-gui', speedRange=speedRange, sublane=False)
sim.plot(show=False, save=True, speedRange=speedRange).close("all")
if numRobots == 0:
break
34 changes: 27 additions & 7 deletions python/loopsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,44 @@ def _addCars(self, paramsList):
cars = {}
self.numCars = 0

# Tabulate total number of cars per lane
num_cars_per_lane = [0] * self.numLanes

# Create car list
for param in paramsList:
self.numCars += param["count"]
for i in range(param["count"]):
vtype = param["name"]
laneSpread = param.get("laneSpread", True)
if laneSpread is not True:
num_cars_per_lane[laneSpread] += 1
carname = "%s-%03d" % (vtype, i)
cars[carname] = (vtype, laneSpread)

lane = 0
lane = -1
carsitems = cars.items()

# Add all cars to simulation ...
random.shuffle(carsitems) # randomly
for i, (carname, (vtype, laneSpread)) in enumerate(carsitems):
x = self.length * i / self.numCars
self._createCar(carname, x, vtype,
lane if laneSpread is True else laneSpread)
lane = (lane + 1) % self.numLanes
random.shuffle(carsitems) # randomly

# Counters of cars added so far (per lane)
cars_added_per_lane = [0] * self.numLanes
# For lanespead = True, set the default cars per lane
default_cars_per_lane = np.ceil(float(self.numCars) / self.numLanes)

for carname, (vtype, laneSpread) in carsitems:
if laneSpread is True:
# If lanespread = True, then uniformly set the car positions
lane = (lane + 1) % self.numLanes
lane_total = default_cars_per_lane
else:
# Otherwise, space the cars out evenly per lane
lane = laneSpread
lane_total = num_cars_per_lane[laneSpread]

x = self.length * cars_added_per_lane[lane] / lane_total
cars_added_per_lane[lane] += 1
self._createCar(carname, x, vtype, lane)

self.carNames = cars.keys()

Expand Down
7 changes: 5 additions & 2 deletions python/sugiyama_jam.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

if __name__ == "__main__":
numLanes = 1
simStepLength = 0.5
simTime = 500
simSteps = int(simTime/simStepLength)

sim = LoopSim("loopsim", length=230, numLanes=numLanes, simStepLength=0.5)
sim = LoopSim("loopsim", length=230, numLanes=numLanes, simStepLength=simStepLength)

vTypeParams = humanParams
vTypeParams["laneSpread"] = True
Expand All @@ -29,7 +32,7 @@

opts = {
"paramsList" : [vTypeParams],
"simSteps" : 500,
"simSteps" : simSteps,
"tag" : "Sugiyama",
}

Expand Down