31 #include "utils/array.h"
53 size_t *result_count) {
54 if (algorithm < 1 || algorithm > 3) {
55 elog(ERROR,
"Unknown algorithm");
60 size_t size_source_verticesArr = 0;
61 int64_t* source_vertices =
64 size_t size_sink_verticesArr = 0;
65 int64_t* sink_vertices =
70 size_t total_edges = 0;
77 if (total_edges == 0) {
78 if (source_vertices) pfree(source_vertices);
79 if (sink_vertices) pfree(sink_vertices);
86 clock_t start_t = clock();
88 char* notice_msg = NULL;
93 source_vertices, size_source_verticesArr,
94 sink_vertices, size_sink_verticesArr,
98 result_tuples, result_count,
105 time_msg(
"pgr_maxFlow(many to many)",
107 }
else if (algorithm == 1) {
108 time_msg(
"pgr_maxFlowPushRelabel(many to many)",
110 }
else if (algorithm == 3) {
111 time_msg(
"pgr_maxFlowEdmondsKarp(many to many)",
114 time_msg(
"pgr_maxFlowBoykovKolmogorov(many to many)",
119 if (edges) pfree(edges);
120 if (source_vertices) pfree(source_vertices);
121 if (sink_vertices) pfree(sink_vertices);
123 if (err_msg && (*result_tuples)) {
124 pfree(*result_tuples);
125 (*result_tuples) = NULL;
131 if (log_msg) pfree(log_msg);
132 if (notice_msg) pfree(notice_msg);
133 if (err_msg) pfree(err_msg);
142 FuncCallContext *funcctx;
143 TupleDesc tuple_desc;
147 size_t result_count = 0;
150 if (SRF_IS_FIRSTCALL()) {
151 MemoryContext oldcontext;
152 funcctx = SRF_FIRSTCALL_INIT();
153 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
159 text_to_cstring(PG_GETARG_TEXT_P(0)),
160 PG_GETARG_ARRAYTYPE_P(1),
161 PG_GETARG_ARRAYTYPE_P(2),
170 #if PGSQL_VERSION > 95
171 funcctx->max_calls = result_count;
173 funcctx->max_calls = (uint32_t)result_count;
175 funcctx->user_fctx = result_tuples;
176 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
177 != TYPEFUNC_COMPOSITE) {
179 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
180 errmsg(
"function returning record called in context "
181 "that cannot accept type record")));
184 funcctx->tuple_desc = tuple_desc;
185 MemoryContextSwitchTo(oldcontext);
188 funcctx = SRF_PERCALL_SETUP();
189 tuple_desc = funcctx->tuple_desc;
190 result_tuples = (
pgr_flow_t *) funcctx->user_fctx;
192 if (funcctx->call_cntr < funcctx->max_calls) {
197 size_t call_cntr = funcctx->call_cntr;
201 values = palloc(6 *
sizeof(Datum));
202 nulls = palloc(6 *
sizeof(
bool));
205 for (i = 0; i < 6; ++i) {
209 values[0] = Int32GetDatum(call_cntr + 1);
210 values[1] = Int64GetDatum(result_tuples[call_cntr].
edge);
211 values[2] = Int64GetDatum(result_tuples[call_cntr].source);
212 values[3] = Int64GetDatum(result_tuples[call_cntr].target);
213 values[4] = Int64GetDatum(result_tuples[call_cntr].flow);
214 values[5] = Int64GetDatum(result_tuples[call_cntr].residual_capacity);
217 tuple = heap_form_tuple(tuple_desc, values, nulls);
218 result = HeapTupleGetDatum(tuple);
219 SRF_RETURN_NEXT(funcctx, result);
221 SRF_RETURN_DONE(funcctx);
static edge_t edges[22573]
PG_FUNCTION_INFO_V1(max_flow_many_to_many)
void time_msg(char *msg, clock_t start_t, clock_t end_t)
void pgr_global_report(char *log, char *notice, char *err)
notice & error
void pgr_SPI_finish(void)
void do_pgr_max_flow(pgr_edge_t *data_edges, size_t total_edges, int64_t *source_vertices, size_t size_source_verticesArr, int64_t *sink_vertices, size_t size_sink_verticesArr, int algorithm, bool only_flow, pgr_flow_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
static void process(char *edges_sql, ArrayType *starts, ArrayType *ends, int algorithm, bool only_flow, pgr_flow_t **result_tuples, size_t *result_count)
void pgr_SPI_connect(void)
PGDLLEXPORT Datum max_flow_many_to_many(PG_FUNCTION_ARGS)