def run(self): self.data_file = open(self.data_file_name, 'w') # count arrived cars and capacity self.car_arrived = 0; self.cap_arrived = 0; for episode in range(NUM_EPISODE - 1): # note this -1 # visualization if self.vis: #print("==========================================================") #print("{:<6} {:<6} {:<6}".format("CarID", "Position", "Destination")) #for car in self.cars: # car.print_status() print("Current episode: "), ;print(episode) self.test_world.draw() if self.mouse == 1: self.test_world.window.getMouse() # cars make decision simutaneously except ASTAR for car in self.cars: if not(car.arrived): if self.alg == STP: car.greedy_act() elif self.alg == ASTAR: car.astar_act() else: # heuristic to improve efficiency of SCMDP algorithms if TOTAL_CAP - self.cap_arrived <= self.test_world.min_cap and SCMDP_STP == True: # print("Switched to STP algorithm") car.greedy_act() else: car.sc_act(self.scmdp_selector, episode, self.state_dict, self.alg) # ASTAR cars move sequentially if self.alg == ASTAR: car.exec_act() if car.check_arrived(): self.car_arrived += 1 self.cap_arrived += car.cap # execute the move if self.alg != ASTAR: for car in self.cars: if not(car.arrived): car.exec_act() if car.check_arrived(): self.car_arrived += 1 self.cap_arrived += car.cap # recording self.record(episode) print("Capacities Arrived at Destinations:"), ;print(self.cap_arrived) # visualization of last step if self.vis: #print("==========================================================") #print("{:<6} {:<6} {:<6}".format("CarID", "Position", "Destination")) #for car in self.cars: # car.print_status() print("Current episode: "), ;print(episode + 1) self.test_world.draw() if self.mouse == 1: self.test_world.window.getMouse() print("Capacities Arrived at Destinations:"), ;print(self.cap_arrived)
def run(self): while (True): # visualization if self.vis: print("==========================================================") print("{:<6} {:<6} {:<6}".format("CarID", "Position", "Destination")) for car in self.cars: car.print_status() self.test_world.draw() self.test_world.window.getMouse() for car in self.cars: if self.alg == GREEDY: car.greedy_act()