Пример #1
0
    def setUp(self) -> None:
        graph_obj = Graph.build_from_parameters(n=2, l=10, g=0.5, p=2)
        demand_obj = Demand.build_from_parameters(graph_obj=graph_obj, y=100, a=0.5, alpha=1 / 3, beta=1 / 3)
        passenger_obj = Passenger.get_default_passenger()
        [bus_obj, metro_obj] = TransportMode.get_default_modes()

        self.network_obj = TransportNetwork(graph_obj=graph_obj)

        feeder_routes_metro = self.network_obj.get_feeder_routes(mode_obj=metro_obj)
        radial_routes_bus = self.network_obj.get_radial_routes(mode_obj=bus_obj)

        for route in feeder_routes_metro:
            self.network_obj.add_route(route_obj=route)

        for route in radial_routes_bus:
            self.network_obj.add_route(route_obj=route)

        self.extended_graph_obj = ExtendedGraph(graph_obj=graph_obj, routes=self.network_obj.get_routes(),
                                                TP=passenger_obj.pt, frequency_routes=None)
        hyperpath_obj = Hyperpath(extended_graph_obj=self.extended_graph_obj, passenger_obj=passenger_obj)

        self.hyperpaths, self.labels, self.successors, self.frequency, self.Vij = hyperpath_obj.get_all_hyperpaths(
            OD_matrix=demand_obj.get_matrix())

        self.OD_assignment = Assignment.get_assignment(hyperpaths=self.hyperpaths, labels=self.labels, p=2,
                                                       vp=passenger_obj.va, spa=passenger_obj.spa,
                                                       spv=passenger_obj.spv)
Пример #2
0
    def test_create_passenger(self):
        """

        """
        va = 1
        pv = 2
        pw = 3
        pa = 4
        pt = 5
        spv = 6
        spw = 7
        spa = 8
        spt = 9

        passenger_obj = Passenger(va, pv, pw, pa, pt, spv, spw, spa, spt)

        self.assertEqual(passenger_obj.va, va)
        self.assertEqual(passenger_obj.pv, pv)
        self.assertEqual(passenger_obj.pw, pw)
        self.assertEqual(passenger_obj.pa, pa)
        self.assertEqual(passenger_obj.pt, pt)
        self.assertEqual(passenger_obj.spv, spv)
        self.assertEqual(passenger_obj.spw, spw)
        self.assertEqual(passenger_obj.spa, spa)
        self.assertEqual(passenger_obj.spt, spt)
Пример #3
0
    def test_resources_consumer(self):

        graph_obj = Graph.build_from_parameters(n=2, l=10, g=0.5, p=2)
        demand_obj = Demand.build_from_parameters(graph_obj=graph_obj,
                                                  y=100,
                                                  a=0.5,
                                                  alpha=1 / 3,
                                                  beta=1 / 3)
        passenger_obj = Passenger.get_default_passenger()
        [bus_obj, metro_obj] = TransportMode.get_default_modes()

        network_obj = TransportNetwork(graph_obj=graph_obj)

        feeder_routes_metro = network_obj.get_feeder_routes(mode_obj=metro_obj)
        radial_routes_bus = network_obj.get_radial_routes(mode_obj=bus_obj)

        for route in feeder_routes_metro:
            network_obj.add_route(route_obj=route)

        for route in radial_routes_bus:
            network_obj.add_route(route_obj=route)

        extended_graph_obj = ExtendedGraph(graph_obj=graph_obj,
                                           routes=network_obj.get_routes(),
                                           TP=passenger_obj.pt,
                                           frequency_routes=None)
        hyperpath_obj = Hyperpath(extended_graph_obj=extended_graph_obj,
                                  passenger_obj=passenger_obj)

        hyperpaths, labels, successors, frequency, Vij = hyperpath_obj.get_all_hyperpaths(
            OD_matrix=demand_obj.get_matrix())

        OD_assignment = Assignment.get_assignment(hyperpaths=hyperpaths,
                                                  labels=labels,
                                                  p=2,
                                                  vp=passenger_obj.va,
                                                  spa=passenger_obj.spa,
                                                  spv=passenger_obj.spv)

        f = defaultdict(float)
        z = defaultdict(lambda: defaultdict(lambda: defaultdict(float)))
        v = defaultdict(lambda: defaultdict(lambda: defaultdict(float)))

        for route in network_obj.get_routes():
            f[route.id] = 28

        CU_obj = UsersCost()
        ta, te, tv, t = CU_obj.resources_consumer(hyperpaths, Vij,
                                                  OD_assignment, successors,
                                                  extended_graph_obj,
                                                  passenger_obj.va, f, z, v)

        self.assertEqual(round(ta, 4), 3.069)
        self.assertEqual(round(te, 4), 13.9597)
        self.assertEqual(round(tv, 4), 74.685)
        self.assertEqual(round(t, 4), 41.6667)
Пример #4
0
    def test_get_default_passenger(self):
        passenger_obj = Passenger.get_default_passenger()

        self.assertEqual(passenger_obj.va, 4.0)
        self.assertEqual(passenger_obj.pv, 2.74)
        self.assertEqual(passenger_obj.pw, 5.48)
        self.assertEqual(passenger_obj.pa, 8.22)
        self.assertEqual(passenger_obj.pt, 16)
        self.assertEqual(passenger_obj.spv, 2.74)
        self.assertEqual(passenger_obj.spw, 5.48)
        self.assertEqual(passenger_obj.spa, 8.22)
        self.assertEqual(passenger_obj.spt, 16)
