PGROUTING  3.2
bdAstar.c File Reference
Include dependency graph for bdAstar.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_bdastar (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_bdastar)
 
static void process (char *edges_sql, char *combinations_sql, ArrayType *starts, ArrayType *ends, bool directed, int heuristic, double factor, double epsilon, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_bdastar()

PGDLLEXPORT Datum _pgr_bdastar ( PG_FUNCTION_ARGS  )

Definition at line 147 of file bdAstar.c.

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

References if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_bdastar  )

◆ process()

static void process ( char *  edges_sql,
char *  combinations_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
int  heuristic,
double  factor,
double  epsilon,
bool  only_cost,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 54 of file bdAstar.c.

64  {
65  check_parameters(heuristic, factor, epsilon);
66 
68 
69  int64_t* start_vidsArr = NULL;
70  size_t size_start_vidsArr = 0;
71 
72  int64_t* end_vidsArr = NULL;
73  size_t size_end_vidsArr = 0;
74 
75  pgr_combination_t *combinations = NULL;
76  size_t total_combinations = 0;
77 
78  if (starts && ends) {
79  start_vidsArr = (int64_t*)
80  pgr_get_bigIntArray(&size_start_vidsArr, starts);
81  end_vidsArr = (int64_t*)
82  pgr_get_bigIntArray(&size_end_vidsArr, ends);
83  } else if (combinations_sql) {
84  pgr_get_combinations(combinations_sql, &combinations, &total_combinations);
85  }
86 
87  Pgr_edge_xy_t *edges = NULL;
88  size_t total_edges = 0;
89 
90  pgr_get_edges_xy(edges_sql, &edges, &total_edges);
91  PGR_DBG("Total %ld edges in query:", total_edges);
92 
93  if (total_edges == 0) {
94  PGR_DBG("No edges found");
95  (*result_count) = 0;
96  (*result_tuples) = NULL;
98  return;
99  }
100 
101  PGR_DBG("Starting processing");
102  char* log_msg = NULL;
103  char* notice_msg = NULL;
104  char* err_msg = NULL;
105  clock_t start_t = clock();
107  edges, total_edges,
108  combinations, total_combinations,
109  start_vidsArr, size_start_vidsArr,
110  end_vidsArr, size_end_vidsArr,
111 
112  directed,
113  heuristic,
114  factor,
115  epsilon,
116  only_cost,
117 
118  result_tuples,
119  result_count,
120  &log_msg,
121  &notice_msg,
122  &err_msg);
123 
124  if (only_cost) {
125  time_msg("pgr_bdAstarCost()", start_t, clock());
126  } else {
127  time_msg("pgr_bdAstar()", start_t, clock());
128  }
129 
130  if (err_msg && (*result_tuples)) {
131  pfree(*result_tuples);
132  (*result_count) = 0;
133  (*result_tuples) = NULL;
134  }
135 
136  pgr_global_report(log_msg, notice_msg, err_msg);
137 
138  if (log_msg) pfree(log_msg);
139  if (notice_msg) pfree(notice_msg);
140  if (err_msg) pfree(err_msg);
141  if (edges) pfree(edges);
142 
143  pgr_SPI_finish();
144 }

References check_parameters(), do_pgr_bdAstar(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_combinations(), pgr_get_edges_xy(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_bdastar().

check_parameters
void check_parameters(int heuristic, double factor, double epsilon)
Definition: check_parameters.c:34
do_pgr_bdAstar
void do_pgr_bdAstar(Pgr_edge_xy_t *edges, size_t total_edges, pgr_combination_t *combinations, size_t total_combinations, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, int heuristic, double factor, double epsilon, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: bdAstar_driver.cpp:141
pgr_get_edges_xy
void pgr_get_edges_xy(char *edges_sql, Pgr_edge_xy_t **edges, size_t *total_edges)
Edges with x, y vertices values.
Definition: edges_input.c:744
process
static void process(char *edges_sql, char *combinations_sql, ArrayType *starts, ArrayType *ends, bool directed, int heuristic, double factor, double epsilon, bool only_cost, General_path_element_t **result_tuples, size_t *result_count)
Definition: bdAstar.c:54
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
edge
Definition: trsp.h:41
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
General_path_element_t
Definition: general_path_element_t.h:37
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
Pgr_edge_xy_t
Definition: pgr_edge_xy_t.h:38
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93