46 int64_t *sourceVertices,
size_t sizeSourceVerticesArr,
47 int64_t *sinkVertices,
size_t sizeSinkVerticesArr,
50 pgr_flow_t **return_tuples,
size_t *return_count,
54 std::ostringstream log;
55 std::ostringstream err;
56 std::ostringstream notice;
65 pgassert((sourceVertices && sinkVertices) || combinations);
66 pgassert((sizeSourceVerticesArr && sizeSinkVerticesArr) || total_combinations);
68 std::vector<pgr_costFlow_t> edges(data_edges, data_edges + total_edges);
69 std::set<int64_t> sources(
70 sourceVertices, sourceVertices + sizeSourceVerticesArr);
71 std::set<int64_t> targets(
72 sinkVertices, sinkVertices + sizeSinkVerticesArr);
73 std::vector< pgr_combination_t > combinations_vector(
74 combinations, combinations + total_combinations);
76 if (!combinations_vector.empty()) {
81 sources.insert(comb.source);
82 targets.insert(comb.target);
86 std::set<int64_t> vertices(sources);
87 vertices.insert(targets.begin(), targets.end());
90 != (sources.size() + targets.size())) {
91 *err_msg =
pgr_msg(
"A source found as sink");
96 edges, sources, targets);
101 std::vector<pgr_flow_t> flow_edges;
109 edge.residual_capacity = -1;
111 edge.agg_cost = min_cost;
112 flow_edges.push_back(
edge);
117 (*return_tuples) =
pgr_alloc(flow_edges.size(), (*return_tuples));
118 for (
size_t i = 0; i < flow_edges.size(); i++) {
119 (*return_tuples)[i] = flow_edges[i];
121 *return_count = flow_edges.size();
124 *log_msg = log.str().empty()?
127 *notice_msg = notice.str().empty()?
131 (*return_tuples) =
pgr_free(*return_tuples);
133 err << except.
what();
134 *err_msg =
pgr_msg(err.str().c_str());
135 *log_msg =
pgr_msg(log.str().c_str());
136 }
catch (std::exception &except) {
137 (*return_tuples) =
pgr_free(*return_tuples);
139 err << except.what();
140 *err_msg =
pgr_msg(err.str().c_str());
141 *log_msg =
pgr_msg(log.str().c_str());
143 (*return_tuples) =
pgr_free(*return_tuples);
145 err <<
"Caught unknown exception!";
146 *err_msg =
pgr_msg(err.str().c_str());
147 *log_msg =
pgr_msg(log.str().c_str());