def test_network_skimming(self):
        # graph
        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field="distance", skim_fields=None)
        # None implies that only the cost field will be skimmed

        # skimming results
        res = SkimResults()
        res.prepare(g)

        aux_res = MultiThreadedNetworkSkimming()
        aux_res.prepare(g, res)
        _ = skimming_single_origin(26, g, res, aux_res, 0)

        skm = NetworkSkimming(g, res)
        skm.execute()

        tot = np.nanmax(res.skims.distance[:, :])

        if tot > 10e10:
            self.fail(
                "Skimming was not successful. At least one np.inf returned.")

        if skm.report:
            self.fail("Skimming returned an error:" + str(skm.report))
    def test_network_skimming(self):
        # graph
        g = Graph()
        g.load_from_disk(test_graph)
        g.set_graph(cost_field='distance', skim_fields=None)
        # None implies that only the cost field will be skimmed

        # skimming results
        res = SkimResults()
        res.prepare(g)

        aux_res = MultiThreadedNetworkSkimming()
        aux_res.prepare(g, res)
        a = skimming_single_origin(26, g, res, aux_res, 0)

        skm = NetworkSkimming(g, res)
        skm.execute()

        tot = np.nanmax(res.skims.distance[:, :])

        if tot > 10e10:
            self.fail('Skimming was not successful. At least one np.inf returned.')

        if skm.report:
            self.fail('Skimming returned an error:' + str(skm.report))
Beispiel #3
0
    def doWork(self):
        res = SkimResults()
        res.prepare(self.graph)

        ns = NetworkSkimming(self.graph, res)
        ns.execute()

        skm = res.skims
        mat = (skm.get_matrix(skm.names[0]) * self.mult).astype(int)
        self.depot = list(skm.index).index(self.depot)
        # Create the routing index manager.
        manager = pywrapcp.RoutingIndexManager(mat.shape[0], self.vehicles, self.depot)

        # Create Routing Model.
        routing = pywrapcp.RoutingModel(manager)

        def distance_callback(from_index, to_index):
            """Returns the distance between the two nodes."""
            # Convert from routing variable Index to distance matrix NodeIndex.
            from_node = manager.IndexToNode(from_index)
            to_node = manager.IndexToNode(to_index)

            return mat[from_node, to_node]

        transit_callback_index = routing.RegisterTransitCallback(distance_callback)

        # Define cost of each arc.
        routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)

        # Setting first solution heuristic.
        search_parameters = pywrapcp.DefaultRoutingSearchParameters()
        search_parameters.first_solution_strategy = (routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)

        # Solve the problem.
        solution = routing.SolveWithParameters(search_parameters)

        # Print solution on console.
        if not solution:
            self.error = 'Solution not found'
            self.report.append(self.error)
        else:
            self.report.append(f'Objective function value: {solution.ObjectiveValue() / self.mult}')
            index = routing.Start(0)
            plan_output = 'Route:\n'
            route_distance = 0

            while not routing.IsEnd(index):
                p = skm.index[manager.IndexToNode(index)]
                self.node_sequence.append(p)
                plan_output += f' {p} ->'
                previous_index = index
                index = solution.Value(routing.NextVar(index))
                route_distance += routing.GetArcCostForVehicle(previous_index, index, 0)

            p = skm.index[manager.IndexToNode(index)]
            self.node_sequence.append(p)
            plan_output += f' {p}\n'
            self.report.append(plan_output)
        self.finished_threaded_procedure.emit("TSP")
## Now to skimming

# %%

from aequilibrae.paths import NetworkSkimming

# %%
# But let's say we only want a skim matrix for nodes 1, 3, 6 & 8
import numpy as np

graph.prepare_graph(np.array([1, 3, 6, 8]))
# %%

# And run the skimming
skm = NetworkSkimming(graph)
skm.execute()

# %%

# The result is an AequilibraEMatrix object
skims = skm.results.skims

# Which we can manipulate directly from its temp file, if we wish
skims.matrices

# %%

# Or access each matrix
skims.free_flow_time

# %%