Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# @author Jakob Erdmann
# @date 2017-01-23
from __future__ import print_function
from __future__ import absolute_import
import os
import subprocess
import sys
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import traci # noqa
import sumolib # noqa
import traci.constants as tc # noqa
sumoBinary = os.environ["SUMO_BINARY"]
PORT = sumolib.miscutils.getFreeSocketPort()
sumoProcess = subprocess.Popen([sumoBinary,
'-n', 'input_net.net.xml',
'-r', 'input_routes.rou.xml',
'--no-step-log',
'--begin', '5',
# '-S', '-Q',
'--remote-port', str(PORT)], stdout=sys.stdout)
traci.init(PORT)
vehID = "v0"
traci.vehicle.add(vehID, "r0")
traci.vehicle.subscribeContext(vehID, tc.CMD_GET_VEHICLE_VARIABLE,
dist=20, begin=0, end=99999999)
traci.simulationStep(10.)
traci.close()
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
import sys
import time
import math
from multiprocessing import Process, freeze_support
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
import sumolib # noqa
import traci # noqa
PORT = sumolib.miscutils.getFreeSocketPort()
DELTA_T = 1000
sumoBinary = sumolib.checkBinary(sys.argv[1])
def traciLoop(port, traciEndTime, index, SUMOsteplength, steplength=0):
orderTime = 0.25
time.sleep(orderTime * index) # assure ordering of outputs
if steplength == 0:
steplength = DELTA_T / 1000.
print("Starting process %s with steplength %s" % (index, steplength))
sys.stdout.flush()
traci.init(port)
traci.setOrder(index)
step = 1
nrEnteredVehicles = 0
sumoStop = False
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
import sys
import time
import math
from multiprocessing import Process, freeze_support
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
import sumolib # noqa
import traci # noqa
import traci.constants as tc # noqa
PORT = sumolib.miscutils.getFreeSocketPort()
DELTA_T = 1000
sumoBinary = sumolib.checkBinary(sys.argv[1])
def traciLoop(port, traciEndTime, i, runNr, steplength=0):
orderTime = 0.25
time.sleep(orderTime * i) # assure ordering of outputs
if steplength == 0:
steplength = DELTA_T / 1000.
# order index dependent on runNr
index = i if (runNr % 2 == 0) else 10 - i
sys.stdout.flush()
traci.init(port)
traci.setOrder(index)
message = ("Starting process %s (order: %s) with steplength %s\n" % (i, index, steplength))
step = 1
# @file runner.py
# @author Laura Bieker
# @date 2017-05-23
from __future__ import print_function
from __future__ import absolute_import
import os
import subprocess
import sys
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import traci # noqa
import sumolib # noqa
sumoBinary = os.environ["SUMO_BINARY"]
PORT = sumolib.miscutils.getFreeSocketPort()
sumoProcess = subprocess.Popen([sumoBinary,
'-c', 'sumo.sumocfg',
'--fcd-output', 'fcd.xml',
'-S', '-Q',
'--remote-port', str(PORT)], stdout=sys.stdout)
traci.init(PORT)
traci.simulationStep()
for i in range(45):
traci.simulationStep()
traci.vehicle.setSpeedMode("rescue", 7)
traci.vehicle.setSpeed("rescue", 13.9)
traci.trafficlight.setRedYellowGreenState("C", "rrrrrrrrrrrrrrrrrr")
for i in range(21):
traci.simulationStep()
traci.close()
from __future__ import print_function
from __future__ import absolute_import
import os
import sys
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
else:
sys.exit("please declare environment variable 'SUMO_HOME'")
import traci # noqa
import sumolib # noqa
sumoBinary = os.environ["SUMO_BINARY"]
PORT = sumolib.miscutils.getFreeSocketPort()
cmd = [sumoBinary,
'-n', 'input_net2.net.xml',
'--no-step-log',
# '-S', '-Q',
]
ANGLE_UNDEF = traci.constants.INVALID_DOUBLE_VALUE
INVALID = traci.constants.INVALID_DOUBLE_VALUE
vehID = "v0"
def check(x, y, angle, exLane, exPos, exPosLat, comment):
traci.vehicle.moveToXY(vehID, "", 0, x, y, angle)
traci.simulationStep()
x2, y2 = traci.vehicle.getPosition(vehID)
# @author Jakob Erdmann
# @author Daniel Krajzewicz
# @date 2011-03-04
from __future__ import print_function
from __future__ import absolute_import
import os
import subprocess
import sys
sys.path.append(os.path.join(os.environ['SUMO_HOME'], 'tools'))
import traci # noqa
import sumolib # noqa
sumoBinary = os.environ["SUMO_BINARY"]
PORT = sumolib.miscutils.getFreeSocketPort()
sumoProcess = subprocess.Popen([sumoBinary,
'-c', 'sumo.sumocfg',
'-S', '-Q',
'--remote-port', str(PORT)], stdout=sys.stdout)
def check(vehID, steps=1):
for i in range(steps):
if i > 0:
traci.simulationStep()
try:
print("%s vehicle %s on lane=%s pos=%s speed=%s" % (
traci.simulation.getTime(),
vehID,
traci.vehicle.getLaneID(vehID),
traci.vehicle.getLanePosition(vehID),
o.connect(("localhost", outPort))
break
except socket.error:
if wait == numTries:
raise
time.sleep(wait)
while 1:
data = i.recv(1024)
if not data:
break
o.sendall(data)
o.close()
i.close()
SUMO_PORT = sumolib.miscutils.getFreeSocketPort()
IN_PORT = sumolib.miscutils.getFreeSocketPort()
OUT_PORT = sumolib.miscutils.getFreeSocketPort()
sumoBinary = sumolib.checkBinary('sumo')
xmlProtoPy = os.path.join(toolDir, 'xml', 'xml2protobuf.py')
protoXmlPy = os.path.join(toolDir, 'xml', 'protobuf2xml.py')
schema = os.path.join(
toolDir, '..', 'data', 'xsd', 'amitran', 'trajectories.xsd')
# file output direct
subprocess.call(
[sumoBinary, "-c", "sumo.sumocfg", "--amitran-output", "direct.xml"])
# protobuf roundtrip
xPro = subprocess.Popen(
['python', xmlProtoPy, '-x', schema, '-o', str(IN_PORT), str(SUMO_PORT)])
pPro = subprocess.Popen(['python', protoXmlPy, '-x', schema, str(OUT_PORT)])
def main(options):
if options.seed:
random.seed(options.seed)
busStops = [bs.id for bs in sumolib.xml.parse_fast(options.additional, 'busStop', ['id'])]
stopColors = {}
if options.poiout:
colorgen = sumolib.miscutils.Colorgen(('distinct', 'distinct', 'distinct'))
net = sumolib.net.readNet(options.netfile)
with open(options.poiout, 'w') as outf:
outf.write('\n')
for bs in sumolib.xml.parse(options.additional, 'busStop'):
laneShape = net.getLane(bs.lane).getShape()
sideShape = sumolib.geomhelper.move2side(laneShape, options.poiOffset)
offset = (float(bs.startPos) + float(bs.endPos)) / 2
x, y = sumolib.geomhelper.positionAtShapeOffset(sideShape, offset)
stopColors[bs.id] = colorgen()
outf.write(' \n' % (
bs.id, x, y, stopColors[bs.id], bs.attr_name))
outf.write('\n')
if len(busStops) < 2:
print("Error: At least two busStops are required", file=sys.stderr)
sys.exit(1)
if options.poi_output is not None:
if len(tracefiles) == 1:
poi_output = options.poi_output
else:
poi_output = os.path.basename(t).split('.')[0] + '.poi.xml'
poiOut = open(poi_output, "w")
sumolib.xml.writeHeader(poiOut, root='additional')
polyOut = None
if options.polygon_output is not None:
if len(tracefiles) == 1:
polygon_output = options.polygon_output
else:
polygon_output = os.path.basename(t).split('.')[0] + '.poly.xml'
polyOut = open(polygon_output, "w")
sumolib.xml.writeHeader(polyOut, root='additional')
colorgen = sumolib.miscutils.Colorgen(('random', 1, 1))
# determine file type by reading the first 10000 bytes
head = open(t).read(10000)
if "\n' % (tid, idx, pos[0], pos[1]))
edges = [e.getID() for e in sumolib.route.mapTrace(
trace, net, *mapOpts) if e.getFunction() != "internal"]
def start(cmd, port=None, numRetries=10, label="default", verbose=False):
"""
Start a sumo server using cmd, establish a connection to it and
store it under the given label. This method is not thread-safe.
"""
if label in _connections:
raise TraCIException("Connection '%s' is already active." % label)
while numRetries >= 0 and label not in _connections:
sumoPort = sumolib.miscutils.getFreeSocketPort() if port is None else port
cmd2 = cmd + ["--remote-port", str(sumoPort)]
if verbose:
print("Calling " + ' '.join(cmd2))
sumoProcess = subprocess.Popen(cmd2)
try:
return init(sumoPort, numRetries, "localhost", label, sumoProcess)
except TraCIException:
if port is not None:
break
warnings.warn("Could not connect to TraCI server using port %s. Retrying with different port." % sumoPort)
numRetries -= 1
raise FatalTraCIError("Could not connect.")