def test_allocate(): intersections = [ # (x,y) is the place of a intersection (0, 0), (0, 2), (0, 6), (0, 8), (0, 12), (0, 14), (2, 0), (2, 2), (2, 6), (2, 7), (2, 8), (2, 12), (2, 14), (3, 0), (3, 2), (3, 6), (3, 7), (3, 8), (3, 12), (3, 14), (4, 0), (4, 2), (4, 4), (4, 6), (4, 7), (4, 8), (4, 12), (4, 14), (5, 0), (5, 2), (5, 4), (5, 6), (5, 8), (5, 12), (5, 14), (7, 0), (7, 2), (7, 4), (7, 6), (7, 8), (7, 12), (7, 14), ] city = City(intersections, 0, None) coordinator = TaxiCoordinator( city=city, auction_type='first-price', drivers_schedule=[ #[(0, 12)], #[(0, 12)], [10, 24] ], init_pos=(4, 8)) print(coordinator.drivers) while city.time_sys.hour_in_sim() < 24: customer_calls = city.step() coordinator.allocate(customer_calls)
def test_payoff_bidding(): intersections = [ # (x,y) is the place of a intersection (0, 0), (0, 2), (0, 6), (0, 8), (0, 12), (0, 14), (2, 0), (2, 2), (2, 6), (2, 7), (2, 8), (2, 12), (2, 14), (3, 0), (3, 2), (3, 6), (3, 7), (3, 8), (3, 12), (3, 14), (4, 0), (4, 2), (4, 4), (4, 6), (4, 7), (4, 8), (4, 12), (4, 14), (5, 0), (5, 2), (5, 4), (5, 6), (5, 8), (5, 12), (5, 14), (7, 0), (7, 2), (7, 4), (7, 6), (7, 8), (7, 12), (7, 14), ] city = City(intersections, 0) coordinator = TaxiCoordinator(city=city, auction_type='second-price', drivers_schedule=[[], [], []], init_pos=(4, 8)) while city.time_sys.hour_in_sim() < 24: customer_calls = city.step() coordinator.allocate(customer_calls) for driver in coordinator.drivers: print('Driver-{} payoff {}'.format(driver.idx, driver.get_payoff())) print('Company payoff', coordinator.get_payoff())
def test_payoff_bidding_city_lambd_schedule(): from util.common import daily_schedules_to_weekly_schedules intersections = [ # (x,y) is the place of a intersection (0, 0), (0, 2), (0, 6), (0, 8), (0, 12), (0, 14), (2, 0), (2, 2), (2, 6), (2, 7), (2, 8), (2, 12), (2, 14), (3, 0), (3, 2), (3, 6), (3, 7), (3, 8), (3, 12), (3, 14), (4, 0), (4, 2), (4, 4), (4, 6), (4, 7), (4, 8), (4, 12), (4, 14), (5, 0), (5, 2), (5, 4), (5, 6), (5, 8), (5, 12), (5, 14), (7, 0), (7, 2), (7, 4), (7, 6), (7, 8), (7, 12), (7, 14), ] lambd_schedule = [(7, 9, 3.0), (17, 19, 3.0), (9, 17, 2.0), (19, 23, 2.0)] city = City(intersections, 0, lambd_schedule) daily_schedule_for_drivers = [[(8, 12), (14, 23)], [(10, 12)]] weekly_schedule_for_drivers = daily_schedules_to_weekly_schedules( daily_schedule_for_drivers) coordinator = TaxiCoordinator(city=city, auction_type='second-price', drivers_schedule=weekly_schedule_for_drivers, init_pos=(4, 8)) while city.time_sys.hour_in_sim() < 24: customer_calls = city.step() coordinator.allocate(customer_calls) for driver in coordinator.drivers: print('Driver-{} payoff {}'.format(driver.idx, driver.get_payoff())) print('Company payoff', coordinator.get_payoff())
config = Config(waiting_time_threshold=args.waiting_time_threshold, payment_ratio=args.payment_ratio) city = City(config.intersections, initial_hour=0, lambd_schedule=config.city_lambd_schedule) coordinator = TaxiCoordinator(city=city, auction_type=args.auction_type, payment_rule=args.payment_rule, bidding_strategy=args.bidding_strategy, drivers_schedule=config.driver_schedules, init_pos=config.init_pos, payment_ratio=config.payment_ratio, driving_velocity=config.driving_velocity, charge_rate_per_kilometer=config.charge_rate_per_kilometer, gas_cost_per_kilometer=config.gas_cost_per_kilometer, waiting_time_threshold=config.waiting_time_threshold) while city.time_sys.hour_in_sim() < args.timelimit: customer_calls = city.step() coordinator.allocate(customer_calls) if args.bidding_strategy == 'lookahead' and city.time_sys.hour_in_sim() % 8 == 0: coordinator.train() logging.info('Update the lookahead policy.') if args.dump: coordinator.dump_history_payoff(os.path.join('data', 'company-history-payoff.npy')) if args.dump: coordinator.dump_history_calls_json(os.path.join('data', 'history-calls.json')) # Print driver status print('===Drivers===') stats_drivers = [] for driver in coordinator.drivers: events = driver.generate_complete_schedule(args.timelimit).events
(3, 6), (3, 7), (3, 8), (3, 12), (3, 14), (4, 0), (4, 2), (4, 4), (4, 6), (4, 7), (4, 8), (4, 12), (4, 14), (5, 0), (5, 2), (5, 4), (5, 6), (5, 8), (5, 12), (5, 14), (7, 0), (7, 2), (7, 4), (7, 6), (7, 8), (7, 12), (7, 14), ] city = City(intersections, 0, None) city.step()