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 __simulateAccident(self, stoppedAgents, simulationStep): #print 'UI' agentIdList = cmdGetVehicleVariable_idList() agentId = agentIdList[random.randint(0, len(agentIdList) - 1)] alreadyStopped = False for stoppedAgent in stoppedAgents: if agentId == stoppedAgent[0]: alreadyStopped = True break if not alreadyStopped: cmdChangeVehicleVariable_speed(agentId, 0) cmdChangeVehicleVariable_color(agentId, STOPPED_AGENT_COLOR) stoppedAgents.append((agentId, ACCIDENT_STOP_TIME)) currentLane = cmdGetVehicleVariable_laneID(agentId) self.__population.stop(agentId, currentLane, ACCIDENT_STOP_TIME, simulationStep)
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