Beispiel #1
0
    def test_build_nodes(self):

        graph_obj = graph.Graph.build_from_parameters(n=5, l=1000, g=0.5, p=2)
        network = TransportNetwork(graph_obj)

        mode_manager = TransportModeManager()
        bus_obj = mode_manager.get_mode("bus")
        metro_obj = mode_manager.get_mode("metro")
        # train_obj = TransportMode("train", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

        feeder_routes = network.get_feeder_routes(bus_obj)
        radial_routes = network.get_radial_routes(metro_obj)
        circular_routes = network.get_circular_routes(bus_obj)

        for route in feeder_routes:
            network.add_route(route)

        for route in radial_routes:
            network.add_route(route)

        for route in circular_routes:
            network.add_route(route)

        city_nodes = ExtendedGraph.build_city_nodes(graph_obj)
        tree_graph = ExtendedGraph.build_tree_graph(network.get_routes(), city_nodes)
        stop_nodes = ExtendedGraph.build_stop_nodes(tree_graph)
        route_nodes = ExtendedGraph.build_route_nodes(network.get_routes(), stop_nodes)

        self.assertEqual(len(city_nodes), 11)
        self.assertEqual(len(stop_nodes), 21)
        self.assertEqual(len(route_nodes), 60)
Beispiel #2
0
    def test_build_edges(self):

        graph_obj = graph.Graph.build_from_parameters(n=5, l=1000, g=0.5, p=2)
        network = TransportNetwork(graph_obj)

        passenger_obj = Passenger(4, 2, 2, 2, 2, 2, 2, 2, 2)

        mode_manager = TransportModeManager()
        bus_obj = mode_manager.get_mode("bus")
        metro_obj = mode_manager.get_mode("metro")
        # train_obj = TransportMode("train", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

        feeder_routes = network.get_feeder_routes(bus_obj)
        radial_routes = network.get_radial_routes(metro_obj)
        circular_routes = network.get_circular_routes(bus_obj)

        for route in feeder_routes:
            network.add_route(route)

        for route in radial_routes:
            network.add_route(route)

        for route in circular_routes:
            network.add_route(route)

        city_nodes = ExtendedGraph.build_city_nodes(graph_obj)
        tree_graph = ExtendedGraph.build_tree_graph(network.get_routes(), city_nodes)
        stop_nodes = ExtendedGraph.build_stop_nodes(tree_graph)
        route_nodes = ExtendedGraph.build_route_nodes(network.get_routes(), stop_nodes)

        extended_graph_nodes = ExtendedGraph.build_extended_graph_nodes(route_nodes)

        initial_frequency = defaultdict(float)

        for route in network.get_routes():
            initial_frequency[route.id] = 28

        access_edges = ExtendedGraph.build_access_edges(extended_graph_nodes)
        boarding_edges = ExtendedGraph.build_boarding_edges(extended_graph_nodes, initial_frequency)
        alighting_edges = ExtendedGraph.build_alighting_edges(extended_graph_nodes, passenger_obj.spt)
        route_edges = ExtendedGraph.build_route_edges(extended_graph_nodes)

        self.assertEqual(len(access_edges), 42)
        self.assertEqual(len(boarding_edges), 40)
        self.assertEqual(len(alighting_edges), 40)
        self.assertEqual(len(route_edges), 40)