def start(processID, parallelMode,useGUI): random.seed(Config.random_seed) """ main entry point into the application """ Config.parallelMode = parallelMode Config.sumoUseGUI = useGUI info('#####################################', Fore.CYAN) info('# Starting TRAPP v0.1 #', Fore.CYAN) info('#####################################', Fore.CYAN) # Check if sumo is installed and available SUMODependency.checkDeps() info('# SUMO-Dependency check OK!', Fore.GREEN) # Load the sumo map we are using into Python Network.loadNetwork() info(Fore.GREEN + "# Map loading OK! " + Fore.RESET) info(Fore.CYAN + "# Nodes: " + str(Network.nodesCount()) + " / Edges: " + str(Network.edgesCount()) + Fore.RESET) # After the network is loaded, we init the router CustomRouter.init() # Start sumo in the background SUMOConnector.start() info("\n# SUMO-Application started OK!", Fore.GREEN) # Start the simulation Simulation.start() # Simulation ended, so we shutdown info(Fore.RED + '# Shutdown' + Fore.RESET) traci.close() sys.stdout.flush() return None
def do_epos_planning(cls, tick): prepare_epos_input_data_folders() cars_to_indexes = {} i = 0 for car_id, car in CarRegistry.cars.iteritems(): if car.create_epos_output_files_based_on_current_location( tick, str(i)): cars_to_indexes[car_id] = i i += 1 number_of_epos_plans = len([ name for name in os.listdir('datasets/plans') if name.endswith("plans") ]) print "Number of EPOS plans: " + str(number_of_epos_plans) Knowledge.time_of_last_EPOS_invocation = tick cls.change_EPOS_config("conf/epos.properties", "numAgents=", "numAgents=" + str(number_of_epos_plans)) cls.change_EPOS_config( "conf/epos.properties", "planDim=", "planDim=" + str(Network.edgesCount() * Knowledge.planning_steps)) cls.change_EPOS_config("conf/epos.properties", "alpha=", "alpha=" + str(Knowledge.alpha)) cls.change_EPOS_config("conf/epos.properties", "beta=", "beta=" + str(Knowledge.beta)) cls.change_EPOS_config( "conf/epos.properties", "globalCostFunction=", "globalCostFunction=" + str(Knowledge.globalCostFunction)) cls.run_epos_apply_results(False, cars_to_indexes, tick)
def start(processID, parallelMode, useGUI): """ main entry point into the application """ Config.processID = processID Config.parallelMode = parallelMode Config.sumoUseGUI = useGUI info('#####################################', Fore.CYAN) info('# Starting CrowdNav v0.2 #', Fore.CYAN) info('#####################################', Fore.CYAN) info('# Configuration:', Fore.YELLOW) info('# Kafka-Host -> ' + Config.kafkaHost, Fore.YELLOW) info('# Kafka-Topic1 -> ' + Config.kafkaTopicTrips, Fore.YELLOW) info('# Kafka-Topic2 -> ' + Config.kafkaTopicPerformance, Fore.YELLOW) # init sending updates to kafka and getting commands from there if Config.kafkaUpdates or Config.mqttUpdates: RTXForword.connect() RTXConnector.connect() # Check if sumo is installed and available SUMODependency.checkDeps() info('# SUMO-Dependency check OK!', Fore.GREEN) # Load the sumo map we are using into Python Network.loadNetwork() info(Fore.GREEN + "# Map loading OK! " + Fore.RESET) info(Fore.CYAN + "# Nodes: " + str(Network.nodesCount()) + " / Edges: " + str(Network.edgesCount()) + Fore.RESET) # After the network is loaded, we init the router CustomRouter.init() # Start sumo in the background SUMOConnector.start() info("\n# SUMO-Application started OK!", Fore.GREEN) # Start the simulation Simulation.start() # Simulation ended, so we shutdown info(Fore.RED + '# Shutdown' + Fore.RESET) traci.close() sys.stdout.flush() return None
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)
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
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
def start(cls): Knowledge.planning_period = Config.planning_period Knowledge.planning_step_horizon = Config.planning_step_horizon Knowledge.planning_steps = Config.planning_steps Knowledge.alpha = Config.alpha Knowledge.beta = Config.beta Knowledge.globalCostFunction = Config.globalCostFunction Util.remove_overhead_and_streets_files() Util.add_data_folder_if_missing() CSVLogger.logEvent("streets", [edge.id for edge in Network.routingEdges]) Util.prepare_epos_input_data_folders() """ start the simulation """ info("# Start adding initial cars to the simulation", Fore.MAGENTA) # apply the configuration from the json file cls.applyFileConfig() CarRegistry.applyCarCounter() if Config.start_with_epos_optimization: Knowledge.time_of_last_EPOS_invocation = 0 CarRegistry.change_EPOS_config("conf/epos.properties", "numAgents=", "numAgents=" + str(Config.totalCarCounter)) CarRegistry.change_EPOS_config("conf/epos.properties", "planDim=", "planDim=" + str(Network.edgesCount() * Knowledge.planning_steps)) CarRegistry.change_EPOS_config("conf/epos.properties", "alpha=", "alpha=" + str(Knowledge.alpha)) CarRegistry.change_EPOS_config("conf/epos.properties", "beta=", "beta=" + str(Knowledge.beta)) CarRegistry.change_EPOS_config("conf/epos.properties", "globalCostFunction=", "globalCostFunction=" + str(Knowledge.globalCostFunction)) cars_to_indexes = {} for i in range(Config.totalCarCounter): cars_to_indexes["car-" + str(i)] = i CarRegistry.run_epos_apply_results(True, cars_to_indexes, 0) cls.loop()