Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To see all issues & pull requests closed by this release see the
* [#3060](https://github.com/pgRouting/pgrouting/issues/3060): dagShortestPath: use the shortest_path process and driver
* [#3064](https://github.com/pgRouting/pgrouting/issues/3064): Astar: create and use a process and driver for Astar
* [#3075](https://github.com/pgRouting/pgrouting/issues/3075): Spanning tree: create and use a process and driver
* [#3086](https://github.com/pgRouting/pgrouting/issues/3086): MaxFlow: create and use a process and driver
Comment thread
cvvergara marked this conversation as resolved.

## pgRouting 4.0

Expand Down
1 change: 1 addition & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ To see all issues & pull requests closed by this release see the
* :issue:`3060`: dagShortestPath: use the shortest_path process and driver
* :issue:`3064`: Astar: create and use a process and driver for Astar
* :issue:`3075`: Spanning tree: create and use a process and driver
* :issue:`3086`: MaxFlow: create and use a process and driver

pgRouting 4.0
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
3 changes: 2 additions & 1 deletion include/c_common/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ enum Which {
PRIM = 510, PRIMDD, PRIMDFS, PRIMBFS,
DFS = 520,
BFS = 530,
DIJKSTRADD = 540
DIJKSTRADD = 540,
MAXFLOW, PUSHRELABEL, BOYKOV, EDMONDSKARP
};

#endif // INCLUDE_C_COMMON_ENUMS_H_
3 changes: 3 additions & 0 deletions include/cpp_common/combinations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ get_combinations(const std::vector<II_t_rt>&);
std::map<int64_t, std::set<int64_t>>
get_combinations(const std::string&, ArrayType*, ArrayType*, bool, bool&);

std::map<int64_t, std::set<int64_t>>
get_combinations(const std::string&, ArrayType*, ArrayType*, bool);

std::map<int64_t, std::set<int64_t>>
get_combinations(const char*, ArrayType*, ArrayType*, bool);

Expand Down
6 changes: 6 additions & 0 deletions include/cpp_common/to_postgres.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 "c_types/routes_t.h"
#include "c_types/path_rt.h"
#include "c_types/mst_rt.h"
#include "c_types/flow_t.h"

#include "cpp_common/path.hpp"
#include "cpp_common/base_graph.hpp"
Expand Down Expand Up @@ -68,6 +69,11 @@ size_t get_tuples(const std::deque<pgrouting::Path>&, Path_rt*&);
*/
size_t get_tuples(const std::deque<pgrouting::Path>&, MST_rt*&);

/*
* @brief get tuples for Flow_t
*/
size_t get_tuples(const std::vector<Flow_t>&, Flow_t*&);

/*
* @brief get tuples for spanning tree driver
*/
Expand Down
2 changes: 2 additions & 0 deletions include/cpp_common/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include "c_common/enums.h"
#include "c_types/mst_rt.h"
#include "c_types/flow_t.h"

namespace pgrouting {

Expand All @@ -42,6 +43,7 @@ std::string get_name(Which, bool, bool, bool);
char estimate_drivingSide(char, Which);
void get_new_queries(const std::string&, const std::string&, std::string&, std::string&);
std::vector<MST_rt> only_root_result(const std::set<int64_t>&);
std::vector<Flow_t> only_maxFlow_result(int64_t);

} // namespace pgrouting

Expand Down
57 changes: 57 additions & 0 deletions include/drivers/maxFlow_driver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*PGR-GNU*****************************************************************
File: maxFlow_driver.hpp

Generated with Template by:
Copyright (c) 2007-2026 pgRouting developers
Mail: project@pgrouting.org

Function's developer:
Copyright (c) 2016 Andrea Nardelli
Mail: nrd.nardelli@gmail.com

------

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_DRIVERS_MAXFLOW_DRIVER_HPP_
#define INCLUDE_DRIVERS_MAXFLOW_DRIVER_HPP_

#include <cstddef>
#include <cstdint>
#include <string>
#include <sstream>

#include "c_common/enums.h"

using Flow_t = struct Flow_t;
using ArrayType = struct ArrayType;

namespace pgrouting {
namespace drivers {

void do_maxFlow(
const std::string&, const std::string&,
ArrayType*, ArrayType*,

Which,
Flow_t*&, size_t&,
std::ostringstream&, std::ostringstream&, std::ostringstream&);

} // namespace drivers
} // namespace pgrouting

#endif // INCLUDE_DRIVERS_MAXFLOW_DRIVER_HPP_
9 changes: 5 additions & 4 deletions include/max_flow/maxflow.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 "c_types/flow_t.h"
#include "cpp_common/edge_t.hpp"
#include "c_common/enums.h"
#include "c_types/path_rt.h"
#include "cpp_common/interruption.hpp"

Expand Down Expand Up @@ -107,10 +108,10 @@ class PgrFlowGraph {
}

PgrFlowGraph(
const std::vector<Edge_t> &edges,
const std::set<int64_t> &source_vertices,
const std::set<int64_t> &sink_vertices,
int algorithm);
const std::vector<Edge_t>&,
const std::set<int64_t>&,
const std::set<int64_t>&,
Which);

PgrFlowGraph(
const std::vector<Edge_t> &edges,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
File: max_flow_driver.h
File: maxFlow_process.h

Generated with Template by:
Copyright (c) 2007-2026 pgRouting developers
Expand Down Expand Up @@ -27,49 +27,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

#ifndef INCLUDE_DRIVERS_MAX_FLOW_MAX_FLOW_DRIVER_H_
#define INCLUDE_DRIVERS_MAX_FLOW_MAX_FLOW_DRIVER_H_
#ifndef INCLUDE_PROCESS_MAXFLOW_PROCESS_H_
#define INCLUDE_PROCESS_MAXFLOW_PROCESS_H_
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <postgres.h>
#include <utils/array.h>

#ifdef __cplusplus
}
#endif

#include "cpp_common/undefPostgresDefine.hpp"

#ifdef __cplusplus
# include <cstddef>
# include <cstdint>
#include <cstddef>
#include <cstdint>
using Flow_t = struct Flow_t;
using ArrayType = struct ArrayType;
#else
# include <stddef.h>
# include <stdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct Flow_t Flow_t;
typedef struct ArrayType ArrayType;
#endif

#include "c_common/enums.h"

#ifdef __cplusplus
extern "C" {
#endif

void pgr_do_max_flow(
const char*,
const char*,
void pgr_process_maxFlow(
const char*, const char*,
ArrayType*, ArrayType*,

int, bool,

Flow_t**, size_t*,
char**, char**, char**);
enum Which,
Flow_t**, size_t*);

#ifdef __cplusplus
}
#endif

#endif // INCLUDE_DRIVERS_MAX_FLOW_MAX_FLOW_DRIVER_H_
#endif // INCLUDE_PROCESS_MAXFLOW_PROCESS_H_
7 changes: 6 additions & 1 deletion locale/en/LC_MESSAGES/pgrouting_doc_strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: pgRouting v4.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-02-21 01:08+0000\n"
"POT-Creation-Date: 2026-03-01 21:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -3961,6 +3961,11 @@ msgid ""
"tree: create and use a process and driver"
msgstr ""

msgid ""
"`#3086 <https://github.com/pgRouting/pgrouting/issues/3086>`__: MaxFlow: "
"create and use a process and driver"
msgstr ""

msgid "All releases"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion locale/pot/pgrouting_doc_strings.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: pgRouting v4.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-02-21 01:08+0000\n"
"POT-Creation-Date: 2026-03-01 21:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -3550,6 +3550,9 @@ msgstr ""
msgid "`#3075 <https://github.com/pgRouting/pgrouting/issues/3075>`__: Spanning tree: create and use a process and driver"
msgstr ""

msgid "`#3086 <https://github.com/pgRouting/pgrouting/issues/3086>`__: MaxFlow: create and use a process and driver"
msgstr ""

msgid "All releases"
msgstr ""

Expand Down
8 changes: 8 additions & 0 deletions src/cpp_common/combinations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,13 @@ get_combinations(
return result;
}

std::map<int64_t , std::set<int64_t>>
get_combinations(
const std::string &combinations_sql,
ArrayType* startsArr, ArrayType* endsArr, bool normal) {
bool is_matrix = false;
return get_combinations(combinations_sql, startsArr, endsArr, normal, is_matrix);
}

} // namespace utilities
} // namespace pgrouting
18 changes: 18 additions & 0 deletions src/cpp_common/to_postgres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "c_types/routes_t.h"
#include "c_types/path_rt.h"
#include "c_types/mst_rt.h"
#include "c_types/flow_t.h"

#include "cpp_common/path.hpp"
#include "cpp_common/alloc.hpp"
Expand Down Expand Up @@ -242,6 +243,23 @@ get_tuples(
return count;
}

size_t
get_tuples(
const std::vector<Flow_t> &results,
Flow_t* &tuples) {
pgassert(!tuples);

auto count = results.size();
if (count == 0) return 0;

tuples = pgr_alloc(count, tuples);

for (size_t i = 0; i < count; i++) {
tuples[i] = results[i];
}
return count;
}


size_t
get_tuples(
Expand Down
19 changes: 19 additions & 0 deletions src/cpp_common/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ get_name(Which which) {
case DIJKSTRADD:
return "pgr_drivingDistance";
break;
case MAXFLOW:
return "pgr_maxFlow";
break;
case PUSHRELABEL:
return "pgr_pushRelabel";
break;
case BOYKOV:
return "pgr_boykovKolmogorov";
break;
case EDMONDSKARP:
return "pgr_edmondsKarp";
break;
default:
return "unknown";
break;
Expand Down Expand Up @@ -213,4 +225,11 @@ only_root_result(const std::set<int64_t> &vids) {
return results;
}

std::vector<Flow_t>
only_maxFlow_result(int64_t maxFlow) {
std::vector<Flow_t> results;
results.push_back({-1, -1, -1, maxFlow, -1, 0, 0});
return results;
}

} // namespace pgrouting
4 changes: 3 additions & 1 deletion src/max_flow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ ADD_LIBRARY(max_flow OBJECT
maximum_cardinality_matching.c
edge_disjoint_paths.c

max_flow_driver.cpp
maxFlow_driver.cpp
maxFlow_process.cpp

maximum_cardinality_matching_driver.cpp
edge_disjoint_paths_driver.cpp
minCostMaxFlow_driver.cpp
Expand Down
Loading