33 #include "utils/array.h"
51 char *combinations_sql,
57 size_t *result_count) {
58 if (algorithm < 1 || algorithm > 3) {
59 elog(ERROR,
"Unknown algorithm");
64 int64_t *source_vertices = NULL;
65 size_t size_source_verticesArr = 0;
67 int64_t *sink_vertices = NULL;
68 size_t size_sink_verticesArr = 0;
71 size_t total_edges = 0;
74 size_t total_combinations = 0;
77 source_vertices = (int64_t*)
79 sink_vertices = (int64_t*)
81 }
else if (combinations_sql) {
83 if (total_combinations == 0) {
96 if (total_edges == 0) {
97 if (source_vertices) pfree(source_vertices);
98 if (sink_vertices) pfree(sink_vertices);
105 clock_t start_t = clock();
106 char* log_msg = NULL;
107 char* notice_msg = NULL;
108 char *err_msg = NULL;
112 combinations, total_combinations,
113 source_vertices, size_source_verticesArr,
114 sink_vertices, size_sink_verticesArr,
118 result_tuples, result_count,
125 time_msg(
"pgr_maxFlow(many to many)",
127 }
else if (algorithm == 1) {
128 time_msg(
"pgr_maxFlowPushRelabel(many to many)",
130 }
else if (algorithm == 3) {
131 time_msg(
"pgr_maxFlowEdmondsKarp(many to many)",
134 time_msg(
"pgr_maxFlowBoykovKolmogorov(many to many)",
139 if (edges) pfree(edges);
140 if (source_vertices) pfree(source_vertices);
141 if (sink_vertices) pfree(sink_vertices);
143 if (err_msg && (*result_tuples)) {
144 pfree(*result_tuples);
145 (*result_tuples) = NULL;
151 if (log_msg) pfree(log_msg);
152 if (notice_msg) pfree(notice_msg);
153 if (err_msg) pfree(err_msg);
162 FuncCallContext *funcctx;
163 TupleDesc tuple_desc;
167 size_t result_count = 0;
170 if (SRF_IS_FIRSTCALL()) {
171 MemoryContext oldcontext;
172 funcctx = SRF_FIRSTCALL_INIT();
173 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
178 if (PG_NARGS() == 5) {
183 text_to_cstring(PG_GETARG_TEXT_P(0)),
185 PG_GETARG_ARRAYTYPE_P(1),
186 PG_GETARG_ARRAYTYPE_P(2),
192 }
else if (PG_NARGS() == 4) {
197 text_to_cstring(PG_GETARG_TEXT_P(0)),
198 text_to_cstring(PG_GETARG_TEXT_P(1)),
210 #if PGSQL_VERSION > 95
211 funcctx->max_calls = result_count;
213 funcctx->max_calls = (uint32_t)result_count;
215 funcctx->user_fctx = result_tuples;
216 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
217 != TYPEFUNC_COMPOSITE) {
219 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
220 errmsg(
"function returning record called in context "
221 "that cannot accept type record")));
224 funcctx->tuple_desc = tuple_desc;
225 MemoryContextSwitchTo(oldcontext);
228 funcctx = SRF_PERCALL_SETUP();
229 tuple_desc = funcctx->tuple_desc;
230 result_tuples = (
pgr_flow_t *) funcctx->user_fctx;
232 if (funcctx->call_cntr < funcctx->max_calls) {
237 size_t call_cntr = funcctx->call_cntr;
241 values = palloc(6 *
sizeof(Datum));
242 nulls = palloc(6 *
sizeof(
bool));
245 for (i = 0; i < 6; ++i) {
249 values[0] = Int32GetDatum(call_cntr + 1);
250 values[1] = Int64GetDatum(result_tuples[call_cntr].
edge);
251 values[2] = Int64GetDatum(result_tuples[call_cntr].source);
252 values[3] = Int64GetDatum(result_tuples[call_cntr].target);
253 values[4] = Int64GetDatum(result_tuples[call_cntr].flow);
254 values[5] = Int64GetDatum(result_tuples[call_cntr].residual_capacity);
257 tuple = heap_form_tuple(tuple_desc, values, nulls);
258 result = HeapTupleGetDatum(tuple);
259 SRF_RETURN_NEXT(funcctx, result);
261 SRF_RETURN_DONE(funcctx);