static
void pgr_fetch_row(
        HeapTuple *tuple,
        TupleDesc *tupdesc,
        Column_info_t info[3],
        Matrix_cell_t *distance) {
    distance->from_vid = pgr_SPI_getBigInt(tuple, tupdesc,  info[0]);
    distance->to_vid = pgr_SPI_getBigInt(tuple, tupdesc,  info[1]);
    distance->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
}
static
void fetch_restriction(
        HeapTuple *tuple,
        TupleDesc *tupdesc,
        Column_info_t info[4],
        Restrict_t *restriction) {
    restriction->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
    restriction->cost = pgr_SPI_getFloat8(tuple, tupdesc,  info[1]);
    char *str = DatumGetCString(
            SPI_getvalue(*tuple, *tupdesc, info[2].colNumber));

// TODO(someone) because its text, no guarantee the text read is correct
// move this code to c++ to tokenize the integers.
    int i = 0;
    for (i = 0; i < MAX_RULE_LENGTH; ++i) restriction->restricted_edges[i] = -1;
    str[0] = ',';
    if (str != NULL) {
        char *token = NULL;
        int i = 0;

        token = (char *)strtok(str, " ,");

        while (token != NULL && i < MAX_RULE_LENGTH) {
            restriction->restricted_edges[i] = atoi(token);
            i++;
            token = (char *)strtok(NULL, " ,");
        }
    }
}
static
void fetch_customer(
        HeapTuple *tuple,
        TupleDesc *tupdesc,
        Column_info_t info[9],
        Customer_t *customer) {
    customer->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
    customer->x = pgr_SPI_getFloat8(tuple, tupdesc, info[1]);
    customer->y = pgr_SPI_getFloat8(tuple, tupdesc, info[2]);
    customer->demand = pgr_SPI_getFloat8(tuple, tupdesc, info[3]);
    customer->Etime = pgr_SPI_getFloat8(tuple, tupdesc, info[4]);
    customer->Ltime = pgr_SPI_getFloat8(tuple, tupdesc, info[5]);
    customer->Stime = pgr_SPI_getFloat8(tuple, tupdesc, info[6]);
    customer->Pindex = pgr_SPI_getBigInt(tuple, tupdesc, info[7]);
    customer->Dindex = pgr_SPI_getBigInt(tuple, tupdesc, info[8]);
    customer->Ddist = 0;
}
Exemple #4
0
static
void fetch_edge_with_xy(
        HeapTuple *tuple,
        TupleDesc *tupdesc,
        Column_info_t info[9],
        int64_t *default_id,
        float8 default_rcost,
        Pgr_edge_xy_t *edge,
        size_t *valid_edges,
        bool normal) {
    if (column_found(info[0].colNumber)) {
        edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
    } else {
        edge->id = *default_id;
        ++(*default_id);
    }

    if (normal) {
        edge->source = pgr_SPI_getBigInt(tuple, tupdesc,  info[1]);
        edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
    } else {
        edge->target = pgr_SPI_getBigInt(tuple, tupdesc,  info[1]);
        edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
    }
    edge->cost = pgr_SPI_getFloat8(tuple, tupdesc, info[3]);

    if (column_found(info[4].colNumber)) {
        edge->reverse_cost = pgr_SPI_getFloat8(tuple, tupdesc, info[4]);
    } else {
        edge->reverse_cost = default_rcost;
    }

    edge->x1 = pgr_SPI_getFloat8(tuple, tupdesc, info[5]);
    edge->y1 = pgr_SPI_getFloat8(tuple, tupdesc, info[6]);
    edge->x2 = pgr_SPI_getFloat8(tuple, tupdesc, info[7]);
    edge->y2 = pgr_SPI_getFloat8(tuple, tupdesc, info[8]);

    *valid_edges = edge->cost < 0? *valid_edges: *valid_edges + 1;
    *valid_edges = edge->reverse_cost < 0? *valid_edges: *valid_edges + 1;
}
Exemple #5
0
static
void fetch_basic_edge(
    HeapTuple *tuple,
    TupleDesc *tupdesc,
    Column_info_t info[5],
    int64_t *default_id,
    pgr_basic_edge_t *edge,
    size_t *valid_edges) {
    if (column_found(info[0].colNumber)) {
        edge->id = pgr_SPI_getBigInt(tuple, tupdesc, info[0]);
    } else {
        edge->id = *default_id;
        ++(*default_id);
    }

    edge->source = pgr_SPI_getBigInt(tuple, tupdesc, info[1]);
    edge->target = pgr_SPI_getBigInt(tuple, tupdesc, info[2]);
    edge->going = pgr_SPI_getFloat8(tuple, tupdesc, info[3]) > 0 ? true : false;
    edge->coming = (column_found(info[4].colNumber) && pgr_SPI_getFloat8(tuple, tupdesc, info[4]) > 0) ? true : false;

    (*valid_edges)++;
}