Skip to content

Commit

Permalink
Merge pull request #8 from naviqore/feature/clean-up-project-structure
Browse files Browse the repository at this point in the history
Feature/clean up project structure
  • Loading branch information
Brunner246 authored Aug 16, 2024
2 parents 09f8b1a + 6f746ad commit 8bb1bfc
Show file tree
Hide file tree
Showing 141 changed files with 4,267 additions and 2,210 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BraceWrapping:
SplitEmptyNamespace: true
AfterCaseLabel: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeBraces: Stroustrup
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/build-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest] #
os: [windows-latest, ubuntu-latest] # , macos-latest
include:
- os: windows-latest
compiler: msvc
- os: ubuntu-latest
compiler: gcc
- os: macos-latest
compiler: clang
# - os: macos-latest
# compiler: clang
steps:
- name: Checkout code
uses: actions/[email protected]
Expand All @@ -42,3 +42,7 @@ jobs:
- name: Build
run: |
cmake --build build --config Release
- name: Test
run: |
cmake --build build --target test
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ add_subdirectory(schedule/test)
add_subdirectory(schedule/benchmarks)
add_subdirectory(raptor)
add_subdirectory(raptor/test)
add_subdirectory(gtfsRaptorConfig)
2 changes: 1 addition & 1 deletion geometry/include/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <cmath>
#include <stdexcept>
#include <numbers>
#include <../../include/spatial/CoordinateComponent.h>
#include <spatial/CoordinateComponent.h>

constexpr long double operator"" _km(const long double value) {
return value;
Expand Down
5 changes: 4 additions & 1 deletion geometry/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project("geometry_test"
)


include(CTest)
enable_testing()

add_executable(${PROJECT_NAME})
Expand All @@ -24,7 +25,9 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
)

set(BINARY ${PROJECT_NAME})
add_test(NAME ${BINARY} COMMAND ${BINARY})

add_test(NAME geomety COMMAND ${BINARY}_test)
add_test(NAME TestK2dTree COMMAND ${BINARY}_test)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/logging/src)
Expand Down
34 changes: 17 additions & 17 deletions geometry/test/test_kdTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
//

#include <gtest/gtest.h>
#include "../../logging/src/LoggingPool.h"
#include "LoggerFactory.h"
#include "utils.h"
#include "usings.h"

#include <ranges>
#include <unordered_map>


TEST(geomety, TestK2dTree) {
TEST(geomety, TestK2dTree)
{
auto kdTree = geometry::kd_tree::spatialK2dTree({});
const auto firstCoordinate = geometry::kd_tree::spatialCoordinate(1.0);
const auto secondCoordinate = geometry::kd_tree::spatialCoordinate(2.0);
Expand All @@ -21,63 +22,62 @@ TEST(geomety, TestK2dTree) {
}


class TestK2dTree : public testing::Test
{
class TestK2dTree : public testing::Test {
using hasher = geometry::utils::CoordinateComponentHash<geometry::kd_tree::spatialCoordinate>;
using equalizer = geometry::utils::CoordinateComponentEqual<geometry::kd_tree::spatialCoordinate>;

protected:
std::unordered_map<geometry::kd_tree::coordinateComponent, std::string, hasher, equalizer> stations;
std::unique_ptr<geometry::kd_tree::spatialK2dTree> kdTree;

void SetUp() override {
void SetUp() override
{
// arrange
LoggingPool::getInstance().getLogger(Target::CONSOLE)->setLevel(LoggerBridge::ERROR);
getConsoleLogger(LoggerName::GEOMETRY)->info("TestK2dTree::SetUp");
stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.4230127859742), geometry::kd_tree::spatialCoordinate(9.369479194531577))] = "St. Gallen Train Station";
stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.41190313108875), geometry::kd_tree::spatialCoordinate(9.25303543394843))] = "Gossau Train Station";
stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.41549705750434), geometry::kd_tree::spatialCoordinate(9.18936624689178))] = "Flawil Train Station";
stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.46216381226957), geometry::kd_tree::spatialCoordinate(9.040973103320258))] = "Wil Train Station";
stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.5002860698031), geometry::kd_tree::spatialCoordinate(8.723829255246654))] = "Wintherthur Train Station";

std::vector<geometry::kd_tree::coordinateComponent> coordinates;
for (const auto& coordinate : stations | std::views::keys)
{
for (const auto& coordinate : stations | std::views::keys) {
coordinates.push_back(coordinate);
}

kdTree = std::make_unique<geometry::kd_tree::spatialK2dTree>(coordinates);
}
};

TEST_F(TestK2dTree, TestK2dTreeStGallenToWinterthur) {
TEST_F(TestK2dTree, TestK2dTreeStGallenToWinterthur)
{
// act
const auto findNearestFromRickenbach = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.53556052653995), geometry::kd_tree::spatialCoordinate(8.789113533722448));
const auto findNeaerestFromKreuzbleiche = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.419620275547636), geometry::kd_tree::spatialCoordinate(9.359281921519944));

const auto nearestRickenbach = kdTree->nearest(findNearestFromRickenbach);
LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Rickenbach is: {}", stations[nearestRickenbach]));
getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Rickenbach is: {}", stations[nearestRickenbach]));

const auto neaerestKreuzbleiche = kdTree->nearest(findNeaerestFromKreuzbleiche);
LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[neaerestKreuzbleiche]));
getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[neaerestKreuzbleiche]));

// assert
ASSERT_TRUE(stations[nearestRickenbach] == "Wintherthur Train Station");
ASSERT_TRUE(stations[neaerestKreuzbleiche] == "St. Gallen Train Station");
}

TEST_F(TestK2dTree, TestK2dTreeRangeSearch) {
TEST_F(TestK2dTree, TestK2dTreeRangeSearch)
{
// act
const auto findNeaerestFromKreuzbleiche = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.419620275547636), geometry::kd_tree::spatialCoordinate(9.359281921519944));

constexpr auto rangeInKiloMeters = 30.0_km;
const auto nearestRickenbach = kdTree->rangeSearch(findNeaerestFromKreuzbleiche, rangeInKiloMeters);

// assert
for (auto it = nearestRickenbach.begin(); it != nearestRickenbach.end(); ++it)
{
LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[*it]));
switch (std::distance(nearestRickenbach.begin(), it))
{
for (auto it = nearestRickenbach.begin(); it != nearestRickenbach.end(); ++it) {
getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[*it]));
switch (std::distance(nearestRickenbach.begin(), it)) {
case 0:
ASSERT_TRUE(stations[*it] == "St. Gallen Train Station");
break;
Expand Down
70 changes: 70 additions & 0 deletions gtfsRaptorConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
project(gtfsRaptorConfig)

add_executable(gtfsSubsetWriter
src/agencySubsetWriter/gtfsSubsetWriter.cpp
)

find_path(P_RANAV_CSV2_INCLUDE_DIRS "csv2/mio.hpp")

add_library(${PROJECT_NAME} SHARED )

target_sources(${PROJECT_NAME} PRIVATE
src/GtfsToRaptorConverter.cpp
src/RoutePartitioner.cpp
src/TimetableManager.cpp
src/SubRoute.cpp
PUBLIC
include/GtfsToRaptorConverter.h
include/RoutePartitioner.h
include/TimetableManager.h
include/SubRoute.h
)

target_include_directories(gtfsSubsetWriter PRIVATE ${CMAKE_SOURCE_DIR}/logging/include)
target_include_directories(gtfsSubsetWriter PRIVATE ${CMAKE_SOURCE_DIR}/gtfsRaptorConfig/src)
target_include_directories(gtfsSubsetWriter PRIVATE ${CMAKE_SOURCE_DIR}/gtfsRaptorConfig/include)
target_include_directories(gtfsSubsetWriter PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
target_include_directories(gtfsSubsetWriter PRIVATE ${P_RANAV_CSV2_INCLUDE_DIRS})

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/gtfsRaptorConfig/src)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/gtfsRaptorConfig/include) # check if public is needed
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/schedule/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/logging/include)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)

target_link_libraries(${PROJECT_NAME} PRIVATE
logging
geometry
schedule
)

