PGROUTING  2.6-dev
dijkstra.c File Reference
Include dependency graph for dijkstra.c:

Go to the source code of this file.

Functions

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

Variables

 PG_MODULE_MAGIC
 

Function Documentation

PGDLLEXPORT Datum many_to_many_dijkstra ( PG_FUNCTION_ARGS  )

Definition at line 134 of file dijkstra.c.

References if(), and process().

134  {
135  FuncCallContext *funcctx;
136  TupleDesc tuple_desc;
137 
138  /**********************************************************************/
139  General_path_element_t *result_tuples = NULL;
140  size_t result_count = 0;
141  /**********************************************************************/
142 
143  if (SRF_IS_FIRSTCALL()) {
144  MemoryContext oldcontext;
145  funcctx = SRF_FIRSTCALL_INIT();
146  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
147 
148 
149  /**********************************************************************/
150  // pgr_dijkstra(
151  // sql TEXT,
152  // start_vids ANYARRAY,
153  // end_vids ANYARRAY,
154  // directed BOOLEAN default true,
155  // only_cost BOOLEAN default false
156  // normal BOOLEAN default true
157 
158  process(
159  text_to_cstring(PG_GETARG_TEXT_P(0)),
160  PG_GETARG_ARRAYTYPE_P(1),
161  PG_GETARG_ARRAYTYPE_P(2),
162  PG_GETARG_BOOL(3),
163  PG_GETARG_BOOL(4),
164  PG_GETARG_BOOL(5),
165  &result_tuples,
166  &result_count);
167 
168  /**********************************************************************/
169 
170 #if PGSQL_VERSION > 95
171  funcctx->max_calls = result_count;
172 #else
173  funcctx->max_calls = (uint32_t)result_count;
174 #endif
175 
176  funcctx->user_fctx = result_tuples;
177  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
178  != TYPEFUNC_COMPOSITE) {
179  ereport(ERROR,
180  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
181  errmsg("function returning record called in context "
182  "that cannot accept type record")));
183  }
184 
185  funcctx->tuple_desc = tuple_desc;
186  MemoryContextSwitchTo(oldcontext);
187  }
188 
189  funcctx = SRF_PERCALL_SETUP();
190  tuple_desc = funcctx->tuple_desc;
191  result_tuples = (General_path_element_t*) funcctx->user_fctx;
192 
193  if (funcctx->call_cntr < funcctx->max_calls) {
194  HeapTuple tuple;
195  Datum result;
196  Datum *values;
197  bool* nulls;
198  size_t call_cntr = funcctx->call_cntr;
199 
200  /**********************************************************************/
201  // OUT seq INTEGER,
202  // OUT path_seq INTEGER,
203  // OUT start_vid BIGINT,
204  // OUT end_vid BIGINT,
205  // OUT node BIGINT,
206  // OUT edge BIGINT,
207  // OUT cost FLOAT,
208  // OUT agg_cost FLOAT)
209 
210  size_t numb = 8;
211  values = palloc(numb * sizeof(Datum));
212  nulls = palloc(numb * sizeof(bool));
213 
214  size_t i;
215  for (i = 0; i < numb; ++i) {
216  nulls[i] = false;
217  }
218 
219  values[0] = Int32GetDatum(call_cntr + 1);
220  values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
221  values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
222  values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
223  values[4] = Int64GetDatum(result_tuples[call_cntr].node);
224  values[5] = Int64GetDatum(result_tuples[call_cntr].edge);
225  values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
226  values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
227  /**********************************************************************/
228 
229  tuple = heap_form_tuple(tuple_desc, values, nulls);
230  result = HeapTupleGetDatum(tuple);
231  SRF_RETURN_NEXT(funcctx, result);
232  } else {
233  SRF_RETURN_DONE(funcctx);
234  }
235 }
Definition: trsp.h:31
static void process(char *edges_sql, ArrayType *starts, ArrayType *ends, bool directed, bool only_cost, bool normal, General_path_element_t **result_tuples, size_t *result_count)
Definition: dijkstra.c:48
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13

Here is the call graph for this function:

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

Definition at line 48 of file dijkstra.c.

References do_pgr_many_to_many_dijkstra(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_get_edges_reversed(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by many_to_many_dijkstra().

56  {
58 
59  int64_t* start_vidsArr = NULL;
60  size_t size_start_vidsArr = 0;
61 
62  int64_t* end_vidsArr = NULL;
63  size_t size_end_vidsArr = 0;
64 
65  pgr_edge_t *edges = NULL;
66  size_t total_edges = 0;
67  if (normal) {
68  pgr_get_edges(edges_sql, &edges, &total_edges);
69  start_vidsArr = (int64_t*)
70  pgr_get_bigIntArray(&size_start_vidsArr, starts);
71  end_vidsArr = (int64_t*)
72  pgr_get_bigIntArray(&size_end_vidsArr, ends);
73  } else {
74  pgr_get_edges_reversed(edges_sql, &edges, &total_edges);
75  end_vidsArr = (int64_t*)
76  pgr_get_bigIntArray(&size_end_vidsArr, starts);
77  start_vidsArr = (int64_t*)
78  pgr_get_bigIntArray(&size_start_vidsArr, ends);
79  }
80 
81  if (total_edges == 0) {
82  if (end_vidsArr) pfree(end_vidsArr);
83  if (start_vidsArr) pfree(start_vidsArr);
85  return;
86  }
87 
88  PGR_DBG("Starting timer");
89  clock_t start_t = clock();
90  char* log_msg = NULL;
91  char* notice_msg = NULL;
92  char* err_msg = NULL;
94  edges, total_edges,
95  start_vidsArr, size_start_vidsArr,
96  end_vidsArr, size_end_vidsArr,
97 
98  directed,
99  only_cost,
100  normal,
101 
102  result_tuples,
103  result_count,
104 
105  &log_msg,
106  &notice_msg,
107  &err_msg);
108 
109  if (only_cost) {
110  time_msg("processing pgr_dijkstraCost", start_t, clock());
111  } else {
112  time_msg("processing pgr_dijkstra", start_t, clock());
113  }
114 
115 
116  if (err_msg && (*result_tuples)) {
117  pfree(*result_tuples);
118  (*result_tuples) = NULL;
119  (*result_count) = 0;
120  }
121 
122  pgr_global_report(log_msg, notice_msg, err_msg);
123 
124  if (log_msg) pfree(log_msg);
125  if (notice_msg) pfree(notice_msg);
126  if (err_msg) pfree(err_msg);
127  if (edges) pfree(edges);
128  if (start_vidsArr) pfree(start_vidsArr);
129  if (end_vidsArr) pfree(end_vidsArr);
130  pgr_SPI_finish();
131 }
#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 do_pgr_many_to_many_dijkstra(pgr_edge_t *data_edges, size_t total_edges, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, bool only_cost, bool normal, General_path_element_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
Definition: e_report.c:93
void pgr_SPI_finish(void)
void pgr_SPI_connect(void)
void pgr_get_edges_reversed(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
Definition: edges_input.c:556

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

PG_MODULE_MAGIC

Definition at line 41 of file dijkstra.c.