Esempio n. 1
0
    def create_epos_output_files_based_on_current_location(
            self, tick, agent_ind):
        route = traci.vehicle.getRoute(self.id)
        route_index = traci.vehicle.getRouteIndex(self.id)
        if route_index < 0:
            if Config.debug:
                print self.id + "\thas not yet started its trip and won't be considered in the optimization."
            return False
        previousEdgeID = route[route_index]
        previousNodeID = Network.getEdgeIDsToNode(previousEdgeID).getID()

        if previousNodeID == self.targetID:
            if Config.debug:
                print self.id + "\tis already reaching its destination and won't be considered in the optimization."
            return False

        self.create_epos_output_files(previousNodeID, self.targetID, tick,
                                      agent_ind)
        return True
Esempio n. 2
0
    def processTick(self, tick):
        """ process changes that happened in the tick to this car """

        self.lastRerouteCounter += 1
        # reroute every x ticks based on config value
        if self.lastRerouteCounter >= CustomRouter.reRouteEveryTicks and CustomRouter.reRouteEveryTicks > 0:
            self.lastRerouteCounter = 0
            if self.smartCar:
                try:
                    oldRoute = self.currentRouterResult.route
                    currentEdgeID = traci.vehicle.getRoadID(self.id)
                    nextNodeID = Network.getEdgeIDsToNode(
                        currentEdgeID).getID()
                    self.currentRouterResult = CustomRouter.route(
                        nextNodeID, self.targetID, tick, self)
                    traci.vehicle.setRoute(self.id, [currentEdgeID] +
                                           self.currentRouterResult.route)
                    # print("OLD: " + str(oldRoute) + " - NEW: " + str(self.currentRouterResult.route))
                except IndexError as e:
                    # print(e)
                    pass
                except traci.exceptions.TraCIException as e:
                    # print(e)
                    pass

        roadID = traci.vehicle.getSubscriptionResults(self.id)[80]
        if roadID != self.currentEdgeID and self.smartCar:
            if self.currentEdgeBeginTick is not None:
                CustomRouter.applyEdgeDurationToAverage(
                    self.currentEdgeID, tick - self.currentEdgeBeginTick, tick)
                # CSVLogger.logEvent("edge", [tick, self.currentEdgeID,
                #                             tick - self.currentEdgeBeginTick, self.id])
                # log to kafak
                # msg = dict()
                # msg["tick"] = tick
                # msg["edgeID"] = self.currentEdgeID,
                # msg["duration"] = tick - self.currentEdgeBeginTick
            # print("changed route to: " + roadID)
            self.currentEdgeBeginTick = tick
            self.currentEdgeID = roadID
            pass