osurs  0.0.1
Functions
connection.c File Reference

Routing connections between nodes on the network without transfers. More...

#include <limits.h>
#include "osurs/reserve.h"
Include dependency graph for connection.c:

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...
 
void delete_connection (Connection *connection)
 Delete a connection. More...
 

Detailed Description

Routing connections between nodes on the network without transfers.

Public transit routing without transfers, checking seat availability and selecting best connections based on arrival time.

Date
: 2022-07-20
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.

◆ 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.