PGROUTING  3.2
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

◆ fetch_pd_orders()

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.

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 }

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().

◆ pgr_get_pd_orders()

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 205 of file orders_input.c.

208  {
209  pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, false);
210 }

References pgr_get_pd_orders_general().

Referenced by process().

◆ pgr_get_pd_orders_general()

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.

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 = "id";
101  info[1].name = "demand";
102  info[2].name = "p_x";
103  info[3].name = "p_y";
104  info[4].name = "p_open";
105  info[5].name = "p_close";
106  info[6].name = "p_service";
107  info[7].name = "d_x";
108  info[8].name = "d_y";
109  info[9].name = "d_open";
110  info[10].name = "d_close";
111  info[11].name = "d_service";
112  info[12].name = "p_node_id";
113  info[13].name = "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 total_tuples;
140 
141  void *SPIplan;
142  SPIplan = pgr_SPI_prepare(pd_orders_sql);
143  Portal SPIportal;
144  SPIportal = pgr_SPI_cursor_open(SPIplan);
145 
146  bool moredata = true;
147  (*total_pd_orders) = total_tuples = 0;
148 
149  /* on the first tuple get the column numbers */
150 
151  while (moredata == true) {
152  SPI_cursor_fetch(SPIportal, true, tuple_limit);
153  if (total_tuples == 0) {
154  pgr_fetch_column_info(info, 14);
155  }
156  size_t ntuples = SPI_processed;
157  total_tuples += ntuples;
158  PGR_DBG("SPI_processed %ld", ntuples);
159  if (ntuples > 0) {
160  if ((*pd_orders) == NULL)
161  (*pd_orders) = (PickDeliveryOrders_t *)palloc0(
162  total_tuples * sizeof(PickDeliveryOrders_t));
163  else
164  (*pd_orders) = (PickDeliveryOrders_t *)repalloc(
165  (*pd_orders),
166  total_tuples * sizeof(PickDeliveryOrders_t));
167 
168  if ((*pd_orders) == NULL) {
169  elog(ERROR, "Out of memory");
170  }
171 
172  size_t t;
173  SPITupleTable *tuptable = SPI_tuptable;
174  TupleDesc tupdesc = SPI_tuptable->tupdesc;
175  PGR_DBG("processing %ld", ntuples);
176  for (t = 0; t < ntuples; t++) {
177  HeapTuple tuple = tuptable->vals[t];
178  fetch_pd_orders(&tuple, &tupdesc, info, with_id,
179  &(*pd_orders)[total_tuples - ntuples + t]);
180  }
181  SPI_freetuptable(tuptable);
182  } else {
183  moredata = false;
184  }
185  }
186 
187  SPI_cursor_close(SPIportal);
188 
189  if (total_tuples == 0) {
190  (*total_pd_orders) = 0;
191  PGR_DBG("NO orders");
192  return;
193  }
194 
195  (*total_pd_orders) = total_tuples;
196  if (with_id) {
197  PGR_DBG("Finish reading %ld orders for matrix", (*total_pd_orders));
198  } else {
199  PGR_DBG("Finish reading %ld orders for euclidean", (*total_pd_orders));
200  }
201  time_msg("reading edges", start_t, clock());
202 }

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().

◆ pgr_get_pd_orders_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.

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

Definition at line 213 of file orders_input.c.

216  {
217  pgr_get_pd_orders_general(pd_orders_sql, pd_orders, total_pd_orders, true);
218 }

References pgr_get_pd_orders_general().

Referenced by process().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
PickDeliveryOrders_t::demand
double demand
Definition: pickDeliveryOrders_t.h:47
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
PickDeliveryOrders_t
Definition: pickDeliveryOrders_t.h:43
pgr_get_pd_orders_general
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
fetch_pd_orders
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
PickDeliveryOrders_t::pick_x
double pick_x
Definition: pickDeliveryOrders_t.h:49
PickDeliveryOrders_t::id
int64_t id
Definition: pickDeliveryOrders_t.h:46
pgr_SPI_getBigInt
int64_t pgr_SPI_getBigInt(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in integer type.
Definition: get_check_data.c:216
pgr_fetch_column_info
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column.
Definition: get_check_data.c:78
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
PickDeliveryOrders_t::deliver_close_t
double deliver_close_t
Definition: pickDeliveryOrders_t.h:62
PickDeliveryOrders_t::deliver_x
double deliver_x
Definition: pickDeliveryOrders_t.h:57
PickDeliveryOrders_t::deliver_service_t
double deliver_service_t
Definition: pickDeliveryOrders_t.h:63
pgr_SPI_getFloat8
double pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
Function returns the value of specified column in double type.
Definition: get_check_data.c:246
PickDeliveryOrders_t::deliver_y
double deliver_y
Definition: pickDeliveryOrders_t.h:58
PickDeliveryOrders_t::pick_open_t
double pick_open_t
Definition: pickDeliveryOrders_t.h:53
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
PickDeliveryOrders_t::deliver_open_t
double deliver_open_t
Definition: pickDeliveryOrders_t.h:61
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
PickDeliveryOrders_t::pick_service_t
double pick_service_t
Definition: pickDeliveryOrders_t.h:55
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
column_found
bool column_found(int colNumber)
Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUT...
Definition: get_check_data.c:36
PickDeliveryOrders_t::pick_node_id
int64_t pick_node_id
Definition: pickDeliveryOrders_t.h:51
PickDeliveryOrders_t::deliver_node_id
int64_t deliver_node_id
Definition: pickDeliveryOrders_t.h:59
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49
PickDeliveryOrders_t::pick_close_t
double pick_close_t
Definition: pickDeliveryOrders_t.h:54
PickDeliveryOrders_t::pick_y
double pick_y
Definition: pickDeliveryOrders_t.h:50