From e5deec180c19217afc862292e703b8829b760458 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 23 Aug 2021 14:46:12 +0200 Subject: [PATCH] Fix indent --- examples/cpp/cvrptw_lib.h | 38 +++++++++-------- examples/cpp/fap_parser.h | 61 ++++++++------------------- examples/cpp/fap_utilities.h | 1 + ortools/algorithms/knapsack_solver.cc | 5 ++- ortools/algorithms/knapsack_solver.h | 4 +- 5 files changed, 44 insertions(+), 65 deletions(-) diff --git a/examples/cpp/cvrptw_lib.h b/examples/cpp/cvrptw_lib.h index 3f0f5b3dea..2f17813364 100644 --- a/examples/cpp/cvrptw_lib.h +++ b/examples/cpp/cvrptw_lib.h @@ -16,6 +16,7 @@ #ifndef OR_TOOLS_EXAMPLES_CVRPTW_LIB_H_ #define OR_TOOLS_EXAMPLES_CVRPTW_LIB_H_ +#include #include #include @@ -37,15 +38,17 @@ int32_t GetSeed(bool deterministic); class LocationContainer { public: LocationContainer(int64_t speed, bool use_deterministic_seed); - void AddLocation(int64_t x, int64_t y) { locations_.push_back(Location(x, y)); } + void AddLocation(int64_t x, int64_t y) { + locations_.push_back(Location(x, y)); + } void AddRandomLocation(int64_t x_max, int64_t y_max); void AddRandomLocation(int64_t x_max, int64_t y_max, int duplicates); int64_t ManhattanDistance(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; int64_t NegManhattanDistance(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; int64_t ManhattanTime(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; bool SameLocation(RoutingIndexManager::NodeIndex node1, RoutingIndexManager::NodeIndex node2) const; @@ -78,7 +81,7 @@ class RandomDemand { bool use_deterministic_seed); void Initialize(); int64_t Demand(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; private: std::unique_ptr demand_; @@ -90,32 +93,33 @@ class RandomDemand { // Service time (proportional to demand) + transition time callback. class ServiceTimePlusTransition { public: - ServiceTimePlusTransition(int64_t time_per_demand_unit, - RoutingNodeEvaluator2 demand, - RoutingNodeEvaluator2 transition_time); + ServiceTimePlusTransition( + int64_t time_per_demand_unit, + operations_research::RoutingNodeEvaluator2 demand, + operations_research::RoutingNodeEvaluator2 transition_time); int64_t Compute(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; private: const int64_t time_per_demand_unit_; - RoutingNodeEvaluator2 demand_; - RoutingNodeEvaluator2 transition_time_; + operations_research::RoutingNodeEvaluator2 demand_; + operations_research::RoutingNodeEvaluator2 transition_time_; }; // Stop service time + transition time callback. class StopServiceTimePlusTransition { public: - StopServiceTimePlusTransition(int64_t stop_time, - const LocationContainer& location_container, - RoutingNodeEvaluator2 transition_time); + StopServiceTimePlusTransition( + int64_t stop_time, const LocationContainer& location_container, + operations_research::RoutingNodeEvaluator2 transition_time); int64_t Compute(RoutingIndexManager::NodeIndex from, - RoutingIndexManager::NodeIndex to) const; + RoutingIndexManager::NodeIndex to) const; private: const int64_t stop_time_; const LocationContainer& location_container_; - RoutingNodeEvaluator2 demand_; - RoutingNodeEvaluator2 transition_time_; + operations_research::RoutingNodeEvaluator2 demand_; + operations_research::RoutingNodeEvaluator2 transition_time_; }; // Route plan displayer. diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index 59b4c373eb..dedd7e9658 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -40,73 +40,49 @@ void ParseFileByLines(const std::string& filename, // The FapVariable struct represents a radio link of the // frequency assignment problem. struct FapVariable { - FapVariable() - : domain_index(-1), - domain_size(0), - domain(), - degree(0), - initial_position(-1), - mobility_index(-1), - mobility_cost(-1), - hard(false) {} - - ~FapVariable() {} - // Fields: // the index of a subset of all available frequencies of the instance - int domain_index; + int domain_index = -1; // the number of the frequencies available for the link - int domain_size; + int domain_size = 0; // the link's domain, i.e. a finite set of frequencies that can be // assigned to this link std::vector domain; // the number of constraints in which the link appears - int degree; + int degree = 0; // if positive, it means that the link has already been assigned a frequency // of that value - int initial_position; + int initial_position = -1; // the index of mobility cost - int mobility_index; + int mobility_index = -1; // the cost of modification of a link's pre-assigned value - int mobility_cost; + int mobility_cost = -1; // if true, it means that the link's pre-assigned position cannot be modified - bool hard; + bool hard = false; }; // The FapConstraint struct represents a constraint between two // radio links of the frequency assignment problem. struct FapConstraint { - FapConstraint() - : variable1(-1), - variable2(-1), - impact(0), - type(""), - operation(""), - value(-1), - weight_index(-1), - weight_cost(-1), - hard(false) {} - ~FapConstraint() {} - // Fields: // the index of the first variable appearing in the constraint - int variable1; + int variable1 = -1; // the index of the second variable appearing in the constraint - int variable2; + int variable2 = -1; // the importance of a constraint based on the degree of its variables, // the operator used in the constraint ("=" or ">") and whether it is a hard // or soft constraint and with what weight cost. // impact = (max_degree + min_degree + operator_impact + hardness_impact) - int impact; + int impact = 0; // the constraint type (D (difference), C (viscosity), F (fixed),P (prefix) // or L (far fields)) which is not used in practice @@ -117,24 +93,21 @@ struct FapConstraint { // the constraint deviation: it defines the constant k12 mentioned in RLFAP // description - int value; + int value = -1; // the index of weight cost - int weight_index; + int weight_index = -1; // the cost of not satisfaction of the constraint - int weight_cost; + int weight_cost = -1; // if true, it means that the constraint must be satisfied - bool hard; + bool hard = false; }; // The FapComponent struct represents an component of the RLFAP graph. // It models an independent sub-problem of the initial instance. struct FapComponent { - FapComponent() : variables(), constraints() {} - ~FapComponent() {} - // Fields: // the variable set of the sub-problem, i.e. the vertices of the component std::map variables; @@ -225,9 +198,9 @@ class ParametersParser { private: const std::string filename_; - static const int constraint_coefficient_no_ = 4; - static const int variable_coefficient_no_ = 4; - static const int coefficient_no_ = 8; + static constexpr int constraint_coefficient_no_ = 4; + static constexpr int variable_coefficient_no_ = 4; + static constexpr int coefficient_no_ = 8; std::string objective_; std::vector constraint_weights_; std::vector variable_weights_; diff --git a/examples/cpp/fap_utilities.h b/examples/cpp/fap_utilities.h index a5f1981030..412ce89ac8 100644 --- a/examples/cpp/fap_utilities.h +++ b/examples/cpp/fap_utilities.h @@ -18,6 +18,7 @@ #ifndef OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_ #define OR_TOOLS_EXAMPLES_FAP_UTILITIES_H_ +#include #include #include #include diff --git a/ortools/algorithms/knapsack_solver.cc b/ortools/algorithms/knapsack_solver.cc index c1e4b4cab6..010a03c9c7 100644 --- a/ortools/algorithms/knapsack_solver.cc +++ b/ortools/algorithms/knapsack_solver.cc @@ -925,8 +925,9 @@ void Knapsack64ItemsSolver::BuildBestSolution() { // ----- KnapsackDynamicProgrammingSolver ----- // KnapsackDynamicProgrammingSolver solves the 0-1 knapsack problem -// using dynamic programming. The time complexity is O(capacity * -// number_of_items^2) and the space complexity is O(capacity + number_of_items). +// using dynamic programming. This algorithm is pseudo-polynomial because it +// depends on capacity, ie. the time and space complexity is +// O(capacity * number_of_items). // The implemented algorithm is 'DP-3' in "Knapsack problems", Hans Kellerer, // Ulrich Pferschy and David Pisinger, Springer book (ISBN 978-3540402862). class KnapsackDynamicProgrammingSolver : public BaseKnapsackSolver { diff --git a/ortools/algorithms/knapsack_solver.h b/ortools/algorithms/knapsack_solver.h index 98c1640fef..3df3d0d0ce 100644 --- a/ortools/algorithms/knapsack_solver.h +++ b/ortools/algorithms/knapsack_solver.h @@ -141,8 +141,8 @@ class KnapsackSolver { /** Dynamic Programming approach for single dimension problems * * Limited to one dimension, this solver is based on a dynamic programming - * algorithm. The time complexity is O(capacity * number_of_items^2) and - * the space complexity is O(capacity + number_of_items). + * algorithm. The time and space complexity is O(capacity * + * number_of_items). */ KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = 2,