Пример #5
0
    def test_raises_user_exceptions(self):
        """
        test user exceptions
        :return:
        """

        with self.assertRaises(exceptions.VaIsNotValidExceptions):
            Passenger(0, 1, 1, 1, 1, 1, 1, 1, 1)
        with self.assertRaises(exceptions.PvIsNotValidExceptions):
            Passenger(1, -1, 1, 1, 1, 1, 1, 1, 1)
        with self.assertRaises(exceptions.PwIsNotValidExceptions):
            Passenger(1, 1, -1, 1, 1, 1, 1, 1, 1)
        with self.assertRaises(exceptions.PaIsNotValidExceptions):
            Passenger(1, 1, 1, -1, 1, 1, 1, 1, 1)
        with self.assertRaises(exceptions.PtIsNotValidExceptions):
            Passenger(1, 1, 1, 1, -1, 1, 1, 1, 1)
        with self.assertRaises(exceptions.SpvIsNotValidExceptions):
            Passenger(1, 1, 1, 1, 1, -1, 1, 1, 1)
        with self.assertRaises(exceptions.SpwIsNotValidExceptions):
            Passenger(1, 1, 1, 1, 1, 1, -1, 1, 1)
        with self.assertRaises(exceptions.SpaIsNotValidExceptions):
            Passenger(1, 1, 1, 1, 1, 1, 1, -1, 1)
        with self.assertRaises(exceptions.SptIsNotValidExceptions):
            Passenger(1, 1, 1, 1, 1, 1, 1, 1, -1)
Пример #6
0
va = 4
pv = 2.74
pw = 2 * 2.74
pa = 3 * 2.74
pt = 16
spv = 2.74
spw = 2 * 2.74
spa = 3 * 2.74
spt = 16

passenger_obj = Passenger(va=va,
                          pv=pv,
                          pw=pw,
                          pa=pa,
                          pt=pt,
                          spv=spv,
                          spw=spw,
                          spa=spa,
                          spt=spt)

[bus, metro] = TransportMode.get_default_modes()
bus.c2 = 92.39

# dc4_metro = network_obj.get_diametral_routes(metro, 4, True)
# tc1_bus = network_obj.get_tangencial_routes(bus, 1, True)
# tc2_bus = network_obj.get_tangencial_routes(bus, 2, True)
# dc3_bus = network_obj.get_diametral_routes(bus, 3, True)
# dc4_bus = network_obj.get_diametral_routes(bus, 4, True)
# rc_bus = network_obj.get_radial_routes(bus, True)
# r_bus = network_obj.get_radial_routes(bus)
Пример #7
0
    def test_get_cycle_time(self):
        """
        test get_cycle_time method of class operators_cost
        :return:
        """
        graph_obj = Graph.build_from_parameters(n=2, l=10, g=0.5, p=2)
        demand_obj = Demand.build_from_parameters(graph_obj=graph_obj,
                                                  y=100,
                                                  a=0.5,
                                                  alpha=1 / 3,
                                                  beta=1 / 3)
        passenger_obj = Passenger.get_default_passenger()
        [bus_obj, metro_obj] = TransportMode.get_default_modes()

        network_obj = TransportNetwork(graph_obj=graph_obj)

        feeder_routes_metro = network_obj.get_feeder_routes(mode_obj=metro_obj)
        radial_routes_bus = network_obj.get_radial_routes(mode_obj=bus_obj)

        for route in feeder_routes_metro:
            network_obj.add_route(route_obj=route)

        for route in radial_routes_bus:
            network_obj.add_route(route_obj=route)

        extended_graph_obj = ExtendedGraph(graph_obj=graph_obj,
                                           routes=network_obj.get_routes(),
                                           TP=passenger_obj.pt,
                                           frequency_routes=None)
        hyperpath_obj = Hyperpath(extended_graph_obj=extended_graph_obj,
                                  passenger_obj=passenger_obj)

        hyperpaths, labels, successors, frequency, Vij = hyperpath_obj.get_all_hyperpaths(
            OD_matrix=demand_obj.get_matrix())

        OD_assignment = Assignment.get_assignment(hyperpaths=hyperpaths,
                                                  labels=labels,
                                                  p=2,
                                                  vp=passenger_obj.va,
                                                  spa=passenger_obj.spa,
                                                  spv=passenger_obj.spv)

        f = defaultdict(float)
        for route in network_obj.get_routes():
            f[route.id] = 28

        z, v, loaded_section_route = Assignment.get_alighting_and_boarding(
            Vij=Vij,
            hyperpaths=hyperpaths,
            successors=successors,
            assignment=OD_assignment,
            f=f)

        lines_travel_time = OperatorsCost.lines_travel_time(
            routes=network_obj.get_routes(),
            edge_distance=graph_obj.get_edges_distance())

        line_cycle_time = OperatorsCost.get_cycle_time(
            z, v, network_obj.get_routes(), lines_travel_time)

        self.assertEqual(round(line_cycle_time["F_metro_1"], 7), 0.2500082)
        self.assertEqual(round(line_cycle_time["R_bus_1"], 7), 1.5032756)
        self.assertEqual(line_cycle_time["l1"], 0)