Пример #1
0
    def start(self, stations, program, config_file):
        PORT = 8813
        sumoBinary = checkBinary(program)
        myfile = (os.path.join(os.path.dirname(__file__),
                               "data/%s" % config_file))
        sumoConfig = myfile

        if not trace.isEmbedded():
            os.system(' %s -c %s &' % (sumoBinary, sumoConfig))
            #subprocess.Popen(' %s -c  %s' % (sumoBinary,sumoConfig), shell=True, stdout=sys.stdout)
            trace.init(PORT)

        step = 0
        ListVeh = []
        ListTravelTime = []
        Visited = []
        ListVisited = []
        time = []
        speed = []
        ListVehInteract = []
        self.setWifiParameters()

        #while len(ListVeh) < len(nodes):
        while True:
            trace.simulationStep()
            for vehID in trace.vehicle.getIDList():
                if not (vehID in ListVeh):
                    Initialisation = initialisation(ListVeh, ListTravelTime,
                                                    ListVisited, Visited, time,
                                                    speed, vehID)
                    ListVeh = Initialisation[0]
                    ListTravelTime = Initialisation[1]
                    ListVisited = Initialisation[2]
                    Visited = Initialisation[3]
                    time = Initialisation[4]
                    speed = Initialisation[5]

                NoChangeSaveTimeAndSpeed = noChangeSaveTimeAndSpeed(
                    Visited, ListVeh, time, speed, vehID)
                Visited = NoChangeSaveTimeAndSpeed[0]
                time = NoChangeSaveTimeAndSpeed[1]
                speed = NoChangeSaveTimeAndSpeed[2]

                ChangeSaveTimeAndSpeed = changeSaveTimeAndSpeed(
                    Visited, ListVeh, time, speed, ListVisited, vehID,
                    ListTravelTime)
                Visited = ChangeSaveTimeAndSpeed[0]
                time = ChangeSaveTimeAndSpeed[1]
                speed = ChangeSaveTimeAndSpeed[2]
                ListVisited = ChangeSaveTimeAndSpeed[3]
                ListTravelTime = ChangeSaveTimeAndSpeed[4]

            for vehID2 in trace.vehicle.getIDList():
                for vehID1 in trace.vehicle.getIDList():
                    Road1 = trace.vehicle.getRoadID(vehID1)
                    Road2 = trace.vehicle.getRoadID(vehID2)
                    OppositeRoad1 = '-' + Road1
                    OppositeRoad2 = '-' + Road2
                    if not ((vehID2, vehID1) in ListVehInteract):
                        x1 = trace.vehicle.getPosition(vehID1)[0]
                        y1 = trace.vehicle.getPosition(vehID1)[1]
                        x2 = trace.vehicle.getPosition(vehID2)[0]
                        y2 = trace.vehicle.getPosition(vehID2)[1]

                        if int(vehID1) < len(stations):
                            stations[int(
                                vehID1)].params['position'] = x1, y1, 0
                            #stations[int(vehID1)].params['range'] = 130

                        if abs(x1 - x2) > 0 and abs(x1 - x2) < 20 and (
                                Road1 == OppositeRoad2
                                or Road2 == OppositeRoad1):
                            ListVehInteract.append((vehID2, vehID1))
                            Route2 = trace.vehicle.getRoute(vehID2)
                            Route1 = trace.vehicle.getRoute(vehID1)
                            Index2 = Route2.index(
                                trace.vehicle.getRoadID(vehID2))
                            Index1 = Route1.index(
                                trace.vehicle.getRoadID(vehID1))
                            VisitedEdge2 = ListVisited[ListVeh.index(vehID2)][
                                0:len(ListVisited[ListVeh.index(vehID2)]) - 1]
                            reroutage(VisitedEdge2, ListTravelTime, vehID1,
                                      vehID2, ListVeh)
            step = step + 1
        trace.close()
        sys.stdout.flush()
