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

Go to the source code of this file.

Functions

static void compute_trsp (char *edges_sql, char *restrictions_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
 
 PG_FUNCTION_INFO_V1 (turn_restriction)
 
PGDLLEXPORT Datum turn_restriction (PG_FUNCTION_ARGS)
 

Function Documentation

static void compute_trsp ( char *  edges_sql,
char *  restrictions_sql,
ArrayType *  starts,
ArrayType *  ends,
bool  directed,
General_path_element_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 50 of file new_trsp.c.

References do_trsp(), PGR_DBG, pgr_get_bigIntArray(), pgr_get_edges(), pgr_get_restrictions(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by turn_restriction().

60  {
62 
63  pgr_edge_t *edges = NULL;
64  size_t total_edges = 0;
65  pgr_get_edges(edges_sql, &edges, &total_edges);
66 
67  Restriction_t * restrictions = NULL;
68  size_t total_restrictions = 0;
69  pgr_get_restrictions(restrictions_sql, &restrictions, &total_restrictions);
70 
71  int64_t* start_vidsArr = NULL;
72  size_t size_start_vidsArr = 0;
73  start_vidsArr = (int64_t*)
74  pgr_get_bigIntArray(&size_start_vidsArr, starts);
75 
76  int64_t* end_vidsArr = NULL;
77  size_t size_end_vidsArr = 0;
78  end_vidsArr = (int64_t*)
79  pgr_get_bigIntArray(&size_end_vidsArr, ends);
80 
81  PGR_DBG("Starting timer");
82  clock_t start_t = clock();
83  char* log_msg = NULL;
84  char* notice_msg = NULL;
85  char* err_msg = NULL;
86 
87  do_trsp(
88  edges,
89  total_edges,
90 
91  restrictions,
92  total_restrictions,
93 
94  start_vidsArr, size_start_vidsArr,
95  end_vidsArr, size_end_vidsArr,
96 
97  directed,
98 
99  result_tuples,
100  result_count,
101  &log_msg,
102  &notice_msg,
103  &err_msg);
104  time_msg("processing _pgr_trsp", start_t, clock());
105 
106  if (err_msg && (*result_tuples)) {
107  pfree(*result_tuples);
108  (*result_tuples) = NULL;
109  (*result_count) = 0;
110  }
111 
112  pgr_global_report(log_msg, notice_msg, err_msg);
113 
114  pgr_SPI_finish();
115 }
void pgr_get_restrictions(char *restrictions_sql, Restriction_t **restrictions, size_t *total_restrictions)
#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_trsp(pgr_edge_t *edges, size_t total_edges, Restriction_t *restrictions, size_t restrictions_size, int64_t *start_vidsArr, size_t size_start_vidsArr, int64_t *end_vidsArr, size_t size_end_vidsArr, bool directed, General_path_element_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: trsp_driver.cpp:41
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)

Here is the call graph for this function:

Here is the caller graph for this function:

PG_FUNCTION_INFO_V1 ( turn_restriction  )
PGDLLEXPORT Datum turn_restriction ( PG_FUNCTION_ARGS  )

Definition at line 120 of file new_trsp.c.

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

120  {
121  FuncCallContext *funcctx;
122  TupleDesc tuple_desc;
123 
124  size_t result_count = 0;
125  General_path_element_t *result_tuples = NULL;
126 
127  // stuff done only on the first call of the function
128  if (SRF_IS_FIRSTCALL()) {
129  MemoryContext oldcontext;
130  funcctx = SRF_FIRSTCALL_INIT();
131  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
132 
133  PGR_DBG("Calling compute_trsp");
134  compute_trsp(
135  text_to_cstring(PG_GETARG_TEXT_P(0)),
136  text_to_cstring(PG_GETARG_TEXT_P(1)),
137  PG_GETARG_ARRAYTYPE_P(2),
138  PG_GETARG_ARRAYTYPE_P(3),
139  PG_GETARG_BOOL(4),
140  &result_tuples, &result_count);
141 
142  //-----------------------------------------------
143 
144 #if PGSQL_VERSION > 95
145  funcctx->max_calls = result_count;
146 #else
147  funcctx->max_calls = (uint32_t)result_count;
148 #endif
149 
150  funcctx->user_fctx = result_tuples;
151  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
152  != TYPEFUNC_COMPOSITE) {
153  ereport(ERROR,
154  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
155  errmsg("function returning record called in context "
156  "that cannot accept type record")));
157  }
158 
159  funcctx->tuple_desc = tuple_desc;
160  MemoryContextSwitchTo(oldcontext);
161  }
162 
163  funcctx = SRF_PERCALL_SETUP();
164 
165  tuple_desc = funcctx->tuple_desc;
166  result_tuples = (General_path_element_t *) funcctx->user_fctx;
167 
168  if (funcctx->call_cntr < funcctx->max_calls) {
169  // do when there is more left to send
170  HeapTuple tuple;
171  Datum result;
172  Datum *values;
173  bool* nulls;
174  size_t call_cntr = funcctx->call_cntr;
175 
176 
177  size_t numb = 8;
178  values = palloc(numb * sizeof(Datum));
179  nulls = palloc(numb * sizeof(bool));
180 
181  size_t i;
182  for (i = 0; i < numb; ++i) {
183  nulls[i] = false;
184  }
185 
186  values[0] = Int32GetDatum(call_cntr + 1);
187  values[1] = Int32GetDatum(result_tuples[call_cntr].seq);
188  values[2] = Int64GetDatum(result_tuples[call_cntr].start_id);
189  values[3] = Int64GetDatum(result_tuples[call_cntr].end_id);
190  values[4] = Int64GetDatum(result_tuples[call_cntr].node);
191  values[5] = Int64GetDatum(result_tuples[call_cntr].edge);
192  values[6] = Float8GetDatum(result_tuples[call_cntr].cost);
193  values[7] = Float8GetDatum(result_tuples[call_cntr].agg_cost);
194 
195  tuple = heap_form_tuple(tuple_desc, values, nulls);
196 
197  result = HeapTupleGetDatum(tuple);
198 
199  pfree(values);
200  pfree(nulls);
201 
202  SRF_RETURN_NEXT(funcctx, result);
203  } else {
204  SRF_RETURN_DONE(funcctx);
205  }
206 }
Definition: trsp.h:31
#define PGR_DBG(...)
Definition: debug_macro.h:34
static void compute_trsp(char *edges_sql, char *restrictions_sql, ArrayType *starts, ArrayType *ends, bool directed, General_path_element_t **result_tuples, size_t *result_count)
Definition: new_trsp.c:50
if(DOXYGEN_FOUND) configure_file($
Definition: CMakeLists.txt:13

Here is the call graph for this function: