Skip to content

Commit

Permalink
Merge pull request #37 from naviqore/feature/NAV-189-clean-up-unit-an…
Browse files Browse the repository at this point in the history
…d-integration-tests

Feature/nav 189 clean up unit and integration tests
  • Loading branch information
Brunner246 authored Sep 23, 2024
2 parents 292e5eb + 56ba22d commit 8266d2c
Show file tree
Hide file tree
Showing 32 changed files with 416 additions and 790,755 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@
/packages/*
/vcpkg_installed/*
/src/gtfsRaptorConfig/src/agencySubsetWriter/__pycache__
/resources/*
29 changes: 29 additions & 0 deletions CMake/DownloadAndUnzip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function(download_and_unzip zip_url unzip_dir)

set(zip_file "${CMAKE_BINARY_DIR}/SWITZERLAND_GTFS.zip")

if(EXISTS ${zip_file})
message(STATUS "ZIP file already exists: ${zip_file}")
else()
message(STATUS "Downloading ${zip_url} to ${zip_file}...")
file(DOWNLOAD ${zip_url} ${zip_file} SHOW_PROGRESS)
endif()

if(EXISTS ${unzip_dir})
message(STATUS "Unzip directory already exists: ${unzip_dir}")
else()
file(MAKE_DIRECTORY ${unzip_dir})

execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${zip_file}
WORKING_DIRECTORY ${unzip_dir}
RESULT_VARIABLE result
)

if(NOT result EQUAL 0)
message(FATAL_ERROR "Unzipping failed!")
else()
message(STATUS "Successfully unzipped to ${unzip_dir}.")
endif()
endif()
endfunction()
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25.1) # 3.28
project(raptorxx VERSION 0.0.2)
cmake_minimum_required(VERSION 3.25.1)
project(raptorxx VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -11,9 +11,9 @@ endif ()
if (MSVC)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(/W3 /WX /wd4251 /experimental:module /std:c++latest /RTC1)
else()
else ()
add_compile_options(/W3 /WX /wd4251 /experimental:module /std:c++latest /O2)
endif()
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wall -Wextra -pedantic -std=c++23) # -Werror => this is too strict for now - causes break when building CSV library
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
Expand All @@ -31,8 +31,12 @@ set(BUILD_SHARED_LIBS ON)

set(CPM_DOWNLOAD_LOCATION "${CMAKE_SOURCE_DIR}/cmake/CPM.cmake")

#set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake
# CACHE STRING "Vcpkg toolchain file")
# Download GTFS Switzerland
include(${CMAKE_SOURCE_DIR}/CMake/DownloadAndUnzip.cmake)
set(ZIP_URL "https://opentransportdata.swiss/en/dataset/timetable-2024-gtfs2020/permalink/gtfs_fp2024_2024-09-23.zip")
set(UNZIP_DIR "${CMAKE_SOURCE_DIR}/resources/gtfs_switzerland")

download_and_unzip(${ZIP_URL} ${UNZIP_DIR})

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output/lib)
Expand All @@ -47,7 +51,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/rel
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/release)

# SOURCE
add_subdirectory(src/interfaces)
add_subdirectory(src/logging)
add_subdirectory(src/geometry)
add_subdirectory(src/schedule)
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# RaptorXX

RaptorXX is a C++ project that uses vcpkg for managing its dependencies.
[![CMake Build Matrix](https://github.com/naviqore/raptorxx/actions/workflows/build-matrix.yml/badge.svg)](https://github.com/naviqore/raptorxx/actions/workflows/build-matrix.yml)

RaptorXX is a C++ project designed to manage and process public transportation data, specifically using the GTFS (
General Transit Feed Specification) format. The project leverages modern C++ standards (C++20/C++23).
The primary functionalities of RaptorXX include:

- **Data Management**: Efficiently handling and processing large datasets of public transportation schedules and routes.
- **Algorithm Implementation**: Implementing the RAPTOR (Round-based Public Transit Routing) algorithm for fast and
efficient route planning.
- **Modular Design**: Organized into multiple subdirectories for logging, geometry, scheduling, and gtfs to raptor
structures configuration, ensuring a clean and maintainable codebase.
- **Testing and Benchmarking**: Comprehensive test suites and benchmarks to ensure the correctness and performance of
the implemented algorithms.

The project is built using CMake, with specific configurations for different compilers and build types. It also includes
scripts for downloading and unzipping necessary data files, ensuring that all required resources are available for the
build process.

## Platform Support

RaptorXX can be compiled for both Windows and Linux platforms. The CMake configuration and vcpkg package manager ensure
that all dependencies and build configurations are handled appropriately for these operating systems.

## Dependencies

Expand Down
4 changes: 1 addition & 3 deletions benchmark/benchmark_gtfsRaptor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(benchmark_gtfsRaptor)

# file(GLOB CHAPTER_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h")

add_executable(${PROJECT_NAME}
gtfsRaptor_benchmark.cpp
)
Expand Down Expand Up @@ -39,7 +37,7 @@ foreach(EXECUTABLE IN LISTS EXECUTABLES)
target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_SOURCE_DIR}/src/gtfsRaptorConfig/include)
endforeach()

add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/switzerland/")
add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/resources/gtfs_switzerland/")



Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark_gtfsRaptor/gtfsRaptor_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ BENCHMARK_F(GtfsRaptorFixture, BM_route_vonwilSG_mels)
(benchmark::State& state)
{
// Route 1: vonwilSG -> mels
BenchmarkRoute(state, "8589640", "8579885", time.secondsOfDay(), time.secondsOfDay() + 60 * 60 * 2, *raptorRouter, queryConfig);
BenchmarkRoute(state, "8589640", "8579885", time.secondsOfDay(), 0, *raptorRouter, queryConfig);
}

BENCHMARK_F(GtfsRaptorFixture, BM_route_AbtwilDorf_Westcenter)
(benchmark::State& state)
{
BenchmarkRoute(state, "8588889", "8589644", time.secondsOfDay(), time.secondsOfDay() + 60 * 60 * 2, *raptorRouter, queryConfig);
BenchmarkRoute(state, "8588889", "8589644", time.secondsOfDay(), 0, *raptorRouter, queryConfig);
}

BENCHMARK_REGISTER_F(GtfsRaptorFixture, BM_route_vonwilSG_mels)->Iterations(50);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_schedule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE

target_compile_definitions(${PROJECT_NAME} PRIVATE gtfs_EXPORTS)

add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/")
add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/resources/gtfs_switzerland/")



Expand Down
99 changes: 73 additions & 26 deletions benchmark/benchmark_schedule/gtfs_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

#include "GtfsReaderStrategyFactory.h"

static void BM_pointer(benchmark::State& state) {
static void BM_pointer(benchmark::State& state)
{
auto vec = std::vector<int*>();

vec.resize(10'000, new int(12));
Expand All @@ -30,7 +31,8 @@ static void BM_pointer(benchmark::State& state) {
}
}

static void BM_reference(benchmark::State& state) {
static void BM_reference(benchmark::State& state)
{
const auto ref = 12;
auto vec = std::vector<int>();
vec.resize(10'000, ref);
Expand All @@ -43,54 +45,93 @@ static void BM_reference(benchmark::State& state) {
}
}

struct Record {
std::string agencyId;
std::string agencyName;
std::string agencyUrl;
std::string agencyTimezone;
std::string agencyLang;
std::string agencyPhone;
};

static void BM_rawPointer(benchmark::State& state)
{
auto vec = std::vector<Record*>();

vec.resize(10'000, new Record{"agencyId", "agencyName", "agencyUrl", "agencyTimezone", "agencyLang", "agencyPhone"});

auto printValue = [](const Record* value) { return value->agencyId; };

for (auto _ : state) {
for (const auto f : vec) {
benchmark::DoNotOptimize(printValue(f));
}
}
}

static void BM_uniquePointer(benchmark::State& state)
{
auto vec = std::vector<std::unique_ptr<Record>>();

vec.resize(10'000);
for (auto& f : vec) {
f = std::make_unique<Record>("agencyId", "agencyName", "agencyUrl", "agencyTimezone", "agencyLang", "agencyPhone");
}

auto printValue = [](const Record* value) { return value->agencyId; };

for (auto _ : state) {
for (const auto& f : vec) {
benchmark::DoNotOptimize(printValue(f.get()));
}
}
}

class GtfsReaderFixture : public benchmark::Fixture {
protected:
protected:
std::unique_ptr<schedule::gtfs::IGtfsReaderStrategyFactory> readerFactory;

public:
void SetUp(::benchmark::State& state) override {
public:
void SetUp(::benchmark::State& state) override
{
readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(
schedule::gtfs::ReaderType::CSV_PARALLEL, TEST_DATA_DIR);
}

void TearDown(::benchmark::State& state) override {}
};

BENCHMARK_F(GtfsReaderFixture, BM_read_agencies)(benchmark::State& state) {
auto strategy =
std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>{};
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy =
readerFactory->getStrategy(GtfsStrategyType::AGENCY);
BENCHMARK_F(GtfsReaderFixture, BM_read_agencies)
(benchmark::State& state)
{
auto strategy = std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>{};
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy = readerFactory->getStrategy(GtfsStrategyType::AGENCY);
strategy.push_back(readerStrategy);
const auto reader =
std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
const auto reader = std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
for (auto _ : state) {
reader->readData();
}
}

BENCHMARK_F(GtfsReaderFixture, BM_read_calendar_dates)
(benchmark::State& state) {
auto strategy =
std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>();
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy =
readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE);
(benchmark::State& state)
{
auto strategy = std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>();
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE);
strategy.push_back(readerStrategy);
const auto reader =
std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
const auto reader = std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
for (auto _ : state) {
reader->readData();
}
}

BENCHMARK_F(GtfsReaderFixture, BM_read_stop_times)(benchmark::State& state) {
auto strategy =
std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>();
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy =
readerFactory->getStrategy(GtfsStrategyType::STOP_TIME);
BENCHMARK_F(GtfsReaderFixture, BM_read_stop_times)
(benchmark::State& state)
{
auto strategy = std::vector<std::function<void(schedule::gtfs::GtfsReader&)>>();
const std::function<void(schedule::gtfs::GtfsReader&)> readerStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME);
strategy.push_back(readerStrategy);
const auto reader =
std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
const auto reader = std::make_unique<schedule::gtfs::GtfsReader>(std::move(strategy));
for (auto _ : state) {
reader->readData();
}
Expand All @@ -101,3 +142,9 @@ BENCHMARK_REGISTER_F(GtfsReaderFixture, BM_read_calendar_dates);
BENCHMARK_REGISTER_F(GtfsReaderFixture, BM_read_stop_times);
BENCHMARK(BM_pointer);
BENCHMARK(BM_reference);
BENCHMARK(BM_rawPointer);
BENCHMARK(BM_uniquePointer);

BENCHMARK_MAIN();


1 change: 0 additions & 1 deletion benchmark/benchmark_schedule/gtfs_schedule_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ static void BM_read_gtfs_schedule(benchmark::State& state) {

BENCHMARK(BM_read_gtfs_schedule);

BENCHMARK_MAIN();
1 change: 1 addition & 0 deletions src/gtfsRaptorConfig/include/GtfsToRaptorConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace converter {
std::shared_ptr<raptor::RaptorData> convert();
void processTrip(const std::shared_ptr<schedule::gtfs::Trip>& trip);
void addSubRoute(const SubRoute& subRoute);
[[nodiscard]] RoutePartitioner& getRoutePartitioner() const;

private:
void addStopTimesToRouterBuilder(schedule::gtfs::StopTime const& stopTime, std::string const& tripId, std::string const& subRouteId, int position);
Expand Down
3 changes: 1 addition & 2 deletions src/gtfsRaptorConfig/include/TimetableManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ namespace converter {
public:
explicit TimetableManager(schedule::gtfs::GtfsData&& data, const raptor::utils::LocalDateTime& localDateTime);

void createRelations() const;

[[nodiscard]] const schedule::gtfs::GtfsData& getData() const;

[[nodiscard]] schedule::gtfs::GtfsData& getData();
Expand All @@ -38,6 +36,7 @@ namespace converter {
[[nodiscard]] const RoutePartitioner& getRoutePartitioner() const;

private:
void createRelations() const;
void buildTripsToRoutesRelations() const;
void buildStopTimesToTripsAndRoutesRelations() const;
void buildStopRelations() const;
Expand Down
5 changes: 5 additions & 0 deletions src/gtfsRaptorConfig/src/GtfsToRaptorConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ namespace converter {
addedSubRoutes.insert(subRoute);
}

RoutePartitioner& GtfsToRaptorConverter::getRoutePartitioner() const
{
return *routePartitioner;
}

void GtfsToRaptorConverter::addStopTimesToRouterBuilder(schedule::gtfs::StopTime const& stopTime, std::string const& tripId, std::string const& subRouteId, const int position)
{
raptorRouterBuilder.addStopTime(subRouteId,
Expand Down
12 changes: 0 additions & 12 deletions src/interfaces/CMakeLists.txt

This file was deleted.

18 changes: 0 additions & 18 deletions src/interfaces/include/ITestInterface.h

This file was deleted.

4 changes: 0 additions & 4 deletions src/raptor/include/RaptorAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@ namespace raptor {

class RAPTOR_API RaptorAlgorithm {
public:
// Destructor
virtual ~RaptorAlgorithm() = default;

// Method to route the earliest arrival
[[nodiscard]] virtual std::vector<std::unique_ptr<Connection>> routeEarliestArrival(
const std::map<std::string, types::raptorInt>& departureStops,
const std::map<std::string, types::raptorInt>& arrivalStops,
const config::QueryConfig& config) const
= 0;

// Method to route latest departure
[[nodiscard]] virtual std::vector<std::shared_ptr<Connection>> routeLatestDeparture(
const std::map<std::string, types::raptorIdx>& departureStops,
const std::map<std::string, std::chrono::system_clock::time_point>& arrivalStops,
const config::QueryConfig& config) const
= 0;

// Method to route isolines
[[nodiscard]] virtual std::map<std::string, std::shared_ptr<Connection>> routeIsolines(
const std::map<std::string, std::chrono::system_clock::time_point>& sourceStops,
const config::QueryConfig& config) const
Expand Down
Loading

0 comments on commit 8266d2c

Please sign in to comment.