From 70286de77fe6d3d1e76a769073281c2568b64908 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 08:33:17 +0100 Subject: [PATCH 01/13] =?UTF-8?q?check=20all=20file=C2=B4s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cpp-linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index 2f0e6d914..e2f615055 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -64,6 +64,7 @@ jobs: tidy-checks: "" version: ${{ env.clang-version }} ignore: "build | test/example-networks | test/example-networks-gen-po | gurobi*" + files-changed-only: false thread-comments: true step-summary: true database: "build" From fa6d899de31cdc98cd32e5a0812a2e403c3b959f Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 08:39:28 +0100 Subject: [PATCH 02/13] try higher ctest parallel level --- .github/workflows/cpp-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cpp-ci.yml b/.github/workflows/cpp-ci.yml index 152249e68..5a6b1f7a5 100644 --- a/.github/workflows/cpp-ci.yml +++ b/.github/workflows/cpp-ci.yml @@ -18,7 +18,7 @@ defaults: env: CMAKE_BUILD_PARALLEL_LEVEL: 3 - CTEST_PARALLEL_LEVEL: 1 + CTEST_PARALLEL_LEVEL: 4 jobs: read-parameters: From fc720602aa210c7b145ce29f01acb9dec731aeca Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 10:31:21 +0100 Subject: [PATCH 03/13] hopefully fix most of the linter warnings --- include/Definitions.hpp | 1 + include/MultiArray.hpp | 1 + include/VSSModel.hpp | 1 + include/datastructure/GeneralTimetable.hpp | 1 + include/datastructure/RailwayNetwork.hpp | 3 +- include/datastructure/Route.hpp | 1 + include/datastructure/Station.hpp | 1 + include/datastructure/Timetable.hpp | 1 + include/datastructure/Train.hpp | 1 + ...GeneralPerformanceOptimizationInstance.hpp | 1 + .../GeneralProblemInstance.hpp | 1 + .../VSSGenerationTimetable.hpp | 1 + include/solver/GeneralSolver.hpp | 1 + include/solver/mip-based/GeneralMIPSolver.hpp | 1 + .../mip-based/VSSGenTimetableSolver.hpp | 1 + src/datastructure/RailwayNetwork.cpp | 66 ++++++++++--------- src/datastructure/Route.cpp | 9 ++- src/datastructure/Station.cpp | 6 +- src/datastructure/Timetable.cpp | 4 +- src/datastructure/Train.cpp | 3 +- ...GeneralPerformanceOptimizationInstance.cpp | 7 +- .../SolVSSGenerationTimetable.cpp | 35 ++++++---- .../VSSGenerationTimetable.cpp | 3 + .../mip-based/GenPOMovingBlockMIPSolver.cpp | 37 ++++++----- .../GenPOMovingBlockMIPSolver_Lazy.cpp | 28 ++++---- ...ovingBlockMIPSolver_SolutionExtraction.cpp | 12 +++- ...TimetableSolver_MovingBlockInformation.cpp | 21 ++++-- .../VSSGenTimetableSolver_fixedRoutes.cpp | 9 ++- .../VSSGenTimetableSolver_freeRoutes.cpp | 17 ++--- .../VSSGenTimetableSolver_general.cpp | 12 +++- .../VSSGenTimetableSolver_helper.cpp | 33 +++++++--- 31 files changed, 209 insertions(+), 110 deletions(-) diff --git a/include/Definitions.hpp b/include/Definitions.hpp index 93f7f68d3..174df1745 100644 --- a/include/Definitions.hpp +++ b/include/Definitions.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include diff --git a/include/MultiArray.hpp b/include/MultiArray.hpp index 7e165a964..60e611d2a 100644 --- a/include/MultiArray.hpp +++ b/include/MultiArray.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include diff --git a/include/VSSModel.hpp b/include/VSSModel.hpp index 6015ec556..ce109f667 100644 --- a/include/VSSModel.hpp +++ b/include/VSSModel.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/include/datastructure/GeneralTimetable.hpp b/include/datastructure/GeneralTimetable.hpp index 2213dc8de..1600cb3bc 100644 --- a/include/datastructure/GeneralTimetable.hpp +++ b/include/datastructure/GeneralTimetable.hpp @@ -7,6 +7,7 @@ #include "nlohmann/json.hpp" #include +#include #include #include #include diff --git a/include/datastructure/RailwayNetwork.hpp b/include/datastructure/RailwayNetwork.hpp index 14f79c23b..0178aacdc 100644 --- a/include/datastructure/RailwayNetwork.hpp +++ b/include/datastructure/RailwayNetwork.hpp @@ -5,6 +5,7 @@ #include "VSSModel.hpp" #include +#include #include #include #include @@ -284,7 +285,7 @@ class Network { } [[nodiscard]] std::vector - vertices_used_by_edges(const std::vector& edges) const; + vertices_used_by_edges(const std::vector& edges_tmp) const; [[nodiscard]] std::vector> all_paths_of_length_starting_in_vertex( diff --git a/include/datastructure/Route.hpp b/include/datastructure/Route.hpp index 97af38599..48c0f9950 100644 --- a/include/datastructure/Route.hpp +++ b/include/datastructure/Route.hpp @@ -2,6 +2,7 @@ #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Train.hpp" +#include #include #include #include diff --git a/include/datastructure/Station.hpp b/include/datastructure/Station.hpp index 313f84515..d57b95780 100644 --- a/include/datastructure/Station.hpp +++ b/include/datastructure/Station.hpp @@ -2,6 +2,7 @@ #include "CustomExceptions.hpp" #include "datastructure/RailwayNetwork.hpp" +#include #include #include #include diff --git a/include/datastructure/Timetable.hpp b/include/datastructure/Timetable.hpp index b8ba2839a..9c6e2ed41 100644 --- a/include/datastructure/Timetable.hpp +++ b/include/datastructure/Timetable.hpp @@ -2,6 +2,7 @@ #include "datastructure/GeneralTimetable.hpp" #include "datastructure/RailwayNetwork.hpp" +#include #include #include #include diff --git a/include/datastructure/Train.hpp b/include/datastructure/Train.hpp index d1182e900..9107ffda8 100644 --- a/include/datastructure/Train.hpp +++ b/include/datastructure/Train.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include diff --git a/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp b/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp index a1e3bf5ed..dd6fab81c 100644 --- a/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp +++ b/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp @@ -10,6 +10,7 @@ #include "nlohmann/json.hpp" #include +#include #include #include #include diff --git a/include/probleminstances/GeneralProblemInstance.hpp b/include/probleminstances/GeneralProblemInstance.hpp index c81ba971a..ce9b903e1 100644 --- a/include/probleminstances/GeneralProblemInstance.hpp +++ b/include/probleminstances/GeneralProblemInstance.hpp @@ -7,6 +7,7 @@ #include "nlohmann/json.hpp" #include +#include #include #include #include diff --git a/include/probleminstances/VSSGenerationTimetable.hpp b/include/probleminstances/VSSGenerationTimetable.hpp index 1b37c6385..5bb24af29 100644 --- a/include/probleminstances/VSSGenerationTimetable.hpp +++ b/include/probleminstances/VSSGenerationTimetable.hpp @@ -6,6 +6,7 @@ #include "datastructure/Route.hpp" #include "datastructure/Timetable.hpp" +#include #include #include diff --git a/include/solver/GeneralSolver.hpp b/include/solver/GeneralSolver.hpp index 9128ccd42..e1d7d2dcc 100644 --- a/include/solver/GeneralSolver.hpp +++ b/include/solver/GeneralSolver.hpp @@ -3,6 +3,7 @@ #include "probleminstances/GeneralProblemInstance.hpp" #include +#include #include #include #include diff --git a/include/solver/mip-based/GeneralMIPSolver.hpp b/include/solver/mip-based/GeneralMIPSolver.hpp index 66d3a7809..b82400391 100644 --- a/include/solver/mip-based/GeneralMIPSolver.hpp +++ b/include/solver/mip-based/GeneralMIPSolver.hpp @@ -4,6 +4,7 @@ #include "gurobi_c++.h" #include "solver/GeneralSolver.hpp" +#include #include #include #include diff --git a/include/solver/mip-based/VSSGenTimetableSolver.hpp b/include/solver/mip-based/VSSGenTimetableSolver.hpp index 68b057869..691fba5ca 100644 --- a/include/solver/mip-based/VSSGenTimetableSolver.hpp +++ b/include/solver/mip-based/VSSGenTimetableSolver.hpp @@ -7,6 +7,7 @@ #include "probleminstances/VSSGenerationTimetable.hpp" #include "unordered_map" +#include #include #include #include diff --git a/src/datastructure/RailwayNetwork.cpp b/src/datastructure/RailwayNetwork.cpp index 9c347962c..82238b31c 100644 --- a/src/datastructure/RailwayNetwork.cpp +++ b/src/datastructure/RailwayNetwork.cpp @@ -3,19 +3,27 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "MultiArray.hpp" +#include "VSSModel.hpp" #include "nlohmann/json.hpp" #include +#include +#include +#include #include #include #include +#include #include #include #include +#include #include #include #include +#include #include +#include #include using json = nlohmann::json; @@ -640,10 +648,10 @@ void cda_rail::Network::export_graphml(const std::filesystem::path& p) const { std::ofstream file(p / "tracks.graphml"); // Write the header. - file << "" << std::endl; + file << "" << '\n'; file << R"()" - << std::endl; + << '\n'; // Write the key relations std::string const breakable = "d0"; @@ -654,60 +662,56 @@ void cda_rail::Network::export_graphml(const std::filesystem::path& p) const { std::string const type = "d5"; std::string const headway = "d6"; file << ")" - << std::endl; + << R"(" for="edge" attr.name="breakable" attr.type="boolean"/>)" << '\n'; file << ")" - << std::endl; + << R"(" for="edge" attr.name="length" attr.type="double"/>)" << '\n'; file << ")" - << std::endl; + << R"(" for="edge" attr.name="max_speed" attr.type="double"/>)" << '\n'; file << ")" - << std::endl; + << '\n'; file << ")" - << std::endl; + << '\n'; file << ")" << std::endl; + << R"(" for="vertex" attr.name="type" attr.type="long"/>)" << '\n'; file << ")" - << std::endl; + << R"(" for="vertex" attr.name="headway" attr.type="double"/>)" << '\n'; // Write the graph header - file << "" << std::endl; + file << "" << '\n'; // Write the vertices for (const auto& vertex : vertices) { - file << "" << std::endl; + file << "" << '\n'; file << "" << static_cast(vertex.type) - << "" << std::endl; + << "" << '\n'; file << "" << vertex.headway << "" - << std::endl; - file << "" << std::endl; + << '\n'; + file << "" << '\n'; } // Write the edges for (const auto& edge : edges) { file << "" << std::endl; + << vertices[edge.target].name << "\">" << '\n'; file << "" << std::boolalpha - << edge.breakable << "" << std::endl; + << edge.breakable << "" << '\n'; file << "" << edge.length << "" - << std::endl; + << '\n'; file << "" << edge.max_speed << "" - << std::endl; + << '\n'; file << "" << edge.min_block_length - << "" << std::endl; + << "" << '\n'; file << "" - << edge.min_stop_block_length << "" << std::endl; - file << "" << std::endl; + << edge.min_stop_block_length << "" << '\n'; + file << "" << '\n'; } // Write the footer - file << "" << std::endl; - file << "" << std::endl; + file << "" << '\n'; + file << "" << '\n'; // Close the file. file.close(); @@ -735,7 +739,7 @@ void cda_rail::Network::export_successors_cpp( } std::ofstream file(p / "successors_cpp.json"); - file << j << std::endl; + file << j << '\n'; } void cda_rail::Network::export_successors_python( @@ -762,7 +766,7 @@ void cda_rail::Network::export_successors_python( << vertices[edge.target].name << "'): "; write_successor_set_to_file(file, i); } - file << "}" << std::endl; + file << "}" << '\n'; } void cda_rail::Network::write_successor_set_to_file(std::ofstream& file, @@ -1799,9 +1803,9 @@ std::vector> cda_rail::Network::all_routes_of_given_length( } std::vector cda_rail::Network::vertices_used_by_edges( - const std::vector& edges) const { + const std::vector& edges_tmp) const { std::unordered_set used_vertices; - for (const auto& edge : edges) { + for (const auto& edge : edges_tmp) { used_vertices.insert(get_edge(edge).source); used_vertices.insert(get_edge(edge).target); } diff --git a/src/datastructure/Route.cpp b/src/datastructure/Route.cpp index 969a4891d..134b2a336 100644 --- a/src/datastructure/Route.cpp +++ b/src/datastructure/Route.cpp @@ -3,9 +3,16 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "datastructure/RailwayNetwork.hpp" +#include "datastructure/Train.hpp" #include "nlohmann/json.hpp" +#include +#include +#include +#include #include +#include +#include using json = nlohmann::json; @@ -395,7 +402,7 @@ void cda_rail::RouteMap::export_routes(const std::filesystem::path& p, } std::ofstream file(p / "routes.json"); - file << j << std::endl; + file << j << '\n'; } void cda_rail::RouteMap::push_back_edge(const std::string& train_name, diff --git a/src/datastructure/Station.cpp b/src/datastructure/Station.cpp index 370b17c7f..9abe3cbf3 100644 --- a/src/datastructure/Station.cpp +++ b/src/datastructure/Station.cpp @@ -5,10 +5,14 @@ #include "datastructure/RailwayNetwork.hpp" #include "nlohmann/json.hpp" +#include +#include #include #include #include #include +#include +#include using json = nlohmann::json; @@ -90,7 +94,7 @@ void cda_rail::StationList::export_stations(const std::filesystem::path& p, } std::ofstream file(p / "stations.json"); - file << j << std::endl; + file << j << '\n'; } std::vector cda_rail::StationList::get_station_names() const { diff --git a/src/datastructure/Timetable.cpp b/src/datastructure/Timetable.cpp index 2ca82a27c..6312e5cf2 100644 --- a/src/datastructure/Timetable.cpp +++ b/src/datastructure/Timetable.cpp @@ -6,9 +6,11 @@ #include "nlohmann/json.hpp" #include +#include #include #include #include +#include using json = nlohmann::json; @@ -40,7 +42,7 @@ cda_rail::Timetable::time_index_interval(size_t train_index, int dt, const auto t_0_index = t_0 / dt; const auto t_n_index = - (t_n % dt == 0 ? t_n / dt - 1 : t_n / dt) + (tn_inclusive ? 1 : 0); + (t_n % dt == 0 ? (t_n / dt) - 1 : t_n / dt) + (tn_inclusive ? 1 : 0); return {static_cast(t_0_index), static_cast(t_n_index)}; } diff --git a/src/datastructure/Train.cpp b/src/datastructure/Train.cpp index cbc1f7e7f..72fd6d07a 100644 --- a/src/datastructure/Train.cpp +++ b/src/datastructure/Train.cpp @@ -4,6 +4,7 @@ #include "Definitions.hpp" #include "nlohmann/json.hpp" +#include #include #include #include @@ -95,7 +96,7 @@ void cda_rail::TrainList::export_trains(const std::filesystem::path& p) const { } std::ofstream file(p / "trains.json"); - file << j << std::endl; + file << j << '\n'; } cda_rail::TrainList::TrainList(const std::filesystem::path& p) { diff --git a/src/probleminstances/GeneralPerformanceOptimizationInstance.cpp b/src/probleminstances/GeneralPerformanceOptimizationInstance.cpp index e95129128..9b53d29ac 100644 --- a/src/probleminstances/GeneralPerformanceOptimizationInstance.cpp +++ b/src/probleminstances/GeneralPerformanceOptimizationInstance.cpp @@ -4,6 +4,9 @@ #include "EOMHelper.hpp" #include "probleminstances/VSSGenerationTimetable.hpp" +#include +#include + void cda_rail::instances::GeneralPerformanceOptimizationInstance:: discretize_stops() { /** @@ -48,9 +51,7 @@ double cda_rail::instances::GeneralPerformanceOptimizationInstance:: const auto exit_edge = this->const_n().in_edges(exit_node).at(0); v_max = this->const_n().get_edge(exit_edge).max_speed; } - if (v_max > tr_object.max_speed) { - v_max = tr_object.max_speed; - } + v_max = std::min(v_max, tr_object.max_speed); return cda_rail::min_travel_time(v, timetable.get_v_n(), v_max, tr_object.acceleration, tr_object.deceleration, tr_object.length); diff --git a/src/probleminstances/SolVSSGenerationTimetable.cpp b/src/probleminstances/SolVSSGenerationTimetable.cpp index 2d7fc4401..961b0c5c5 100644 --- a/src/probleminstances/SolVSSGenerationTimetable.cpp +++ b/src/probleminstances/SolVSSGenerationTimetable.cpp @@ -1,13 +1,24 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" +#include "VSSModel.hpp" +#include "gurobi_c++.h" +#include "gurobi_c.h" #include "nlohmann/json.hpp" +#include "plog/Severity.h" +#include "probleminstances/GeneralProblemInstance.hpp" #include "probleminstances/VSSGenerationTimetable.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include +#include +#include #include +#include #include +#include #include +#include #include using json = nlohmann::json; @@ -53,8 +64,8 @@ cda_rail::instances::SolVSSGenerationTimetable::get_train_pos(size_t train_id, if (approx_equal(x_2 - x_1, 0.5 * dt * (v_1 + v_2))) { const auto a = (v_2 - v_1) / dt; - const auto tau = time - static_cast(t0 + t_1) * dt; - return x_1 + v_1 * tau + 0.5 * a * tau * tau; + const auto tau = time - (static_cast(t0 + t_1) * dt); + return x_1 + (v_1 * tau) + (0.5 * a * tau * tau); } throw exceptions::ConsistencyException( @@ -90,8 +101,8 @@ double cda_rail::instances::SolVSSGenerationTimetable::get_train_speed( if (approx_equal(x_2 - x_1, 0.5 * dt * (v_1 + v_2))) { const auto a = (v_2 - v_1) / dt; - const auto tau = time - static_cast(t0 + t_1) * dt; - return v_1 + a * tau; + const auto tau = time - (static_cast(t0 + t_1) * dt); + return v_1 + (a * tau); } throw exceptions::ConsistencyException( @@ -248,7 +259,7 @@ bool cda_rail::instances::SolVSSGenerationTimetable::check_consistency() const { } for (size_t tr_id = 0; tr_id < train_speed.size(); ++tr_id) { const auto& train = instance.get_train_list().get_train(tr_id); - for (double v : train_speed.at(tr_id)) { + for (const double v : train_speed.at(tr_id)) { if (v + EPS < 0 || v > train.max_speed + EPS) { return false; } @@ -304,7 +315,7 @@ void cda_rail::instances::SolVSSGenerationTimetable::export_solution( data["mip_obj"] = mip_obj; data["postprocessed"] = postprocessed; std::ofstream data_file(p / "solution" / "data.json"); - data_file << data << std::endl; + data_file << data << '\n'; data_file.close(); json vss_pos_json; @@ -317,7 +328,7 @@ void cda_rail::instances::SolVSSGenerationTimetable::export_solution( } std::ofstream vss_pos_file(p / "solution" / "vss_pos.json"); - vss_pos_file << vss_pos_json << std::endl; + vss_pos_file << vss_pos_json << '\n'; vss_pos_file.close(); json train_pos_json; @@ -337,11 +348,11 @@ void cda_rail::instances::SolVSSGenerationTimetable::export_solution( } std::ofstream train_pos_file(p / "solution" / "train_pos.json"); - train_pos_file << train_pos_json << std::endl; + train_pos_file << train_pos_json << '\n'; train_pos_file.close(); std::ofstream train_speed_file(p / "solution" / "train_speed.json"); - train_speed_file << train_speed_json << std::endl; + train_speed_file << train_speed_json << '\n'; train_speed_file.close(); } @@ -698,9 +709,7 @@ cda_rail::solver::mip_based::VSSGenTimetableSolver::extract_solution( const double e_pos = sol_obj.get_instance() .route_edge_pos(train.name, e_index) .first; - if (lda_val + e_pos < train_pos) { - train_pos = lda_val + e_pos; - } + train_pos = std::min(lda_val + e_pos, train_pos); } } } @@ -712,7 +721,7 @@ cda_rail::solver::mip_based::VSSGenTimetableSolver::extract_solution( } auto t_final = train_interval[tr].second + 1; - double train_pos_final = -1; + double train_pos_final = NAN; if (fix_routes) { train_pos_final = round_to(vars.at("mu").at(tr, t_final - 1).get(GRB_DoubleAttr_X), diff --git a/src/probleminstances/VSSGenerationTimetable.cpp b/src/probleminstances/VSSGenerationTimetable.cpp index 300be1079..36b109fdd 100644 --- a/src/probleminstances/VSSGenerationTimetable.cpp +++ b/src/probleminstances/VSSGenerationTimetable.cpp @@ -2,9 +2,12 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" +#include "VSSModel.hpp" #include "datastructure/RailwayNetwork.hpp" +#include #include +#include void cda_rail::instances::VSSGenerationTimetable::discretize( const vss::SeparationFunction& sep_func) { diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp index 405314815..2f7671d85 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp @@ -1,21 +1,33 @@ #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" +#include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" +#include "plog/Log.h" +#include "plog/Logger.h" +#include "plog/Severity.h" +#include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "solver/mip-based/GeneralMIPSolver.hpp" #include +#include +#include #include +#include +#include #include #include #include +#include +#include #include #include #include -// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation) +// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) cda_rail::instances::SolGeneralPerformanceOptimizationInstance< cda_rail::instances::GeneralPerformanceOptimizationInstance> @@ -79,8 +91,9 @@ cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::solve( for (size_t i = 0; i < num_vars; i++) { auto col_v = model->getCol(vars_tmp[i]); for (size_t j = 0; j < col_v.size(); j++) { - if (std::abs(col_v.getCoeff(j)) < integer_tol && col_v.getCoeff(j) != 0) { - auto c = col_v.getConstr(j); + if (std::abs(col_v.getCoeff(static_cast(j))) < integer_tol && + col_v.getCoeff(static_cast(j)) != 0) { + auto c = col_v.getConstr(static_cast(j)); model->chgCoeff(c, vars_tmp[i], 0); num_fixed++; } @@ -96,7 +109,7 @@ cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::solve( model_created - start) .count(); - auto time_left = time_limit - create_time / 1000; + auto time_left = time_limit - (create_time / 1000); if (time_left < 0 && time_limit > 0) { time_left = 1; } @@ -489,9 +502,7 @@ void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver:: double speed = 0; while (speed < max_vertex_speed) { speed += model_detail.max_velocity_delta; - if (speed > max_vertex_speed) { - speed = max_vertex_speed; - } + speed = std::min(speed, max_vertex_speed); v_velocity_extensions.emplace_back(speed); } tr_velocity_extensions.emplace_back(v_velocity_extensions); @@ -537,7 +548,7 @@ void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver:: // Buffer, because due to numerics some values might be slightly too // big. const auto sqrt_tmp = std::max( - std::sqrt(speed * speed + 2 * tr_speed_change * min_n_length) - + std::sqrt((speed * speed) + (2 * tr_speed_change * min_n_length)) - V_MIN, speed + V_MIN); speed = std::min({speed + model_detail.max_velocity_delta, sqrt_tmp, @@ -2108,12 +2119,8 @@ std::tuple cda_rail::solver::mip_based:: hw_tmp = t_bound; } - if (hw_tmp > hw_max) { - hw_max = hw_tmp; - } - if (hw_tmp_ttd > hw_max_ttd) { - hw_max_ttd = hw_tmp_ttd; - } + hw_max = std::max(hw_tmp, hw_max); + hw_max_ttd = std::max(hw_tmp_ttd, hw_max_ttd); headway_tr_on_e += vars["y"](tr, e, v_source_index, v_target_index) * hw_tmp; @@ -2143,4 +2150,4 @@ void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::cleanup() { relevant_reverse_edges.clear(); } -// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation) +// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp index 737a4699a..8259d2965 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp @@ -3,6 +3,8 @@ #include "EOMHelper.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" +#include "plog/Log.h" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" #include "solver/mip-based/GeneralMIPSolver.hpp" @@ -470,8 +472,10 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: const auto intersecting_ttd = cda_rail::Network::get_intersecting_ttd(p, solver->ttd_sections); for (const auto& [ttd_index, e_index] : intersecting_ttd) { - const auto& p_tmp = - std::vector(p.begin(), p.begin() + e_index); + const auto& p_tmp = std::vector( + p.begin(), + p.begin() + + static_cast::difference_type>(e_index)); const auto p_tmp_len = std::accumulate( p_tmp.begin(), p_tmp.end(), 0.0, [this](double sum, const auto& edge_index) { @@ -542,23 +546,23 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: // this TTD section const auto& rel_tr_order_ttd = train_orders_on_ttd.at(ttd_index); std::unordered_set other_trains_ttd; - const auto tr_index = + const auto tr_index_tmp = std::find(rel_tr_order_ttd.begin(), rel_tr_order_ttd.end(), tr) - rel_tr_order_ttd.begin(); assert(tr_index != rel_tr_order_ttd.end() - rel_tr_order_ttd.begin()); for (size_t tr_other_idx = 0; tr_other_idx < rel_tr_order_ttd.size(); tr_other_idx++) { - if (tr_other_idx == tr_index) { + if (tr_other_idx == tr_index_tmp) { continue; } if (solver->solver_strategy.lazy_train_selection_strategy == LazyTrainSelectionStrategy::OnlyAdjacent && std::abs(static_cast(tr_other_idx) - - static_cast(tr_index)) > 1) { + static_cast(tr_index_tmp)) > 1) { continue; } if (!solver->solver_strategy.include_reverse_headways && - tr_other_idx > tr_index) { + tr_other_idx > tr_index_tmp) { // In this case tr_other follows tr, which is irrelevant for tr ma continue; } @@ -666,8 +670,8 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::vector>>>& train_orders_on_edges) { // Check for violated vertex headways - bool violated_constraint_found = false; - bool only_one_constraint = + bool violated_constraint_found = false; + const bool only_one_constraint = solver->solver_strategy.lazy_constraint_selection_strategy == LazyConstraintSelectionStrategy::OnlyFirstFound; @@ -856,8 +860,8 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::vector>>>& train_orders_on_edges) { // Prevent trains from front crashing into each other - bool violated_constraint_found = false; - bool only_one_constraint = + bool violated_constraint_found = false; + const bool only_one_constraint = solver->solver_strategy.lazy_constraint_selection_strategy == LazyConstraintSelectionStrategy::OnlyFirstFound; @@ -966,8 +970,8 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::vector>>>& train_orders_on_edges, const std::vector>& train_orders_on_ttd) { - bool violated_constraint_found = false; - bool only_one_constraint = + bool violated_constraint_found = false; + const bool only_one_constraint = solver->solver_strategy.lazy_constraint_selection_strategy == LazyConstraintSelectionStrategy::OnlyFirstFound; diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp index 6276905b9..1210fa825 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp @@ -1,16 +1,24 @@ +#include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" +#include "plog/Log.h" +#include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" #include "solver/mip-based/GeneralMIPSolver.hpp" +#include +#include +#include #include +#include #include #include #include -// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation) +// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::extract_solution( cda_rail::instances::SolGeneralPerformanceOptimizationInstance< @@ -159,4 +167,4 @@ double cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::extract_speed( std::to_string(vertex_id)); } -// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation) +// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp b/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp index 03a869e7d..ae0de6d1e 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp @@ -1,10 +1,14 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "MultiArray.hpp" +#include "VSSModel.hpp" #include "gurobi_c++.h" +#include "probleminstances/VSSGenerationTimetable.hpp" +#include "solver/mip-based/GeneralMIPSolver.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" #include +#include #include #include #include @@ -17,7 +21,7 @@ #include #include -// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) // NOLINTBEGIN(performance-inefficient-string-concatenation) @@ -119,11 +123,12 @@ void cda_rail::solver::mip_based:: t_steps < train_interval[tr].second; ++t_steps) { const auto t = t_steps * dt; const auto approx_info = - moving_block_solution.get_approximate_train_pos_and_vel(tr_name, t); + moving_block_solution.get_approximate_train_pos_and_vel( + tr_name, static_cast(t)); if (approx_info.has_value()) { const auto& [pos_approx, vel_approx] = approx_info.value(); if (std::abs(vel_approx) < GRB_EPS && - instance.is_forced_to_stop(tr_name, t)) { + instance.is_forced_to_stop(tr_name, static_cast(t))) { // Train is stopping model->addConstr( vars["lda"](tr, t_steps) >= pos_approx - tr_len - STOP_TOLERANCE, @@ -164,7 +169,8 @@ void cda_rail::solver::mip_based:: t_steps <= train_interval[tr].second; t_steps++) { const auto t = t_steps * dt; const auto [pos_lb, pos_ub, vel_lb, vel_ub] = - moving_block_solution.get_exact_pos_and_vel_bounds(tr_name, t); + moving_block_solution.get_exact_pos_and_vel_bounds( + tr_name, static_cast(t)); if (fix_exact_positions) { model->addConstr( @@ -222,7 +228,8 @@ void cda_rail::solver::mip_based:: t_steps <= train_interval[tr].second + 1; ++t_steps) { const auto t = t_steps * dt; const auto approx_info = - moving_block_solution.get_approximate_train_pos_and_vel(tr_name, t); + moving_block_solution.get_approximate_train_pos_and_vel( + tr_name, static_cast(t)); if (approx_info.has_value()) { const auto& [pos_approx, vel_approx] = approx_info.value(); const double bl = include_braking_curves ? vel_approx * vel_approx / @@ -327,7 +334,7 @@ void cda_rail::solver::mip_based:: t_idx <= std::max(tr_prev_interval.second, tr_following_interval.second); ++t_idx) { - const int t = t_idx * dt; + const int t = static_cast(t_idx) * dt; if (t_idx >= tr_prev_interval.first && t_idx <= tr_prev_interval.second) { prev_x_expr += vars["x"](tr_prev, t_idx, prev_e); @@ -373,4 +380,4 @@ void cda_rail::solver::mip_based:: // NOLINTEND(performance-inefficient-string-concatenation) -// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp b/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp index b07257341..c61db2e3d 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp @@ -1,11 +1,16 @@ #include "CustomExceptions.hpp" +#include "Definitions.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" #include +#include +#include +#include -// NOLINTBEGIN(performance-inefficient-string-concatenation) +// NOLINTBEGIN(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) void cda_rail::solver::mip_based::VSSGenTimetableSolver:: create_fixed_routes_variables() { @@ -484,4 +489,4 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: } } -// NOLINTEND(performance-inefficient-string-concatenation) +// NOLINTEND(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp b/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp index 33f2f857f..d5d6d129f 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp @@ -1,11 +1,16 @@ #include "CustomExceptions.hpp" +#include "Definitions.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include +#include +#include -// NOLINTBEGIN(performance-inefficient-string-concatenation) +// NOLINTBEGIN(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) void cda_rail::solver::mip_based::VSSGenTimetableSolver:: create_free_routes_variables() { @@ -504,9 +509,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: dist_before = INF; for (const auto& e_tmp : before_after_struct.edges_before) { const auto tmp_val = apsp[e_tmp][e] - e_len; - if (tmp_val < dist_before) { - dist_before = tmp_val; - } + dist_before = std::min(tmp_val, dist_before); } } @@ -537,9 +540,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: for (const auto& e_tmp : before_after_struct.edges_after) { const auto tmp_val = apsp[e][e_tmp] - instance.n().get_edge(e_tmp).length; - if (tmp_val < dist_after) { - dist_after = tmp_val; - } + dist_after = std::min(tmp_val, dist_after); } } @@ -745,4 +746,4 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: } } -// NOLINTEND(performance-inefficient-string-concatenation) +// NOLINTEND(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_general.cpp b/src/solver/mip-based/VSSGenTimetableSolver_general.cpp index 8445cf689..5f7f4faae 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_general.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_general.cpp @@ -1,19 +1,27 @@ #include "CustomExceptions.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" +#include "probleminstances/VSSGenerationTimetable.hpp" +#include "solver/mip-based/GeneralMIPSolver.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" #include #include +#include +#include #include #include #include #include #include #include +#include #include -// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) // NOLINTBEGIN(performance-inefficient-string-concatenation) @@ -1720,4 +1728,4 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver::create_constraints() { // NOLINTEND(performance-inefficient-string-concatenation) -// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp b/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp index 51aeaefba..d21be39cd 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp @@ -1,11 +1,28 @@ #include "CustomExceptions.hpp" +#include "Definitions.hpp" +#include "VSSModel.hpp" +#include "gurobi_c++.h" +#include "gurobi_c.h" +#include "plog/Logger.h" +#include "plog/Severity.h" +#include "probleminstances/VSSGenerationTimetable.hpp" +#include "solver/mip-based/GeneralMIPSolver.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include +#include #include +#include +#include +#include +#include #include +#include #include +#include +#include -// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) std::vector cda_rail::solver::mip_based::VSSGenTimetableSolver::unbreakable_section_indices( @@ -221,9 +238,7 @@ bool cda_rail::solver::mip_based::VSSGenTimetableSolver::update_vss( ? static_cast(std::round(obj_ub - 1)) : current_vss_number_e + increase_val; - if (target_vss_number_e >= vss_number_e) { - target_vss_number_e = vss_number_e; - } + target_vss_number_e = std::min(target_vss_number_e, vss_number_e); if (target_vss_number_e <= current_vss_number_e) { return false; } @@ -457,7 +472,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver::set_timeout( model_created - start) .count(); - auto time_left = time_limit - create_time / 1000; + auto time_left = time_limit - (create_time / 1000); if (time_left < 0 && time_limit > 0) { time_left = 1; } @@ -554,9 +569,7 @@ cda_rail::solver::mip_based::VSSGenTimetableSolver::optimize( static_cast(max_vss_per_edge_in_iteration.at(i)) + 1; } } - if (obj_lb_tmp > obj_lb) { - obj_lb = obj_lb_tmp; - } + obj_lb = std::max(obj_lb_tmp, obj_lb); if (obj_lb + GRB_EPS >= obj_ub && (sol_object->has_solution())) { PLOGD << "Break because obj_lb (" << obj_lb << ") >= obj_ub (" << obj_ub @@ -614,7 +627,7 @@ cda_rail::solver::mip_based::VSSGenTimetableSolver::optimize( start) .count(); - auto time_left = time_limit - current_time_span / 1000; + auto time_left = time_limit - (current_time_span / 1000); if (time_left < 0) { PLOGD << "Break because of timeout"; @@ -692,4 +705,4 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: } } -// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +// NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) From 1c99d8d9ec45b38bacf53bea481b407b5bc3d4f6 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 11:02:03 +0100 Subject: [PATCH 04/13] bugfix in renaming --- src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp index 8259d2965..af2e6beb1 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp @@ -549,7 +549,8 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: const auto tr_index_tmp = std::find(rel_tr_order_ttd.begin(), rel_tr_order_ttd.end(), tr) - rel_tr_order_ttd.begin(); - assert(tr_index != rel_tr_order_ttd.end() - rel_tr_order_ttd.begin()); + assert(tr_index_tmp != + rel_tr_order_ttd.end() - rel_tr_order_ttd.begin()); for (size_t tr_other_idx = 0; tr_other_idx < rel_tr_order_ttd.size(); tr_other_idx++) { if (tr_other_idx == tr_index_tmp) { From 5473e1f109210b94f3d4344d7df12d0d06d0f399 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 12:12:33 +0100 Subject: [PATCH 05/13] fix some linter warnings --- include/CustomExceptions.hpp | 1 + include/Definitions.hpp | 27 +++++++++++++++---- include/EOMHelper.hpp | 3 ++- include/MultiArray.hpp | 1 - include/VSSModel.hpp | 19 ++++++------- include/solver/GeneralSolver.hpp | 8 +++--- .../mip-based/GenPOMovingBlockMIPSolver.hpp | 5 +++- include/solver/mip-based/GeneralMIPSolver.hpp | 6 ++++- .../mip-based/VSSGenTimetableSolver.hpp | 6 ++++- .../VSSGenTimetableSolver_fixedRoutes.cpp | 1 - 10 files changed, 54 insertions(+), 23 deletions(-) diff --git a/include/CustomExceptions.hpp b/include/CustomExceptions.hpp index 15c6dc53e..f8c46b4a5 100644 --- a/include/CustomExceptions.hpp +++ b/include/CustomExceptions.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include diff --git a/include/Definitions.hpp b/include/Definitions.hpp index 174df1745..0bfb3f6d3 100644 --- a/include/Definitions.hpp +++ b/include/Definitions.hpp @@ -1,8 +1,13 @@ #pragma once #include #include +#include #include #include +#include +#include +#include +#include #include namespace cda_rail { @@ -17,15 +22,20 @@ constexpr double ABS_PWL_ERROR = 10; constexpr double LINE_SPEED_ACCURACY = 0.1; constexpr double LINE_SPEED_TIME_ACCURACY = 0.1; -enum class VertexType { NoBorder = 0, VSS = 1, TTD = 2, NoBorderVSS = 3 }; -enum class SolutionStatus { +enum class VertexType : std::uint8_t { + NoBorder = 0, + VSS = 1, + TTD = 2, + NoBorderVSS = 3 +}; +enum class SolutionStatus : std::uint8_t { Optimal = 0, Feasible = 1, Infeasible = 2, Timeout = 3, Unknown = 4 }; -enum class ExportOption { +enum class ExportOption : std::uint8_t { NoExport = 0, ExportSolution = 1, ExportSolutionWithInstance = 2, @@ -33,8 +43,15 @@ enum class ExportOption { ExportSolutionAndLP = 4, ExportSolutionWithInstanceAndLP = 5 }; -enum class OptimalityStrategy { Optimal = 0, TradeOff = 1, Feasible = 2 }; -enum class VelocityRefinementStrategy { None = 0, MinOneStep = 1 }; +enum class OptimalityStrategy : std::uint8_t { + Optimal = 0, + TradeOff = 1, + Feasible = 2 +}; +enum class VelocityRefinementStrategy : std::uint8_t { + None = 0, + MinOneStep = 1 +}; // Helper functions diff --git a/include/EOMHelper.hpp b/include/EOMHelper.hpp index 7fea6dd1f..d6ae3702e 100644 --- a/include/EOMHelper.hpp +++ b/include/EOMHelper.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include // EOM = Equations of Motion @@ -74,7 +75,7 @@ double max_time_profile_from_rear_to_ma_point(double v_1, double v_2, double v_m, double a, double d, double s, double obd); -enum class MATimingStrategy { ExtremeProfiles = 0 }; +enum class MATimingStrategy : std::uint8_t { ExtremeProfiles = 0 }; double min_time_from_rear_to_ma_point( double v_1, double v_2, double v_min, double v_max, double a, double d, diff --git a/include/MultiArray.hpp b/include/MultiArray.hpp index 60e611d2a..36b9af980 100644 --- a/include/MultiArray.hpp +++ b/include/MultiArray.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include diff --git a/include/VSSModel.hpp b/include/VSSModel.hpp index ce109f667..a242d9c76 100644 --- a/include/VSSModel.hpp +++ b/include/VSSModel.hpp @@ -1,16 +1,19 @@ #pragma once +#include #include #include +#include #include #include #include +#include #include namespace cda_rail::vss { using SeparationFunction = std::function; -enum class ModelType { +enum class ModelType : std::uint8_t { Discrete = 0, Continuous = 1, Inferred = 2, @@ -20,9 +23,7 @@ enum class ModelType { namespace functions { [[nodiscard]] static double uniform(size_t i, size_t n) { double ret_val = (static_cast(i) + 1) / static_cast(n); - if (ret_val > 1) { - ret_val = 1; - } + ret_val = std::min(ret_val, 1); return ret_val; } @@ -34,7 +35,7 @@ namespace functions { const auto n_points = static_cast(n) - 1; const auto k = n_points - static_cast(i); constexpr double pi = 3.14159265358979323846; - return 0.5 + 0.5 * std::cos((2 * k - 1) * pi / (2 * n_points)); + return 0.5 + (0.5 * std::cos((2 * k - 1) * pi / (2 * n_points))); } [[nodiscard]] static size_t max_n_blocks(const SeparationFunction& sep_func, @@ -57,15 +58,15 @@ namespace functions { } } - return static_cast(std::floor(1 / min_frac + eps)); + return static_cast(std::floor((1 / min_frac) + eps)); } } // namespace functions class Model { private: - ModelType model_type = ModelType::Continuous; - bool only_stop_at_vss = false; - std::vector separation_functions = {}; + ModelType model_type = ModelType::Continuous; + bool only_stop_at_vss = false; + std::vector separation_functions; public: // Constructors diff --git a/include/solver/GeneralSolver.hpp b/include/solver/GeneralSolver.hpp index e1d7d2dcc..df151f7c2 100644 --- a/include/solver/GeneralSolver.hpp +++ b/include/solver/GeneralSolver.hpp @@ -3,11 +3,13 @@ #include "probleminstances/GeneralProblemInstance.hpp" #include -#include +#include +#include #include #include -#include -#include +#include +#include +#include #include namespace cda_rail::solver { diff --git a/include/solver/mip-based/GenPOMovingBlockMIPSolver.hpp b/include/solver/mip-based/GenPOMovingBlockMIPSolver.hpp index ef73a5d8c..dd35046ae 100644 --- a/include/solver/mip-based/GenPOMovingBlockMIPSolver.hpp +++ b/include/solver/mip-based/GenPOMovingBlockMIPSolver.hpp @@ -1,11 +1,14 @@ #pragma once #include "Definitions.hpp" -#include "datastructure/GeneralTimetable.hpp" +#include "datastructure/RailwayNetwork.hpp" +#include "datastructure/Train.hpp" +#include "gurobi_c++.h" #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "solver/GeneralSolver.hpp" #include "solver/mip-based/GeneralMIPSolver.hpp" +// NOLINTNEXTLINE(misc-include-cleaner) #include "gtest/gtest_prod.h" #include #include diff --git a/include/solver/mip-based/GeneralMIPSolver.hpp b/include/solver/mip-based/GeneralMIPSolver.hpp index b82400391..25a5bacde 100644 --- a/include/solver/mip-based/GeneralMIPSolver.hpp +++ b/include/solver/mip-based/GeneralMIPSolver.hpp @@ -1,15 +1,19 @@ #pragma once +#include "Definitions.hpp" #include "MultiArray.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" +#include "probleminstances/GeneralProblemInstance.hpp" #include "solver/GeneralSolver.hpp" -#include +#include #include #include #include #include #include +#include namespace cda_rail::solver::mip_based { diff --git a/include/solver/mip-based/VSSGenTimetableSolver.hpp b/include/solver/mip-based/VSSGenTimetableSolver.hpp index 691fba5ca..efd422cd5 100644 --- a/include/solver/mip-based/VSSGenTimetableSolver.hpp +++ b/include/solver/mip-based/VSSGenTimetableSolver.hpp @@ -5,17 +5,20 @@ #include "gurobi_c++.h" #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "probleminstances/VSSGenerationTimetable.hpp" +#include "solver/GeneralSolver.hpp" #include "unordered_map" #include +#include #include #include #include #include +#include namespace cda_rail::solver::mip_based { -enum class UpdateStrategy { Fixed = 0, Relative = 1 }; +enum class UpdateStrategy : std::uint8_t { Fixed = 0, Relative = 1 }; struct SolverStrategy { bool iterative_approach = false; @@ -46,6 +49,7 @@ struct ModelDetailMBInformation { }; struct ModelSettings { + // NOLINTNEXTLINE(readability-redundant-member-init) vss::Model model_type = vss::Model(); bool use_pwl = false; bool use_schedule_cuts = true; diff --git a/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp b/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp index c61db2e3d..062fceb06 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_fixedRoutes.cpp @@ -7,7 +7,6 @@ #include #include -#include #include // NOLINTBEGIN(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) From 90e5c902dec0ba3e14bb2c308a59339fc25ea332 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 14:06:13 +0100 Subject: [PATCH 06/13] fix linter warnings for source files --- src/datastructure/RailwayNetwork.cpp | 9 ++++-- src/datastructure/Route.cpp | 3 ++ src/datastructure/Station.cpp | 1 + src/datastructure/Timetable.cpp | 8 +----- src/datastructure/Train.cpp | 1 + .../SolVSSGenerationTimetable.cpp | 1 + .../VSSGenerationTimetable.cpp | 3 +- .../mip-based/GenPOMovingBlockMIPSolver.cpp | 3 +- .../GenPOMovingBlockMIPSolver_Lazy.cpp | 28 ++++++++++++++++++- ...ovingBlockMIPSolver_SolutionExtraction.cpp | 4 +-- ...TimetableSolver_MovingBlockInformation.cpp | 8 ++---- .../VSSGenTimetableSolver_freeRoutes.cpp | 6 ++-- .../VSSGenTimetableSolver_general.cpp | 26 ++++++++++------- .../VSSGenTimetableSolver_helper.cpp | 4 ++- 14 files changed, 72 insertions(+), 33 deletions(-) diff --git a/src/datastructure/RailwayNetwork.cpp b/src/datastructure/RailwayNetwork.cpp index 82238b31c..3c5b3f2ca 100644 --- a/src/datastructure/RailwayNetwork.cpp +++ b/src/datastructure/RailwayNetwork.cpp @@ -2,9 +2,9 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" -#include "MultiArray.hpp" #include "VSSModel.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include @@ -1530,7 +1530,8 @@ cda_rail::Network::sort_edge_pairs( std::unordered_map> vertex_neighbors; for (size_t i = 0; i < edge_pairs.size(); ++i) { const auto& edge_pair = edge_pairs[i]; - const auto& edge = get_edge(edge_pair.first.value()); + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) + const auto& edge = get_edge(edge_pair.first.value()); vertex_neighbors[edge.source].emplace(i); vertex_neighbors[edge.target].emplace(i); } @@ -1555,6 +1556,7 @@ cda_rail::Network::sort_edge_pairs( const auto edge_pair_index = *vertex_neighbors[j].begin(); const auto& edge_pair = edge_pairs[edge_pair_index]; + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) const auto& edge = get_edge(edge_pair.first.value()); vertex_neighbors[edge.source].erase(edge_pair_index); vertex_neighbors[edge.target].erase(edge_pair_index); @@ -1738,10 +1740,12 @@ std::vector> cda_rail::Network::all_routes_of_given_length( "Desired length is not strictly positive"); } + // NOLINTBEGIN(readability-avoid-nested-conditional-operator) const std::vector edges_to_consider_tmp = v_0.has_value() ? (reverse_direction ? in_edges(v_0.value()) : out_edges(v_0.value())) : std::vector{e_0.value()}; + // NOLINTEND(readability-avoid-nested-conditional-operator) auto edges_to_consider = edges_used_by_train.empty() ? edges_to_consider_tmp : std::vector(); @@ -1843,6 +1847,7 @@ double cda_rail::Network::maximal_vertex_speed( max_speed_neighboring_vertex = other_vertex(e, v); } else if (edge.max_speed > second_max_speed && max_speed_neighboring_vertex.has_value() && + // NOLINTNEXTLINE(bugprone-unchecked-optional-access) other_vertex(e, v) != max_speed_neighboring_vertex.value()) { second_max_speed = edge.max_speed; } diff --git a/src/datastructure/Route.cpp b/src/datastructure/Route.cpp index 134b2a336..842936431 100644 --- a/src/datastructure/Route.cpp +++ b/src/datastructure/Route.cpp @@ -5,6 +5,7 @@ #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Train.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include @@ -12,9 +13,11 @@ #include #include #include +#include #include using json = nlohmann::json; +using std::size_t; void cda_rail::Route::push_back_edge(size_t edge_index, const Network& network) { diff --git a/src/datastructure/Station.cpp b/src/datastructure/Station.cpp index 9abe3cbf3..47a4cde86 100644 --- a/src/datastructure/Station.cpp +++ b/src/datastructure/Station.cpp @@ -4,6 +4,7 @@ #include "Definitions.hpp" #include "datastructure/RailwayNetwork.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include diff --git a/src/datastructure/Timetable.cpp b/src/datastructure/Timetable.cpp index 6312e5cf2..9b0ae66c4 100644 --- a/src/datastructure/Timetable.cpp +++ b/src/datastructure/Timetable.cpp @@ -1,18 +1,12 @@ #include "datastructure/Timetable.hpp" #include "CustomExceptions.hpp" -#include "Definitions.hpp" -#include "datastructure/Station.hpp" -#include "nlohmann/json.hpp" -#include #include -#include -#include #include #include -using json = nlohmann::json; +using std::size_t; std::pair cda_rail::Timetable::time_index_interval(size_t train_index, int dt, diff --git a/src/datastructure/Train.cpp b/src/datastructure/Train.cpp index 72fd6d07a..8edca7d25 100644 --- a/src/datastructure/Train.cpp +++ b/src/datastructure/Train.cpp @@ -3,6 +3,7 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include diff --git a/src/probleminstances/SolVSSGenerationTimetable.cpp b/src/probleminstances/SolVSSGenerationTimetable.cpp index 961b0c5c5..e9e516c07 100644 --- a/src/probleminstances/SolVSSGenerationTimetable.cpp +++ b/src/probleminstances/SolVSSGenerationTimetable.cpp @@ -4,6 +4,7 @@ #include "gurobi_c++.h" #include "gurobi_c.h" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include "plog/Severity.h" #include "probleminstances/GeneralProblemInstance.hpp" #include "probleminstances/VSSGenerationTimetable.hpp" diff --git a/src/probleminstances/VSSGenerationTimetable.cpp b/src/probleminstances/VSSGenerationTimetable.cpp index 36b109fdd..4747d4b12 100644 --- a/src/probleminstances/VSSGenerationTimetable.cpp +++ b/src/probleminstances/VSSGenerationTimetable.cpp @@ -1,7 +1,6 @@ #include "probleminstances/VSSGenerationTimetable.hpp" #include "CustomExceptions.hpp" -#include "Definitions.hpp" #include "VSSModel.hpp" #include "datastructure/RailwayNetwork.hpp" @@ -9,6 +8,8 @@ #include #include +using std::size_t; + void cda_rail::instances::VSSGenerationTimetable::discretize( const vss::SeparationFunction& sep_func) { /** diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp index 2f7671d85..72e0c30e9 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver.cpp @@ -156,7 +156,7 @@ cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::solve( solution_settings.export_option == ExportOption::ExportSolutionWithInstanceAndLP) { PLOGI << "Saving model and solution"; - std::filesystem::path path = solution_settings.path; + const std::filesystem::path path = solution_settings.path; if (!is_directory_and_create(path)) { PLOGE << "Could not create directory " << path.string(); @@ -1638,6 +1638,7 @@ void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver:: // departure because ma might move forward, otherwise arrival and // departure are equal due to non-zero velocity + // NOLINTNEXTLINE(misc-const-correctness) GRBVar tr_t_var = vars["t_front_departure"](tr, v_source); const auto tr_on_e = instance.trains_on_edge_mixed_routing( diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp index af2e6beb1..95e2359bb 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver_Lazy.cpp @@ -1,7 +1,6 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" -#include "MultiArray.hpp" #include "gurobi_c++.h" #include "gurobi_c.h" #include "plog/Log.h" @@ -22,6 +21,8 @@ #include #include +using std::size_t; + // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation) void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: @@ -112,7 +113,9 @@ std::vector> cda_rail::solver::mip_based:: assert(train_orders_on_ttd.size() == ttd + 1); std::unordered_map train_ttd_times; for (size_t tr = 0; tr < solver->num_tr; tr++) { + // NOLINTNEXTLINE(misc-const-correctness) GRBVar x_ttd = solver->vars["x_ttd"](tr, ttd); + // NOLINTNEXTLINE(misc-const-correctness) GRBVar t_ttd = solver->vars["t_ttd_departure"](tr, ttd); if (!x_ttd.sameAs(GRBVar()) && getSolution(x_ttd) > 0.5) { train_ttd_times[tr] = getSolution(t_ttd); @@ -153,8 +156,10 @@ cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: routes[tr][i + 1].first == edge_object.target) || (routes[tr][i].first == edge_object.target && routes[tr][i + 1].first == edge_object.source)) { + // NOLINTNEXTLINE(misc-const-correctness) GRBVar t_source = solver->vars["t_front_departure"](tr, edge_object.source); + // NOLINTNEXTLINE(misc-const-correctness) GRBVar t_target = solver->vars["t_rear_departure"](tr, edge_object.target); // Assume they exist by choice of routes @@ -591,6 +596,7 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: if (add_constr) { const auto t_bound_tmp = std::max(t_bound, solver->ub_timing_variable(other_tr)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs = other_tr_t_variable + t_bound_tmp * @@ -789,25 +795,31 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::max(tr_t_bound, solver->ub_timing_variable(other_tr)); // Introduce basic constraints on order + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr order_expr = solver->vars["order"](tr, other_tr, edge_index) + solver->vars["order"](other_tr, tr, edge_index); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr edge_expr = solver->vars["x"](tr, edge_index) + solver->vars["x"](other_tr, edge_index); addLazy(order_expr <= 0.5 * edge_expr); addLazy(order_expr >= edge_expr - 1); // Add headway constraints + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs_source = tr_t_var_source_front + (t_bound_tmp + hw_s1_max) * (1 - solver->vars["order"](tr, other_tr, edge_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs_source = other_tr_t_var_source_rear + hw_s1; + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs_target = tr_t_var_target_front + (t_bound_tmp + hw_t1_max) * (1 - solver->vars["order"](tr, other_tr, edge_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs_target = other_tr_t_var_target_rear + hw_t1; // Reverse constraints are needed. Otherwise, the solver can @@ -816,16 +828,20 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: auto [hw_s2_max, hw_s2, hw_t2_max, hw_t2] = solver->get_vertex_headway_expressions(other_tr, edge_index); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs_source_2 = other_tr_t_var_source_front + (t_bound_tmp + hw_s2_max) * (1 - solver->vars["order"](other_tr, tr, edge_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs_source_2 = tr_t_var_source_rear + hw_s2; + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs_target_2 = other_tr_t_var_target_front + (t_bound_tmp + hw_t2_max) * (1 - solver->vars["order"](other_tr, tr, edge_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs_target_2 = tr_t_var_target_rear + hw_t2; addLazy(lhs_source >= rhs_source); @@ -923,18 +939,24 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: const auto& tr1_edge = tr1_direction ? e1 : e2; const auto& tr2_edge = tr2_direction ? e1 : e2; + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs1 = solver->vars["reverse_order"](tr1, tr2, idx) + solver->vars["reverse_order"](tr2, tr1, idx); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs1 = solver->vars["x"](tr1, tr1_edge) + solver->vars["x"](tr2, tr2_edge) - 1; + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs2 = tr1_t_var_front + t_bound * (1 - solver->vars["reverse_order"](tr1, tr2, idx)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs2 = tr2_t_var_rear; + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs3 = tr2_t_var_front + t_bound * (1 - solver->vars["reverse_order"](tr2, tr1, idx)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs3 = tr1_t_var_rear; addLazy(lhs1 >= rhs1); @@ -1051,10 +1073,12 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::max(tr_t_bound, solver->ub_timing_variable(tr_other_idx)); if (add_constr) { + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs = tr_t_var - tr_other_t_var + (t_bound_tmp + hw_max) * (1 - solver->vars["order"](tr, tr_other_idx, edge_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs = headway_tr_on_e; addLazy(lhs >= rhs); if (solver->solution_settings.export_option == @@ -1136,10 +1160,12 @@ bool cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::LazyCallback:: std::max(tr_t_bound, solver->ub_timing_variable(tr_other_ttd)); if (add_constr) { + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr lhs = tr_t_var - tr_other_t_var_ttd + (t_bound_tmp + hw_max_ttd) * (1 - solver->vars["order_ttd"]( tr, tr_other_ttd, ttd_index)); + // NOLINTNEXTLINE(misc-const-correctness) GRBLinExpr rhs = headway_tr_on_ttd; addLazy(lhs >= rhs); if (solver->solution_settings.export_option == diff --git a/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp b/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp index 1210fa825..106f47d26 100644 --- a/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp +++ b/src/solver/mip-based/GenPOMovingBlockMIPSolver_SolutionExtraction.cpp @@ -1,13 +1,11 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" -#include "MultiArray.hpp" #include "gurobi_c++.h" #include "gurobi_c.h" #include "plog/Log.h" #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" -#include "solver/mip-based/GeneralMIPSolver.hpp" #include #include @@ -18,6 +16,8 @@ #include #include +using std::size_t; + // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) void cda_rail::solver::mip_based::GenPOMovingBlockMIPSolver::extract_solution( diff --git a/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp b/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp index ae0de6d1e..bc5f347e2 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_MovingBlockInformation.cpp @@ -1,6 +1,5 @@ #include "CustomExceptions.hpp" #include "Definitions.hpp" -#include "MultiArray.hpp" #include "VSSModel.hpp" #include "gurobi_c++.h" #include "probleminstances/VSSGenerationTimetable.hpp" @@ -9,18 +8,15 @@ #include #include -#include #include #include -#include #include -#include -#include -#include #include #include #include +using std::size_t; + // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) // NOLINTBEGIN(performance-inefficient-string-concatenation) diff --git a/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp b/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp index d5d6d129f..2bbf7237b 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_freeRoutes.cpp @@ -10,6 +10,8 @@ #include #include +using std::size_t; + // NOLINTBEGIN(performance-inefficient-string-concatenation,bugprone-unchecked-optional-access) void cda_rail::solver::mip_based::VSSGenTimetableSolver:: @@ -686,7 +688,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: "]"; const auto& e_len = edge.length; for (size_t vss = 0; vss < vss_number_e; ++vss) { - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -714,7 +716,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: "," + instance.n().get_vertex(edge.target).name + "]"; const auto& e_len = edge.length; - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { diff --git a/src/solver/mip-based/VSSGenTimetableSolver_general.cpp b/src/solver/mip-based/VSSGenTimetableSolver_general.cpp index 5f7f4faae..631cfc246 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_general.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_general.cpp @@ -1,6 +1,9 @@ #include "CustomExceptions.hpp" +#include "Definitions.hpp" #include "MultiArray.hpp" +#include "VSSModel.hpp" #include "gurobi_c++.h" +#include "gurobi_c.h" #include "plog/Init.h" #include "plog/Logger.h" #include "plog/Severity.h" @@ -8,7 +11,7 @@ #include "solver/mip-based/GeneralMIPSolver.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" -#include +#include #include #include #include @@ -16,10 +19,13 @@ #include #include #include -#include #include +#include #include #include +#include + +using std::size_t; // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) @@ -278,7 +284,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: vars["b_pos"](i, vss) = model->addVar(lb, ub, 0, GRB_CONTINUOUS, "b_pos_" + edge_name + "_" + std::to_string(vss)); - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { for (size_t t = train_interval[tr].first; t <= train_interval[tr].second; ++t) { vars["b_front"](tr, t, i, vss) = model->addVar( @@ -383,7 +389,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: "," + instance.n().get_vertex(edge.target).name + "]"; for (size_t vss = 0; vss < vss_number_e; ++vss) { - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -401,7 +407,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: const auto& edge_name = "[" + instance.n().get_vertex(edge.source).name + "," + instance.n().get_vertex(edge.target).name + "]"; - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -1532,7 +1538,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: const auto& edge_name = "[" + instance.const_n().get_vertex(edge.source).name + "," + instance.const_n().get_vertex(edge.target).name + "]"; - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -1561,7 +1567,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: vss_e = instance.const_n().max_vss_on_edge(e); } - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -1585,7 +1591,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: const auto& tr_name = instance.get_train_list().get_train(tr).name; const auto& edge_used_tr = instance.edges_used_by_train(tr, this->fix_routes); - for (size_t e : edge_used_tr) { + for (const size_t e : edge_used_tr) { const auto& edge = instance.const_n().get_edge(e); const auto& edge_name = "[" + instance.const_n().get_vertex(edge.source).name + "," + @@ -1626,7 +1632,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: "[" + instance.const_n().get_vertex(edge.source).name + "," + instance.const_n().get_vertex(edge.target).name + "]"; const auto& vss_e = instance.const_n().max_vss_on_edge(e); - for (size_t tr : instance.trains_on_edge(e, this->fix_routes)) { + for (const size_t tr : instance.trains_on_edge(e, this->fix_routes)) { const auto& tr_name = instance.get_train_list().get_train(tr).name; for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { @@ -1654,7 +1660,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: for (size_t t = train_interval[tr].first + 2; t <= train_interval[tr].second; ++t) { GRBLinExpr lhs = 0; - for (size_t e : edge_used_tr) { + for (const size_t e : edge_used_tr) { lhs += vars["e_tight"](tr, t, e); const auto& edge = instance.const_n().get_edge(e); if (!edge.breakable) { diff --git a/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp b/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp index d21be39cd..234e4c42f 100644 --- a/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp +++ b/src/solver/mip-based/VSSGenTimetableSolver_helper.cpp @@ -22,6 +22,8 @@ #include #include +using std::size_t; + // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-unchecked-optional-access) std::vector @@ -671,7 +673,7 @@ void cda_rail::solver::mip_based::VSSGenTimetableSolver:: export_option == ExportOption::ExportSolutionAndLP || export_option == ExportOption::ExportSolutionWithInstanceAndLP) { PLOGI << "Saving model and solution"; - std::filesystem::path path = solution_settings.path; + const std::filesystem::path path = solution_settings.path; if (!is_directory_and_create(path)) { PLOGE << "Could not create directory " << path.string(); From f8cb6d84d06eb2ef45c19cd082d98b57d758b5f2 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 14:21:18 +0100 Subject: [PATCH 07/13] fix some linter warnings in apps --- apps/gen_po_moving_block_lazy_testing.cpp | 6 +++++- apps/gen_po_moving_block_lazy_vss_gen_testing.cpp | 8 +++++++- apps/gen_po_moving_block_simplified_testing.cpp | 6 +++++- apps/gen_po_moving_block_simplified_vss_gen_testing.cpp | 8 +++++++- ...s_generation_timetable_iterative_parameter_testing.cpp | 8 ++++++-- ...vss_generation_timetable_mip_iterative_vss_testing.cpp | 8 ++++++-- apps/vss_generation_timetable_mip_testing.cpp | 8 ++++++-- ..._generation_timetable_using_mb_information_testing.cpp | 5 ++++- 8 files changed, 46 insertions(+), 11 deletions(-) diff --git a/apps/gen_po_moving_block_lazy_testing.cpp b/apps/gen_po_moving_block_lazy_testing.cpp index 1cc4c7ccd..6781fea8e 100644 --- a/apps/gen_po_moving_block_lazy_testing.cpp +++ b/apps/gen_po_moving_block_lazy_testing.cpp @@ -1,11 +1,15 @@ #include "Definitions.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape) diff --git a/apps/gen_po_moving_block_lazy_vss_gen_testing.cpp b/apps/gen_po_moving_block_lazy_vss_gen_testing.cpp index 0ef3a5698..b336e33d8 100644 --- a/apps/gen_po_moving_block_lazy_vss_gen_testing.cpp +++ b/apps/gen_po_moving_block_lazy_vss_gen_testing.cpp @@ -1,11 +1,17 @@ #include "Definitions.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" +#include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" +#include "probleminstances/VSSGenerationTimetable.hpp" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape) diff --git a/apps/gen_po_moving_block_simplified_testing.cpp b/apps/gen_po_moving_block_simplified_testing.cpp index f30e14241..0c57929aa 100644 --- a/apps/gen_po_moving_block_simplified_testing.cpp +++ b/apps/gen_po_moving_block_simplified_testing.cpp @@ -1,11 +1,15 @@ #include "Definitions.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape) diff --git a/apps/gen_po_moving_block_simplified_vss_gen_testing.cpp b/apps/gen_po_moving_block_simplified_vss_gen_testing.cpp index 8067ac8eb..0d74ea387 100644 --- a/apps/gen_po_moving_block_simplified_vss_gen_testing.cpp +++ b/apps/gen_po_moving_block_simplified_vss_gen_testing.cpp @@ -1,11 +1,17 @@ #include "Definitions.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" +#include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" +#include "probleminstances/VSSGenerationTimetable.hpp" #include "solver/mip-based/GenPOMovingBlockMIPSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay,bugprone-exception-escape) diff --git a/apps/vss_generation_timetable_iterative_parameter_testing.cpp b/apps/vss_generation_timetable_iterative_parameter_testing.cpp index 35c0a1337..90d0d932d 100644 --- a/apps/vss_generation_timetable_iterative_parameter_testing.cpp +++ b/apps/vss_generation_timetable_iterative_parameter_testing.cpp @@ -1,12 +1,16 @@ #include "Definitions.hpp" #include "VSSModel.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) @@ -98,7 +102,7 @@ int main(int argc, char** argv) { PLOGI << " output path: " << output_path; PLOGI << " file name: " << file_name; - cda_rail::vss::Model vss_model(cda_rail::vss::ModelType::Continuous); + const cda_rail::vss::Model vss_model(cda_rail::vss::ModelType::Continuous); // NOLINTNEXTLINE(clang-diagnostic-unused-result) solver.solve( diff --git a/apps/vss_generation_timetable_mip_iterative_vss_testing.cpp b/apps/vss_generation_timetable_mip_iterative_vss_testing.cpp index 16cad3c15..775c41872 100644 --- a/apps/vss_generation_timetable_mip_iterative_vss_testing.cpp +++ b/apps/vss_generation_timetable_mip_iterative_vss_testing.cpp @@ -1,12 +1,16 @@ #include "Definitions.hpp" #include "VSSModel.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) @@ -86,7 +90,7 @@ int main(int argc, char** argv) { std::to_string(static_cast(optimality_strategy_int)) + "_" + std::to_string(timeout); - cda_rail::vss::Model vss_model(cda_rail::vss::ModelType::Continuous); + const cda_rail::vss::Model vss_model(cda_rail::vss::ModelType::Continuous); // NOLINTNEXTLINE(clang-diagnostic-unused-result) solver.solve( diff --git a/apps/vss_generation_timetable_mip_testing.cpp b/apps/vss_generation_timetable_mip_testing.cpp index d86ef476d..e11bf2e81 100644 --- a/apps/vss_generation_timetable_mip_testing.cpp +++ b/apps/vss_generation_timetable_mip_testing.cpp @@ -1,12 +1,16 @@ #include "Definitions.hpp" #include "VSSModel.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include #include #include -#include #include +#include // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-array-to-pointer-decay) @@ -74,7 +78,7 @@ int main(int argc, char** argv) { std::to_string(static_cast(use_schedule_cuts)) + "_" + std::to_string(timeout); - cda_rail::vss::Model vss_model = + const cda_rail::vss::Model vss_model = discretize_vss_positions ? cda_rail::vss::Model(cda_rail::vss::ModelType::Discrete, {&cda_rail::vss::functions::uniform}) diff --git a/apps/vss_generation_timetable_using_mb_information_testing.cpp b/apps/vss_generation_timetable_using_mb_information_testing.cpp index 805512175..f24e32c5e 100644 --- a/apps/vss_generation_timetable_using_mb_information_testing.cpp +++ b/apps/vss_generation_timetable_using_mb_information_testing.cpp @@ -1,12 +1,15 @@ #include "Definitions.hpp" #include "VSSModel.hpp" +#include "plog/Init.h" +#include "plog/Logger.h" +#include "plog/Severity.h" #include "solver/mip-based/VSSGenTimetableSolver.hpp" +#include #include #include #include #include -#include #include #include From d07e24716058f0645c23703cf9666dc71e8961b4 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 14:54:29 +0100 Subject: [PATCH 08/13] fix linter warnings in header files --- include/datastructure/GeneralTimetable.hpp | 17 +++++++------- include/datastructure/RailwayNetwork.hpp | 4 +--- include/datastructure/Route.hpp | 1 + include/datastructure/Station.hpp | 4 +++- include/datastructure/Timetable.hpp | 5 +++- ...GeneralPerformanceOptimizationInstance.hpp | 23 +++++++++++++------ .../GeneralProblemInstance.hpp | 14 ++++++++--- .../VSSGenerationTimetable.hpp | 5 +++- include/solver/GeneralSolver.hpp | 1 + 9 files changed, 49 insertions(+), 25 deletions(-) diff --git a/include/datastructure/GeneralTimetable.hpp b/include/datastructure/GeneralTimetable.hpp index 1600cb3bc..cea332344 100644 --- a/include/datastructure/GeneralTimetable.hpp +++ b/include/datastructure/GeneralTimetable.hpp @@ -1,10 +1,12 @@ #pragma once #include "CustomExceptions.hpp" +#include "Definitions.hpp" #include "RailwayNetwork.hpp" #include "Station.hpp" #include "Train.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include @@ -84,12 +86,9 @@ class GeneralScheduledStop { [[nodiscard]] std::pair get_forced_stopping_interval() const { std::pair interval = {begin.second, end.first}; - if (begin.first + min_stopping_time > interval.second) { - interval.second = begin.first + min_stopping_time; - } - if (end.second - min_stopping_time < interval.first) { - interval.first = end.second - min_stopping_time; - } + interval.second = + std::max(begin.first + min_stopping_time, interval.second); + interval.first = std::min(end.second - min_stopping_time, interval.first); return interval; } @@ -103,8 +102,8 @@ class GeneralScheduledStop { // Constructor GeneralScheduledStop(std::pair begin, std::pair end, int min_stopping_time, std::string station) - : begin(std::move(begin)), end(std::move(end)), - min_stopping_time(min_stopping_time), station(std::move(station)) { + : begin(begin), end(end), min_stopping_time(min_stopping_time), + station(std::move(station)) { if (this->begin.second < this->begin.first) { throw exceptions::InvalidInputException( "Interval begin has negative length"); @@ -465,7 +464,7 @@ class GeneralTimetable : BaseTimetable { } std::ofstream file(p / "schedules.json"); - file << j << std::endl; + file << j << '\n'; }; Train& editable_tr(size_t index) { return train_list.editable_tr(index); }; diff --git a/include/datastructure/RailwayNetwork.hpp b/include/datastructure/RailwayNetwork.hpp index 0178aacdc..91550d631 100644 --- a/include/datastructure/RailwayNetwork.hpp +++ b/include/datastructure/RailwayNetwork.hpp @@ -1,15 +1,13 @@ #pragma once #include "CustomExceptions.hpp" #include "Definitions.hpp" -#include "MultiArray.hpp" #include "VSSModel.hpp" -#include #include #include +#include #include #include -#include #include #include #include diff --git a/include/datastructure/Route.hpp b/include/datastructure/Route.hpp index 48c0f9950..fccd51d93 100644 --- a/include/datastructure/Route.hpp +++ b/include/datastructure/Route.hpp @@ -2,6 +2,7 @@ #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Train.hpp" +#include #include #include #include diff --git a/include/datastructure/Station.hpp b/include/datastructure/Station.hpp index d57b95780..ed5e0cf65 100644 --- a/include/datastructure/Station.hpp +++ b/include/datastructure/Station.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace cda_rail { @@ -15,7 +16,8 @@ struct Station { * @param name Name of the station * @param tracks Unordered set of edges that define the station. */ - std::string name; + std::string name; + // NOLINTNEXTLINE(readability-redundant-member-init) std::vector tracks = {}; }; diff --git a/include/datastructure/Timetable.hpp b/include/datastructure/Timetable.hpp index 9c6e2ed41..fe157bff8 100644 --- a/include/datastructure/Timetable.hpp +++ b/include/datastructure/Timetable.hpp @@ -1,11 +1,14 @@ #pragma once #include "datastructure/GeneralTimetable.hpp" #include "datastructure/RailwayNetwork.hpp" +#include "datastructure/Station.hpp" +#include "datastructure/Train.hpp" #include #include +#include #include -#include +#include #include #include diff --git a/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp b/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp index dd6fab81c..e38b25e3f 100644 --- a/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp +++ b/include/probleminstances/GeneralPerformanceOptimizationInstance.hpp @@ -1,5 +1,6 @@ #pragma once +#include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" #include "GeneralProblemInstance.hpp" @@ -8,14 +9,19 @@ #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Route.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" +#include #include #include #include #include +#include #include #include +#include #include +#include #include #include #include @@ -217,7 +223,7 @@ class GeneralPerformanceOptimizationInstance j["lambda"] = lambda; std::ofstream file(path / "problem_data.json"); - file << j << std::endl; + file << j << '\n'; }; [[nodiscard]] bool check_consistency() const override { @@ -264,7 +270,7 @@ template class SolGeneralPerformanceOptimizationInstance : public SolGeneralProblemInstanceWithScheduleAndRoutes { static_assert( - std::is_base_of::value, + std::is_base_of_v, "T must be derived from GeneralPerformanceOptimizationInstance"); std::vector> train_pos; std::vector> train_speed; @@ -701,9 +707,11 @@ class SolGeneralPerformanceOptimizationInstance SolGeneralProblemInstanceWithScheduleAndRoutes< T>::export_general_solution_data_with_routes(p, export_instance, true); + // NOLINTBEGIN(misc-const-correctness) json train_pos_json; json train_speed_json; json train_routed_json; + // NOLINTEND(misc-const-correctness) for (size_t tr_id = 0; tr_id < this->instance.get_train_list().size(); ++tr_id) { const auto& train = this->instance.get_train_list().get_train(tr_id); @@ -713,15 +721,15 @@ class SolGeneralPerformanceOptimizationInstance } std::ofstream train_pos_file(p / "solution" / "train_pos.json"); - train_pos_file << train_pos_json << std::endl; + train_pos_file << train_pos_json << '\n'; train_pos_file.close(); std::ofstream train_speed_file(p / "solution" / "train_speed.json"); - train_speed_file << train_speed_json << std::endl; + train_speed_file << train_speed_json << '\n'; train_speed_file.close(); std::ofstream train_routed_file(p / "solution" / "train_routed.json"); - train_routed_file << train_routed_json << std::endl; + train_routed_file << train_routed_json << '\n'; train_routed_file.close(); }; [[nodiscard]] bool check_consistency() const override { @@ -807,7 +815,7 @@ template class SolVSSGeneralPerformanceOptimizationInstance : public SolGeneralPerformanceOptimizationInstance { static_assert( - std::is_base_of::value, + std::is_base_of_v, "T must be derived from GeneralPerformanceOptimizationInstance"); std::vector> vss_pos; @@ -921,6 +929,7 @@ class SolVSSGeneralPerformanceOptimizationInstance SolGeneralPerformanceOptimizationInstance::export_solution( p, export_instance); + // NOLINTNEXTLINE(misc-const-correctness) json vss_pos_json; for (size_t edge_id = 0; edge_id < this->instance.const_n().number_of_edges(); ++edge_id) { @@ -931,7 +940,7 @@ class SolVSSGeneralPerformanceOptimizationInstance } std::ofstream vss_pos_file(p / "solution" / "vss_pos.json"); - vss_pos_file << vss_pos_json << std::endl; + vss_pos_file << vss_pos_json << '\n'; vss_pos_file.close(); }; [[nodiscard]] bool check_consistency() const override { diff --git a/include/probleminstances/GeneralProblemInstance.hpp b/include/probleminstances/GeneralProblemInstance.hpp index ce9b903e1..e6b438747 100644 --- a/include/probleminstances/GeneralProblemInstance.hpp +++ b/include/probleminstances/GeneralProblemInstance.hpp @@ -1,17 +1,25 @@ #pragma once +#include "CustomExceptions.hpp" #include "Definitions.hpp" #include "datastructure/GeneralTimetable.hpp" #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Route.hpp" +#include "datastructure/Station.hpp" +#include "datastructure/Train.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include #include #include +#include +#include +#include #include #include #include +#include using json = nlohmann::json; @@ -545,7 +553,7 @@ class GeneralProblemInstanceWithScheduleAndRoutes }; template class SolGeneralProblemInstance { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of_v, "T must be a child of GeneralProblemInstance"); protected: @@ -578,7 +586,7 @@ template class SolGeneralProblemInstance { data["obj"] = obj; data["has_solution"] = has_sol; std::ofstream data_file(p / "solution" / "data.json"); - data_file << data << std::endl; + data_file << data << '\n'; data_file.close(); } }; @@ -641,7 +649,7 @@ template class SolGeneralProblemInstance { template class SolGeneralProblemInstanceWithScheduleAndRoutes : public SolGeneralProblemInstance { - static_assert(std::is_base_of::value, + static_assert(std::is_base_of_v, "T must be a child of GeneralProblemInstance"); protected: diff --git a/include/probleminstances/VSSGenerationTimetable.hpp b/include/probleminstances/VSSGenerationTimetable.hpp index 5bb24af29..56d938845 100644 --- a/include/probleminstances/VSSGenerationTimetable.hpp +++ b/include/probleminstances/VSSGenerationTimetable.hpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include namespace cda_rail::instances { class VSSGenerationTimetable @@ -48,7 +51,7 @@ class VSSGenerationTimetable [[nodiscard]] static VSSGenerationTimetable import_instance(const std::filesystem::path& p, bool every_train_must_have_route = true) { - VSSGenerationTimetable return_instance(p); + const VSSGenerationTimetable return_instance(p); if (!return_instance.check_consistency(every_train_must_have_route)) { throw exceptions::ConsistencyException( "Imported instance object is not consistent"); diff --git a/include/solver/GeneralSolver.hpp b/include/solver/GeneralSolver.hpp index df151f7c2..9b4e4ada2 100644 --- a/include/solver/GeneralSolver.hpp +++ b/include/solver/GeneralSolver.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include From 52359120b67f130380016dada7ded64d06558fb1 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 14:57:26 +0100 Subject: [PATCH 09/13] linter warning in apps --- apps/vss_generation_timetable_using_mb_information_testing.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/vss_generation_timetable_using_mb_information_testing.cpp b/apps/vss_generation_timetable_using_mb_information_testing.cpp index f24e32c5e..bf425af27 100644 --- a/apps/vss_generation_timetable_using_mb_information_testing.cpp +++ b/apps/vss_generation_timetable_using_mb_information_testing.cpp @@ -3,6 +3,7 @@ #include "plog/Init.h" #include "plog/Logger.h" #include "plog/Severity.h" +#include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" #include @@ -97,7 +98,7 @@ int main(int argc, char** argv) { } else { const std::filesystem::path vss_instance_path = std::filesystem::path(instance_path) / "instance"; - cda_rail::instances::GeneralPerformanceOptimizationInstance + const cda_rail::instances::GeneralPerformanceOptimizationInstance vss_instance_before_parse(vss_instance_path); const auto vss_instance = vss_instance_before_parse.cast_to_vss_generation(true); From 8c7fe64bc043ae94382b412ecd0e83518183183c Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 15:39:55 +0100 Subject: [PATCH 10/13] linter warnings in google tests --- test/test_abstract_data_structure.cpp | 30 ++++---- ...ral_performance_optimization_instances.cpp | 2 +- test/test_gurobi_vss_gen.cpp | 76 ++++++++++--------- test/test_multiarray.cpp | 7 +- test/test_plog.cpp | 6 +- test/test_probleminstances.cpp | 52 ++++++++----- test/test_railwaynetwork.cpp | 1 + 7 files changed, 99 insertions(+), 75 deletions(-) diff --git a/test/test_abstract_data_structure.cpp b/test/test_abstract_data_structure.cpp index 23b2cf701..9509fbbf8 100644 --- a/test/test_abstract_data_structure.cpp +++ b/test/test_abstract_data_structure.cpp @@ -1,9 +1,11 @@ #include "CustomExceptions.hpp" #include "datastructure/GeneralTimetable.hpp" +#include "datastructure/RailwayNetwork.hpp" #include "datastructure/Route.hpp" #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "gtest/gtest.h" +#include #include using namespace cda_rail; @@ -28,7 +30,7 @@ TEST(GeneralAbstractDataStructure, GeneralScheduledStopExceptions) { } TEST(GeneralAbstractDataStructure, GeneralScheduledStopConstructor) { - cda_rail::GeneralScheduledStop stop({0, 2}, {3, 4}, 2, "Test"); + const cda_rail::GeneralScheduledStop stop({0, 2}, {3, 4}, 2, "Test"); EXPECT_EQ(stop.get_begin_range(), (std::pair(0, 2))); EXPECT_EQ(stop.get_end_range(), (std::pair(3, 4))); EXPECT_EQ(stop.get_min_stopping_time(), 2); @@ -36,17 +38,17 @@ TEST(GeneralAbstractDataStructure, GeneralScheduledStopConstructor) { } TEST(GeneralAbstractDataStructure, GeneralSchedulesStopForcedStoppingInterval) { - cda_rail::GeneralScheduledStop stop1({0, 2}, {3, 4}, 1, "Test"); + const cda_rail::GeneralScheduledStop stop1({0, 2}, {3, 4}, 1, "Test"); EXPECT_EQ(stop1.get_forced_stopping_interval(), (std::pair(2, 3))); EXPECT_FALSE(stop1.is_forced_to_stop(1)); EXPECT_TRUE(stop1.is_forced_to_stop(2)); EXPECT_TRUE(stop1.is_forced_to_stop(3)); EXPECT_FALSE(stop1.is_forced_to_stop(4)); - cda_rail::GeneralScheduledStop stop2({0, 2}, {3, 4}, 2, "Test"); + const cda_rail::GeneralScheduledStop stop2({0, 2}, {3, 4}, 2, "Test"); EXPECT_EQ(stop2.get_forced_stopping_interval(), (std::pair(2, 3))); - cda_rail::GeneralScheduledStop stop3({0, 2}, {3, 4}, 3, "Test"); + const cda_rail::GeneralScheduledStop stop3({0, 2}, {3, 4}, 3, "Test"); EXPECT_EQ(stop3.get_forced_stopping_interval(), (std::pair(1, 3))); EXPECT_FALSE(stop3.is_forced_to_stop(0)); EXPECT_TRUE(stop3.is_forced_to_stop(1)); @@ -54,24 +56,24 @@ TEST(GeneralAbstractDataStructure, GeneralSchedulesStopForcedStoppingInterval) { EXPECT_TRUE(stop3.is_forced_to_stop(3)); EXPECT_FALSE(stop3.is_forced_to_stop(4)); - cda_rail::GeneralScheduledStop stop4({0, 2}, {3, 4}, 4, "Test"); + const cda_rail::GeneralScheduledStop stop4({0, 2}, {3, 4}, 4, "Test"); EXPECT_EQ(stop4.get_forced_stopping_interval(), (std::pair(0, 4))); - cda_rail::GeneralScheduledStop stop5({0, 5}, {0, 5}, 1, "Test"); + const cda_rail::GeneralScheduledStop stop5({0, 5}, {0, 5}, 1, "Test"); EXPECT_EQ(stop5.get_forced_stopping_interval(), (std::pair(4, 1))); } TEST(GeneralAbstractDataStructure, GeneralScheduledStopConflicts) { - cda_rail::GeneralScheduledStop stop1({0, 2}, {3, 4}, 1, "Test"); - cda_rail::GeneralScheduledStop stop2({5, 6}, {7, 8}, 1, "Test"); + const cda_rail::GeneralScheduledStop stop1({0, 2}, {3, 4}, 1, "Test"); + const cda_rail::GeneralScheduledStop stop2({5, 6}, {7, 8}, 1, "Test"); EXPECT_TRUE(stop1.conflicts(stop2)); EXPECT_TRUE(stop2.conflicts(stop1)); - cda_rail::GeneralScheduledStop stop3({4, 5}, {10, 11}, 1, "Test1"); - cda_rail::GeneralScheduledStop stop4({0, 1}, {7, 8}, 1, "Test2"); - cda_rail::GeneralScheduledStop stop5({0, 1}, {2, 3}, 1, "Test3"); - cda_rail::GeneralScheduledStop stop6({0, 5}, {0, 5}, 1, "Test4"); + const cda_rail::GeneralScheduledStop stop3({4, 5}, {10, 11}, 1, "Test1"); + const cda_rail::GeneralScheduledStop stop4({0, 1}, {7, 8}, 1, "Test2"); + const cda_rail::GeneralScheduledStop stop5({0, 1}, {2, 3}, 1, "Test3"); + const cda_rail::GeneralScheduledStop stop6({0, 5}, {0, 5}, 1, "Test4"); EXPECT_TRUE(stop3.conflicts(stop4)); EXPECT_TRUE(stop4.conflicts(stop3)); @@ -93,7 +95,7 @@ TEST(GeneralAbstractDataStructure, GeneralScheduledStopConflicts) { } TEST(GeneralAbstractDataStructure, GeneralTimetable) { - Network network("./example-networks/SimpleStation/network/"); + const Network network("./example-networks/SimpleStation/network/"); GeneralTimetable> timetable; @@ -176,7 +178,7 @@ TEST(GeneralAbstractDataStructure, GeneralTimetable) { } TEST(GeneralAbstractDataStructure, GeneralTimetableExportImport) { - Network network("./example-networks/SimpleStation/network/"); + const Network network("./example-networks/SimpleStation/network/"); GeneralTimetable> timetable; diff --git a/test/test_general_performance_optimization_instances.cpp b/test/test_general_performance_optimization_instances.cpp index 3702a1f07..211e594d7 100644 --- a/test/test_general_performance_optimization_instances.cpp +++ b/test/test_general_performance_optimization_instances.cpp @@ -1,4 +1,3 @@ -#include "CustomExceptions.hpp" #include "Definitions.hpp" #include "EOMHelper.hpp" #include "datastructure/GeneralTimetable.hpp" @@ -6,6 +5,7 @@ #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" #include "gtest/gtest.h" +#include #include #include diff --git a/test/test_gurobi_vss_gen.cpp b/test/test_gurobi_vss_gen.cpp index 721846f68..635bb9fc1 100644 --- a/test/test_gurobi_vss_gen.cpp +++ b/test/test_gurobi_vss_gen.cpp @@ -1,11 +1,16 @@ +#include "Definitions.hpp" #include "VSSModel.hpp" #include "solver/mip-based/VSSGenTimetableSolver.hpp" #include "gtest/gtest.h" +#include +#include #include #include #include +using std::size_t; + TEST(Solver, GurobiVSSDiscretizeInstanceWithoutChange) { cda_rail::solver::mip_based::VSSGenTimetableSolver solver( "./example-networks/SimpleStation/"); @@ -25,19 +30,19 @@ TEST(Solver, GurobiVSSGenDeltaTDefault) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; auto obj_val_6 = solver.solve({6}); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; auto obj_val_15 = solver.solve({15}); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; auto obj_val_11 = solver.solve({11}); std::cout << "--------------------- TEST 4 ---------------------------" - << std::endl; + << '\n'; auto obj_val_18 = solver.solve({18}); std::cout << "--------------------- TEST 5 ---------------------------" - << std::endl; + << '\n'; auto obj_val_30 = solver.solve({30}); EXPECT_EQ(obj_val_6.get_status(), cda_rail::SolutionStatus::Optimal); @@ -64,13 +69,13 @@ TEST(Solver, GurobiVSSGenDeltaT) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_2 = solver.solve({30, false}); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_1 = solver.solve({30, true}); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_3 = solver.solve( {30, true, false, false}, {cda_rail::vss::Model(cda_rail::vss::ModelType::Discrete, @@ -95,7 +100,7 @@ TEST(Solver, GurobiVSSGenDefault) { // Test various options std::cout << "--------------------- DEFAULT ---------------------------" - << std::endl; + << '\n'; const auto obj_val_default = solver.solve(); EXPECT_EQ(obj_val_default.get_status(), cda_rail::SolutionStatus::Optimal); EXPECT_EQ(obj_val_default.get_obj(), 1); @@ -103,13 +108,13 @@ TEST(Solver, GurobiVSSGenDefault) { } TEST(Solver, GurobiVSSGenDefaultInstance) { - cda_rail::instances::VSSGenerationTimetable instance( + const cda_rail::instances::VSSGenerationTimetable instance( "./example-networks/SimpleStation/"); cda_rail::solver::mip_based::VSSGenTimetableSolver solver(instance); // Test various options std::cout << "--------------------- DEFAULT ---------------------------" - << std::endl; + << '\n'; const auto obj_val_default = solver.solve(); EXPECT_EQ(obj_val_default.get_status(), cda_rail::SolutionStatus::Optimal); EXPECT_EQ(obj_val_default.get_obj(), 1); @@ -117,12 +122,13 @@ TEST(Solver, GurobiVSSGenDefaultInstance) { } TEST(Solver, GurobiVSSGenDefaultInstancePath) { - std::filesystem::path instance_path("./example-networks/SimpleStation/"); + const std::filesystem::path instance_path( + "./example-networks/SimpleStation/"); cda_rail::solver::mip_based::VSSGenTimetableSolver solver(instance_path); // Test various options std::cout << "--------------------- DEFAULT ---------------------------" - << std::endl; + << '\n'; const auto obj_val_default = solver.solve(); EXPECT_EQ(obj_val_default.get_status(), cda_rail::SolutionStatus::Optimal); EXPECT_EQ(obj_val_default.get_obj(), 1); @@ -130,12 +136,12 @@ TEST(Solver, GurobiVSSGenDefaultInstancePath) { } TEST(Solver, GurobiVSSGenDefaultInstanceString) { - std::string instance_path("./example-networks/SimpleStation/"); + const std::string instance_path("./example-networks/SimpleStation/"); cda_rail::solver::mip_based::VSSGenTimetableSolver solver(instance_path); // Test various options std::cout << "--------------------- DEFAULT ---------------------------" - << std::endl; + << '\n'; const auto obj_val_default = solver.solve(); EXPECT_EQ(obj_val_default.get_status(), cda_rail::SolutionStatus::Optimal); EXPECT_EQ(obj_val_default.get_obj(), 1); @@ -147,15 +153,15 @@ TEST(Solver, GurobiVSSGenModelDetailFixed) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_1 = solver.solve({}, {}, {}, {}, 60, true); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_2 = solver.solve({}, {}, {}, {}, 60, true); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_3 = solver.solve({15, true, true, false}, {cda_rail::vss::Model(cda_rail::vss::ModelType::Continuous), @@ -163,19 +169,19 @@ TEST(Solver, GurobiVSSGenModelDetailFixed) { {}, {}, 60, true); std::cout << "--------------------- TEST 4 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_4 = solver.solve( {}, {cda_rail::vss::Model(cda_rail::vss::ModelType::Continuous), true, true}, {}, {}, 60, true); std::cout << "--------------------- TEST 5 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_5 = solver.solve({15, true, true, false}, {}, {}, {}, 60, true); std::cout << "--------------------- TEST 6 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_6 = solver.solve({15, true, false, false}, {}, {}, {}, 60, true); @@ -207,7 +213,7 @@ TEST(Solver, GurobiVSSGenModelDetailFree1) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_1 = solver.solve({15, false}, {}, {}, {}, 280, true); EXPECT_EQ(obj_val_1.get_status(), cda_rail::SolutionStatus::Optimal); @@ -220,7 +226,7 @@ TEST(Solver, GurobiVSSGenModelDetailFree2) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_2 = solver.solve({15, false}, {}, {}, {}, 280, true); EXPECT_EQ(obj_val_2.get_status(), cda_rail::SolutionStatus::Optimal); @@ -233,7 +239,7 @@ TEST(Solver, GurobiVSSGenModelDetailFree3) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_3 = solver.solve( {15, false}, {cda_rail::vss::Model(), true, true}, {}, {}, 280, true); @@ -247,7 +253,7 @@ TEST(Solver, GurobiVSSGenModelDetailFree4) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 4 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_4 = solver.solve({15, false, true, false}, {}, {}, {}, 280, true); @@ -261,7 +267,7 @@ TEST(Solver, GurobiVSSGenModelDetailFree5) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 5 ---------------------------" - << std::endl; + << '\n'; const auto obj_val_5 = solver.solve({15, false, false, false}, {}, {}, {}, 280, true); @@ -291,7 +297,7 @@ TEST(Solver, GurobiVSSGenTim) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr1").tim); EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr2").tim); @@ -299,7 +305,7 @@ TEST(Solver, GurobiVSSGenTim) { const auto obj_val_1 = solver.solve({15, false}); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr1").tim = false; @@ -309,7 +315,7 @@ TEST(Solver, GurobiVSSGenTim) { const auto obj_val_2 = solver.solve({15, false}); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr1").tim = true; solver.editable_instance().editable_tr("tr2").tim = false; @@ -336,7 +342,7 @@ TEST(Solver, GurobiVSSGenTimFixed) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr1").tim); EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr2").tim); @@ -344,7 +350,7 @@ TEST(Solver, GurobiVSSGenTimFixed) { const auto obj_val_1 = solver.solve(); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr1").tim = false; @@ -354,7 +360,7 @@ TEST(Solver, GurobiVSSGenTimFixed) { const auto obj_val_2 = solver.solve(); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr1").tim = true; solver.editable_instance().editable_tr("tr2").tim = false; @@ -381,7 +387,7 @@ TEST(Solver, GurobiVSSGenTimDiscrete1) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 1 ---------------------------" - << std::endl; + << '\n'; EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr1").tim); EXPECT_TRUE(solver.get_instance().get_train_list().get_train("tr2").tim); @@ -403,7 +409,7 @@ TEST(Solver, GurobiVSSGenTimDiscrete2) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 2 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr1").tim = false; @@ -427,7 +433,7 @@ TEST(Solver, GurobiVSSGenTimDiscrete3) { "./example-networks/SimpleStation/"); std::cout << "--------------------- TEST 3 ---------------------------" - << std::endl; + << '\n'; solver.editable_instance().editable_tr("tr2").tim = false; diff --git a/test/test_multiarray.cpp b/test/test_multiarray.cpp index dc2cb29aa..a40f48d02 100644 --- a/test/test_multiarray.cpp +++ b/test/test_multiarray.cpp @@ -1,7 +1,12 @@ #include "MultiArray.hpp" #include "gtest/gtest.h" +#include #include +#include +#include + +using std::size_t; TEST(Functionality, MultiArray) { cda_rail::MultiArray a1(1, 2, 3); @@ -19,7 +24,7 @@ TEST(Functionality, MultiArray) { for (size_t i = 0; i < 1; ++i) { for (size_t j = 0; j < 2; ++j) { for (size_t k = 0; k < 3; ++k) { - EXPECT_EQ(a1(i, j, k), 6 * i + 3 * j + k); + EXPECT_EQ(a1(i, j, k), (6 * i) + (3 * j + k)); } } } diff --git a/test/test_plog.cpp b/test/test_plog.cpp index e6674d95d..4f2348baf 100644 --- a/test/test_plog.cpp +++ b/test/test_plog.cpp @@ -3,11 +3,11 @@ #include "gtest/gtest.h" #include #include -#include +#include +#include #include -#include -#include #include +#include #include TEST(Logging, VSSGenDefaultLogging) { diff --git a/test/test_probleminstances.cpp b/test/test_probleminstances.cpp index 3f3b85509..0f9e4412b 100644 --- a/test/test_probleminstances.cpp +++ b/test/test_probleminstances.cpp @@ -1,7 +1,17 @@ +#include "CustomExceptions.hpp" #include "Definitions.hpp" +#include "datastructure/RailwayNetwork.hpp" +#include "datastructure/Timetable.hpp" #include "probleminstances/VSSGenerationTimetable.hpp" #include "gtest/gtest.h" +#include +#include +#include +#include +#include + +using std::size_t; struct EdgeTarget { std::string source; @@ -33,8 +43,8 @@ void check_instance_import( EXPECT_EQ(network.number_of_vertices(), vertex_names.size()); for (size_t i = 0; i < vertex_names.size(); i++) { - std::string v_name = vertex_names[i]; - cda_rail::Vertex v = network.get_vertex(v_name); + const std::string v_name = vertex_names[i]; + const cda_rail::Vertex& v = network.get_vertex(v_name); EXPECT_EQ(v.name, v_name); EXPECT_EQ(v.type, type[i]); } @@ -66,7 +76,7 @@ void check_instance_import( EXPECT_EQ(network.number_of_edges(), edge_targets.size()); for (const auto& edge : edge_targets) { - cda_rail::Edge e = network.get_edge(edge.source, edge.target); + const cda_rail::Edge e = network.get_edge(edge.source, edge.target); EXPECT_EQ(network.get_vertex(e.source).name, edge.source); EXPECT_EQ(network.get_vertex(e.target).name, edge.target); EXPECT_EQ(e.length, edge.length); @@ -385,7 +395,7 @@ TEST(Functionality, VSSGenerationTimetableInstanceImport1) { } TEST(Functionality, VSSGenerationTimetableInstanceImport2) { - std::string p("./example-networks/SimpleStation/"); + const std::string p("./example-networks/SimpleStation/"); auto instance = cda_rail::instances::VSSGenerationTimetable::import_instance(p); @@ -394,7 +404,7 @@ TEST(Functionality, VSSGenerationTimetableInstanceImport2) { } TEST(Functionality, VSSGenerationTimetableInstanceImport3) { - std::filesystem::path p("./example-networks/SimpleStation/"); + const std::filesystem::path p("./example-networks/SimpleStation/"); auto instance = cda_rail::instances::VSSGenerationTimetable::import_instance(p); @@ -485,15 +495,15 @@ TEST(Functionality, VSSGenerationTimetableExport) { const auto& successors_target = network.get_successors(i); std::vector successors_target_transformed; for (auto successor : successors_target) { - const auto& e = network.get_edge(successor); - std::string source = network.get_vertex(e.source).name; - std::string target = network.get_vertex(e.target).name; + const auto& e = network.get_edge(successor); + const std::string source = network.get_vertex(e.source).name; + const std::string target = network.get_vertex(e.target).name; successors_target_transformed.emplace_back( network_read.get_edge_index(source, target)); } - const auto& e = network.get_edge(i); - std::string source = network.get_vertex(e.source).name; - std::string target = network.get_vertex(e.target).name; + const auto& e = network.get_edge(i); + const std::string source = network.get_vertex(e.source).name; + const std::string target = network.get_vertex(e.target).name; auto successors_target_read = network_read.get_successors(source, target); std::sort(successors_target_transformed.begin(), successors_target_transformed.end()); @@ -2168,10 +2178,10 @@ TEST(Example, Stammstrecke) { auto ost3_donnersberger = pairs[e28rl_3][e9rl_a] + instance.n().get_edge(e28rl_3).length; - int full_expected = 11090; - int laim_expected_lr = 7788; - int laim_expected_rl = laim_expected_lr + 210 + 370 + 30; - int donnersberger_expected = 5391; + const int full_expected = 11090; + const int laim_expected_lr = 7788; + const int laim_expected_rl = laim_expected_lr + 210 + 370 + 30; + const int donnersberger_expected = 5391; EXPECT_EQ(pasing_ost4, full_expected); EXPECT_EQ(pasing_ost5, full_expected); @@ -2385,9 +2395,9 @@ TEST(Functionality, SolVSSGenerationTimetable) { EXPECT_EQ(sol1.get_train_speed(tr1, 30), 5); EXPECT_EQ(sol1.get_train_speed(tr2, 258), 7); - std::vector vss_pos = {20, 30, 60}; - std::vector vss_pos_simple = {40}; - std::vector vss_pos_empty = {}; + const std::vector vss_pos = {20, 30, 60}; + const std::vector vss_pos_simple = {40}; + const std::vector vss_pos_empty = {}; sol1.set_vss_pos(v0_v1, vss_pos_simple); EXPECT_EQ(sol1.get_vss_pos(v0_v1), vss_pos_simple); @@ -2573,9 +2583,9 @@ TEST(ProblemInstances, TimetableConsistency) { network2.add_vertex("v1", cda_rail::VertexType::TTD); network2.add_vertex("v2", cda_rail::VertexType::TTD); - int e11 = network1.add_edge("v0", "v1", 100, 10, true, 10); - int e12 = network2.add_edge("v0", "v1", 100, 10, true, 10); - int e22 = network2.add_edge("v1", "v2", 100, 10, true, 10); + const int e11 = network1.add_edge("v0", "v1", 100, 10, true, 10); + const int e12 = network2.add_edge("v0", "v1", 100, 10, true, 10); + const int e22 = network2.add_edge("v1", "v2", 100, 10, true, 10); EXPECT_EQ(e11, e12); diff --git a/test/test_railwaynetwork.cpp b/test/test_railwaynetwork.cpp index a251d0694..b5501bcd2 100644 --- a/test/test_railwaynetwork.cpp +++ b/test/test_railwaynetwork.cpp @@ -5,6 +5,7 @@ #include "datastructure/Route.hpp" #include "datastructure/Timetable.hpp" #include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #include "gtest/gtest.h" #include From 1b4cc9fadc3332d40f7d89d3c8a3e3fc7b9874b8 Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 16:10:36 +0100 Subject: [PATCH 11/13] fix hopefully final linter warnings --- include/datastructure/GeneralTimetable.hpp | 4 ++++ test/test_abstract_data_structure.cpp | 21 ++++++++++++++------- test/test_gurobi_vss_gen.cpp | 1 + test/test_multiarray.cpp | 1 - test/test_railwaynetwork.cpp | 17 +++++++++++++---- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/datastructure/GeneralTimetable.hpp b/include/datastructure/GeneralTimetable.hpp index cea332344..8746d7d03 100644 --- a/include/datastructure/GeneralTimetable.hpp +++ b/include/datastructure/GeneralTimetable.hpp @@ -100,10 +100,14 @@ class GeneralScheduledStop { [[nodiscard]] const std::string& get_station_name() const { return station; } // Constructor + // NOLINTBEGIN(modernize-pass-by-value) + // cpp-linter cycles here because std::move were trivial for std::pair and + // should not be used in that context GeneralScheduledStop(std::pair begin, std::pair end, int min_stopping_time, std::string station) : begin(begin), end(end), min_stopping_time(min_stopping_time), station(std::move(station)) { + // NOLINTEND(modernize-pass-by-value) if (this->begin.second < this->begin.first) { throw exceptions::InvalidInputException( "Interval begin has negative length"); diff --git a/test/test_abstract_data_structure.cpp b/test/test_abstract_data_structure.cpp index 9509fbbf8..2a67090a7 100644 --- a/test/test_abstract_data_structure.cpp +++ b/test/test_abstract_data_structure.cpp @@ -1,14 +1,21 @@ #include "CustomExceptions.hpp" +#include "Definitions.hpp" #include "datastructure/GeneralTimetable.hpp" #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Route.hpp" +#include "datastructure/Timetable.hpp" #include "probleminstances/GeneralPerformanceOptimizationInstance.hpp" +#include "probleminstances/VSSGenerationTimetable.hpp" #include "gtest/gtest.h" +#include +#include #include #include +#include using namespace cda_rail; +using std::size_t; TEST(GeneralAbstractDataStructure, GeneralScheduledStopExceptions) { EXPECT_THROW(cda_rail::GeneralScheduledStop({10, 9}, {12, 15}, 1, "Test1"), @@ -202,7 +209,7 @@ TEST(GeneralAbstractDataStructure, GeneralTimetableExportImport) { // Write timetable to directory timetable.export_timetable("./tmp/test-general-timetable/", network); - GeneralTimetable> timetable_read( + const GeneralTimetable> timetable_read( "./tmp/test-general-timetable/", network); std::filesystem::remove_all("./tmp"); @@ -265,10 +272,10 @@ TEST(GeneralAbstractDataStructure, GeneralTimetableExportImport) { } TEST(GeneralAbstractDataStructure, ParseSchedule) { - cda_rail::ScheduledStop stop1(0, 4, "Test"); - cda_rail::ScheduledStop stop2(6, 8, "Test"); + const cda_rail::ScheduledStop stop1(0, 4, "Test"); + const cda_rail::ScheduledStop stop2(6, 8, "Test"); - cda_rail::Schedule schedule(0, 10, 1, 20, 5, 2, {stop1, stop2}); + const cda_rail::Schedule schedule(0, 10, 1, 20, 5, 2, {stop1, stop2}); const auto general_schedule = schedule.parse_to_general_schedule(); EXPECT_EQ(general_schedule.get_t_0_range(), (std::pair(0, 0))); @@ -555,8 +562,8 @@ void check_instance_import_general_cast( EXPECT_EQ(network.number_of_vertices(), vertex_names.size()); for (size_t i = 0; i < vertex_names.size(); i++) { - std::string v_name = vertex_names[i]; - cda_rail::Vertex v = network.get_vertex(v_name); + const std::string v_name = vertex_names[i]; + const cda_rail::Vertex& v = network.get_vertex(v_name); EXPECT_EQ(v.name, v_name); EXPECT_EQ(v.type, type[i]); } @@ -588,7 +595,7 @@ void check_instance_import_general_cast( EXPECT_EQ(network.number_of_edges(), edge_targets.size()); for (const auto& edge : edge_targets) { - cda_rail::Edge e = network.get_edge(edge.source, edge.target); + const cda_rail::Edge e = network.get_edge(edge.source, edge.target); EXPECT_EQ(network.get_vertex(e.source).name, edge.source); EXPECT_EQ(network.get_vertex(e.target).name, edge.target); EXPECT_EQ(e.length, edge.length); diff --git a/test/test_gurobi_vss_gen.cpp b/test/test_gurobi_vss_gen.cpp index 635bb9fc1..5f72a61c6 100644 --- a/test/test_gurobi_vss_gen.cpp +++ b/test/test_gurobi_vss_gen.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include using std::size_t; diff --git a/test/test_multiarray.cpp b/test/test_multiarray.cpp index a40f48d02..6c7f3c693 100644 --- a/test/test_multiarray.cpp +++ b/test/test_multiarray.cpp @@ -2,7 +2,6 @@ #include "gtest/gtest.h" #include -#include #include #include diff --git a/test/test_railwaynetwork.cpp b/test/test_railwaynetwork.cpp index b5501bcd2..28744e822 100644 --- a/test/test_railwaynetwork.cpp +++ b/test/test_railwaynetwork.cpp @@ -3,15 +3,23 @@ #include "VSSModel.hpp" #include "datastructure/RailwayNetwork.hpp" #include "datastructure/Route.hpp" +#include "datastructure/Station.hpp" #include "datastructure/Timetable.hpp" -#include "nlohmann/json.hpp" +#include "datastructure/Train.hpp" #include "nlohmann/json_fwd.hpp" #include "gtest/gtest.h" #include +#include +#include +#include #include +#include +#include +#include using json = nlohmann::json; +using std::size_t; struct EdgeTarget { std::string source; @@ -23,10 +31,10 @@ struct EdgeTarget { double min_stop_block_length = 100; }; -// NOLINTBEGIN(clang-diagnostic-unused-result,clang-analyzer-deadcode.DeadStores) +// NOLINTBEGIN(clang-diagnostic-unused-result,clang-analyzer-deadcode.DeadStores,bugprone-unchecked-optional-access) TEST(Functionality, NetworkTTDIntersection) { - std::vector> expected({{0, 1}, {2, 4}}); + const std::vector> expected({{0, 1}, {2, 4}}); const auto actual = cda_rail::Network::get_intersecting_ttd( {0, 1, 2, 3, 4}, {{1, 2, 5}, {6, 9, 10}, {11, 4, 10}}); EXPECT_EQ(actual, expected); @@ -3342,6 +3350,7 @@ TEST(Functionality, TimetableConsistency) { auto network2 = cda_rail::Network::import_network( "./example-networks/SimpleStation/network/"); network2.add_edge("r0", "l1", 100, 10, false); + // NOLINTNEXTLINE(misc-const-correctness) cda_rail::Network network3; cda_rail::Network network4; network4.add_vertex("l0", cda_rail::VertexType::TTD); @@ -3765,4 +3774,4 @@ TEST(Functionality, IsFullyInStation) { EXPECT_FALSE(stations.is_fully_in_station("Station1", {0, 2})); } -// NOLINTEND(clang-diagnostic-unused-result,clang-analyzer-deadcode.DeadStores) +// NOLINTEND(clang-diagnostic-unused-result,clang-analyzer-deadcode.DeadStores,bugprone-unchecked-optional-access) From eb85811de0ee340657e5fce69b35ee83928f485b Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 16:27:09 +0100 Subject: [PATCH 12/13] linter warning wrong header --- test/test_gurobi_vss_gen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_gurobi_vss_gen.cpp b/test/test_gurobi_vss_gen.cpp index 5f72a61c6..e59c27a1f 100644 --- a/test/test_gurobi_vss_gen.cpp +++ b/test/test_gurobi_vss_gen.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include using std::size_t; From fc399d1b32196c0036845441c58df29fc779f5bf Mon Sep 17 00:00:00 2001 From: Stefan Engels Date: Fri, 21 Feb 2025 16:41:32 +0100 Subject: [PATCH 13/13] =?UTF-8?q?Revert=20"check=20all=20file=C2=B4s"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 70286de77fe6d3d1e76a769073281c2568b64908. --- .github/workflows/cpp-linter.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cpp-linter.yml b/.github/workflows/cpp-linter.yml index e2f615055..2f0e6d914 100644 --- a/.github/workflows/cpp-linter.yml +++ b/.github/workflows/cpp-linter.yml @@ -64,7 +64,6 @@ jobs: tidy-checks: "" version: ${{ env.clang-version }} ignore: "build | test/example-networks | test/example-networks-gen-po | gurobi*" - files-changed-only: false thread-comments: true step-summary: true database: "build"