Skip to content

Commit

Permalink
Honoring cancellation request (closes pgRouting#232)
Browse files Browse the repository at this point in the history
* allpairs
* astar
* bellman_ford
* breadthFirstSearch
* dagShortestPath
* dijsktra
* contraction
* cpp_common
* max_flow
* spanningTree
* topologicalSort
* alpha_shape
* components
* trsp
  • Loading branch information
mbakli committed Jul 3, 2020
1 parent f4de22f commit ddfd9a2
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 7 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

pgRouting 3.0.1 Release Notes
-------------------------------------------------------------------------------

*Bug fixes*

* [#1361 ](https://github.com/pgRouting/pgrouting/pull/1361)_: Add code to interrupt the execution


pgRouting 3.0.0 Release Notes
-------------------------------------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion doc/src/pgRouting-introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Cayetano Benavent,
Gudesa Venkata Sai Akhil,
Hang Wu,
Maoguang Wang, Martha Vergara,
Mohamed Bakli,
Regina Obe, Rohith Reddy,
Sourabh Garg,
Virginia Vergara
Expand Down Expand Up @@ -87,7 +88,7 @@ Gerald Fenoy, Gudesa Venkata Sai Akhil,
Hang Wu,
Jay Mahadeokar, Jinfu Leng,
Kai Behncke, Kishore Kumar, Ko Nagase,
Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Zia, Mukul Priya,
Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Zia, Mohamed Bakli, Mukul Priya,
Razequl Islam,
Regina Obe, Rohith Reddy,
Sarthak Agarwal, Sourabh Garg, Stephen Woodbridge, Sylvain Housseman, Sylvain Pasche,
Expand Down
10 changes: 10 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To see the full list of changes check the list of `Git commits <https://github.c

.. changelog start
* :ref:`changelog_3_0_1`
* :ref:`changelog_3_0_0`
* :ref:`changelog_2_6_3`
* :ref:`changelog_2_6_2`
Expand Down Expand Up @@ -47,6 +48,15 @@ To see the full list of changes check the list of `Git commits <https://github.c

.. changelog end
.. _changelog_3_0_1:

pgRouting 3.0.1 Release Notes
-------------------------------------------------------------------------------

.. rubric:: Bug fixes

* `#1361 <https://github.com/pgRouting/pgrouting/pull/1361>`__: Add code to interrupt the execution

.. _changelog_3_0_0:

pgRouting 3.0.0 Release Notes
Expand Down
17 changes: 17 additions & 0 deletions include/allpairs/pgr_allpairs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"

// TODO(vicky) don't keep it here
#include "cpp_common/pgr_alloc.hpp"
Expand Down Expand Up @@ -99,6 +100,10 @@ class Pgr_allpairs {
std::vector< std::vector<double>> matrix;
make_matrix(graph.num_vertices(), matrix);
inf_plus<double> combine;

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

boost::floyd_warshall_all_pairs_shortest_paths(
graph.graph,
matrix,
Expand All @@ -116,6 +121,10 @@ class Pgr_allpairs {
std::vector< std::vector<double>> matrix;
make_matrix(graph.num_vertices(), matrix);
inf_plus<double> combine;

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

boost::floyd_warshall_all_pairs_shortest_paths(
graph.graph,
matrix,
Expand All @@ -134,6 +143,10 @@ class Pgr_allpairs {
std::vector< std::vector<double>> matrix;
make_matrix(graph.num_vertices(), matrix);
inf_plus<double> combine;

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

boost::johnson_all_pairs_shortest_paths(
graph.graph,
matrix,
Expand All @@ -152,6 +165,10 @@ class Pgr_allpairs {
std::vector< std::vector<double>> matrix;
make_matrix(graph.num_vertices(), matrix);
inf_plus<double> combine;

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

boost::johnson_all_pairs_shortest_paths(
graph.graph,
matrix,
Expand Down
5 changes: 5 additions & 0 deletions include/astar/pgr_astar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"

namespace pgrouting {
namespace algorithms {
Expand Down Expand Up @@ -293,6 +294,8 @@ class Pgr_astar {
double factor,
double epsilon) {
bool found = false;
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
// Call A* named parameter interface
boost::astar_search(
Expand Down Expand Up @@ -320,6 +323,8 @@ class Pgr_astar {
double factor,
double epsilon) {
bool found = false;
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::astar_search(
graph.graph, source,
Expand Down
6 changes: 5 additions & 1 deletion include/bellman_ford/pgr_bellman_ford.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "cpp_common/pgr_messages.h"
#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"



Expand Down Expand Up @@ -188,7 +189,8 @@ class Pgr_bellman_ford : public pgrouting::Pgr_messages {
V source,
V target) {
log << std::string(__FUNCTION__) << "\n";

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
bool negative = boost::bellman_ford_shortest_paths(
graph.graph,
Expand All @@ -213,6 +215,8 @@ class Pgr_bellman_ford : public pgrouting::Pgr_messages {
G &graph,
V source) {
log << std::string(__FUNCTION__) << "\n";
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::bellman_ford_shortest_paths(
graph.graph,
Expand Down
4 changes: 4 additions & 0 deletions include/bellman_ford/pgr_edwardMoore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"
//******************************************

namespace pgrouting {
Expand Down Expand Up @@ -159,6 +160,9 @@ class Pgr_edwardMoore {
std::vector<E> &from_edge,
std::deque<int64_t> &dq,
int64_t &head_vertex) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

auto out_edges = boost::out_edges(head_vertex, graph.graph);
E e;
EO_i out_i;
Expand Down
4 changes: 4 additions & 0 deletions include/breadthFirstSearch/pgr_breadthFirstSearch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <vector>

#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"
//******************************************

namespace pgrouting {
Expand Down Expand Up @@ -63,6 +64,9 @@ class Pgr_breadthFirstSearch {

auto single_source_results = get_results(visited_order, source, depth, graph);
results.insert(results.end(), single_source_results.begin(), single_source_results.end());

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
}
}
return results;
Expand Down
5 changes: 5 additions & 0 deletions include/contraction/pgr_deadEndContraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <functional>
#include <vector>
#include "cpp_common/identifiers.hpp"
#include "cpp_common/interruption.h"

namespace pgrouting {
namespace contraction {
Expand Down Expand Up @@ -100,6 +101,10 @@ class Pgr_deadend {

graph[v].contracted_vertices().clear();
boost::clear_vertex(v, graph.graph);

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();

for (const auto u : local) {
if (is_dead_end(graph, u) && !forbiddenVertices.has(u)) {
deadendVertices += u;
Expand Down
39 changes: 39 additions & 0 deletions include/cpp_common/interruption.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*PGR-GNU*****************************************************************
Copyright (c) 2015 pgRouting developers
Mail: [email protected]
Copyright (c) 2020 Mohamed Bakli, Esteban Zimányi, Mahmoud Sakr
[email protected], [email protected], [email protected]
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/

#ifndef INCLUDE_CPP_COMMON_INTERRUPTION_H_
#define INCLUDE_CPP_COMMON_INTERRUPTION_H_
/*
* Suppress the -Wpedantic warning temporarily about the postgres file
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
extern "C" {
#include <postgres.h>
#include <miscadmin.h>
}
#pragma GCC diagnostic pop
#endif // INCLUDE_CPP_COMMON_INTERRUPTION_H_
5 changes: 5 additions & 0 deletions include/dagShortestPath/pgr_dagShortestPath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"

template < class G >
class Pgr_dag {
Expand Down Expand Up @@ -190,6 +191,8 @@ class Pgr_dag {
G &graph,
V source,
V target) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dag_shortest_paths(graph.graph, source,
boost::predecessor_map(&predecessors[0])
Expand All @@ -216,6 +219,8 @@ class Pgr_dag {
V source,
const std::vector< V > &targets,
size_t n_goals = std::numeric_limits<size_t>::max()) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dag_shortest_paths(graph.graph, source,
boost::predecessor_map(&predecessors[0])
Expand Down
9 changes: 9 additions & 0 deletions include/dijkstra/pgr_dijkstra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
#include "cpp_common/interruption.h"
#include "visitors/dijkstra_one_goal_visitor.hpp"

#if 0
Expand Down Expand Up @@ -307,6 +308,8 @@ class Pgr_dijkstra {
G &graph,
V source,
V target) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dijkstra_shortest_paths(graph.graph, source,
boost::predecessor_map(&predecessors[0])
Expand Down Expand Up @@ -338,6 +341,8 @@ class Pgr_dijkstra {
G &graph,
V source,
double distance) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dijkstra_shortest_paths(graph.graph, source,
boost::predecessor_map(&predecessors[0])
Expand Down Expand Up @@ -372,6 +377,8 @@ class Pgr_dijkstra {
pgassert(distances.size() == graph.num_vertices());
distances[source] = 0;
std::vector<boost::default_color_type> color_map(graph.num_vertices());
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dijkstra_shortest_paths_no_init(graph.graph, source,
make_iterator_property_map(
Expand Down Expand Up @@ -669,6 +676,8 @@ class Pgr_dijkstra {
V source,
const std::vector< V > &targets,
size_t n_goals = std::numeric_limits<size_t>::max()) {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
try {
boost::dijkstra_shortest_paths(graph.graph, source,
boost::predecessor_map(&predecessors[0])
Expand Down
10 changes: 9 additions & 1 deletion include/max_flow/pgr_maxflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_types/pgr_flow_t.h"
#include "c_types/pgr_edge_t.h"
#include "c_types/general_path_element_t.h"

#include "cpp_common/interruption.h"


namespace pgrouting {
Expand All @@ -70,27 +70,35 @@ class PgrFlowGraph {

public:
int64_t push_relabel() {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
return boost::push_relabel_max_flow(
graph,
supersource,
supersink);
}

int64_t edmonds_karp() {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
return boost::edmonds_karp_max_flow(
graph,
supersource,
supersink);
}

int64_t boykov_kolmogorov() {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
return boost::boykov_kolmogorov_max_flow(
graph,
supersource,
supersink);
}

std::vector<General_path_element_t> edge_disjoint_paths() {
/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
auto flow = boost::boykov_kolmogorov_max_flow(
graph,
supersource,
Expand Down
4 changes: 3 additions & 1 deletion include/spanningTree/pgr_kruskal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <vector>
#include "spanningTree/pgr_mst.hpp"
#include "cpp_common/interruption.h"

namespace pgrouting {
namespace functions {
Expand Down Expand Up @@ -70,7 +71,8 @@ template <class G>
void
Pgr_kruskal<G>::generate_mst(const G &graph) {
this->clear();

/* abort in case of an interruption occurs (e.g. the query is being cancelled) */
CHECK_FOR_INTERRUPTS();
boost::kruskal_minimum_spanning_tree(
graph.graph,
std::inserter(this->m_spanning_tree.edges, this->m_spanning_tree.edges.begin()),
Expand Down
Loading

0 comments on commit ddfd9a2

Please sign in to comment.