示例#1
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)
示例#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.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)
示例#3
0
 def applyEdgeDurationToAverage(self, duration, tick):
     """ adds a duration to drive on this edge to the calculation """
     # VARIANTE 1
     # # if a hugh traffic happened some time ago, the new values should be more important
     oldDataInfluence = max(
         1,
         self.edgeAverageInfluence - (tick - self.lastDurationUpdateTick))
     # # self.averageDurationCounter += 1 -- not used
     self.averageDuration = addToAverage(oldDataInfluence,
                                         self.averageDuration, duration)
     # # print(str(oldDataInfluence))
     self.lastDurationUpdateTick = tick