PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 134 of file bdAstar.c.

References PGR_DBG, and process().

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

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 50 of file bdAstar.c.

References check_parameters(), do_pgr_bdAstar(), edges, 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().

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