def init(manager): optParser = OptionParser() optParser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="tell me what you are doing") optParser.add_option("-g", "--gui", action="store_true", dest="gui", default=False, help="run with GUI") optParser.add_option("-c", "--cyber", action="store_true", dest="cyber", default=False, help="use small cybercars instead of big busses") optParser.add_option("-d", "--demand", type="int", dest="demand", default=15, help="period with which the persons are emitted") optParser.add_option("-b", "--break", type="int", dest="breakstep", metavar="TIMESTEP", help="let a vehicle break for %s seconds at TIMESTEP" % BREAK_DELAY) (options, args) = optParser.parse_args() sumoExe = SUMO if options.gui: sumoExe = SUMOGUI sumoConfig = "%s%02i.sumo.cfg" % (PREFIX, options.demand) if options.cyber: sumoConfig = "%s%02i_cyber.sumo.cfg" % (PREFIX, options.demand) sumoProcess = subprocess.Popen("%s -c %s" % (sumoExe, sumoConfig), shell=True, stdout=sys.stdout) initTraCI(PORT) setting.manager = manager setting.verbose = options.verbose setting.cyber = options.cyber setting.breakstep = options.breakstep try: while setting.step < 100 or statistics.personsRunning > 0: doStep() statistics.evaluate() finally: cmdClose()
def runSingle(traciEndTime): step = 0 sumoProcess = subprocess.Popen("%s -c used.sumo.cfg %s" % (sumoBinary, addOption), shell=True, stdout=sys.stdout) traciControl.initTraCI(PORT) while not step>traciEndTime: traciControl.cmdSimulationStep2(DELTA_T) step += 1 print "Print ended at step %s" % (traciControl.cmdGetSimulationVariable_currentTime() / DELTA_T) traciControl.cmdClose() sys.stdout.flush()
def init(manager): optParser = OptionParser() optParser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="tell me what you are doing") optParser.add_option("-g", "--gui", action="store_true", dest="gui", default=False, help="run with GUI") optParser.add_option("-c", "--cyber", action="store_true", dest="cyber", default=False, help="use small cybercars instead of big busses") optParser.add_option("-d", "--demand", type="int", dest="demand", default=15, help="period with which the persons are emitted") optParser.add_option( "-b", "--break", type="int", dest="breakstep", metavar="TIMESTEP", help="let a vehicle break for %s seconds at TIMESTEP" % BREAK_DELAY) (options, args) = optParser.parse_args() sumoExe = SUMO if options.gui: sumoExe = SUMOGUI sumoConfig = "%s%02i.sumo.cfg" % (PREFIX, options.demand) if options.cyber: sumoConfig = "%s%02i_cyber.sumo.cfg" % (PREFIX, options.demand) sumoProcess = subprocess.Popen("%s -c %s" % (sumoExe, sumoConfig), shell=True, stdout=sys.stdout) initTraCI(PORT) setting.manager = manager setting.verbose = options.verbose setting.cyber = options.cyber setting.breakstep = options.breakstep try: while setting.step < 100 or statistics.personsRunning > 0: doStep() statistics.evaluate() finally: cmdClose()
def runSingle(addOption): step = 0 timeline = [] sumoProcess = subprocess.Popen("%s -c %s %s" % (sumoBinary, "sumo.sumo.cfg", addOption), shell=True, stdout=sys.stdout) traciControl.initTraCI(PORT) while not step>10000: try: traciControl.cmdSimulationStep2(DELTA_T) vehs = traciControl.cmdGetVehicleVariable_idList() timeline.append({}) for v in vehs: timeline[-1][v] = traciControl.cmdGetVehicleVariable_speed(v) step += 1 except traciControl.FatalTraCIError: print "Closed by SUMO" break traciControl.cmdClose() sys.stdout.flush() return timeline
def runSingle(sumoEndTime, traciEndTime): fdi = open("sumo.sumo.cfg") fdo = open("used.sumo.cfg", "w") for line in fdi: line = line.replace("%end%", str(sumoEndTime)) fdo.write(line) fdi.close() fdo.close() doClose = True step = 0 sumoProcess = subprocess.Popen("%s -c used.sumo.cfg %s" % (sumoBinary, addOption), shell=True, stdout=sys.stdout) traciControl.initTraCI(PORT) while not step>traciEndTime: traciControl.cmdSimulationStep2(DELTA_T) vehs = traciControl.cmdGetVehicleVariable_idList() if vehs.index("horiz")<0 or len(vehs)>1: print "Something is false" step += 1 print "Print ended at step %s" % (traciControl.cmdGetSimulationVariable_currentTime()/DELTA_T) traciControl.cmdClose() sys.stdout.flush()
def runSingle(addOption): step = 0 timeline = [] sumoProcess = subprocess.Popen("%s -c %s %s" % (sumoBinary, "sumo.sumo.cfg", addOption), shell=True, stdout=sys.stdout) traciControl.initTraCI(PORT) while not step > 10000: try: traciControl.cmdSimulationStep2(DELTA_T) vehs = traciControl.cmdGetVehicleVariable_idList() timeline.append({}) for v in vehs: timeline[-1][v] = traciControl.cmdGetVehicleVariable_speed(v) step += 1 except traciControl.FatalTraCIError: print "Closed by SUMO" break traciControl.cmdClose() sys.stdout.flush() return timeline
def runSimulation(self): print "ESTA AKI!!!!!!!!!!!!!!!!!!!!!!" f = open('output.txt', 'a') f.write( 'Network = ' + sys.argv[1] + '\nnumpy.average(durations) numpy.average(routeLengths) avgOccupancyAvgs avgDevOccupancyStdDevs)\n' ) # create set of plans # os.system('python ../simulations/randomTrips2.py -n ' + self.__networkFile + ' -o trips.xml -r ' + self.__routesFile + ' -e ' + sys.argv[2] + ' -p ' + sys.argv[3] + ' -B ' + sys.argv[4]) print "ESTA AKI2!!!!!!!!!!!!!!!!!!!!!!" # calls for the parsing of the network file self.__population = Population(self.__routesFile, self.__network) if not self.__population.isValid(): sys.exit('Can\'t parse the file ' + self.__routesFile + '. Please recheck the file\'s name and syntax') GRAPHICAL_INTERFACE = 1 # starts sumo and opens communication with traci (-N para iniciar o sumo-gui em pausa) if (GRAPHICAL_INTERFACE): subprocess.Popen('%s -c %s -N' % (os.path.join( '..', '..', 'sumo-0.12.2', 'bin', 'sumo-gui'), sys.argv[1]), shell=True, stdout=sys.stdout) else: subprocess.Popen('%s -c %s' % (os.path.join( '..', '..', 'sumo-0.12.2', 'bin', 'sumo'), sys.argv[1]), shell=True, stdout=sys.stdout) initTraCI(self.__port) activeAgents = [] stoppedAgents = [] # runs until simulation time is over and there is no more active agents simulationStep = self.__simulationFirstStep testess = 0 while not (simulationStep >= self.__simulationFinalStep and activeAgents == []): # advances 1s in the simulation and checks for active agents simulationStep += 1 activeAgents = cmdSimulationStep(1000) if len(activeAgents) == 0: continue # updates status of stopped agents self.__accidentTimer(stoppedAgents) # updates the network weights and statistics and checks agent decisions, providing departed and arrived agents for the simulated step self.__updateEdgeWeights() #print self.__network #self.__network.updateOccupancyStats() self.__population.agentActions( simulationStep, cmdGetSimulationVariable_departedIDList(), cmdGetSimulationVariable_arrivedIDList(), testess, self) testess = (testess + 1) % 2 #print testess # simulates accidents #if random.random() < ACCIDENT_PROBABILITY: # self.__simulateAccident(stoppedAgents,simulationStep) # closes the communication with traci cmdClose() # adds simulation results to output file and decreases number of scheduled simulations self.__printSimulationOutput(f)
for root, dirs, files in os.walk(srcRoot): if "input_edges.edg.xml" in files: roots.append(root) for root in sorted(roots): print "-- Test: %s" % root[len(srcRoot)+1:] prefix = os.path.join(root, "input_") sys.stdout.flush() subprocess.call([netconvertBinary, "-n", prefix+"nodes.nod.xml", "-e", prefix+"edges.edg.xml", "-x", prefix+"connections.con.xml", "-o", "./input_net.net.xml"], stdout=sys.stdout) sys.stdout.flush() shutil.copy(prefix + "routes.rou.xml", "./input_routes.rou.xml") shutil.copy(prefix + "additional.add.xml", "./input_additional.add.xml") sumoProcess = subprocess.Popen("%s -c sumo.sumo.cfg" % (sumoBinary), shell=True, stdout=sys.stdout) traciControl.initTraCI(8813) step = 0 traciControl.cmdSimulationStep(DELTA_T) step += 1 lanes = traciControl.cmdGetVehicleVariable_bestLanes("0") sys.stdout.flush() for l in lanes: print "lane %s:" % (l[0]) print " length: %s" % (l[1]) print " offset: %s" % (l[3]) print " allowsContinuation: %s" % (l[4]) print " over: %s" % (l[5]) traciControl.cmdClose() sys.stdout.flush() fdi = open(root + "/expected.txt")
vehNr, i) vehNr += 1 lastVeh = i print >> routes, "</routes>" routes.close() sumoExe = "sumo-gui" if "SUMO" in os.environ: sumoExe = os.path.join(os.environ["SUMO"], "sumo-gui") sumoConfig = "cross.sumo.cfg" sumoProcess = subprocess.Popen("%s -c %s" % (sumoExe, sumoConfig), shell=True, stdout=sys.stdout) initTraCI(PORT) programPointer = len(PROGRAM) - 1 veh = [] step = 0 while not (step > lastVeh and veh == []): veh = cmdSimulationStep(1000) programPointer = min(programPointer + 1, len(PROGRAM) - 1) no = cmdGetInductionLoopVariable_lastStepVehicleNumber("0") if no > 0: programPointer = (0 if programPointer == len(PROGRAM) - 1 else 3) cmdChangeTrafficLightsVariable_stateRYG("0", PROGRAM[programPointer]) step += 1 cmdClose()
vehNr += 1 lastVeh = i print >> routes, "</routes>" routes.close() sumoExe = "sumo-gui" if "SUMO" in os.environ: sumoExe = os.path.join(os.environ["SUMO"], "sumo-gui") sumoConfig = "cross.sumo.cfg" sumoProcess = subprocess.Popen("%s -c %s" % (sumoExe, sumoConfig), shell=True, stdout=sys.stdout) initTraCI(PORT) programPointer = len(PROGRAM)-1 veh = [] step = 0 while not (step > lastVeh and veh == []): veh = cmdSimulationStep(1000) programPointer = min(programPointer+1, len(PROGRAM)-1) no = cmdGetInductionLoopVariable_lastStepVehicleNumber("0") if no > 0: programPointer = (0 if programPointer == len(PROGRAM)-1 else 3) cmdChangeTrafficLightsVariable_stateRYG("0", PROGRAM[programPointer]) step += 1 cmdClose()