PGROUTING  3.2
edge_disjoint_paths.c File Reference
#include <stdbool.h>
#include "c_common/postgres_connection.h"
#include "utils/array.h"
#include "c_common/debug_macro.h"
#include "c_common/e_report.h"
#include "c_common/time_msg.h"
#include "c_common/edges_input.h"
#include "c_common/arrays_input.h"
#include "c_common/combinations_input.h"
#include "drivers/max_flow/edge_disjoint_paths_driver.h"
Include dependency graph for edge_disjoint_paths.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_edgedisjointpaths (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_edgedisjointpaths)
 
static void process (char *edges_sql, char *combinations_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_edgedisjointpaths()

PGDLLEXPORT Datum _pgr_edgedisjointpaths ( PG_FUNCTION_ARGS  )

Definition at line 138 of file edge_disjoint_paths.c.

138  {
139  FuncCallContext *funcctx;
140  TupleDesc tuple_desc;
141 
142  General_path_element_t *result_tuples = NULL;
143  size_t result_count = 0;
144 
145  if (SRF_IS_FIRSTCALL()) {
146  MemoryContext oldcontext;
147  funcctx = SRF_FIRSTCALL_INIT();
148  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
149 
150 
151  if (PG_NARGS() == 4) {
152  /*
153  * many to many
154  */
155  process(
156  text_to_cstring(PG_GETARG_TEXT_P(0)),
157  NULL,
158  PG_GETARG_ARRAYTYPE_P(1),
159  PG_GETARG_ARRAYTYPE_P(2),
160  PG_GETARG_BOOL(3),
161  &result_tuples,
162  &result_count);
163 
164  } else if (PG_NARGS() == 3) {
165  /*
166  * combinations
167  */
168  process(
169  text_to_cstring(PG_GETARG_TEXT_P(0)),
170  text_to_cstring(PG_GETARG_TEXT_P(1)),
171  NULL,
172  NULL,
173  PG_GETARG_BOOL(2),
174  &result_tuples,
175  &result_count);
176  }
177 
178 
179 #if PGSQL_VERSION > 95
180  funcctx->max_calls = result_count;
181 #else
182  funcctx->max_calls = (uint32_t)result_count;
183 #endif
184  funcctx->user_fctx = result_tuples;
185  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
186  != TYPEFUNC_COMPOSITE) {
187  ereport(ERROR,
188  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
189  errmsg("function returning record called in context "
190  "that cannot accept type record")));
191  }
192 
193  funcctx->tuple_desc = tuple_desc;
194  MemoryContextSwitchTo(oldcontext);
195  }
196 
197  funcctx = SRF_PERCALL_SETUP();
198  tuple_desc = funcctx->tuple_desc;
199  result_tuples = (General_path_element_t *) funcctx->user_fctx;
200 
201  if (funcctx->call_cntr < funcctx->max_calls) {
202  HeapTuple tuple;
203  Datum result;
204  Datum *values;
205  bool *nulls;
206 
207 
208  values = palloc(9 * sizeof(Datum));
209  nulls = palloc(9 * sizeof(bool));
210 
211  size_t i;
212  for (i = 0; i < 9; ++i) {
213  nulls[i] = false;
214  }
215 
216  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
217  values[1] = Int32GetDatum(
218  result_tuples[funcctx->call_cntr].start_id + 1);
219  values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
220  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
221  values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id);
222  values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
223  values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
224  values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
225  values[8] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
226 
227  tuple = heap_form_tuple(tuple_desc, values, nulls);
228  result = HeapTupleGetDatum(tuple);
229  SRF_RETURN_NEXT(funcctx, result);
230  } else {
231  SRF_RETURN_DONE(funcctx);
232  }
233 }

References General_path_element_t::agg_cost, General_path_element_t::cost, General_path_element_t::edge, General_path_element_t::end_id, if(), General_path_element_t::node, process(), General_path_element_t::seq, and General_path_element_t::start_id.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_edgedisjointpaths  )

◆ process()

static void process ( char *  edges_sql,
char *  combinations_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 48 of file edge_disjoint_paths.c.

56  {
58 
59  int64_t *source_vertices = NULL;
60  size_t size_source_verticesArr = 0;
61 
62  int64_t *sink_vertices = NULL;
63  size_t size_sink_verticesArr = 0;
64 
65 
66  pgr_edge_t *edges = NULL;
67  size_t total_edges = 0;
68 
69  pgr_combination_t *combinations = NULL;
70  size_t total_combinations = 0;
71 
72  if (starts && ends) {
73  source_vertices = (int64_t*)
74  pgr_get_bigIntArray(&size_source_verticesArr, starts);
75  sink_vertices = (int64_t*)
76  pgr_get_bigIntArray(&size_sink_verticesArr, ends);
77  } else if (combinations_sql) {
78  pgr_get_combinations(combinations_sql, &combinations, &total_combinations);
79  if (total_combinations == 0) {
80  if (combinations)
81  pfree(combinations);
83  return;
84  }
85  }
86 
87  pgr_get_edges(edges_sql, &edges, &total_edges);
88 
89  if (total_edges == 0) {
90  if (source_vertices) pfree(source_vertices);
91  if (sink_vertices) pfree(sink_vertices);
93  return;
94  }
95 
96 
97  PGR_DBG("Starting timer");
98  clock_t start_t = clock();
99  char* log_msg = NULL;
100  char* notice_msg = NULL;
101  char* err_msg = NULL;
102 
104  edges, total_edges,
105  combinations, total_combinations,
106  source_vertices, size_source_verticesArr,
107  sink_vertices, size_sink_verticesArr,
108  directed,
109 
110  result_tuples, result_count,
111 
112  &log_msg,
113  &notice_msg,
114  &err_msg);
115 
116  time_msg("pgr_edgeDisjointPaths(many to many)", start_t, clock());
117 
118  if (edges) pfree(edges);
119  if (source_vertices) pfree(source_vertices);
120  if (sink_vertices) pfree(sink_vertices);
121 
122  if (err_msg && (*result_tuples)) {
123  pfree(*result_tuples);
124  (*result_tuples) = NULL;
125  (*result_count) = 0;
126  }
127 
128  pgr_global_report(log_msg, notice_msg, err_msg);
129 
130  if (log_msg) pfree(log_msg);
131  if (notice_msg) pfree(notice_msg);
132  if (err_msg) pfree(err_msg);
133  pgr_SPI_finish();
134 }

References do_pgr_edge_disjoint_paths(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_combinations(), pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_edgedisjointpaths().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
process
static void process(char *edges_sql, char *combinations_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
Definition: edge_disjoint_paths.c:48
pgr_get_bigIntArray
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
Enforces the input array to be NOT empty.
Definition: arrays_input.c:146
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
pgr_combination_t
Definition: pgr_combination_t.h:43
pgr_get_combinations
void pgr_get_combinations(char *combinations_sql, pgr_combination_t **combinations, size_t *total_combinations)
combinations_sql
Definition: combinations_input.c:147
pgr_get_edges
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:711
General_path_element_t
Definition: general_path_element_t.h:37
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
do_pgr_edge_disjoint_paths
void do_pgr_edge_disjoint_paths(pgr_edge_t *data_edges, size_t total_edges, pgr_combination_t *combinations, size_t total_combinations, int64_t *sources, size_t size_source_verticesArr, int64_t *sinks, size_t size_sink_verticesArr, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: edge_disjoint_paths_driver.cpp:66
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93