コード例 #1
0
 def test_od_demand_2(self):
     """Test instanciation of OD demand."""
     od_demand = utils.OriginDestinationDemand("O->A", "B->D", 10.5, 43.2)
     self.assertEqual(od_demand.origin, "O->A")
     self.assertEqual(od_demand.destination, "B->D")
     self.assertEqual(od_demand.departure_time, 10.5)
     self.assertEqual(od_demand.counts, 43.2)
コード例 #2
0
def create_games(origin,
                 destination,
                 num_vehicles,
                 graph,
                 max_time_step,
                 time_step_length=1.0,
                 departure_time=None):
    if departure_time is not None:
        raise NotImplementedError("To do.")
    list_of_vehicles = [
        dynamic_routing_utils.Vehicle(origin, destination)
        for _ in range(num_vehicles)
    ]
    game = dynamic_routing.DynamicRoutingGame(
        {
            "max_num_time_step": max_time_step,
            "time_step_length": time_step_length
        },
        network=graph,
        vehicles=list_of_vehicles)
    seq_game = pyspiel.convert_to_turn_based(game)
    od_demand = [
        dynamic_routing_utils.OriginDestinationDemand(origin, destination, 0,
                                                      num_vehicles)
    ]
    mfg_game = mean_field_routing_game.MeanFieldRoutingGame(
        {
            "max_num_time_step": max_time_step,
            "time_step_length": time_step_length
        },
        network=graph,
        od_demand=od_demand)
    return game, seq_game, mfg_game
コード例 #3
0
def _create_empty_mfg_state(game: dynamic_routing.DynamicRoutingGame):
  """Create an empty MFG state for the N player routing game.

  Args:
    game: the N player game.

  Returns:
    new_mfg_state: an empty MFG state corresponding to the N player game.
  """
  od_demand_dict = {}
  for vehicle in game._vehicles:  # pylint:disable=protected-access
    key = (vehicle.origin, vehicle.destination, vehicle.departure_time)
    if key not in od_demand_dict:
      od_demand_dict[key] = 0
    od_demand_dict[key] += 1
  od_demand = []
  for (origin, destination, departure_time), counts in od_demand_dict.items():
    od_demand.append(
        dynamic_routing_utils.OriginDestinationDemand(origin, destination,
                                                      departure_time, counts))
  return mean_field_routing_game.MeanFieldRoutingGame(
      {
          "max_num_time_step": game.max_game_length(),
          "time_step_length": game.time_step_length
      },
      network=game.network,
      od_demand=od_demand,
      perform_sanity_checks=game.perform_sanity_checks).new_initial_state()
コード例 #4
0
 def test_multiple_departure_time_vehicle(self):
     """Check that departure time can be define."""
     od_demand = [
         dynamic_routing_utils.OriginDestinationDemand(
             "O->A", "D->E", 0, 5),
         dynamic_routing_utils.OriginDestinationDemand(
             "O->A", "D->E", 0.5, 5),
         dynamic_routing_utils.OriginDestinationDemand(
             "O->A", "D->E", 1.0, 5)
     ]
     game = dynamic_routing.MeanFieldRoutingGame(
         {
             "max_num_time_step": 10,
             "time_step_length": 0.5,
             "players": -1
         },
         od_demand=od_demand)
     pyspiel.random_sim_test(game,
                             num_sims=10,
                             serialize=False,
                             verbose=True)
コード例 #5
0
 def test_vehicle_destination_outside_network(self):
     """Check raise assertion if vehicle's destination is outside the Network."""
     od_demand = [
         dynamic_routing_utils.OriginDestinationDemand(
             "O->A", "E->F", 0, 5)
     ]
     with self.assertRaises(ValueError):
         dynamic_routing.MeanFieldRoutingGame(
             {
                 "max_num_time_step": 10,
                 "time_step_length": 0.5,
                 "players": -1
             },
             od_demand=od_demand)
コード例 #6
0
from open_spiel.python.games import dynamic_routing_utils

