Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# network
if fileNeedsRebuild(self.netName, "netconvert"):
print("Network in '%s' needs to be rebuild" % self.netName)
defaultEdge = Edge(numLanes=1, maxSpeed=13.89)
defaultEdge.addSplit(100, 1)
defaultEdge.lanes = [Lane(dirs="rs"), Lane(dirs="l")]
netGen = netGenerator.cross(None, defaultEdge)
# not nice, the network name should be given/returned
netGen.build(self.netName)
# demand
if withDefaultDemand:
print("Demand in '%s' needs to be rebuild" % self.demandName)
self.demand = demandGenerator.Demand()
# why isn't it possible to get a network and return all possible
# routes or whatever - to ease the process
self.demand.addStream(demandGenerator.Stream(
None, 0, 3600, 1000, "2/1_to_1/1", "1/1_to_0/1", {"hdv": .2, "passenger": .8}))
if fileNeedsRebuild(self.demandName, "duarouter"):
self.demand.build(0, 3600, self.netName, self.demandName)
Scenario.__init__(self, self.NAME)
self.netName = self.fullPath(self.NET_FILE)
self.demandName = self.fullPath("routes.rou.xml")
# network
if fileNeedsRebuild(self.netName, "netconvert"):
print("Network in '%s' needs to be rebuild" % self.netName)
defaultEdge = Edge(numLanes=1, maxSpeed=13.89)
defaultEdge.addSplit(100, 1)
defaultEdge.lanes = [Lane(dirs="rs"), Lane(dirs="l")]
netGen = netGenerator.cross(None, defaultEdge)
# not nice, the network name should be given/returned
netGen.build(self.netName)
# demand
if withDefaultDemand:
print("Demand in '%s' needs to be rebuild" % self.demandName)
self.demand = demandGenerator.Demand()
# why isn't it possible to get a network and return all possible
# routes or whatever - to ease the process
self.demand.addStream(demandGenerator.Stream(
None, 0, 3600, 1000, "2/1_to_1/1", "1/1_to_0/1", {.2: "hdv", .8: "passenger"}))
if fileNeedsRebuild(self.demandName, "duarouter"):
self.demand.build(0, 3600, self.netName, self.demandName)
def __init__(self, params, withDefaultDemand=True):
Scenario.__init__(self, self.THIS_DIR)
self.params = params
if "equipment-rate" not in self.params:
self.params["equipment-rate"] = 1
# network
if fileNeedsRebuild(os.path.join(self.THIS_DIR, self.NET_FILE), "netconvert"):
netconvert = sumolib.checkBinary("netconvert")
subprocess.call([netconvert, "-c", os.path.join(self.THIS_DIR, "build.netc.cfg")])
# build the demand model (streams)
if withDefaultDemand:
self.demand = demandGenerator.Demand()
for f in flowsRiLSA1:
for rel in f[1]:
prob = rel[2] / 100.
iprob = 1. - prob
pkwEprob = iprob * self.params["equipment-rate"]
pkwNprob = iprob - pkwEprob
lkwEprob = prob * self.params["equipment-rate"]
lkwNprob = prob - lkwEprob
self.demand.addStream(demandGenerator.Stream(f[0] + "__" + rel[0], 0, 3600, rel[1], f[0], rel[0],
{"passenger": pkwEprob,
"COLOMBO_undetectable_passenger": pkwNprob,
"hdv": lkwEprob,
"COLOMBO_undetectable_hdv": lkwNprob}))
if fileNeedsRebuild(self.fullPath("routes.rou.xml"), "duarouter"):
netconvert = sumolib.checkBinary("netconvert")
subprocess.call([netconvert, "-c", os.path.join(self.THIS_DIR, "build.netc.cfg")])
# build the demand model (streams)
if withDefaultDemand:
self.demand = demandGenerator.Demand()
for f in flowsRiLSA1:
for rel in f[1]:
prob = rel[2] / 100.
iprob = 1. - prob
pkwEprob = iprob * self.params["equipment-rate"]
pkwNprob = iprob - pkwEprob
lkwEprob = prob * self.params["equipment-rate"]
lkwNprob = prob - lkwEprob
self.demand.addStream(demandGenerator.Stream(f[0] + "__" + rel[0], 0, 3600, rel[1], f[0], rel[0],
{"passenger": pkwEprob,
"COLOMBO_undetectable_passenger": pkwNprob,
"hdv": lkwEprob,
"COLOMBO_undetectable_hdv": lkwNprob}))
if fileNeedsRebuild(self.fullPath("routes.rou.xml"), "duarouter"):
self.demand.build(
0, 3600, self.fullPath(self.NET_FILE), self.fullPath("routes.rou.xml"))
self.demandName = self.fullPath("routes.rou.xml")
self.netName = self.sandboxPath(self.NET_FILE)
shutil.copy(
self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
# shutil.copy(self.fullPath(self.TLS_FILE), self.sandboxPath(self.TLS_FILE))
cr = math.cos(rot * x / 2. * y / 2.)
# * abs(3-x)/3.
netGen._nodes[
"%s/%s" % (x, y)].x = netGen._nodes["%s/%s" % (x, y)].x + sr * m * 250
# * abs(3-y)/3.
netGen._nodes[
"%s/%s" % (x, y)].y = netGen._nodes["%s/%s" % (x, y)].y + cr * m * 250
# not nice, the network name should be given/returned
netGen.build(self.netName)
# demand
if withDefaultDemand:
print("Demand in '%s' needs to be rebuild" % self.demandName)
self.demand = demandGenerator.Demand()
# why isn't it possible to get a network and return all possible
# routes or whatever - to ease the process
self.demand.addStream(demandGenerator.Stream(
None, 0, 3600, 1000, "6/1_to_5/1", "1/1_to_0/1", {"hdv": .2, "passenger": .8}))
if fileNeedsRebuild(self.demandName, "duarouter"):
self.demand.build(0, 3600, self.netName, self.demandName)
def extrapolateDemand(stream, freq, probs, pivot=demandGenerator.PIVOT__PEAK, tBeg=0):
ret = demandGenerator.Demand()
if pivot == demandGenerator.PIVOT__PEAK:
mmax = 0
mpos = []
for i, p in enumerate(probs):
if p > mmax:
mpos = i
mmax = p
# !!! should be done
# if count(probs, p)>1:
# raise "more than one maximum value"
# else:
# pivot = mpos
pivot = mpos
t = tBeg
for i, p in enumerate(probs):
def __init__(self, params, withDefaultDemand=True):
Scenario.__init__(self, self.THIS_DIR)
self.params = params
if "equipment-rate" not in self.params:
self.params["equipment-rate"] = 1
# network
if fileNeedsRebuild(os.path.join(self.THIS_DIR, self.NET_FILE), "netconvert"):
netconvert = sumolib.checkBinary("netconvert")
retCode = subprocess.call(
[netconvert, "-c", os.path.join(self.THIS_DIR, "build.netc.cfg")])
# build the demand model (streams)
if withDefaultDemand:
self.demand = demandGenerator.Demand()
for f in flowsRiLSA1:
for rel in f[1]:
prob = rel[2] / 100.
iprob = 1. - prob
pkwEprob = iprob * self.params["equipment-rate"]
pkwNprob = iprob - pkwEprob
lkwEprob = prob * self.params["equipment-rate"]
lkwNprob = prob - lkwEprob
self.demand.addStream(demandGenerator.Stream(f[0] + "__" + rel[0], 0, 3600, rel[1], f[0], rel[0],
{"passenger": pkwEprob, "COLOMBO_undetectable_passenger": pkwNprob, "hdv": lkwEprob, "COLOMBO_undetectable_hdv": lkwNprob}))
if fileNeedsRebuild(self.fullPath("routes.rou.xml"), "duarouter"):
self.demand.build(
0, 3600, self.fullPath(self.NET_FILE), self.fullPath("routes.rou.xml"))
self.demandName = self.fullPath("routes.rou.xml")
def extrapolateDemand(stream, freq, probs, pivot=demandGenerator.PIVOT__PEAK, tBeg=0):
ret = demandGenerator.Demand()
if pivot == demandGenerator.PIVOT__PEAK:
mmax = 0
mpos = []
for i, p in enumerate(probs):
if p > mmax:
mpos = i
mmax = p
# !!! should be done
# if count(probs, p)>1:
# raise "more than one maximum value"
# else:
# pivot = mpos
pivot = mpos
t = tBeg
for i, p in enumerate(probs):
mpos = []
for i, p in enumerate(probs):
if p > mmax:
mpos = i
mmax = p
# !!! should be done
# if count(probs, p)>1:
# raise "more than one maximum value"
# else:
# pivot = mpos
pivot = mpos
t = tBeg
for i, p in enumerate(probs):
# ok, this works just if _numberModel is a number
num = float(stream._numberModel) * p / probs[pivot]
ret.addStream(demandGenerator.Stream(stream.sid + "_" + str(i), t, t + freq,
num, stream._departEdgeModel, stream._arrivalEdgeModel,
stream._vTypeModel))
t = t + freq
return ret
retCode = subprocess.call(
[netconvert, "-c", os.path.join(self.THIS_DIR, "build.netc.cfg")])
# build the demand model (streams)
if withDefaultDemand:
self.demand = demandGenerator.Demand()
for f in flowsRiLSA1:
for rel in f[1]:
prob = rel[2] / 100.
iprob = 1. - prob
pkwEprob = iprob * self.params["equipment-rate"]
pkwNprob = iprob - pkwEprob
lkwEprob = prob * self.params["equipment-rate"]
lkwNprob = prob - lkwEprob
self.demand.addStream(demandGenerator.Stream(f[0] + "__" + rel[0], 0, 3600, rel[1], f[0], rel[0],
{"passenger": pkwEprob, "COLOMBO_undetectable_passenger": pkwNprob, "hdv": lkwEprob, "COLOMBO_undetectable_hdv": lkwNprob}))
if fileNeedsRebuild(self.fullPath("routes.rou.xml"), "duarouter"):
self.demand.build(
0, 3600, self.fullPath(self.NET_FILE), self.fullPath("routes.rou.xml"))
self.demandName = self.fullPath("routes.rou.xml")
self.netName = self.sandboxPath(self.NET_FILE)
shutil.copy(
self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
# shutil.copy(self.fullPath(self.TLS_FILE), self.sandboxPath(self.TLS_FILE))