Skip to content

Commit

Permalink
Fix edge disjoint paths main (#2277)
Browse files Browse the repository at this point in the history
* [build] pump up to 3.3.2
* [edgeDijointPaths] fix for start_vid & combinations problem
* [doc] updating NEWS and edgeDisjointPath documentation
* [lint] fixing lint problem
  • Loading branch information
cvvergara authored May 3, 2022
1 parent f846bef commit 2329137
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
old_pgr: [3.3.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0, 3.2.1, 3.2.1]
old_pgr: [3.3.1, 3.3.0, 3.0.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.0.5, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.2.0, 3.2.1, 3.2.1]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Test old version after update
run: |
sudo service postgresql start
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.1';"
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.2';"
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();"
sudo -u postgres bash ./tools/testers/pg_prove_tests.sh postgres 5432
sudo -u postgres dropdb -p 5432 ___pgr___test___
Expand All @@ -113,6 +113,6 @@ jobs:
- name: Test old version with new lib after update
run: |
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.1';"
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "ALTER EXTENSION pgrouting UPDATE TO '3.3.2';"
sudo -u postgres psql -p 5432 -d ___pgr___test___ -c "SELECT * FROM pgr_full_version();"
sudo -u postgres bash ./tools/testers/pg_prove_tests.sh postgres 5432
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include(pgr/BuildType)
#---------------------------------------------
#---------------------------------------------

project(PGROUTING VERSION 3.3.1
project(PGROUTING VERSION 3.3.2
LANGUAGES C CXX )
set(PROJECT_VERSION_DEV "")
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
Expand All @@ -33,7 +33,8 @@ string(TIMESTAMP COMPILATION_DATE "%Y/%m/%d")

set(MINORS 3.3 3.2 3.1 3.0 2.6)
set(OLD_SIGNATURES
3.3.0
3.3.1
3.3.0
3.2.2 3.2.1 3.2.0
3.1.4 3.1.3 3.1.2 3.1.1 3.1.0
3.0.6 3.0.5 3.0.4 3.0.3 3.0.2 3.0.1 3.0.0
Expand Down
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
pgRouting 3.3.2 Release Notes
-------------------------------------------------------------------------------

To see all issues & pull requests closed by this release see the `Git closed
milestone for 3.3.2
<https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.3.2%22>`_

**Issue fixes**

* [#2276](https://github.com/pgRouting/pgrouting/issues/2276):
edgeDisjointPaths issues with start_vid and combinations

pgRouting 3.3.1 Release Notes
-------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion doc/max_flow/pgr_edgeDisjointPaths.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Combinations
RETURNS SET OF (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
:Example: Using a combinations table, equivalent to calculating result from vertices :math:`\{3, 6\}` to vertices :math:`\{4, 5, 10\}` on a **directed** graph.
:Example: Manually selecting combinations to be processed

.. literalinclude:: doc-pgr_edgeDisjointPaths.queries
:start-after: -- q6
Expand Down
13 changes: 13 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ To see the full list of changes check the list of `Git commits <https://github.c
:local:



pgRouting 3.3.2 Release Notes
-------------------------------------------------------------------------------

To see all issues & pull requests closed by this release see the `Git closed
milestone for 3.3.2
<https://github.com/pgRouting/pgrouting/issues?utf8=%E2%9C%93&q=milestone%3A%22Release%203.3.2%22>`_

.. rubric:: Issue fixes

* `#2276 <https://github.com/pgRouting/pgrouting/issues/2276>`__:
edgeDisjointPaths issues with start_vid and combinations

pgRouting 3.3.1 Release Notes
-------------------------------------------------------------------------------

Expand Down
110 changes: 49 additions & 61 deletions docqueries/max_flow/doc-pgr_edgeDisjointPaths.result
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ SELECT * FROM pgr_edgeDisjointPaths(
);
seq | path_id | path_seq | start_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+------+------+------+----------
1 | 1 | 1 | 0 | 3 | 2 | 1 | 0
2 | 1 | 2 | 0 | 2 | 4 | 1 | 1
3 | 1 | 3 | 0 | 5 | -1 | 0 | 2
4 | 2 | 1 | 1 | 3 | 5 | 1 | 0
5 | 2 | 2 | 1 | 6 | 8 | 1 | 1
6 | 2 | 3 | 1 | 5 | -1 | 0 | 2
7 | 3 | 1 | 2 | 6 | 8 | 1 | 0
8 | 3 | 2 | 2 | 5 | -1 | 0 | 1
9 | 4 | 1 | 3 | 6 | 9 | 1 | 0
10 | 4 | 2 | 3 | 9 | 16 | 1 | 1
11 | 4 | 3 | 3 | 4 | 3 | 1 | 2
12 | 4 | 4 | 3 | 3 | 2 | 1 | 3
13 | 4 | 5 | 3 | 2 | 4 | 1 | 4
14 | 4 | 6 | 3 | 5 | -1 | 0 | 5
1 | 1 | 1 | 3 | 3 | 2 | 1 | 0
2 | 1 | 2 | 3 | 2 | 4 | 1 | 1
3 | 1 | 3 | 3 | 5 | -1 | 0 | 2
4 | 2 | 1 | 3 | 3 | 5 | 1 | 0
5 | 2 | 2 | 3 | 6 | 8 | 1 | 1
6 | 2 | 3 | 3 | 5 | -1 | 0 | 2
7 | 3 | 1 | 6 | 6 | 8 | 1 | 0
8 | 3 | 2 | 6 | 5 | -1 | 0 | 1
9 | 4 | 1 | 6 | 6 | 9 | 1 | 0
10 | 4 | 2 | 6 | 9 | 16 | 1 | 1
11 | 4 | 3 | 6 | 4 | 3 | 1 | 2
12 | 4 | 4 | 6 | 3 | 2 | 1 | 3
13 | 4 | 5 | 6 | 2 | 4 | 1 | 4
14 | 4 | 6 | 6 | 5 | -1 | 0 | 5
(14 rows)

/* -- q5 */
Expand All @@ -93,34 +93,34 @@ SELECT * FROM pgr_edgeDisjointPaths(
);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | 0 | 4 | 3 | 5 | 1 | 0
2 | 1 | 2 | 0 | 4 | 6 | 9 | 1 | 1
3 | 1 | 3 | 0 | 4 | 9 | 16 | 1 | 2
4 | 1 | 4 | 0 | 4 | 4 | -1 | 0 | 3
5 | 2 | 1 | 1 | 5 | 3 | 2 | 1 | 0
6 | 2 | 2 | 1 | 5 | 2 | 4 | 1 | 1
7 | 2 | 3 | 1 | 5 | 5 | -1 | 0 | 2
8 | 3 | 1 | 2 | 5 | 3 | 5 | 1 | 0
9 | 3 | 2 | 2 | 5 | 6 | 8 | 1 | 1
10 | 3 | 3 | 2 | 5 | 5 | -1 | 0 | 2
1 | 1 | 1 | 3 | 4 | 3 | 5 | 1 | 0
2 | 1 | 2 | 3 | 4 | 6 | 9 | 1 | 1
3 | 1 | 3 | 3 | 4 | 9 | 16 | 1 | 2
4 | 1 | 4 | 3 | 4 | 4 | -1 | 0 | 3
5 | 2 | 1 | 3 | 5 | 3 | 2 | 1 | 0
6 | 2 | 2 | 3 | 5 | 2 | 4 | 1 | 1
7 | 2 | 3 | 3 | 5 | 5 | -1 | 0 |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 SELECT * FROM pgr_edgeDisjointPaths(
);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | 0 | 4 | 3 | 5 | 1 | 0
2 | 1 | 2 | 0 | 4 | 6 | 9 | 1 | 1
3 | 1 | 3 | 0 | 4 | 9 | 16 | 1 | 2
4 | 1 | 4 | 0 | 4 | 4 | -1 | 0 | 3
5 | 2 | 1 | 1 | 5 | 3 | 2 | 1 | 0
6 | 2 | 2 | 1 | 5 | 2 | 4 | 1 | 1
7 | 2 | 3 | 1 | 5 | 5 | -1 | 0 | 2
8 | 3 | 1 | 2 | 5 | 3 | 5 | 1 | 0
9 | 3 | 2 | 2 | 5 | 6 | 8 | 1 | 1
10 | 3 | 3 | 2 | 5 | 5 | -1 | 0 | 2
11 | 4 | 1 | 3 | 10 | 3 | 2 | 1 | 0
12 | 4 | 2 | 3 | 10 | 2 | 4 | 1 | 1
13 | 4 | 3 | 3 | 10 | 5 | 10 | 1 | 2
14 | 4 | 4 | 3 | 10 | 10 | -1 | 0 | 3
15 | 5 | 1 | 4 | 4 | 6 | 9 | 1 | 0
16 | 5 | 2 | 4 | 4 | 9 | 16 | 1 | 1
17 | 5 | 3 | 4 | 4 | 4 | -1 | 0 | 2
18 | 6 | 1 | 5 | 5 | 6 | 8 | 1 | 0
19 | 6 | 2 | 5 | 5 | 5 | -1 | 0 | 1
20 | 7 | 1 | 6 | 5 | 6 | 9 | 1 | 0
21 | 7 | 2 | 6 | 5 | 9 | 16 | 1 | 1
22 | 7 | 3 | 6 | 5 | 4 | 3 | 1 | 2
23 | 7 | 4 | 6 | 5 | 3 | 2 | 1 | 3
24 | 7 | 5 | 6 | 5 | 2 | 4 | 1 | 4
25 | 7 | 6 | 6 | 5 | 5 | -1 | 0 | 5
26 | 8 | 1 | 7 | 10 | 6 | 8 | 1 | 0
27 | 8 | 2 | 7 | 10 | 5 | 10 | 1 | 1
28 | 8 | 3 | 7 | 10 | 10 | -1 | 0 | 2
(28 rows)
1 | 1 | 1 | 3 | 4 | 3 | 5 | 1 | 0
2 | 1 | 2 | 3 | 4 | 6 | 9 | 1 | 1
3 | 1 | 3 | 3 | 4 | 9 | 16 | 1 | 2
4 | 1 | 4 | 3 | 4 | 4 | -1 | 0 | 3
5 | 2 | 1 | 3 | 10 | 3 | 2 | 1 | 0
6 | 2 | 2 | 3 | 10 | 2 | 4 | 1 | 1
7 | 2 | 3 | 3 | 10 | 5 | 10 | 1 | 2
8 | 2 | 4 | 3 | 10 | 10 | -1 | 0 | 3
9 | 3 | 1 | 6 | 5 | 6 | 8 | 1 | 0
10 | 3 | 2 | 6 | 5 | 5 | -1 | 0 | 1
11 | 4 | 1 | 6 | 5 | 6 | 9 | 1 | 0
12 | 4 | 2 | 6 | 5 | 9 | 16 | 1 | 1
13 | 4 | 3 | 6 | 5 | 4 | 3 | 1 | 2
14 | 4 | 4 | 6 | 5 | 3 | 2 | 1 | 3
15 | 4 | 5 | 6 | 5 | 2 | 4 | 1 | 4
16 | 4 | 6 | 6 | 5 | 5 | -1 | 0 | 5
(16 rows)

/* -- q7 */
ROLLBACK;
Expand Down
2 changes: 1 addition & 1 deletion docqueries/version/doc-full_version.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SET
SELECT version, library FROM pgr_full_version();
version | library
---------+-----------------
3.3.1 | pgrouting-3.3.1
3.3.2 | pgrouting-3.3.2
(1 row)

/* -- q2 */
Expand Down
2 changes: 1 addition & 1 deletion docqueries/version/doc-version.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SET
SELECT pgr_version();
pgr_version
-------------
3.3.1
3.3.2
(1 row)

/* -- q2 */
Expand Down
23 changes: 20 additions & 3 deletions src/max_flow/edge_disjoint_paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,34 @@ _pgr_edgedisjointpaths(PG_FUNCTION_ARGS) {
nulls[i] = false;
}

int path_id = 1;
int seq = 1;
if (funcctx->call_cntr != 0) {
if (result_tuples[funcctx->call_cntr - 1].edge == -1) {
path_id = result_tuples[funcctx->call_cntr - 1].start_id + 1;
seq = 1;
} else {
path_id = result_tuples[funcctx->call_cntr - 1].start_id;
seq = result_tuples[funcctx->call_cntr - 1].end_id + 1;
}
}

values[0] = Int32GetDatum(funcctx->call_cntr + 1);
values[1] = Int32GetDatum(
result_tuples[funcctx->call_cntr].start_id + 1);
values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
values[1] = Int32GetDatum(path_id);
values[2] = Int32GetDatum(seq);
values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id);
values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
values[8] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);

/*
* storing in the previous record values to use on the next record
*/
result_tuples[funcctx->call_cntr].start_id = path_id;
result_tuples[funcctx->call_cntr].end_id = seq;

tuple = heap_form_tuple(tuple_desc, values, nulls);
result = HeapTupleGetDatum(tuple);
SRF_RETURN_NEXT(funcctx, result);
Expand Down
73 changes: 43 additions & 30 deletions src/max_flow/edge_disjoint_paths_driver.cpp
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 <sstream>
#include <vector>
#include <set>
#include <map>

#include "max_flow/pgr_maxflow.hpp"

Expand All @@ -41,6 +42,36 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "c_types/ii_t_rt.h"


static
std::map<int64_t , std::set<int64_t>>
get_combinations(const II_t_rt *combinations, size_t total) {
std::map<int64_t, std::set<int64_t>> result;

for (size_t i = 0; i < total; i++) {
auto row = combinations[i];
result[row.d1.source].insert(row.d2.target);
}
return result;
}

static
std::map<int64_t , std::set<int64_t>>
get_combinations(
int64_t *start_arr,
size_t size_start_arr,
int64_t *end_arr,
size_t size_end_arr) {
std::map<int64_t, std::set<int64_t>> result;

for (size_t i = 0; i < size_start_arr; ++i) {
for (size_t j = 0; j < size_end_arr; ++j) {
result[start_arr[i]].insert(end_arr[j]);
}
}
return result;
}

static
std::vector<Path_rt>
single_execution(
Expand Down Expand Up @@ -93,32 +124,24 @@ do_pgr_edge_disjoint_paths(
pgassert((sources && sinks) || combinations);
pgassert((size_source_verticesArr && size_sink_verticesArr) || total_combinations);

std::set<int64_t> set_source_vertices(
sources, sources + size_source_verticesArr);
std::set<int64_t> set_sink_vertices(
sinks, sinks + size_sink_verticesArr);
std::vector< II_t_rt > combinations_vector(
combinations, combinations + total_combinations);
auto combinations_data = total_combinations?
get_combinations(combinations, total_combinations)
: get_combinations(sources, size_source_verticesArr, sinks, size_sink_verticesArr);

std::vector<Edge_t> edges(
data_edges, data_edges + total_edges);

if (!combinations_vector.empty()) {
pgassert(set_source_vertices.empty());
pgassert(set_sink_vertices.empty());

for (const II_t_rt &comb : combinations_vector) {
set_source_vertices.insert(comb.d1.source);
set_sink_vertices.insert(comb.d2.target);
}
}


std::vector<Path_rt> paths;
for (const auto &s : set_source_vertices) {
for (const auto &t : set_sink_vertices) {
for (const auto &c : combinations_data) {
for (const auto &t : c.second) {
/*
* a source can not be a sink
* aka there is no path
*/
if (c.first == t) continue;
auto path = single_execution(
edges,
s,
c.first,
t,
directed);
paths.insert(paths.end(), path.begin(), path.end());
Expand Down Expand Up @@ -166,16 +189,6 @@ do_pgr_edge_disjoint_paths(
prev = r;
}

/*
* Numbering the paths
*/
int path_id(0);
for (auto &r : paths) {
r.start_id = path_id;
if (r.edge == -1) ++path_id;
}


(*return_tuples) = pgr_alloc(paths.size(), (*return_tuples));
for (size_t i = 0; i < paths.size(); ++i) {
(*return_tuples)[i] = paths[i];
Expand Down
Loading

0 comments on commit 2329137

Please sign in to comment.