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