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

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (withPoints_ksp)
 
static void process (char *edges_sql, char *points_sql, int64_t start_pid, int64_t end_pid, int k, bool directed, bool heap_paths, char *driving_side, bool details, General_path_element_t **result_tuples, size_t *result_count)
 
PGDLLEXPORT Datum withPoints_ksp (PG_FUNCTION_ARGS)
 

Function Documentation

PG_FUNCTION_INFO_V1 ( withPoints_ksp  )
static void process ( char *  edges_sql,
char *  points_sql,
int64_t  start_pid,
int64_t  end_pid,
int  k,
bool  directed,
bool  heap_paths,
char *  driving_side,
bool  details,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 49 of file withPoints_ksp.c.

References do_pgr_withPointsKsp(), get_new_queries(), PGR_DBG, pgr_get_edges(), pgr_get_points(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by withPoints_ksp().

62  {
63  driving_side[0] = (char) tolower(driving_side[0]);
64  PGR_DBG("driving side:%c", driving_side[0]);
65  if (!((driving_side[0] == 'r')
66  || (driving_side[0] == 'l'))) {
67  driving_side[0] = 'b';
68  }
69 
71 
72  Point_on_edge_t *points = NULL;
73  size_t total_points = 0;
74  pgr_get_points(points_sql, &points, &total_points);
75 
76  char *edges_of_points_query = NULL;
77  char *edges_no_points_query = NULL;
79  edges_sql, points_sql,
80  &edges_of_points_query,
81  &edges_no_points_query);
82 
83 
84  pgr_edge_t *edges_of_points = NULL;
85  size_t total_edges_of_points = 0;
86  pgr_get_edges(edges_of_points_query,
87  &edges_of_points,
88  &total_edges_of_points);
89 
90  pgr_edge_t *edges = NULL;
91  size_t total_edges = 0;
92  pgr_get_edges(edges_no_points_query, &edges, &total_edges);
93 
94  PGR_DBG("freeing allocated memory not used anymore");
95  pfree(edges_of_points_query);
96  pfree(edges_no_points_query);
97 
98  if ((total_edges + total_edges_of_points) == 0) {
99  PGR_DBG("No edges found");
100  (*result_count) = 0;
101  (*result_tuples) = NULL;
102  pgr_SPI_finish();
103  return;
104  }
105 
106  PGR_DBG("Starting processing");
107  clock_t start_t = clock();
108 
109  char *log_msg = NULL;
110  char *notice_msg = NULL;
111  char *err_msg = NULL;
113  edges,
114  total_edges,
115  points,
116  total_points,
117  edges_of_points,
118  total_edges_of_points,
119  start_pid,
120  end_pid,
121  k,
122 
123  directed,
124  heap_paths,
125  driving_side[0],
126  details,
127 
128  result_tuples,
129  result_count,
130 
131  &log_msg,
132  &notice_msg,
133  &err_msg);
134  time_msg(" processing withPointsKSP", start_t, clock());
135 
136  if (err_msg && (*result_tuples)) {
137  pfree(*result_tuples);
138  (*result_tuples) = NULL;
139  (*result_count) = 0;
140  }
141 
142  pgr_global_report(log_msg, notice_msg, err_msg);
143 
144  if (log_msg) pfree(log_msg);
145  if (notice_msg) pfree(notice_msg);
146  if (err_msg) pfree(err_msg);
147 
148  pfree(edges);
149  pfree(edges_of_points);
150  pfree(points);
151 
152  pgr_SPI_finish();
153 }
#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
void pgr_get_points(char *points_sql, Point_on_edge_t **points, size_t *total_points)
pgr_get_points
Definition: points_input.c:63
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
int do_pgr_withPointsKsp(pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t start_pid, int64_t end_pid, int k, bool directed, bool heap_paths, char driving_side, bool details, 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 get_new_queries(char *edges_sql, char *points_sql, char **edges_of_points_query, char **edges_no_points_query)
void pgr_SPI_connect(void)

Here is the call graph for this function:

Here is the caller graph for this function:

PGDLLEXPORT Datum withPoints_ksp ( PG_FUNCTION_ARGS  )

Definition at line 158 of file withPoints_ksp.c.

References General_path_element_t::agg_cost, General_path_element_t::cost, General_path_element_t::edge, if(), General_path_element_t::node, PGR_DBG, process(), General_path_element_t::seq, and General_path_element_t::start_id.

158  {
159  FuncCallContext *funcctx;
160  TupleDesc tuple_desc;
161 
162  General_path_element_t *result_tuples = 0;
163  size_t result_count = 0;
164 
165  if (SRF_IS_FIRSTCALL()) {
166  MemoryContext oldcontext;
167  funcctx = SRF_FIRSTCALL_INIT();
168  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
169 
170 
171  /*
172  CREATE OR REPLACE FUNCTION pgr_withPoint(
173  edges_sql TEXT,
174  points_sql TEXT,
175  start_pid INTEGER,
176  end_pid BIGINT,
177  k BIGINT,
178 
179  directed BOOLEAN -- DEFAULT true,
180  heap_paths BOOLEAN -- DEFAULT false,
181  driving_side CHAR -- DEFAULT 'b',
182  details BOOLEAN -- DEFAULT false
183  */
184 
185  PGR_DBG("Calling process");
186  PGR_DBG("initial driving side:%s",
187  text_to_cstring(PG_GETARG_TEXT_P(7)));
188  process(
189  text_to_cstring(PG_GETARG_TEXT_P(0)),
190  text_to_cstring(PG_GETARG_TEXT_P(1)),
191  PG_GETARG_INT64(2),
192  PG_GETARG_INT64(3),
193  PG_GETARG_INT32(4),
194  PG_GETARG_BOOL(5),
195  PG_GETARG_BOOL(6),
196  text_to_cstring(PG_GETARG_TEXT_P(7)),
197  PG_GETARG_BOOL(8),
198  &result_tuples,
199  &result_count);
200 
201 
202 #if PGSQL_VERSION > 95
203  funcctx->max_calls = result_count;
204 #else
205  funcctx->max_calls = (uint32_t)result_count;
206 #endif
207  funcctx->user_fctx = result_tuples;
208  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
209  != TYPEFUNC_COMPOSITE)
210  ereport(ERROR,
211  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
212  errmsg("function returning record called in context "
213  "that cannot accept type record")));
214 
215  funcctx->tuple_desc = tuple_desc;
216  MemoryContextSwitchTo(oldcontext);
217  }
218 
219  funcctx = SRF_PERCALL_SETUP();
220  tuple_desc = funcctx->tuple_desc;
221  result_tuples = (General_path_element_t*) funcctx->user_fctx;
222 
223  if (funcctx->call_cntr < funcctx->max_calls) {
224  HeapTuple tuple;
225  Datum result;
226  Datum *values;
227  bool* nulls;
228 
229  values = palloc(7 * sizeof(Datum));
230  nulls = palloc(7 * sizeof(bool));
231 
232  size_t i;
233  for (i = 0; i < 7; ++i) {
234  nulls[i] = false;
235  }
236 
237  /*
238  OUT seq INTEGER, OUT path_id INTEGER, OUT path_seq INTEGER,
239  OUT node BIGINT, OUT edge BIGINT,
240  OUT cost FLOAT, OUT agg_cost FLOAT)
241  */
242 
243 
244  // postgres starts counting from 1
245  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
246  values[1] = Int32GetDatum((int)
247  (result_tuples[funcctx->call_cntr].start_id + 1));
248  values[2] = Int32GetDatum(result_tuples[funcctx->call_cntr].seq);
249  values[3] = Int64GetDatum(result_tuples[funcctx->call_cntr].node);
250  values[4] = Int64GetDatum(result_tuples[funcctx->call_cntr].edge);
251  values[5] = Float8GetDatum(result_tuples[funcctx->call_cntr].cost);
252  values[6] = Float8GetDatum(result_tuples[funcctx->call_cntr].agg_cost);
253 
254  tuple = heap_form_tuple(tuple_desc, values, nulls);
255  result = HeapTupleGetDatum(tuple);
256  SRF_RETURN_NEXT(funcctx, result);
257  } else {
258  SRF_RETURN_DONE(funcctx);
259  }
260 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13
static void process(char *edges_sql, char *points_sql, int64_t start_pid, int64_t end_pid, int k, bool directed, bool heap_paths, char *driving_side, bool details, General_path_element_t **result_tuples, size_t *result_count)

Here is the call graph for this function: