PGROUTING  2.5
orders_input.c File Reference
Include dependency graph for orders_input.c:

Go to the source code of this file.

Functions

static void fetch_pd_orders (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[14], bool matrix_version, PickDeliveryOrders_t *pd_order)
 
void pgr_get_pd_orders (char *pd_orders_sql, PickDeliveryOrders_t **pd_orders, size_t *total_pd_orders)
 Reads the pick-Deliver orders. More...
 
static void pgr_get_pd_orders_general (char *pd_orders_sql, PickDeliveryOrders_t **pd_orders, size_t *total_pd_orders, bool with_id)
 
void pgr_get_pd_orders_with_id (char *pd_orders_sql, PickDeliveryOrders_t **pd_orders, size_t *total_pd_orders)
 Reads the pick-Deliver orders. More...
 

Function Documentation

static void fetch_pd_orders ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[14],
bool  matrix_version,
PickDeliveryOrders_t pd_order 
)
static

Definition at line 35 of file orders_input.c.

References column_found(), PickDeliveryOrders_t::deliver_close_t, PickDeliveryOrders_t::deliver_node_id, PickDeliveryOrders_t::deliver_open_t, PickDeliveryOrders_t::deliver_service_t, PickDeliveryOrders_t::deliver_x, PickDeliveryOrders_t::deliver_y, PickDeliveryOrders_t::demand, PickDeliveryOrders_t::id, pgr_SPI_getBigInt(), pgr_SPI_getFloat8(), PickDeliveryOrders_t::pick_close_t, PickDeliveryOrders_t::pick_node_id, PickDeliveryOrders_t::pick_open_t, PickDeliveryOrders_t::pick_service_t, PickDeliveryOrders_t::pick_x, and PickDeliveryOrders_t::pick_y.

Referenced by pgr_get_pd_orders_general().

40  {
41  pd_order->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
42  pd_order->demand = pgr_SPI_getFloat8(tuple, tupdesc, info[1]);
43 
44  /*
45  * the pickups
46  */
47  pd_order->pick_x = matrix_version ?
48  0 : pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
49  pd_order->pick_y = matrix_version ?
50  0 : pgr_SPI_getFloat8(tuple, tupdesc, info[3]);
51  pd_order->pick_open_t = pgr_SPI_getFloat8(tuple, tupdesc, info[4]);
52  pd_order->pick_close_t = pgr_SPI_getFloat8(tuple, tupdesc, info[5]);
53  pd_order->pick_service_t = column_found(info[6].colNumber) ?
54  pgr_SPI_getFloat8(tuple, tupdesc, info[6]) : 0;
55 
56  /*
57  * the deliveries
58  */
59  pd_order->deliver_x = matrix_version ?
60  0 : pgr_SPI_getFloat8(tuple, tupdesc, info[7]);
61  pd_order->deliver_y = matrix_version ?
62  0 : pgr_SPI_getFloat8(tuple, tupdesc, info[8]);
63  pd_order->deliver_open_t = pgr_SPI_getFloat8(tuple, tupdesc, info[9]);
64  pd_order->deliver_close_t = pgr_SPI_getFloat8(tuple, tupdesc, info[10]);
65  pd_order->deliver_service_t = column_found(info[11].colNumber) ?
66  pgr_SPI_getFloat8(tuple, tupdesc, info[11]) : 0;
67 
68  pd_order->pick_node_id = matrix_version ?
69  pgr_SPI_getBigInt(tuple, tupdesc, info[12]) : 0;
70  pd_order->deliver_node_id = matrix_version ?
71  pgr_SPI_getBigInt(tuple, tupdesc, info[13]) : 0;
72 }
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
bool column_found(int colNumber)
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)

Here is the call graph for this function:

Here is the caller graph for this function:

void pgr_get_pd_orders ( char *  pd_orders_sql,
PickDeliveryOrders_t **  pd_orders,
size_t *  total_pd_orders 
)

Reads the pick-Deliver orders.

Parameters
[in]pd_orders_sql
[out]pd_orders
[out]total_pd_orders

Definition at line 206 of file orders_input.c.

References pgr_get_pd_orders_general().

Referenced by process().

209  {
210  pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, false);
211 }
static void pgr_get_pd_orders_general(char *pd_orders_sql, PickDeliveryOrders_t **pd_orders, size_t *total_pd_orders, bool with_id)
Definition: orders_input.c:78

Here is the call graph for this function:

Here is the caller graph for this function:

static void pgr_get_pd_orders_general ( char *  pd_orders_sql,
PickDeliveryOrders_t **  pd_orders,
size_t *  total_pd_orders,
bool  with_id 
)
static

Definition at line 78 of file orders_input.c.

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, fetch_pd_orders(), Column_info_t::name, PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Referenced by pgr_get_pd_orders(), and pgr_get_pd_orders_with_id().

82  {
83  clock_t start_t = clock();
84 
85  const int tuple_limit = 1000000;
86 
87  PGR_DBG("pgr_get_pd_orders_data");
88  PGR_DBG("%s", pd_orders_sql);
89 
90  Column_info_t info[14];
91 
92  int i;
93  for (i = 0; i < 14; ++i) {
94  info[i].colNumber = -1;
95  info[i].type = 0;
96  info[i].strict = true;
97  info[i].eType = ANY_NUMERICAL;
98  }
99 
100  info[0].name = strdup("id");
101  info[1].name = strdup("demand");
102  info[2].name = strdup("p_x");
103  info[3].name = strdup("p_y");
104  info[4].name = strdup("p_open");
105  info[5].name = strdup("p_close");
106  info[6].name = strdup("p_service");
107  info[7].name = strdup("d_x");
108  info[8].name = strdup("d_y");
109  info[9].name = strdup("d_open");
110  info[10].name = strdup("d_close");
111  info[11].name = strdup("d_service");
112  info[12].name = strdup("p_node_id");
113  info[13].name = strdup("d_node_id");
114 
115  info[0].eType = ANY_INTEGER;
116  info[12].eType = ANY_INTEGER;
117  info[13].eType = ANY_INTEGER;
118 
119  /* service is optional*/
120  info[6].strict = false;
121  info[11].strict = false;
122  /* nodes are going to be ignored*/
123  info[12].strict = false;
124  info[13].strict = false;
125 
126  if (with_id) {
127  /* (x,y) values are ignored*/
128  info[2].strict = false;
129  info[3].strict = false;
130  info[7].strict = false;
131  info[8].strict = false;
132  /* nodes are compulsory*/
133  info[12].strict = true;
134  info[13].strict = true;
135  }
136 
137 
138 
139  size_t ntuples;
140  size_t total_tuples;
141 
142  void *SPIplan;
143  SPIplan = pgr_SPI_prepare(pd_orders_sql);
144  Portal SPIportal;
145  SPIportal = pgr_SPI_cursor_open(SPIplan);
146 
147  bool moredata = true;
148  (*total_pd_orders) = total_tuples = 0;
149 
150  /* on the first tuple get the column numbers */
151 
152  while (moredata == true) {
153  SPI_cursor_fetch(SPIportal, true, tuple_limit);
154  if (total_tuples == 0) {
155  pgr_fetch_column_info(info, 14);
156  }
157  ntuples = SPI_processed;
158  total_tuples += ntuples;
159  PGR_DBG("SPI_processed %ld", ntuples);
160  if (ntuples > 0) {
161  if ((*pd_orders) == NULL)
162  (*pd_orders) = (PickDeliveryOrders_t *)palloc0(
163  total_tuples * sizeof(PickDeliveryOrders_t));
164  else
165  (*pd_orders) = (PickDeliveryOrders_t *)repalloc(
166  (*pd_orders),
167  total_tuples * sizeof(PickDeliveryOrders_t));
168 
169  if ((*pd_orders) == NULL) {
170  elog(ERROR, "Out of memory");
171  }
172 
173  size_t t;
174  SPITupleTable *tuptable = SPI_tuptable;
175  TupleDesc tupdesc = SPI_tuptable->tupdesc;
176  PGR_DBG("processing %ld", ntuples);
177  for (t = 0; t < ntuples; t++) {
178  HeapTuple tuple = tuptable->vals[t];
179  fetch_pd_orders(&tuple, &tupdesc, info, with_id,
180  &(*pd_orders)[total_tuples - ntuples + t]);
181  }
182  SPI_freetuptable(tuptable);
183  } else {
184  moredata = false;
185  }
186  }
187 
188  SPI_cursor_close(SPIportal);
189 
190  if (total_tuples == 0) {
191  (*total_pd_orders) = 0;
192  PGR_DBG("NO orders");
193  return;
194  }
195 
196  (*total_pd_orders) = total_tuples;
197  if (with_id) {
198  PGR_DBG("Finish reading %ld orders for matrix", (*total_pd_orders));
199  } else {
200  PGR_DBG("Finish reading %ld orders for eucledian", (*total_pd_orders));
201  }
202  time_msg("reading edges", start_t, clock());
203 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:77
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
static void fetch_pd_orders(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[14], bool matrix_version, PickDeliveryOrders_t *pd_order)
Definition: orders_input.c:35
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
SPIPlanPtr pgr_SPI_prepare(char *sql)
expectType eType
Definition: column_info_t.h:80

Here is the call graph for this function:

Here is the caller graph for this function:

void pgr_get_pd_orders_with_id ( char *  pd_orders_sql,
PickDeliveryOrders_t **  pd_orders,
size_t *  total_pd_orders 
)

Reads the pick-Deliver orders.

Parameters
[in]pd_orders_sql
[out]pd_orders
[out]total_pd_orders

Definition at line 214 of file orders_input.c.

References pgr_get_pd_orders_general().

Referenced by process().

217  {
218  pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, true);
219 }
static void pgr_get_pd_orders_general(char *pd_orders_sql, PickDeliveryOrders_t **pd_orders, size_t *total_pd_orders, bool with_id)
Definition: orders_input.c:78

Here is the call graph for this function:

Here is the caller graph for this function: