osurs
0.0.1
|
Connection routing, checking seat availability and reservation. More...
#include "osurs/network.h"
Go to the source code of this file.
Functions | |
Connection * | new_connection (const Node *orig, const Node *dest, int time) |
Create connection between nodes. More... | |
int | check_connection (Connection *connection, int seats, int *trip_count) |
Check if seats are available in connection. More... | |
Connection * | select_connection (Connection *connection, int seats) |
Selects the best connection. More... | |
Reservation * | new_reservation (Connection *connection, int seats, char *id) |
Create a new reservation. More... | |
void | delete_connection (Connection *connection) |
Delete a connection. More... | |
Connection routing, checking seat availability and reservation.
Simple connection routing algorithm without transfers. After checking seat availability in connections reservations can be booked on the network.
int check_connection | ( | Connection * | connection, |
int | seats, | ||
int * | trip_count | ||
) |
Check if seats are available in connection.
Check a connection if the desired number of seats is available. This is important since reservations can change or avoid double booking of a searched connection.
connection | The queried connection to check. |
seats | The number of seats to check. |
trip_count | The trip number on the route, needed for getting the reserved count. |
void delete_connection | ( | Connection * | connection | ) |
Delete a connection.
Frees the memory from a connection chain on the heap.
connection | The connection chain to delete. |
Connection* new_connection | ( | const Node * | orig, |
const Node * | dest, | ||
int | time | ||
) |
Create connection between nodes.
Searches connections between nodes on the network considering a departure time. If more than one connection is possible between to nodes on the network, a connection chain is created. In a connection chain, the .last property of the connection structure points to the last connection or NULL if it is the root of the chain. Identically, the .next property points to the next connection or to NULL if it is the end of the chain.
orig | Origin node in network for connection. |
dest | Destination node in network for connection. |
time | The departure time in seconds after midnight (00:00:00). |
Reservation* new_reservation | ( | Connection * | connection, |
int | seats, | ||
char * | id | ||
) |
Create a new reservation.
Books a connection on the network, if the desired seats are available. If enough seats are available the reservation counts of the corresponding trip on the stops of the routes are increased and a new reservation is allocated and connected to the network.
connection | The connection to reserve. |
seats | The number of seats to reserve. |
id | The UUID of the reservation or NULL to generate a new one. |
Connection* select_connection | ( | Connection * | connection, |
int | seats | ||
) |
Selects the best connection.
Chooses the best connection based on arrival time and seat availability.
connection | Connection results from new_connection(). |
seats | The number of seats that should be available on the connection. |