Пример #2
0
    def start(self, cars, config_file, clients, port):
        sumoBinary = checkBinary('sumo-gui')
        myfile = (os.path.join(os.path.dirname(__file__),
                               "data/%s" % config_file))
        sumoConfig = myfile

        if not trace.isEmbedded():
            os.system(' %s -c %s --num-clients %s '
                      '--remote-port %s &' %
                      (sumoBinary, sumoConfig, clients, port))
            trace.init(port)
            trace.setOrder(0)

        step = 0
        speed = []
        time = []
        visited = []
        veh_list = []
        visited_list = []
        veh_interact_list = []
        travel_time_list = []
        self.setWifiParameters()

        while True:
            trace.simulationStep()
            vehicleCommands = trace._vehicle.VehicleDomain()
            vehicleCommands._connection = trace.getConnection(label="default")
            for vehID in vehicleCommands.getIDList():
                if not (vehID in veh_list):
                    init = initialisation(veh_list, travel_time_list,
                                          visited_list, visited, time, speed,
                                          vehID, vehicleCommands)
                    veh_list = init[0]
                    travel_time_list = init[1]
                    visited_list = init[2]
                    visited = init[3]
                    time = init[4]
                    speed = init[5]

                no_change = noChangeSaveTimeAndSpeed(visited, veh_list, time,
                                                     speed, vehID,
                                                     vehicleCommands)
                visited = no_change[0]
                time = no_change[1]
                speed = no_change[2]

                change = changeSaveTimeAndSpeed(visited, veh_list, time, speed,
                                                visited_list, vehID,
                                                travel_time_list,
                                                vehicleCommands)
                visited = change[0]
                time = change[1]
                speed = change[2]
                visited_list = change[3]
                travel_time_list = change[4]

            for vehID2 in vehicleCommands.getIDList():
                for vehID1 in vehicleCommands.getIDList():
                    road1 = vehicleCommands.getRoadID(vehID1)
                    road2 = vehicleCommands.getRoadID(vehID2)
                    opposite_road1 = '-' + road1
                    opposite_road2 = '-' + road2
                    if not ((vehID2, vehID1) in veh_interact_list):
                        x1 = vehicleCommands.getPosition(vehID1)[0]
                        y1 = vehicleCommands.getPosition(vehID1)[1]
                        x2 = vehicleCommands.getPosition(vehID2)[0]
                        y2 = vehicleCommands.getPosition(vehID2)[1]

                        if int(vehID1) < len(cars):
                            cars[int(vehID1)].params['position'] = x1, y1, 0
                            cars[int(vehID1)].set_pos_wmediumd(
                                cars[int(vehID1)].params['position'])

                        if abs(x1-x2)>0 and abs(x1-x2)<20 \
                                and (road1 == opposite_road2 or road2 == opposite_road1):
                            veh_interact_list.append((vehID2, vehID1))
                            route2 = vehicleCommands.getRoute(vehID2)
                            route1 = vehicleCommands.getRoute(vehID1)
                            index2 = route2.index(
                                vehicleCommands.getRoadID(vehID2))
                            index1 = route1.index(
                                vehicleCommands.getRoadID(vehID1))
                            visited_edge_2 = visited_list[veh_list.index(
                                vehID2
                            )][0:len(visited_list[veh_list.index(vehID2)]) - 1]
                            reroutage(visited_edge_2, travel_time_list, vehID1,
                                      vehID2, veh_list)
            step = step + 1
        trace.close()
        sys.stdout.flush()
Пример #3
0
    def start( self, cars, config_file, clients, port ):
        sumoBinary = checkBinary('sumo-gui')
        myfile = (os.path.join( os.path.dirname(__file__), "data/%s" % config_file))
        sumoConfig = myfile

        if not trace.isEmbedded():
            os.system(' %s -c %s --num-clients %s '
                      '--remote-port %s &' % (sumoBinary, sumoConfig,
                                              clients, port))
            trace.init(port)
            trace.setOrder(0)

        step = 0
        speed = []
        time = []
        visited = []
        veh_list = []
        visited_list = []
        veh_interact_list = []
        travel_time_list = []
        self.setWifiParameters()

        while True:
            trace.simulationStep()
            vehicleCmds = trace._vehicle.VehicleDomain()
            vehicleCmds._connection = trace.getConnection(label="default")

            for vehID in vehicleCmds.getIDList():
                if not(vehID in veh_list):
                    init=initialisation(veh_list, travel_time_list,
                                        visited_list, visited, time,
                                        speed, vehID, vehicleCmds)
                    veh_list = init[0]
                    travel_time_list = init[1]
                    visited_list = init[2]
                    visited = init[3]
                    time = init[4]
                    speed = init[5]

                no_change = noChangeSaveTimeAndSpeed(
                    visited, veh_list, time, speed, vehID, vehicleCmds)
                visited = no_change[0]
                time = no_change[1]
                speed = no_change[2]

                change = changeSaveTimeAndSpeed(
                    visited, veh_list, time, speed, visited_list, vehID,
                    travel_time_list, vehicleCmds)
                visited = change[0]
                time = change[1]
                speed = change[2]
                visited_list = change[3]
                travel_time_list = change[4]

            for vehID2 in vehicleCmds.getIDList():
                for vehID1 in vehicleCmds.getIDList():
                    road1 = vehicleCmds.getRoadID(vehID1)
                    road2 = vehicleCmds.getRoadID(vehID2)
                    opposite_road1 = '-' + road1
                    opposite_road2 = '-' + road2
                    if not((vehID2,vehID1) in veh_interact_list):
                        x1 = vehicleCmds.getPosition(vehID1)[0]
                        y1 = vehicleCmds.getPosition(vehID1)[1]
                        x2 = vehicleCmds.getPosition(vehID2)[0]
                        y2 = vehicleCmds.getPosition(vehID2)[1]

                        if int(vehID1) < len(cars):
                            cars[int(vehID1)].params['position'] = x1, y1, 0
                            cars[int(vehID1)].set_pos_wmediumd(cars[int(vehID1)].params['position'])

                        if abs(x1-x2)>0 and abs(x1-x2)<20 \
                                and (road1 == opposite_road2 or road2 == opposite_road1):
                            veh_interact_list.append((vehID2,vehID1))
                            route2 = vehicleCmds.getRoute(vehID2)
                            route1 = vehicleCmds.getRoute(vehID1)
                            index2 = route2.index(vehicleCmds.getRoadID(vehID2))
                            index1 = route1.index(vehicleCmds.getRoadID(vehID1))
                            visited_edge_2 = visited_list[veh_list.index(vehID2)][0:len(
                                visited_list[veh_list.index(vehID2)])-1]
                            reroutage(visited_edge_2, travel_time_list,
                                      vehID1, vehID2, veh_list, vehicleCmds)
            step=step+1
        trace.close()
        sys.stdout.flush()