30 #include "./../../common/src/postgres_connection.h"
31 #include "utils/array.h"
33 #include "./../../common/src/debug_macro.h"
34 #include "./../../common/src/e_report.h"
35 #include "./../../common/src/time_msg.h"
36 #include "./../../common/src/pgr_types.h"
37 #include "./../../common/src/edges_input.h"
38 #include "./../../common/src/arrays_input.h"
49 int64_t source_vertex,
54 size_t *result_count) {
55 if (!(strcmp(algorithm,
"push_relabel") == 0
56 || strcmp(algorithm,
"edmonds_karp") == 0
57 || strcmp(algorithm,
"boykov_kolmogorov") == 0)) {
58 elog(ERROR,
"Unknown algorithm");
63 size_t size_sink_verticesArr = 0;
64 int64_t* sink_vertices =
72 size_t total_tuples = 0;
76 if (total_tuples == 0) {
77 if (sink_vertices) pfree(sink_vertices);
83 clock_t start_t = clock();
85 char* notice_msg = NULL;
91 sink_vertices, size_sink_verticesArr,
95 result_tuples, result_count,
102 time_msg(
"pgr_maxFlow(many to many)",
104 }
else if (strcmp(algorithm,
"push_relabel") == 0) {
105 time_msg(
"pgr_maxFlowPushRelabel(one to many)",
107 }
else if (strcmp(algorithm,
"edmonds_karp") == 0) {
108 time_msg(
"pgr_maxFlowEdmondsKarp(one to many)",
111 time_msg(
"pgr_maxFlowBoykovKolmogorov(one to many)",
116 if (edges) pfree(edges);
117 if (sink_vertices) pfree(sink_vertices);
119 if (err_msg && (*result_tuples)) {
120 pfree(*result_tuples);
121 (*result_tuples) = NULL;
127 if (log_msg) pfree(log_msg);
128 if (notice_msg) pfree(notice_msg);
129 if (err_msg) pfree(err_msg);
137 FuncCallContext *funcctx;
138 TupleDesc tuple_desc;
142 size_t result_count = 0;
145 if (SRF_IS_FIRSTCALL()) {
146 MemoryContext oldcontext;
147 funcctx = SRF_FIRSTCALL_INIT();
148 oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
154 text_to_cstring(PG_GETARG_TEXT_P(0)),
156 PG_GETARG_ARRAYTYPE_P(2),
157 text_to_cstring(PG_GETARG_TEXT_P(3)),
164 #if PGSQL_VERSION > 95
165 funcctx->max_calls = result_count;
167 funcctx->max_calls = (uint32_t)result_count;
169 funcctx->user_fctx = result_tuples;
170 if (get_call_result_type(fcinfo, NULL, &tuple_desc)
171 != TYPEFUNC_COMPOSITE) {
173 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
174 errmsg(
"function returning record called in context "
175 "that cannot accept type record")));
178 funcctx->tuple_desc = tuple_desc;
179 MemoryContextSwitchTo(oldcontext);
182 funcctx = SRF_PERCALL_SETUP();
183 tuple_desc = funcctx->tuple_desc;
184 result_tuples = (
pgr_flow_t *) funcctx->user_fctx;
186 if (funcctx->call_cntr < funcctx->max_calls) {
191 size_t call_cntr = funcctx->call_cntr;
195 values = palloc(6 *
sizeof(Datum));
196 nulls = palloc(6 *
sizeof(
bool));
199 for (i = 0; i < 6; ++i) {
203 values[0] = Int32GetDatum(call_cntr + 1);
204 values[1] = Int64GetDatum(result_tuples[call_cntr].
edge);
205 values[2] = Int64GetDatum(result_tuples[call_cntr].source);
206 values[3] = Int64GetDatum(result_tuples[call_cntr].target);
207 values[4] = Int64GetDatum(result_tuples[call_cntr].flow);
208 values[5] = Int64GetDatum(result_tuples[call_cntr].residual_capacity);
212 tuple = heap_form_tuple(tuple_desc, values, nulls);
213 result = HeapTupleGetDatum(tuple);
214 SRF_RETURN_NEXT(funcctx, result);
216 SRF_RETURN_DONE(funcctx);
PG_FUNCTION_INFO_V1(max_flow_one_to_many)
void time_msg(char *msg, clock_t start_t, clock_t end_t)
void do_pgr_max_flow(pgr_edge_t *data_edges, size_t total_tuples, int64_t *source_vertices, size_t size_source_verticesArr, int64_t *sink_vertices, size_t size_sink_verticesArr, char *algorithm, bool only_flow, pgr_flow_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
void pgr_global_report(char *log, char *notice, char *err)
notice & error
void pgr_SPI_finish(void)
void pgr_SPI_connect(void)
static void process(char *edges_sql, int64_t source_vertex, ArrayType *ends, char *algorithm, bool only_flow, pgr_flow_t **result_tuples, size_t *result_count)
PGDLLEXPORT Datum max_flow_one_to_many(PG_FUNCTION_ARGS)