target_link_libraries(gtfsSubsetWriter PRIVATE
logging
geometry
schedule
)

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME}
BASE_NAME ${PROJECT_NAME}
EXPORT_MACRO_NAME GTFS_RAPTOR_API
EXPORT_FILE_NAME ${PROJECT_NAME}_export.h
STATIC_DEFINE ${PROJECT_NAME}_BUILT_AS_STATIC
)

set(INCLUDE_INSTALL_DIR include)

install(FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION
${INCLUDE_INSTALL_DIR}
)
15 changes: 15 additions & 0 deletions gtfsRaptorConfig/include/GtfsToRaptorConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by MichaelBrunner on 26/07/2024.
//

#pragma once

#include <gtfsRaptorConfig_export.h>

namespace converter {

class GTFS_RAPTOR_API GtfsToRaptorConverter
{
};

} // converter
44 changes: 44 additions & 0 deletions gtfsRaptorConfig/include/RoutePartitioner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by MichaelBrunner on 19/07/2024.
//

#ifndef ROUTEPARTITIONER_H
#define ROUTEPARTITIONER_H

#include "GtfsData.h"
#include "model/Route.h"

#include <functional>
#include <map>
#include <utility>
#include <gtfsRaptorConfig_export.h>

namespace converter {
class SubRoute;

class GTFS_RAPTOR_API RoutePartitioner
{

public:
explicit RoutePartitioner(schedule::gtfs::GtfsData* data);

[[nodiscard]] std::vector<SubRoute> getSubRoutes(std::string const& routeId) const;

[[nodiscard]] const SubRoute& getSubRoute(std::string const& tripId) const;


private:
std::unordered_map<std::string, std::unordered_map<std::string, SubRoute> /*, decltype(routeHash), decltype(routeEqual)*/> subRoutes{};
schedule::gtfs::GtfsData* data;

void processRoute(schedule::gtfs::Route const& route);

[[nodiscard]] std::string generateStopSequenceKey(const std::string& tripId) const;

[[nodiscard]] std::vector<schedule::gtfs::Stop> extractStopSequence(schedule::gtfs::Trip const& aTrip) const;
};

} // gtfs
// schedule

#endif //ROUTEPARTITIONER_H
60 changes: 60 additions & 0 deletions gtfsRaptorConfig/include/SubRoute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Created by MichaelBrunner on 02/08/2024.
//

#pragma once

#include "GtfsData.h"

#include <functional>
#include <gtfsRaptorConfig_export.h>

namespace converter {

class GTFS_RAPTOR_API SubRoute
{
std::string SubRouteId{};
std::string routeId{};
std::string stopSequenceKey{};
std::vector<schedule::gtfs::Stop> stopsSequence{};
std::vector<schedule::gtfs::Trip> trips{};

public:
explicit SubRoute(std::string&& subRouteId, std::string routeId, std::string stopSequenceKey, std::vector<schedule::gtfs::Stop>&& stopsSequence);

SubRoute(const SubRoute& aSubRoute);

SubRoute(SubRoute&& aSubRoute) noexcept = default;
SubRoute& operator=(const SubRoute& aSubRoute) = default;
SubRoute& operator=(SubRoute&& aSubRoute) noexcept = default;

void addTrip(schedule::gtfs::Trip const& trip);

[[nodiscard]] const std::string& getSubRouteId() const ;

[[nodiscard]] const std::string& getRouteId() const;

[[nodiscard]] const std::string& getStopSequenceKey() const {
return stopSequenceKey;
}

[[nodiscard]] const std::vector<schedule::gtfs::Stop>& getStopsSequence() const;

[[nodiscard]] size_t stopIndex(std::string_view stopId) const ;

[[nodiscard]] const std::vector<schedule::gtfs::Trip>& getTrips() const;

bool operator==(const SubRoute& aSubRoute) const;

std::function<size_t(const SubRoute&)> SubRouteHash = [](const SubRoute& aSubRoute) {
return std::hash<std::string>{}(aSubRoute.getSubRouteId());
};

std::function<bool(const SubRoute&, const SubRoute&)> SubRouteEqual = [](const SubRoute& aSubRoute, const SubRoute& anotherSubRoute) {
return aSubRoute == anotherSubRoute;
};
};



} // converter
Loading

0 comments on commit 8bb1bfc

Please sign in to comment.