Open SeanMcOwen opened 4 months ago
A lot of these can probably be state preparation functions to more easily encapsulate
def adjust_inputs(seed=0, upper_limit=1000): base_width = 4 base_height = 4 base_weight = 2 base_num_riders = 4
seed = max(0, min(seed, 100)) random.seed(time.time()) increase_factor = 1 + (seed / 100) * 500 random_factor = lambda: random.uniform(0.9, 1.1) grid_width = ceil(base_width * increase_factor * random_factor()) grid_height = ceil(base_height * increase_factor * random_factor()) grid_weight = ceil(base_weight * increase_factor * random_factor()) num_riders = ceil(base_num_riders * increase_factor * random_factor()) rider_driver_delta = random.randint(-100, -1) num_drivers = max(1, min(num_riders + rider_driver_delta, upper_limit)) grid_width = max(2, min(grid_width, 15)) grid_height = max(2, min(grid_height, 15)) grid_weight = max(1, min(grid_weight, 10)) num_riders = max(1, min(num_riders, upper_limit)) num_drivers = max(1, min(num_drivers, num_riders - 1)) grid = Grid(width=grid_width, height=grid_height) shortest_paths = grid.shortest_paths riders = [Rider(f'Rider {i}', random.choice(list(grid.zones.values()))) for i in range(num_riders)] drivers = [Driver(f'Driver {i}', random.choice(list(grid.zones.values())), { "cost_weight": 0.4, "distance_weight": 0.1, "duration_weight": 0.1, "driver_rating_weight": 0.2, "rider_rating_weight": 0.2, "acceptance_threshold": 20 }) for i in range(floor(num_riders / 4))] ride_requests = { i + 1: RideRequest(i + 1, riders[i], random.choice(list(grid.zones.values())), random.choice(list(grid.zones.values())), grid) for i in range(num_riders) } return grid, riders, drivers, ride_requests
A lot of these can probably be state preparation functions to more easily encapsulate
def adjust_inputs(seed=0, upper_limit=1000): base_width = 4 base_height = 4 base_weight = 2 base_num_riders = 4