LINE_NETWORK = dynamic_routing_utils.Network({
    "bef_O": "O",
    "O": ["A"],
    "A": ["D"],
    "D": ["aft_D"],
    "aft_D": []
})

LINE_NETWORK_VEHICLES_DEMAND = [
    dynamic_routing_utils.Vehicle("bef_O->O", "D->aft_D") for _ in range(2)
]

LINE_NETWORK_OD_DEMAND = [
    dynamic_routing_utils.OriginDestinationDemand("bef_O->O", "D->aft_D", 0,
                                                  100)
]

BRAESS_NUM_PLAYER = 5
BRAESS_NETWORK = dynamic_routing_utils.Network(
    {
        "O": "A",
        "A": ["B", "C"],
        "B": ["C", "D"],
        "C": ["D"],
        "D": ["E"],
        "E": []
    },
    node_position={
        "O": (0, 0),
        "A": (1, 0),
コード例 #7
0
def create_sioux_falls_network():
    sioux_falls_adjacency_list = {}
    sioux_falls_node_position = {}
    bpr_a_coefficient = {}
    bpr_b_coefficient = {}
    capacity = {}
    free_flow_travel_time = {}

    content = open("./SiouxFalls_node.csv", "r").read()
    for line in content.split("\n")[1:]:
        row = line.split(",")
        sioux_falls_node_position[row[0]] = [
            int(row[1]) / 1e5, int(row[2]) / 1e5
        ]
        sioux_falls_node_position[f"bef_{row[0]}"] = [
            int(row[1]) / 1e5, int(row[2]) / 1e5
        ]
        sioux_falls_node_position[f"aft_{row[0]}"] = [
            int(row[1]) / 1e5, int(row[2]) / 1e5
        ]
        sioux_falls_adjacency_list[f"bef_{row[0]}"] = [row[0]]
        sioux_falls_adjacency_list[row[0]] = [f"aft_{row[0]}"]
        sioux_falls_adjacency_list[f"aft_{row[0]}"] = []

        bpr_a_coefficient[f"{row[0]}->aft_{row[0]}"] = 0.0
        bpr_b_coefficient[f"{row[0]}->aft_{row[0]}"] = 1.0
        capacity[f"{row[0]}->aft_{row[0]}"] = 0.0
        free_flow_travel_time[f"{row[0]}->aft_{row[0]}"] = 0.0

        bpr_a_coefficient[f"bef_{row[0]}->{row[0]}"] = 0.0
        bpr_b_coefficient[f"bef_{row[0]}->{row[0]}"] = 1.0
        capacity[f"bef_{row[0]}->{row[0]}"] = 0.0
        free_flow_travel_time[f"bef_{row[0]}->{row[0]}"] = 0.0

    content = open("./SiouxFalls_net.csv", "r").read()
    for l in content.split("\n")[1:-1]:
        _, origin, destination, a0, a1, a2, a3, a4 = l.split(",")
        assert all(int(x) == 0 for x in [a1, a2, a3])
        sioux_falls_adjacency_list[origin].append(destination)
        road_section = f"{origin}->{destination}"
        bpr_a_coefficient[road_section] = float(a4)
        bpr_b_coefficient[road_section] = 4.0
        capacity[road_section] = 1.0
        free_flow_travel_time[road_section] = float(a0)

    sioux_falls_od_demand = []
    content = open("./SiouxFalls_od.csv", "r").read()
    for line in content.split("\n")[1:-1]:
        row = line.split(",")
        sioux_falls_od_demand.append(
            dynamic_routing_utils.OriginDestinationDemand(
                f"bef_{row[0]}->{row[0]}", f"{row[1]}->aft_{row[1]}", 0,
                float(row[2])))

    return dynamic_routing_utils.Network(
        sioux_falls_adjacency_list,
        node_position=sioux_falls_node_position,
        bpr_a_coefficient=bpr_a_coefficient,
        bpr_b_coefficient=bpr_b_coefficient,
        capacity=capacity,
        free_flow_travel_time=free_flow_travel_time), sioux_falls_od_demand