def test_time_dist_fixed_add_with_weight(): random.seed(0) time_dist = TimeDist('fixed', 1, unit='minutes', weight=0.1) \ + TimeDist('fixed', 2, unit='minutes', weight=0.9) counter = Counter([time_dist.random_variate() for i in range(1_000)]) assert counter[timedelta(minutes=1)] == 114 assert counter[timedelta(minutes=2)] == 886
def test_time_dist_fixed_add_another(): time_dist = TimeDist('fixed', 1, unit='minutes', weight=1.0) \ + TimeDist('fixed', 2, unit='minutes', weight=1.0) \ + TimeDist('fixed', 3, unit='minutes', weight=1.0) assert time_dist.random_variate() in (timedelta(minutes=1), timedelta(minutes=2), timedelta(minutes=3))
def test_simulation_helper_skip_load_agents(): restaurants, customers, sessions, couriers = skip_load_agents( date(2020, 4, 29), 'Winnipeg - NW') for restaurant in restaurants: restaurant.wait = TimeDist('norm', 5, 2) simulation = Simulation(restaurants=restaurants, customers=customers, sessions=sessions, couriers=couriers, assigner=MipAssigner(), metrics=[DeliveryTime()]) simulation.run(verbose=0, until=timedelta(2)) simulation.reporting.get_results() assert True
def test_customer_customer_session_started(): env = Env() customer = Customer('test_customer_id', 0, 0, TimeDist('fixed', 10)) env.register(customer) input_data = { 'restaurant_id': 'test_restaurant_id', 'customer_id': 'test_customer_id' } env.publish('customer_session_started', input_data) for topic, output_data in env.run(): if topic == 'order_placed': assert env.now == timedelta(minutes=0) assert input_data == output_data return assert False
def test_mock_restaurant(): env = Env() restaurant = Restaurant('test_id', 0, 0, timedelta(0), timedelta(1), TimeDist('fixed', 10, unit='minutes')) env.register(restaurant) input_data = { 'order_id': '1', 'restaurant_id': restaurant.id, 'customer_id': '3', 'courier_id': '4' } env.publish('courier_at_restaurant', input_data) for topic, output_data in env.run(): if topic == 'restaurant_order_ready': assert env.now == timedelta(minutes=10) assert input_data == output_data return assert False
def __init__(self, wait: Optional[TimeDist] = None, **kwargs) -> None: super().__init__(**kwargs) self.wait = wait or TimeDist('fixed', 0)
def test_time_dist_fixed(): time_dist = TimeDist('fixed', 1, unit='minutes') assert time_dist.random_variate() == timedelta(minutes=1)
def test_time_dist_fixed_add_most_likely_estimate(): time_dist = TimeDist('fixed', 1, unit='minutes', weight=1.0) \ + TimeDist('fixed', 2, unit='minutes', weight=1.0) assert time_dist.most_likely_estimate() == timedelta(seconds=90)
def test_time_dist_fixed_most_likely_estimate(): time_dist = TimeDist('fixed', 1, unit='minutes') assert time_dist.most_likely_estimate() == timedelta(minutes=1)
def __init__(self, average_speed: float = 10.0, noise: Optional[TimeDist] = None) -> None: self.average_speed = average_speed # average speed m/s self.noise = noise or TimeDist('fixed', 0.0) # default
query_job = client.query(query_string, job_config=job_config) return query_job.result().to_dataframe() ''' dfrestaurants = query(qrestaurants) restaurants = query(qrestaurants).values.tolist() restaurants = [Restaurant(id = restaurants[i][0], lat = restaurants[i][1], lng = restaurants[i][2]) for i in range(len(restaurants))] lat = dfrestaurants['address_latitude'].mean() lng = dfrestaurants['address_longitude'].mean() ''' num_customers = 279 radius = 500 # meters num_couriers = 5 num_restaurants = 5 time_dist = TimeDist('norm', 16.0, 1.0, unit='hours') restaurants = list([]) for i in range(num_restaurants): lat, lng = random_lat_lng(51.5076, -0.0994, radius) restaurants.append(Restaurant(f'Restaurant {i}', lat, lng)) customers = list([]) for j in range(num_customers): lat, lng = random_lat_lng(lat, lng, radius) customers.append(Customer(f'Customer {j}', lat, lng)) sessions = list([]) for customer in customers: restaurant = random.choice(restaurants) timestamp = time_dist.random_variate()