Skip to content

Commit

Permalink
REFACTOR: refactor whole project due to restructuring the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunner246 committed Aug 16, 2024
1 parent 91b9033 commit 6f746ad
Show file tree
Hide file tree
Showing 45 changed files with 377 additions and 778 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
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
5 changes: 2 additions & 3 deletions raptor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ project("raptor"
DESCRIPTION "C++ implementation of raptor algorithm"
)

add_library(${PROJECT_NAME} SHARED
src/utils/helperFunctions.h
)
add_library(${PROJECT_NAME} SHARED)

target_sources(${PROJECT_NAME} PRIVATE
src/Raptor.cpp
Expand Down Expand Up @@ -45,6 +43,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/RaptorConnection.cpp
src/RaptorConnection.h
src/utils/LocalDateTime.cpp
src/utils/helperFunctions.h
PUBLIC
include/RaptorAlgorithm.h
include/config/QueryConfig.h
Expand Down
3 changes: 2 additions & 1 deletion raptor/include/LocalDateTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace raptor::utils {
dateTime = local_days{year / month / day} + hour + minute + second;
}

LocalDateTime() = default;

[[nodiscard]] long long secondsOfDay() const {
using namespace std::chrono;
const auto time_since_epoch = dateTime.time_since_epoch();
Expand Down Expand Up @@ -54,7 +56,6 @@ namespace raptor::utils {
const auto new_seconds = duration_cast<seconds>(time_of_day % minutes(1));
return LocalDateTime{year{1970}, month{1}, day{1}, new_hours, new_minutes, new_seconds};
}

};

inline LocalDateTime fromSecondsOfDay(const long long total_seconds, const std::chrono::year year, const std::chrono::month month, const std::chrono::day day) {
Expand Down
4 changes: 0 additions & 4 deletions raptor/src/LabelPostprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ namespace raptor {
throw std::runtime_error("Unknown label type");
}

// Convert timestamps to LocalDateTime if necessary
// auto departureTime = DateTimeUtils::convertToLocalDateTime(departureTimestamp, referenceDate);
// auto arrivalTime = DateTimeUtils::convertToLocalDateTime(arrivalTimestamp, referenceDate);

connection->addLeg(std::make_shared<LegImpl>(routeId, tripId, fromStopId, toStopId, departureTimestamp, arrivalTimestamp, type));
}

Expand Down
10 changes: 4 additions & 6 deletions raptor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ project("raptor_test"
DESCRIPTION "Raptor test"
)


include(CTest)
enable_testing()

add_executable(${PROJECT_NAME})

target_sources(${PROJECT_NAME} PRIVATE
test_raptor.cpp
test_routeBuilder.cpp
test_raptorDataBuilder.cpp
test_raptorAlgorithm.cpp
RaptorRouterTestBuilder.h
RaptorRouterTestBuilder.cpp
)
Expand All @@ -29,7 +28,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
)

set(BINARY ${PROJECT_NAME})
add_test(NAME ${BINARY} COMMAND ${BINARY})
add_test(NAME RaptorAlgoTest COMMAND ${BINARY}_test)
add_test(NAME RouteBuilderTest COMMAND ${BINARY}_test)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/logging/include)
Expand All @@ -38,8 +38,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/raptor/in
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/raptor/include/config)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/schedule/include)

add_definitions(-DTEST_DATA_DIRRECTORY="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/Verkehrsbetriebe_der_Stadt_St_Gallen/")

# if(USE_ZURICH_GTFS)
#
# # add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/2024_google_transit/")
Expand Down
4 changes: 1 addition & 3 deletions raptor/test/RaptorRouterTestBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Created by MichaelBrunner on 20/07/2024.
//

#ifndef RAPTORROUTERTESTBUILDER_H
#define RAPTORROUTERTESTBUILDER_H
#pragma once

#include "utils/RaptorDataBuilder.h"
#include <vector>
Expand Down Expand Up @@ -75,4 +74,3 @@ class RaptorRouterTestBuilder
static std::shared_ptr<raptor::RaptorData> build(const std::vector<Route>& routes, const std::vector<Transfer>& transfers, int dayStart, int dayEnd, int sameStopTransferTime);
};

#endif //RAPTORROUTERTESTBUILDER_H
2 changes: 0 additions & 2 deletions raptor/test/sample-feed/agency.txt

This file was deleted.

3 changes: 0 additions & 3 deletions raptor/test/sample-feed/calendar.txt

This file was deleted.

2 changes: 0 additions & 2 deletions raptor/test/sample-feed/calendar_dates.txt

This file was deleted.

3 changes: 0 additions & 3 deletions raptor/test/sample-feed/fare_attributes.txt

This file was deleted.

5 changes: 0 additions & 5 deletions raptor/test/sample-feed/fare_rules.txt

This file was deleted.

12 changes: 0 additions & 12 deletions raptor/test/sample-feed/frequencies.txt

This file was deleted.

6 changes: 0 additions & 6 deletions raptor/test/sample-feed/routes.txt

This file was deleted.

1 change: 0 additions & 1 deletion raptor/test/sample-feed/shapes.txt

This file was deleted.

29 changes: 0 additions & 29 deletions raptor/test/sample-feed/stop_times.txt

This file was deleted.

10 changes: 0 additions & 10 deletions raptor/test/sample-feed/stops.txt

This file was deleted.

12 changes: 0 additions & 12 deletions raptor/test/sample-feed/trips.txt

This file was deleted.

11 changes: 0 additions & 11 deletions raptor/test/test-data-fictional/routes.txt

This file was deleted.

Loading

0 comments on commit 6f746ad

Please sign in to comment.