Skip to content

Commit

Permalink
Merge pull request #27 from naviqore/feature/clean-up-project-structure
Browse files Browse the repository at this point in the history
error: error: expected primary-expression before ‘)’ token
  • Loading branch information
Brunner246 authored Aug 17, 2024
2 parents f8a0736 + 04848ed commit aecd5dd
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 104 deletions.
7 changes: 4 additions & 3 deletions geometry/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ project("geometry_tests"
)


include(CTest)
enable_testing()

add_executable(${PROJECT_NAME})

target_sources(${PROJECT_NAME} PRIVATE
Expand Down Expand Up @@ -37,3 +34,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/geometry/







83 changes: 49 additions & 34 deletions raptor/src/RaptorRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,62 @@ namespace raptor {
constexpr types::raptorInt MIN_WALKING_TIME_TO_TARGET = 0;
constexpr types::raptorInt MAX_DIFFERENCE_IN_SOURCE_STOP_TIMES = 24 * 60 * 60;

void checkNonNullOrEmptyStops(const std::map<std::string, types::raptorInt>& stops, const std::string& labelSource) {
if (stops.empty())
{
void checkNonNullOrEmptyStops(const std::map<std::string, types::raptorInt>& stops, const std::string& labelSource)
{
if (stops.empty()) {
throw std::invalid_argument(labelSource + " stops must not be empty.");
}
}

void validateSourceStopTimes(const std::map<std::string, types::raptorIdx>& sourceStops) {
for (const auto& entry : sourceStops)
{
if (entry.second == 0)
{
void validateSourceStopTimes(const std::map<std::string, types::raptorIdx>& sourceStops)
{
for (const auto& entry : sourceStops) {
if (entry.second == 0) {
throw std::invalid_argument("Source stop times must not be null.");
}
}

if (const auto minMaxPair = std::minmax_element(sourceStops.begin(), sourceStops.end(), [](const auto& a, const auto& b) { return a.second < b.second; }); minMaxPair.second->second - minMaxPair.first->second > MAX_DIFFERENCE_IN_SOURCE_STOP_TIMES)
{
if (const auto minMaxPair = std::minmax_element(sourceStops.begin(), sourceStops.end(), [](const auto& a, const auto& b) { return a.second < b.second; }); minMaxPair.second->second - minMaxPair.first->second > MAX_DIFFERENCE_IN_SOURCE_STOP_TIMES) {
throw std::invalid_argument("Difference between source stop times must be less than 24 hours.");
}
}

void validateStopPermutations(const std::map<std::string, types::raptorInt>& sourceStops, const std::map<std::string, types::raptorInt>& targetStops) {
void validateStopPermutations(const std::map<std::string, types::raptorInt>& sourceStops, const std::map<std::string, types::raptorInt>& targetStops)
{
// Ensure departure and arrival stops are not the same
std::set<std::string> sourceKeys;
for (const auto& key : sourceStops | std::views::keys)
{
for (const auto& key : sourceStops | std::views::keys) {
sourceKeys.insert(key);
}

for (const auto& stop : targetStops | std::views::keys)
{
if (sourceKeys.contains(stop))
{
for (const auto& stop : targetStops | std::views::keys) {
if (sourceKeys.contains(stop)) {
throw std::invalid_argument("Source and target stop IDs must not be the same.");
}
}
}


std::map<types::raptorInt, types::raptorInt> validateStopsAndGetIndices(const std::map<std::string, types::raptorInt>& stops, const std::unordered_map<std::string, types::raptorIdx>& stopsToIdx) {
if (stops.empty())
{
std::map<types::raptorInt, types::raptorInt> validateStopsAndGetIndices(const std::map<std::string, types::raptorInt>& stops, const std::unordered_map<std::string, types::raptorIdx>& stopsToIdx)
{
if (stops.empty()) {
throw std::invalid_argument("At least one stop ID must be provided.");
}

std::map<types::raptorInt, types::raptorInt> validStopIds;
for (const auto& [stopId, time] : stops)
{
for (const auto& [stopId, time] : stops) {
if (auto it = stopsToIdx.find(stopId);
it != stopsToIdx.end())
{
it != stopsToIdx.end()) {
getConsoleLogger(LoggerName::RAPTOR)->info(std::to_string(it->second));
getConsoleLogger(LoggerName::RAPTOR)->info(std::to_string(time));
validStopIds[it->second] = time;
}
else
{
else {
getConsoleLogger(LoggerName::RAPTOR)->error(std::format("Stop ID {} not found in lookup, removing from query.", stopId));
}
}

if (validStopIds.empty())
{
if (validStopIds.empty()) {
throw std::invalid_argument("No valid stops provided.");
}

Expand All @@ -99,11 +91,14 @@ namespace raptor {
}

RaptorRouter::RaptorRouter(RaptorData raptorData)
: raptorData(std::move(raptorData)) {}
: raptorData(std::move(raptorData))
{
}

std::vector<std::unique_ptr<Connection>> RaptorRouter::routeEarliestArrival(const std::map<std::string, types::raptorInt>& departureStops,
const std::map<std::string, types::raptorInt>& arrivalStops,
const config::QueryConfig& config) const {
const config::QueryConfig& config) const
{
validation::checkNonNullOrEmptyStops(departureStops, "Departure");
validation::checkNonNullOrEmptyStops(arrivalStops, "Arrival");

Expand All @@ -120,10 +115,26 @@ namespace raptor {
auto validatedSourceStops = validation::validateStopsAndGetIndices(departureStops, raptorData.getLookup().stops);
auto validatedTargetStops = validation::validateStopsAndGetIndices(arrivalStops, raptorData.getLookup().stops);

// not all compilers support std::ranges::to =(
#ifdef _MSC_VER
const auto sourceStopIndices = validatedSourceStops | std::views::keys | std::ranges::to<std::vector<types::raptorIdx>>();
const auto targetStopIndices = validatedTargetStops | std::views::keys | std::ranges::to<std::vector<types::raptorIdx>>();
const auto sourceTimes = validatedSourceStops | std::views::values | std::ranges::to<std::vector<types::raptorInt>>();
const auto walkingDurationsToTarget = validatedTargetStops | std::views::values | std::ranges::to<std::vector<types::raptorInt>>();
#else
std::vector<types::raptorIdx> sourceStopIndices;
std::ranges::transform(validatedSourceStops, std::back_inserter(sourceStopIndices), [](const auto& pair) { return pair.first; });

std::vector<types::raptorIdx> targetStopIndices;
std::ranges::transform(validatedTargetStops, std::back_inserter(targetStopIndices), [](const auto& pair) { return pair.first; });

std::vector<types::raptorInt> sourceTimes;
std::ranges::transform(validatedSourceStops, std::back_inserter(sourceTimes), [](const auto& pair) { return pair.second; });

std::vector<types::raptorInt> walkingDurationsToTarget;
std::ranges::transform(validatedTargetStops, std::back_inserter(walkingDurationsToTarget), [](const auto& pair) { return pair.second; });
#endif


const auto queryParams = QueryParams{
.raptorData = raptorData,
Expand All @@ -142,20 +153,24 @@ namespace raptor {
return connection.reconstructParetoOptimalSolutions(bestLabelsPerRound, validatedTargetStops, referenceDate);
}

std::vector<std::shared_ptr<Connection>> RaptorRouter::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 {
std::vector<std::shared_ptr<Connection>> RaptorRouter::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
{
throw std::runtime_error("Not implemented");
}

std::map<std::string, std::shared_ptr<Connection>> RaptorRouter::routeIsolines(const std::map<std::string, std::chrono::system_clock::time_point>& sourceStops, const config::QueryConfig& config) const {
std::map<std::string, std::shared_ptr<Connection>> RaptorRouter::routeIsolines(const std::map<std::string, std::chrono::system_clock::time_point>& sourceStops, const config::QueryConfig& config) const
{
throw std::runtime_error("Not implemented");
}

const RaptorData& RaptorRouter::getRaptorData() const {
const RaptorData& RaptorRouter::getRaptorData() const
{
return raptorData;
}


std::vector<std::shared_ptr<Connection>> RaptorRouter::getConnections(const std::map<std::string, types::raptorIdx>& sourceStops, const std::map<std::string, types::raptorIdx>& targetStops, const config::QueryConfig& config) const {
std::vector<std::shared_ptr<Connection>> RaptorRouter::getConnections(const std::map<std::string, types::raptorIdx>& sourceStops, const std::map<std::string, types::raptorIdx>& targetStops, const config::QueryConfig& config) const
{
validation::validateSourceStopTimes(sourceStops);

// Mocked implementation for processing
Expand Down
Loading

0 comments on commit aecd5dd

Please sign in to comment.