osurs  0.0.1
Functions
reserve.h File Reference

Connection routing, checking seat availability and reservation. More...

#include "osurs/network.h"
Include dependency graph for reserve.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Connectionnew_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...
 
Connectionselect_connection (Connection *connection, int seats)
 Selects the best connection. More...
 
Reservationnew_reservation (Connection *connection, int seats, char *id)
 Create a new reservation. More...
 
void delete_connection (Connection *connection)
 Delete a connection. More...
 

Detailed Description

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.

Note
There are already powerful routing algorithms for public transport, so the algorithm included here is minimal and only serves to book reservations on already known/found connections to the right segments of the trips (without transfers).
Date
: 2022-07-12
Author
: Merlin Unterfinger

Function Documentation

◆ check_connection()

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.

Note
This function is called internally by new_reservation(Connection).
Parameters
connectionThe queried connection to check.
seatsThe number of seats to check.
trip_countThe trip number on the route, needed for getting the reserved count.
Returns
Returns 0 if failure and 1 if success.

◆ delete_connection()

void delete_connection ( Connection connection)

Delete a connection.

Frees the memory from a connection chain on the heap.

Note
This function has to be called for every queried connection to prevent memory leaks.
Parameters
connectionThe connection chain to delete.

◆ new_connection()

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.

Note
Queried connections are not stored on the network and must be released individually to prevent a memory leak (delete_connection(Connection*)).
Parameters
origOrigin node in network for connection.
destDestination node in network for connection.
timeThe departure time in seconds after midnight (00:00:00).
Returns
Returns a pointer to a connection chain or NULL if no connection was found.

◆ new_reservation()

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.

Parameters
connectionThe connection to reserve.
seatsThe number of seats to reserve.
idThe UUID of the reservation or NULL to generate a new one.
Returns
Returns a reservation or null if no seats are available.

◆ select_connection()

Connection* select_connection ( Connection connection,
int  seats 
)

Selects the best connection.

Chooses the best connection based on arrival time and seat availability.

Parameters
connectionConnection results from new_connection().
seatsThe number of seats that should be available on the connection.
Returns
The shifted pointer to the best connection (Connection*) or NULL if no suitable connection is found.