Exemplo n.º 1
0
    def create_epos_output_files(self, sourceID, targetID, tick, agent_ind):

        router_res_length = CustomRouter.route_by_min_length(
            sourceID, targetID)
        if len(router_res_length.route) > 0:
            self.create_output_files(
                history_prefs[self.id]["min_length"], router_res_length.route,
                self.find_occupancy_for_route(router_res_length.meta),
                agent_ind)

        router_res_speeds = CustomRouter.route_by_max_speed(sourceID, targetID)
        if len(router_res_speeds.route) > 0:
            self.create_output_files(
                history_prefs[self.id]["max_speed"], router_res_speeds.route,
                self.find_occupancy_for_route(router_res_speeds.meta),
                agent_ind)

        router_res_length_and_speeds = CustomRouter.minimalRoute(
            sourceID, targetID)
        if len(router_res_length_and_speeds.route) > 0:
            self.create_output_files(
                history_prefs[self.id]["balanced"],
                router_res_length_and_speeds.route,
                self.find_occupancy_for_route(
                    router_res_length_and_speeds.meta), agent_ind)
Exemplo n.º 2
0
    def setArrived(self, tick):
        """ car arrived at its target, so we add some statistic data """

        # import here because python can not handle circular-dependencies
        from app.entitiy.CarRegistry import CarRegistry
        # add a round to the car
        self.rounds += 1
        self.lastRerouteCounter = 0
        if tick > Config.initialWaitTicks and self.smartCar:  # as we ignore the first 1000 ticks for this
            # add a route to the global registry
            CarRegistry.totalTrips += 1
            # add the duration for this route to the global tripAverage
            durationForTrip = (tick - self.currentRouteBeginTick)
            CarRegistry.totalTripAverage = addToAverage(
                CarRegistry.totalTrips,  # 100 for faster updates
                CarRegistry.totalTripAverage,
                durationForTrip)
            # CSVLogger.logEvent("arrived", [tick, self.sourceID, self.targetID,
            #                                durationForTip, self.id,self.currentRouterResult.isVictim])
            # log the overrhead values
            minimalCosts = CustomRouter.minimalRoute(self.sourceID,
                                                     self.targetID, None,
                                                     None).totalCost
            tripOverhead = durationForTrip / minimalCosts / 1.1  # 1.6 is to correct acceleration and deceleration
            # when the distance is very short, we have no overhead
            if durationForTrip < 10:
                tripOverhead = 1
            # in rare cases a trip does take very long - as most outliers are <30, we cap the overhead to 30 here
            if tripOverhead > 30:
                print("-> capped overhead to 30 - " + str(minimalCosts) +
                      " - " + str(durationForTrip) + " - " + str(tripOverhead))
                tripOverhead = 30

            CarRegistry.totalTripOverheadAverage = addToAverage(
                CarRegistry.totalTrips, CarRegistry.totalTripOverheadAverage,
                tripOverhead)
            CSVLogger.logEvent("overhead", [
                tick, self.sourceID, self.targetID, durationForTrip,
                minimalCosts, tripOverhead, self.id,
                self.currentRouterResult.isVictim
            ])
            # log to kafka
            msg = dict()
            msg["tick"] = tick
            msg["overhead"] = tripOverhead
            msg["complaint"] = self.generate_complaint(tripOverhead)
            RTXForword.publish(msg, Config.kafkaTopicTrips)

        # if car is still enabled, restart it in the simulation
        if self.disabled is False:
            self.addToSimulation(tick)
Exemplo n.º 3
0
    def setArrived(self, tick):
        """ car arrived at its target, so we add some statistic data """

        # import here because python can not handle circular-dependencies
        from app.entity.CarRegistry import CarRegistry

        self.lastRerouteCounter = 0
        if self.smartCar:  # as we ignore the first 1000 ticks for this
            # add a route to the global registry
            CarRegistry.totalTrips += 1
            # add the duration for this route to the global tripAverage
            durationForTrip = (tick - self.currentRouteBeginTick)
            CarRegistry.totalTripAverage = addToAverage(
                CarRegistry.totalTrips,  # 100 for faster updates
                CarRegistry.totalTripAverage,
                durationForTrip)

            minimalCosts = CustomRouter.minimalRoute(self.sourceID,
                                                     self.targetID).totalCost
            tripOverhead = durationForTrip / minimalCosts / 1.1  # 1.6 is to correct acceleration and deceleration
            # when the distance is very short, we have no overhead
            if durationForTrip < 10:
                tripOverhead = 1
            # in rare cases a trip does take very long - as most outliers are <30, we cap the overhead to 30 here
            if tripOverhead > 30:
                print("-> capped overhead to 30 - " + str(minimalCosts) +
                      " - " + str(durationForTrip) + " - " + str(tripOverhead))
                tripOverhead = 30

            CarRegistry.totalTripOverheadAverage = addToAverage(
                CarRegistry.totalTrips, CarRegistry.totalTripOverheadAverage,
                tripOverhead)

            CSVLogger.logEvent("overheads", [
                tick, self.sourceID, self.targetID, self.rounds,
                durationForTrip, minimalCosts, tripOverhead, self.id,
                self.driver_preference
            ])

        # if car is still enabled, restart it in the simulation
        if self.disabled is False:
            # add a round to the car
            self.rounds += 1
            self.addToSimulation(tick, False)
Exemplo n.º 4
0
    def __createNewRoute(self, tick):
        """ creates a new route to a random target and uploads this route to SUMO """
        if self.targetID is None:
            self.sourceID = Network.get_random_node_id_of_passenger_edge(
                random)
        else:
            self.sourceID = self.targetID  # We start where we stopped
        self.targetID = Network.get_random_node_id_of_passenger_edge(random)
        self.currentRouteID = self.id + "-" + str(self.rounds)

        try:
            if self.driver_preference == "min_length":
                self.currentRouterResult = CustomRouter.route_by_min_length(
                    self.sourceID, self.targetID)
            elif self.driver_preference == "max_speed":
                self.currentRouterResult = CustomRouter.route_by_max_speed(
                    self.sourceID, self.targetID)
            else:
                self.currentRouterResult = CustomRouter.minimalRoute(
                    self.sourceID, self.targetID)

            if len(self.currentRouterResult.route) > 0:
                traci.route.add(self.currentRouteID,
                                self.currentRouterResult.route)
                return self.currentRouteID
            else:
                if Config.debug:
                    print "vehicle " + str(
                        self.id) + " could not be added, retrying"
                return self.__createNewRoute(tick)

        except:
            if Config.debug:
                print "vehicle " + str(
                    self.id) + " could not be added [exception], retrying"
            return self.__createNewRoute(tick)