vrpRouting  0.3
matrixRows_input.c File Reference
Include dependency graph for matrixRows_input.c:

Go to the source code of this file.

Functions

static void fetch_plain (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *row)
 
static void fetch_timestamps (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *row)
 
void get_matrixRows (char *sql, Matrix_cell_t **rows, size_t *total_rows)
 Get the travel time matrix. More...
 
static void get_matrixRows_general (char *sql, Column_info_t *info, const int kind, Matrix_cell_t **rows, size_t *total_rows)
 bigint start_vid, bigint end_vid, float agg_cost, More...
 
void get_matrixRows_plain (char *sql, Matrix_cell_t **rows, size_t *total_rows)
 Get the travel time matrix with numerical types. More...
 

Function Documentation

◆ fetch_plain()

static void fetch_plain ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[3],
Matrix_cell_t row 
)
static

Definition at line 62 of file matrixRows_input.c.

66  {
67  row->from_vid = get_Id(tuple, tupdesc, info[0], -1);
68  row->to_vid = get_Id(tuple, tupdesc, info[1], -1);
69  row->cost = get_PositiveTInterval_plain(tuple, tupdesc, info[2], 0);
70 }

References Matrix_cell_t::cost, Matrix_cell_t::from_vid, get_Id(), get_PositiveTInterval_plain(), and Matrix_cell_t::to_vid.

Referenced by get_matrixRows_general().

◆ fetch_timestamps()

static void fetch_timestamps ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info[3],
Matrix_cell_t row 
)
static

Definition at line 73 of file matrixRows_input.c.

77  {
78  row->from_vid = get_Id(tuple, tupdesc, info[0], -1);
79  row->to_vid = get_Id(tuple, tupdesc, info[1], -1);
80  row->cost = get_PositiveTInterval(tuple, tupdesc, info[2], 0);
81 }

References Matrix_cell_t::cost, Matrix_cell_t::from_vid, get_Id(), get_PositiveTInterval(), and Matrix_cell_t::to_vid.

Referenced by get_matrixRows_general().

◆ get_matrixRows()

void get_matrixRows ( char *  sql,
Matrix_cell_t **  rows,
size_t *  total_rows 
)

Get the travel time matrix.

Parameters
[in]sqlSQL query that has the following columns: start_vid, end_vid, agg_cost
[out]rowsC Container that holds all the matrix rows
[out]total_rowsTotal rows recieved

Definition at line 176 of file matrixRows_input.c.

179  {
180  Column_info_t info[3];
181 
182  int i;
183  for (i = 0; i < 3; ++i) {
184  info[i].colNumber = -1;
185  info[i].type = 0;
186  info[i].strict = true;
187  info[i].eType = ANY_INTEGER;
188  }
189  info[0].name = "start_vid";
190  info[1].name = "end_vid";
191  info[2].name = "travel_time";
192 
193  info[2].eType = INTERVAL;
194  get_matrixRows_general(sql, info, 0, rows, total_rows);
195 }

References ANY_INTEGER, Column_info_t::colNumber, Column_info_t::eType, get_matrixRows_general(), INTERVAL, Column_info_t::name, Column_info_t::strict, and Column_info_t::type.

Referenced by process().

◆ get_matrixRows_general()

static void get_matrixRows_general ( char *  sql,
Column_info_t info,
const int  kind,
Matrix_cell_t **  rows,
size_t *  total_rows 
)
static

bigint start_vid, bigint end_vid, float agg_cost,

Definition at line 90 of file matrixRows_input.c.

95  {
96 #ifdef PROFILE
97  clock_t start_t = clock();
98  PGR_DBG("%s", sql);
99 #endif
100 
101  const int tuple_limit = 1000000;
102  size_t total_tuples = 0;
103  const int column_count = 3;
104 
105  void *SPIplan;
106  SPIplan = pgr_SPI_prepare(sql);
107 
108  Portal SPIportal;
109  SPIportal = pgr_SPI_cursor_open(SPIplan);
110 
111 
112  bool moredata = true;
113  (*total_rows) = total_tuples;
114 
115  while (moredata == true) {
116  SPI_cursor_fetch(SPIportal, true, tuple_limit);
117  if (total_tuples == 0)
118  pgr_fetch_column_info(info, column_count);
119 
120  size_t ntuples = SPI_processed;
121  total_tuples += ntuples;
122 
123  if (ntuples > 0) {
124  if ((*rows) == NULL)
125  (*rows) = (Matrix_cell_t *)palloc0(
126  total_tuples * sizeof(Matrix_cell_t));
127  else
128  (*rows) = (Matrix_cell_t *)repalloc(
129  (*rows), total_tuples * sizeof(Matrix_cell_t));
130 
131  if ((*rows) == NULL) {
132  elog(ERROR, "Out of memory");
133  }
134 
135  SPITupleTable *tuptable = SPI_tuptable;
136  TupleDesc tupdesc = SPI_tuptable->tupdesc;
137 
138  size_t t;
139  for (t = 0; t < ntuples; t++) {
140  HeapTuple tuple = tuptable->vals[t];
141  switch (kind) {
142  case 0 : fetch_timestamps(&tuple, &tupdesc, info,
143  &(*rows)[total_tuples - ntuples + t]);
144  break;
145  case 1 : fetch_plain(&tuple, &tupdesc, info,
146  &(*rows)[total_tuples - ntuples + t]);
147  break;
148  }
149  }
150  SPI_freetuptable(tuptable);
151  } else {
152  moredata = false;
153  }
154  }
155 
156  SPI_cursor_close(SPIportal);
157 
158 
159  if (total_tuples == 0) {
160  (*total_rows) = 0;
161  return;
162  }
163 
164  (*total_rows) = total_tuples;
165 #ifdef PROFILE
166  time_msg(" reading time matrix", start_t, clock());
167 #endif
168 }

References fetch_plain(), fetch_timestamps(), PGR_DBG, pgr_fetch_column_info(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), and time_msg().

Referenced by get_matrixRows(), and get_matrixRows_plain().

◆ get_matrixRows_plain()

void get_matrixRows_plain ( char *  sql,
Matrix_cell_t **  rows,
size_t *  total_rows 
)

Get the travel time matrix with numerical types.

Parameters
[in]sqlSQL query that has the following columns: start_vid, end_vid, agg_cost
[out]rowsC Container that holds all the matrix rows
[out]total_rowsTotal rows recieved

Definition at line 203 of file matrixRows_input.c.

206  {
207  Column_info_t info[3];
208 
209  int i;
210  for (i = 0; i < 3; ++i) {
211  info[i].colNumber = -1;
212  info[i].type = 0;
213  info[i].strict = true;
214  info[i].eType = ANY_INTEGER;
215  }
216  info[0].name = "start_vid";
217  info[1].name = "end_vid";
218  info[2].name = "agg_cost";
219 
220  info[2].eType = ANY_NUMERICAL;
221  get_matrixRows_general(sql, info, 1, rows, total_rows);
222 }

References ANY_INTEGER, ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, get_matrixRows_general(), Column_info_t::name, Column_info_t::strict, and Column_info_t::type.

Referenced by process().

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:54
Column_info_t::strict
bool strict
Definition: column_info_t.h:56
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:88
get_Id
Id get_Id(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, Id opt_value)
@params [in] tuple @params [in] tupdesc @params [in] info about the column been fetched @params [in] ...
Definition: get_check_data.c:562
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:905
Column_info_t::name
char * name
Definition: column_info_t.h:57
fetch_timestamps
static void fetch_timestamps(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *row)
Definition: matrixRows_input.c:73
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:98
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
INTERVAL
@ INTERVAL
Definition: column_info_t.h:48
get_PositiveTInterval
TInterval get_PositiveTInterval(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value)
@params [in] tuple @params [in] tupdesc @params [in] info about the column been fetched @params [in] ...
Definition: get_check_data.c:511
fetch_plain
static void fetch_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[3], Matrix_cell_t *row)
Definition: matrixRows_input.c:62
Matrix_cell_t
struct Matrix_cell_t Matrix_cell_t
Definition: matrixRows_input.h:31
Column_info_t::eType
expectType eType
Definition: column_info_t.h:58
Matrix_cell_t
traveling costs
Definition: matrix_cell_t.h:41
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
Matrix_cell_t::cost
TInterval cost
arrival node's identifier
Definition: matrix_cell_t.h:44
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:40
get_matrixRows_general
static void get_matrixRows_general(char *sql, Column_info_t *info, const int kind, Matrix_cell_t **rows, size_t *total_rows)
bigint start_vid, bigint end_vid, float agg_cost,
Definition: matrixRows_input.c:90
get_PositiveTInterval_plain
TInterval get_PositiveTInterval_plain(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, TInterval opt_value)
@params [in] tuple @params [in] tupdesc @params [in] info about the column been fetched @params [in] ...
Definition: get_check_data.c:546
Matrix_cell_t::from_vid
Id from_vid
Definition: matrix_cell_t.h:42
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:41
Column_info_t::type
uint64_t type
Definition: column_info_t.h:55
Column_info_t
Definition: column_info_t.h:52
Matrix_cell_t::to_vid
Id to_vid
departure node's identifier
Definition: matrix_cell_t.h:43