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))
Пример #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")
Пример #4
0
    def run_skimming(self):  # Saving results

        if self.error is None:
            self.browse_outfile()
            cost_field = self.cb_minimizing.currentText().encode('utf-8')

            # We prepare the graph to set all nodes as centroids
            if self.rdo_all_nodes.isChecked():
                self.graph.prepare_graph(self.graph.all_nodes)

            self.graph.set_graph(
                cost_field=cost_field,
                skim_fields=self.skim_fields,
                block_centroid_flows=self.block_paths.isChecked())

            self.result.prepare(self.graph)

            self.funding1.setVisible(False)
            self.funding2.setVisible(False)
            self.progressbar.setVisible(True)
            self.progress_label.setVisible(True)
            self.worker_thread = NetworkSkimming(self.graph, self.result)
            try:
                self.run_thread()
            except ValueError as error:
                qgis.utils.iface.messageBar().pushMessage("Input error",
                                                          error.message,
                                                          level=3)
        else:
            qgis.utils.iface.messageBar().pushMessage("Error:",
                                                      self.error,
                                                      level=3)
    def run_skimming(self):  # Saving results
        if not self.browse_outfile():
            return

        mode = self.all_modes[self.cb_modes.currentText()]
        self.project.network.build_graphs()
        self.graph = self.project.network.graphs[mode]

        # We prepare the graph to set all nodes as centroids
        if self.rdo_all_nodes.isChecked():
            self.graph.prepare_graph(self.graph.all_nodes)

        self.graph.set_graph(cost_field=self.cb_minimizing.currentText())
        self.graph.set_blocked_centroid_flows(self.block_paths.isChecked())

        if self.chb_chosen_links.isChecked():
            idx = self.link_layer.dataProvider().fieldNameIndex('link_id')
            remove = [
                feat.attributes()[idx]
                for feat in self.link_layer.selectedFeatures()
            ]
            self.graph.exclude_links(remove)

        self.graph.set_skimming(self.skim_fields)

        self.result.prepare(self.graph)

        self.funding1.setVisible(False)
        self.funding2.setVisible(False)
        self.progressbar.setVisible(True)
        self.progress_label.setVisible(True)
        self.worker_thread = NetworkSkimming(self.graph, self.result)
        try:
            self.run_thread()
        except ValueError as error:
            qgis.utils.iface.messageBar().pushMessage("Input error",
                                                      error.message,
                                                      level=3)
## 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