PGROUTING  2.5
edge_disjoint_paths.c File Reference
Include dependency graph for edge_disjoint_paths.c:

Go to the source code of this file.

Functions

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

Function Documentation

PGDLLEXPORT Datum edge_disjoint_paths_many_to_many ( PG_FUNCTION_ARGS  )

Definition at line 117 of file edge_disjoint_paths.c.

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.

Referenced by process().

117  {
118  FuncCallContext *funcctx;
119  TupleDesc tuple_desc;
120 
121  /**************************************************************************/
122  General_path_element_t *result_tuples = NULL;
123  size_t result_count = 0;
124  /**************************************************************************/
125 
126  if (SRF_IS_FIRSTCALL()) {
127  MemoryContext oldcontext;
128  funcctx = SRF_FIRSTCALL_INIT();
129  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
130 
131 
132  /**********************************************************************/
133 
134  process(
135  text_to_cstring(PG_GETARG_TEXT_P(0)),
136  PG_GETARG_ARRAYTYPE_P(1),
137  PG_GETARG_ARRAYTYPE_P(2),
138  PG_GETARG_BOOL(3),
139  &result_tuples,
140  &result_count);
141 
142  /**********************************************************************/
143 
144 #if PGSQL_VERSION > 95
145  funcctx->max_calls = result_count;
146 #else
147  funcctx->max_calls = (uint32_t)result_count;
148 #endif
149  funcctx->user_fctx = result_tuples;
150  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
151  != TYPEFUNC_COMPOSITE) {
152  ereport(ERROR,
153  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
154  errmsg("function returning record called in context "
155  "that cannot accept type record")));
156  }
157 
158  funcctx->tuple_desc = tuple_desc;
159  MemoryContextSwitchTo(oldcontext);
160  }
161 
162  funcctx = SRF_PERCALL_SETUP();
163  tuple_desc = funcctx->tuple_desc;
164  result_tuples = (General_path_element_t *) funcctx->user_fctx;
165 
166  if (funcctx->call_cntr < funcctx->max_calls) {
167  HeapTuple tuple;
168  Datum result;
169  Datum *values;
170  bool *nulls;
171 
172  /**********************************************************************/
173  /* MODIFY AS NEEDED */
174 
175  values = palloc(9 * sizeof(Datum));
176  nulls = palloc(9 * sizeof(bool));
177 
178  size_t i;
179  for (i = 0; i < 9; ++i) {
180  nulls[i] = false;
181  }
182 
183  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
184  values[1] = Int32GetDatum(result_tuples[funcctx->call_cntr].start_id + 1);
185  values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
186  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].start_id);
187  values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].end_id);
188  values[5] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
189  values[6] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
190  values[7] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
191  values[8] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
192  /**********************************************************************/
193 
194  tuple = heap_form_tuple(tuple_desc, values, nulls);
195  result = HeapTupleGetDatum(tuple);
196  SRF_RETURN_NEXT(funcctx, result);
197  } else {
198  SRF_RETURN_DONE(funcctx);
199  }
200 }
static void process(char *edges_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13

Here is the call graph for this function:

Here is the caller graph for this function:

PG_FUNCTION_INFO_V1 ( edge_disjoint_paths_many_to_many  )

Referenced by process().

Here is the caller graph for this function:

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

Definition at line 45 of file edge_disjoint_paths.c.

References do_pgr_edge_disjoint_paths(), edge_disjoint_paths_many_to_many(), edges, PG_FUNCTION_INFO_V1(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by edge_disjoint_paths_many_to_many().

52  {
54 
55  size_t size_source_verticesArr = 0;
56  int64_t* source_vertices =
57  pgr_get_bigIntArray(&size_source_verticesArr, starts);
58 
59  size_t size_sink_verticesArr = 0;
60  int64_t* sink_vertices =
61  pgr_get_bigIntArray(&size_sink_verticesArr, ends);
62 
63 
64  pgr_edge_t *edges = NULL;
65  size_t total_edges = 0;
66 
67  pgr_get_edges(edges_sql, &edges, &total_edges);
68 
69  if (total_edges == 0) {
70  if (source_vertices) pfree(source_vertices);
71  if (sink_vertices) pfree(sink_vertices);
73  return;
74  }
75 
76 
77  PGR_DBG("Starting timer");
78  clock_t start_t = clock();
79  char* log_msg = NULL;
80  char* notice_msg = NULL;
81  char* err_msg = NULL;
82 
84  edges, total_edges,
85  source_vertices, size_source_verticesArr,
86  sink_vertices, size_sink_verticesArr,
87  directed,
88 
89  result_tuples, result_count,
90 
91  &log_msg,
92  &notice_msg,
93  &err_msg);
94 
95  time_msg("pgr_edgeDisjointPaths(many to many)", start_t, clock());
96 
97  if (edges) pfree(edges);
98  if (source_vertices) pfree(source_vertices);
99  if (sink_vertices) pfree(sink_vertices);
100 
101  if (err_msg && (*result_tuples)) {
102  pfree(*result_tuples);
103  (*result_tuples) = NULL;
104  (*result_count) = 0;
105  }
106 
107  pgr_global_report(log_msg, notice_msg, err_msg);
108 
109  if (log_msg) pfree(log_msg);
110  if (notice_msg) pfree(notice_msg);
111  if (err_msg) pfree(err_msg);
112  pgr_SPI_finish();
113 }
static edge_t edges[22573]
#define PGR_DBG(...)
Definition: debug_macro.h:34
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:540
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
enforces the input array to be NOT empty
Definition: arrays_input.c:124
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93
void do_pgr_edge_disjoint_paths(pgr_edge_t *data_edges, size_t total_edges, 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)
void pgr_SPI_finish(void)
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: