Developer documentation (C/C++)
-
struct NetworkRow
- #include <network.h>
Structure representing a row in a network.
Public Members
-
char trip_id[MAX_STRING_LENGTH]
Trip ID
-
char from_stop_id[MAX_STRING_LENGTH]
From stop ID
-
char to_stop_id[MAX_STRING_LENGTH]
To stop ID
-
double arrival_time
Arrival time as epoch
-
double departure_time
Departure time as epoch
-
double travel_time
Travel time
-
bool nulls[6]
Array of boolean flags indicating null values
-
char trip_id[MAX_STRING_LENGTH]
-
struct RoundData
- #include <raptor.h>
Contains data related to stops and arrival times for a round.
This struct holds information about stops and their associated data, including arrival times, previous stops, trip IDs, and the number of transfers.
Public Members
-
std::unordered_map<std::string, std::tuple<double, std::string, std::string, int>> stops
Maps stop identifiers to detailed stop information.
This map associates each stop identifier (as a string) with a tuple containing:
Arrival time (double)
Previous stop identifier (string)
Trip ID (string)
Number of transfers (int)
-
std::unordered_map<std::string, double> arrival_times
Maps stop identifiers to their arrival times.
This map associates each stop identifier (as a string) with its corresponding arrival time (double).
-
std::unordered_map<std::string, std::tuple<double, std::string, std::string, int>> stops
-
struct Solution
- #include <solution.h>
Structure representing a solution for the public transportation algorithms.
-
struct SolutionAlg
- file pgtfs.cpp
- #include <postgres.h>#include <fmgr.h>#include <utils/builtins.h>#include <funcapi.h>#include “src/models/network.h”#include “src/algorithms/csa/csa.h”#include “src/algorithms/raptor/raptor.h”
Implementation of PostgreSQL extension functions.
Functions
-
Datum pgtfs_csa(PG_FUNCTION_ARGS)
Implements the pgtfs_csa PostgreSQL extension function.
This function performs the Connection Scan Algorithm (CSA) to find connections between the specified origin and destination at the given departure time.
- Parameters:
fcinfo – Function call information.
- Returns:
A set of rows representing the solutions found.
-
PG_FUNCTION_INFO_V1(pgtfs_version)
-
Datum pgtfs_version(PG_FUNCTION_ARGS)
Returns version information about the extension.
This function returns a textual representation of version information including the extension version, PostgreSQL version, and compiler version.
- Parameters:
fcinfo – Function call information.
- Returns:
A text representation of the version information.
-
PG_FUNCTION_INFO_V1(pgtfs_raptor)
-
Datum pgtfs_raptor(PG_FUNCTION_ARGS)
-
Datum pgtfs_csa(PG_FUNCTION_ARGS)
- file csa.h
- #include “postgres.h”#include <vector>#include <ctime>#include <string>#include “src/models/network.h”#include “src/models/solution.h”
Declarations for the CSA (Connection Scan Algorithm) module.
Functions
-
std::vector<SolutionAlg> perform_CSA(const char *origin, const char *destination, float8 departure_time, NetworkRow *network, int64_t network_size)
Performs the Connection Scan Algorithm.
This function performs the Connection Scan Algorithm (CSA) to find connections between the specified origin and destination at the given departure time.
- Parameters:
origin – The origin stop ID.
destination – The destination stop ID.
departure_time – The departure time.
network – Pointer to the network of stops.
network_size – The size of the network.
- Returns:
A vector of SolutionCSA structures representing the solutions found.
-
std::vector<SolutionAlg> perform_CSA_Minimize_Transfers(const char *origin, const char *destination, float8 departure_time, NetworkRow *network, int64_t network_size)
Performs the Connection Scan Algorithm and minimizes transfers when creating route from solution.
This function performs the Connection Scan Algorithm (CSA) to find connections between the specified origin and destination at the given departure time. It keeps an array of trip_ids that are relevant for each stop and arrival time pair that is then used to stay on the same trip_id as the previous stop when multiple trip_ids are relevant. This does not minimize number of transfers as a tradeoff with arrival time, it only ensures that the final route does not randomly change between trip_ids when maintaining the same trip_id is possible.
- Parameters:
origin – The origin stop ID.
destination – The destination stop ID.
departure_time – The departure time.
network – Pointer to the network of stops.
network_size – The size of the network.
- Returns:
A vector of SolutionCSA structures representing the solutions found.
-
std::vector<SolutionAlg> perform_CSA(const char *origin, const char *destination, float8 departure_time, NetworkRow *network, int64_t network_size)
- file raptor.h
- #include “postgres.h”#include <fmgr.h>#include <utils/builtins.h>#include <vector>#include <string>#include <unordered_map>#include <queue>#include “src/models/network.h”#include “src/models/solution.h”
Functions
-
std::vector<SolutionAlg> perform_RAPTOR(const char *origin, const char *destination, float8 departure_time, NetworkRow *network, int64_t network_size, int max_rounds)
Performs the RAPTOR algorithm to find the best route.
This function executes the RAPTOR algorithm to find connections between the specified origin and destination at the given departure time.
- Parameters:
origin – The origin stop ID.
destination – The destination stop ID.
departure_time – The departure time.
network – Pointer to the network of stops.
network_size – The size of the network.
max_rounds – The limit on the number of rounds to be performed by RAPTOR.
- Returns:
A vector of SolutionRAPTOR structures representing the solutions found.
-
void preprocess_timetable(NetworkRow *network, int64_t network_size, std::unordered_map<std::string, std::vector<NetworkRow>> &departures)
Preprocesses the timetable for the RAPTOR algorithm.
This function preprocesses the timetable data to optimize the performance of the RAPTOR algorithm.
- Parameters:
network – The network data.
network_size – The size of the network data.
departures – A reference to an unordered map that will hold the preprocessed departure data.
-
std::vector<SolutionAlg> perform_RAPTOR(const char *origin, const char *destination, float8 departure_time, NetworkRow *network, int64_t network_size, int max_rounds)
- file network.h
- #include <postgres.h>#include <fmgr.h>#include <executor/spi.h>#include <utils/builtins.h>#include <catalog/pg_type.h>#include <utils/array.h>#include <utils/typcache.h>#include <utils/lsyscache.h>
Declarations for functions related to network operations.
Defines
-
MAX_STRING_LENGTH
Functions
-
NetworkRow *create_network(const char *network_query_str, int64_t *network_size)
Creates a network from the given query string.
This function creates a network based on the provided query string and returns a pointer to the network.
- Parameters:
network_query_str – The query string specifying the network.
network_size – Pointer to store the size of the network.
- Returns:
Pointer to the created network.
-
void print_network_rows(NetworkRow *network_rows, int64_t network_size)
Prints the network rows.
This function prints the given network rows along with their details.
- Parameters:
network_rows – Pointer to the network rows array.
network_size – The size of the network.
-
MAX_STRING_LENGTH
- file solution.h
- #include <string>
- dir src/algorithms
- dir src/algorithms/csa
- dir src/models
- dir src/algorithms/raptor
- dir src