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

Go to the source code of this file.

Functions

PGDLLEXPORT Datum bd_astar (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (bd_astar)
 
static void process (char *edges_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

PGDLLEXPORT Datum bd_astar ( PG_FUNCTION_ARGS  )

Definition at line 136 of file bdAstar.c.

References if(), PGR_DBG, and process().

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

Here is the call graph for this function:

PG_FUNCTION_INFO_V1 ( bd_astar  )
static void process ( char *  edges_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 52 of file bdAstar.c.

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

Referenced by bd_astar().

61  {
62  check_parameters(heuristic, factor, epsilon);
63 
65 
66  int64_t* start_vidsArr = NULL;
67  size_t size_start_vidsArr = 0;
68  start_vidsArr = (int64_t*)
69  pgr_get_bigIntArray(&size_start_vidsArr, starts);
70 
71  int64_t* end_vidsArr = NULL;
72  size_t size_end_vidsArr = 0;
73  end_vidsArr = (int64_t*)
74  pgr_get_bigIntArray(&size_end_vidsArr, ends);
75 
76  PGR_DBG("Load data");
77  Pgr_edge_xy_t *edges = NULL;
78  size_t total_edges = 0;
79 
80  pgr_get_edges_xy(edges_sql, &edges, &total_edges);
81  PGR_DBG("Total %ld edges in query:", total_edges);
82 
83  if (total_edges == 0) {
84  PGR_DBG("No edges found");
85  (*result_count) = 0;
86  (*result_tuples) = NULL;
88  return;
89  }
90 
91  PGR_DBG("Starting processing");
92  char* log_msg = NULL;
93  char* notice_msg = NULL;
94  char* err_msg = NULL;
95  clock_t start_t = clock();
97  edges, total_edges,
98  start_vidsArr, size_start_vidsArr,
99  end_vidsArr, size_end_vidsArr,
100 
101  directed,
102  heuristic,
103  factor,
104  epsilon,
105  only_cost,
106 
107  result_tuples,
108  result_count,
109  &log_msg,
110  &notice_msg,
111  &err_msg);
112 
113  if (only_cost) {
114  time_msg("pgr_bdAstarCost()", start_t, clock());
115  } else {
116  time_msg("pgr_bdAstar()", start_t, clock());
117  }
118 
119  if (err_msg && (*result_tuples)) {
120  pfree(*result_tuples);
121  (*result_count) = 0;
122  (*result_tuples) = NULL;
123  }
124 
125  pgr_global_report(log_msg, notice_msg, err_msg);
126 
127  if (log_msg) pfree(log_msg);
128  if (notice_msg) pfree(notice_msg);
129  if (err_msg) pfree(err_msg);
130  if (edges) pfree(edges);
131 
132  pgr_SPI_finish();
133 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
void do_pgr_bdAstar(Pgr_edge_xy_t *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, 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)
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 pgr_SPI_finish(void)
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:578
void check_parameters(int heuristic, double factor, double epsilon)
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function: