diff --git a/examples/cpp/acp_challenge.cc b/examples/cpp/acp_challenge.cc index d68b7619882..129854e972b 100644 --- a/examples/cpp/acp_challenge.cc +++ b/examples/cpp/acp_challenge.cc @@ -20,14 +20,14 @@ #include "base/hash.h" #include "base/integral_types.h" #include "base/logging.h" -#include "base/split.h" #include "base/map_util.h" +#include "base/split.h" #include "base/stringprintf.h" #include "base/strtoint.h" #include "constraint_solver/constraint_solver.h" #include "constraint_solver/routing.h" -#include "util/tuple_set.h" #include "util/filelineiter.h" +#include "util/tuple_set.h" /* Data format 15 @@ -129,9 +129,7 @@ class AcpData { } break; } - default: { - LOG(ERROR) << "Should not be here"; - } + default: { LOG(ERROR) << "Should not be here"; } } } @@ -172,7 +170,7 @@ class RandomIntervalLns : public BaseLns { rand_(seed), number_of_variables_(number_of_variables), number_of_intervals_(number_of_intervals), - num_product_(num_product) { + num_product_(num_product) { CHECK_GT(number_of_variables_, 0); CHECK_LE(number_of_variables_, Size()); CHECK_GT(number_of_intervals_, 0); @@ -241,9 +239,7 @@ class RandomIntervalLns : public BaseLns { class Swap : public IntVarLocalSearchOperator { public: explicit Swap(const std::vector& variables) - : IntVarLocalSearchOperator(variables), - index1_(0), - index2_(0) {} + : IntVarLocalSearchOperator(variables), index1_(0), index2_(0) {} virtual ~Swap() {} @@ -277,9 +273,7 @@ class Swap : public IntVarLocalSearchOperator { class Reverse : public IntVarLocalSearchOperator { public: explicit Reverse(const std::vector& variables) - : IntVarLocalSearchOperator(variables), - start_(-1), - len_(3) {} + : IntVarLocalSearchOperator(variables), start_(-1), len_(3) {} virtual ~Reverse() {} @@ -296,7 +290,7 @@ class Reverse : public IntVarLocalSearchOperator { return false; } for (int i = 0; i < len_; ++i) { - SetValue(start_ + len_ - i - 1, OldValue(start_ + i)); + SetValue(start_ + len_ - i - 1, OldValue(start_ + i)); } return true; } @@ -313,10 +307,8 @@ class Reverse : public IntVarLocalSearchOperator { class NRandomSwaps : public IntVarLocalSearchOperator { public: - explicit NRandomSwaps(const std::vector& variables, - int num_swaps, - int num_rounds, - int ls_seed) + explicit NRandomSwaps(const std::vector& variables, int num_swaps, + int num_rounds, int ls_seed) : IntVarLocalSearchOperator(variables), num_swaps_(num_swaps), num_rounds_(num_rounds), @@ -350,9 +342,7 @@ class NRandomSwaps : public IntVarLocalSearchOperator { } private: - virtual void OnStart() { - round_ = 0; - } + virtual void OnStart() { round_ = 0; } const int num_swaps_; const int num_rounds_; @@ -472,9 +462,7 @@ class SmartInsert : public IntVarLocalSearchOperator { } private: - bool IsProduct(int value) { - return value >= 0 && value < num_items_; - } + bool IsProduct(int value) { return value >= 0 && value < num_items_; } bool Increment() { if (!up_) { @@ -589,7 +577,7 @@ class Filter : public IntVarLocalSearchFilter { for (int i = 0; i < tmp_solution_.size(); ++i) { const int item = tmp_solution_[i]; const int product = ItemToProduct(item); - if (previous != -1 && product != -1 && previous != product) { + if (previous != -1 && product != -1 && previous != product) { transition_cost += transitions_[previous][product]; } if (product != -1) { @@ -691,7 +679,6 @@ void Solve(const std::string& filename, const std::string& solution_file) { tuple[3] = i; tuple[4] = 0; transition_cost_tuples.Insert(tuple); - } // Add initial state in case no production periods are packed at the start. tuple[0] = -1; @@ -718,8 +705,8 @@ void Solve(const std::string& filename, const std::string& solution_file) { solver.MakeIntVarArray(data.num_periods(), -1, data.num_products() - 1, "product_", &products); std::vector items; - solver.MakeIntVarArray(data.num_periods(), 0, data.num_periods() - 1, - "item_", &items); + solver.MakeIntVarArray(data.num_periods(), 0, data.num_periods() - 1, "item_", + &items); std::vector deliveries; std::vector due_dates; LOG(INFO) << " - build inventory costs"; @@ -803,27 +790,27 @@ void Solve(const std::string& filename, const std::string& solution_file) { // Create objective. IntVar* const objective_var = - solver.MakeSum(solver.MakeProd(solver.MakeSum(inventory_costs), - data.inventory_cost()), - solver.MakeSum(transition_costs))->Var(); - SearchMonitor* const objective = FLAGS_use_tabu ? - solver.MakeTabuSearch(false, objective_var, 1, items, FLAGS_tabu_size, - FLAGS_tabu_size, FLAGS_tabu_factor) : - (FLAGS_use_sa ? - solver.MakeSimulatedAnnealing(false, objective_var, 1, - FLAGS_sa_temperature) : - solver.MakeMinimize(objective_var, 1)); + solver + .MakeSum(solver.MakeProd(solver.MakeSum(inventory_costs), + data.inventory_cost()), + solver.MakeSum(transition_costs)) + ->Var(); + SearchMonitor* const objective = + FLAGS_use_tabu + ? solver.MakeTabuSearch(false, objective_var, 1, items, + FLAGS_tabu_size, FLAGS_tabu_size, + FLAGS_tabu_factor) + : (FLAGS_use_sa ? solver.MakeSimulatedAnnealing( + false, objective_var, 1, FLAGS_sa_temperature) + : solver.MakeMinimize(objective_var, 1)); // Create search monitors. SearchMonitor* const log = solver.MakeSearchLog(1000000, objective_var); - DecisionBuilder* const db = solver.MakePhase(items, - Solver::CHOOSE_MIN_SIZE, + DecisionBuilder* const db = solver.MakePhase(items, Solver::CHOOSE_MIN_SIZE, Solver::ASSIGN_MIN_VALUE); - DecisionBuilder* const random_db = - solver.MakePhase(items, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_RANDOM_VALUE); + DecisionBuilder* const random_db = solver.MakePhase( + items, Solver::CHOOSE_FIRST_UNBOUND, Solver::ASSIGN_RANDOM_VALUE); SearchLimit* const lns_limit = solver.MakeFailuresLimit(FLAGS_lns_limit); DecisionBuilder* const inner_db = solver.MakeSolveOnce(random_db, lns_limit); @@ -832,16 +819,11 @@ void Solve(const std::string& filename, const std::string& solution_file) { LocalSearchOperator* insert = solver.RevAlloc(new Insert(items, num_items)); LocalSearchOperator* smart_insert = solver.RevAlloc(new SmartInsert(items, num_items)); - LocalSearchOperator* random_swap = - solver.RevAlloc(new NRandomSwaps( - items, FLAGS_ls_swaps, FLAGS_ls_rounds, FLAGS_ls_seed)); - LocalSearchOperator* random_lns = - solver.RevAlloc(new RandomIntervalLns(items, - item_to_product, - FLAGS_lns_size, - FLAGS_lns_intervals, - FLAGS_lns_seed, - FLAGS_lns_product)); + LocalSearchOperator* random_swap = solver.RevAlloc( + new NRandomSwaps(items, FLAGS_ls_swaps, FLAGS_ls_rounds, FLAGS_ls_seed)); + LocalSearchOperator* random_lns = solver.RevAlloc(new RandomIntervalLns( + items, item_to_product, FLAGS_lns_size, FLAGS_lns_intervals, + FLAGS_lns_seed, FLAGS_lns_product)); std::vector operators; operators.push_back(swap); operators.push_back(reverse); @@ -857,18 +839,17 @@ void Solve(const std::string& filename, const std::string& solution_file) { std::vector filters; if (FLAGS_use_filter) { - filters.push_back(solver.RevAlloc(new Filter(items, item_to_product, - due_dates, data.transitions(), - data.inventory_cost()))); + filters.push_back( + solver.RevAlloc(new Filter(items, item_to_product, due_dates, + data.transitions(), data.inventory_cost()))); } LocalSearchPhaseParameters* const ls_params = solver.MakeLocalSearchPhaseParameters(moves, inner_db, nullptr, filters); - DecisionBuilder* ls_db = nullptr; if (solution.empty()) { - ls_db = solver.MakeLocalSearchPhase(items, db, ls_params); + ls_db = solver.MakeLocalSearchPhase(items, db, ls_params); } else { vector offsets(data.num_products() + 1, 0); for (int i = 0; i < data.num_products(); ++i) { @@ -882,7 +863,7 @@ void Solve(const std::string& filename, const std::string& solution_file) { solution_assignment->Add(item); solution_assignment->SetRange(item, value, item_value); } - ls_db = solver.MakeLocalSearchPhase(solution_assignment, ls_params); + ls_db = solver.MakeLocalSearchPhase(solution_assignment, ls_params); } solver.NewSearch(ls_db, objective, log); diff --git a/examples/cpp/acp_challenge_routing.cc b/examples/cpp/acp_challenge_routing.cc index b1726f4d138..85517e11525 100644 --- a/examples/cpp/acp_challenge_routing.cc +++ b/examples/cpp/acp_challenge_routing.cc @@ -21,8 +21,8 @@ #include "base/hash.h" #include "base/integral_types.h" #include "base/logging.h" -#include "base/split.h" #include "base/map_util.h" +#include "base/split.h" #include "base/stringprintf.h" #include "base/strtoint.h" #include "constraint_solver/constraint_solver.h" @@ -98,9 +98,7 @@ class AcpData { } break; } - default: { - LOG(ERROR) << "Should not be here"; - } + default: { LOG(ERROR) << "Should not be here"; } } } @@ -170,7 +168,7 @@ int Evaluate(const AcpData& data, const std::vector& schedule) { int previous = -1; int transition_cost = 0; for (const int product : schedule) { - if (previous != -1 && product != -1 && previous != product) { + if (previous != -1 && product != -1 && previous != product) { transition_cost += data.transitions()[previous][product]; } if (product != -1) { @@ -184,7 +182,6 @@ int64 OneDistance(RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) { return 1; } - class ProductMatrix { public: ProductMatrix(const AcpData& data, const std::vector& item_to_product) @@ -206,7 +203,6 @@ class ProductMatrix { }; void Solve(const std::string& filename, const std::string& solution_file) { - const char* kTime = "Time"; LOG(INFO) << "Load " << filename; diff --git a/examples/cpp/code_samples_sat.cc b/examples/cpp/code_samples_sat.cc index 6686ba3d42e..18ade2e1121 100644 --- a/examples/cpp/code_samples_sat.cc +++ b/examples/cpp/code_samples_sat.cc @@ -174,8 +174,8 @@ void BinpackingProblem() { const int kSlackCapacity = 20; const int kNumBins = 10; - const std::vector> items = - { {20, 12}, {15, 12}, {30, 8}, {45, 5} }; + const std::vector> items = { + {20, 12}, {15, 12}, {30, 8}, {45, 5}}; const int num_items = items.size(); // Model. @@ -206,8 +206,8 @@ void BinpackingProblem() { lin->add_domain(ub); }; - auto add_reified_variable_bounds = [&cp_model]( - int var, int64 lb, int64 ub, int lit) { + auto add_reified_variable_bounds = [&cp_model](int var, int64 lb, int64 ub, + int lit) { ConstraintProto* const ct = cp_model.add_constraints(); ct->add_enforcement_literal(lit); LinearConstraintProto* const lin = ct->mutable_linear(); @@ -277,8 +277,8 @@ void BinpackingProblem() { // slack[b] => load[b] <= safe_capacity. add_reified_variable_bounds(load[b], kint64min, safe_capacity, slack[b]); // not(slack[b]) => load[b] > safe_capacity. - add_reified_variable_bounds( - load[b], safe_capacity + 1, kint64max, NegatedRef(slack[b])); + add_reified_variable_bounds(load[b], safe_capacity + 1, kint64max, + NegatedRef(slack[b])); } // Maximize sum of slacks. @@ -345,7 +345,7 @@ void OptionalIntervalSample() { }; auto new_optional_interval = [&cp_model](int start, int duration, int end, - int presence) { + int presence) { const int index = cp_model.constraints_size(); ConstraintProto* const ct = cp_model.add_constraints(); ct->add_enforcement_literal(presence); @@ -360,11 +360,10 @@ void OptionalIntervalSample() { const int duration_var = new_constant(10); const int end_var = new_variable(0, kHorizon); const int presence_var = new_variable(0, 1); - const int interval_var = new_optional_interval(start_var, duration_var, - end_var, presence_var); + const int interval_var = + new_optional_interval(start_var, duration_var, end_var, presence_var); LOG(INFO) << "start_var = " << start_var - << ", duration_var = " << duration_var - << ", end_var = " << end_var + << ", duration_var = " << duration_var << ", end_var = " << end_var << ", presence_var = " << presence_var << ", interval_var = " << interval_var; } diff --git a/examples/cpp/costas_array.cc b/examples/cpp/costas_array.cc index 44e037f7e7f..f1c59df526d 100644 --- a/examples/cpp/costas_array.cc +++ b/examples/cpp/costas_array.cc @@ -26,13 +26,12 @@ #include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" -#include "ortools/base/random.h" DEFINE_int32(minsize, 0, "Minimum degree of Costas matrix."); DEFINE_int32(maxsize, 0, "Maximum degree of Costas matrix."); @@ -267,7 +266,8 @@ void CostasSoft(const int dim) { for (int64 j = dim + 1; j <= 2 * dim; ++j) { // Penalize if an element occurs more than once. vars[index] = - solver.MakeSemiContinuousExpr(solver.MakeSum(matrix_count[j], -1), 0, 1) + solver + .MakeSemiContinuousExpr(solver.MakeSum(matrix_count[j], -1), 0, 1) ->Var(); occurences.push_back(vars[index++]); @@ -291,8 +291,9 @@ void CostasSoft(const int dim) { // Penalize occurrences of more than one for (int64 j = 0; j <= 2 * dim; ++j) { - vars[index] = solver.MakeSemiContinuousExpr( - solver.MakeSum(domain_count[j], -1), 0, dim - i) + vars[index] = solver + .MakeSemiContinuousExpr( + solver.MakeSum(domain_count[j], -1), 0, dim - i) ->Var(); occurences.push_back(vars[index++]); @@ -424,7 +425,7 @@ void CostasHard(const int dim) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); int min = 1; int max = 10; diff --git a/examples/cpp/cryptarithm.cc b/examples/cpp/cryptarithm.cc index 79a943c6471..b3fdf16417b 100644 --- a/examples/cpp/cryptarithm.cc +++ b/examples/cpp/cryptarithm.cc @@ -20,7 +20,6 @@ // Solution: // S=9; M=1; O=0; E=5; N=6; D=7; R=8; Y=2. -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -105,7 +104,7 @@ void Cryptoarithmetics() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::Cryptoarithmetics(); return 0; } diff --git a/examples/cpp/cvrp_disjoint_tw.cc b/examples/cpp/cvrp_disjoint_tw.cc index 465b7c4ad1a..5516ab2e704 100644 --- a/examples/cpp/cvrp_disjoint_tw.cc +++ b/examples/cpp/cvrp_disjoint_tw.cc @@ -24,24 +24,22 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -using operations_research::RoutingModel; -using operations_research::RoutingSearchParameters; +using operations_research::ACMRandom; +using operations_research::GetSeed; using operations_research::LocationContainer; using operations_research::RandomDemand; +using operations_research::RoutingModel; +using operations_research::RoutingSearchParameters; using operations_research::ServiceTimePlusTransition; -using operations_research::GetSeed; -using operations_research::ACMRandom; - DEFINE_int32(vrp_orders, 100, "Nodes in the problem."); DEFINE_int32(vrp_vehicles, 20, "Size of Traveling Salesman Problem instance."); @@ -57,7 +55,7 @@ const int64 kMaxNodesPerGroup = 10; const int64 kSameVehicleCost = 1000; int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; // VRP of size FLAGS_vrp_size. diff --git a/examples/cpp/cvrptw.cc b/examples/cpp/cvrptw.cc index b71ff39ec16..de96a010d66 100644 --- a/examples/cpp/cvrptw.cc +++ b/examples/cpp/cvrptw.cc @@ -23,25 +23,23 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -#include "ortools/base/random.h" -using operations_research::RoutingModel; -using operations_research::RoutingSearchParameters; +using operations_research::ACMRandom; +using operations_research::GetSeed; using operations_research::LocationContainer; using operations_research::RandomDemand; +using operations_research::RoutingModel; +using operations_research::RoutingSearchParameters; using operations_research::ServiceTimePlusTransition; -using operations_research::GetSeed; -using operations_research::ACMRandom; - DEFINE_int32(vrp_orders, 100, "Nodes in the problem."); DEFINE_int32(vrp_vehicles, 20, "Size of Traveling Salesman Problem instance."); @@ -56,7 +54,7 @@ const int64 kMaxNodesPerGroup = 10; const int64 kSameVehicleCost = 1000; int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; // VRP of size FLAGS_vrp_size. diff --git a/examples/cpp/cvrptw_lib.cc b/examples/cpp/cvrptw_lib.cc index deb8a62754f..076f9fb1a3f 100644 --- a/examples/cpp/cvrptw_lib.cc +++ b/examples/cpp/cvrptw_lib.cc @@ -16,10 +16,9 @@ #include #include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/routing.h" -#include "ortools/base/random.h" -#include "ortools/base/random.h" namespace operations_research { diff --git a/examples/cpp/cvrptw_lib.h b/examples/cpp/cvrptw_lib.h index f3005fd93b2..7e2c9ed8b6b 100644 --- a/examples/cpp/cvrptw_lib.h +++ b/examples/cpp/cvrptw_lib.h @@ -18,8 +18,8 @@ #include -#include "ortools/constraint_solver/routing.h" #include "ortools/base/random.h" +#include "ortools/constraint_solver/routing.h" namespace operations_research { diff --git a/examples/cpp/cvrptw_with_breaks.cc b/examples/cpp/cvrptw_with_breaks.cc index 9c447a1428e..82a04869595 100644 --- a/examples/cpp/cvrptw_with_breaks.cc +++ b/examples/cpp/cvrptw_with_breaks.cc @@ -27,26 +27,24 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -#include "ortools/base/random.h" -using operations_research::RoutingModel; -using operations_research::RoutingSearchParameters; +using operations_research::ACMRandom; +using operations_research::GetSeed; using operations_research::LocationContainer; using operations_research::RandomDemand; +using operations_research::RoutingModel; +using operations_research::RoutingSearchParameters; using operations_research::ServiceTimePlusTransition; -using operations_research::GetSeed; -using operations_research::ACMRandom; - DEFINE_int32(vrp_orders, 100, "Nodes in the problem."); DEFINE_int32(vrp_vehicles, 20, "Size of Traveling Salesman Problem instance."); @@ -57,7 +55,7 @@ const char* kTime = "Time"; const char* kCapacity = "Capacity"; int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; // VRP of size FLAGS_vrp_size. diff --git a/examples/cpp/cvrptw_with_refueling.cc b/examples/cpp/cvrptw_with_refueling.cc index 58c71f58c58..5b6a373c8a5 100644 --- a/examples/cpp/cvrptw_with_refueling.cc +++ b/examples/cpp/cvrptw_with_refueling.cc @@ -21,28 +21,26 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -#include "ortools/base/random.h" +using operations_research::ACMRandom; using operations_research::GetSeed; using operations_research::LocationContainer; using operations_research::RandomDemand; using operations_research::RoutingModel; using operations_research::RoutingSearchParameters; using operations_research::ServiceTimePlusTransition; -using operations_research::ACMRandom; using operations_research::StringAppendF; using operations_research::StringPrintf; - DEFINE_int32(vrp_orders, 100, "Nodes in the problem."); DEFINE_int32(vrp_vehicles, 20, "Size of Traveling Salesman Problem instance."); DEFINE_bool(vrp_use_deterministic_random_seed, false, @@ -59,7 +57,7 @@ bool IsRefuelNode(int64 node) { } int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; // VRP of size FLAGS_vrp_size. diff --git a/examples/cpp/cvrptw_with_resources.cc b/examples/cpp/cvrptw_with_resources.cc index 59fba279cf8..502b86063cf 100644 --- a/examples/cpp/cvrptw_with_resources.cc +++ b/examples/cpp/cvrptw_with_resources.cc @@ -23,24 +23,23 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -#include "ortools/base/random.h" -using operations_research::RoutingModel; -using operations_research::RoutingSearchParameters; +using operations_research::ACMRandom; +using operations_research::GetSeed; using operations_research::LocationContainer; using operations_research::RandomDemand; +using operations_research::RoutingModel; +using operations_research::RoutingSearchParameters; using operations_research::ServiceTimePlusTransition; -using operations_research::GetSeed; -using operations_research::ACMRandom; using operations_research::StringAppendF; using operations_research::StringPrintf; @@ -53,7 +52,7 @@ const char* kTime = "Time"; const char* kCapacity = "Capacity"; int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_orders) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_vehicles) << "Specify a non-null vehicle fleet size."; // VRP of size FLAGS_vrp_size. diff --git a/examples/cpp/cvrptw_with_stop_times_and_resources.cc b/examples/cpp/cvrptw_with_stop_times_and_resources.cc index 4aba96da43e..744a4d104d2 100644 --- a/examples/cpp/cvrptw_with_stop_times_and_resources.cc +++ b/examples/cpp/cvrptw_with_stop_times_and_resources.cc @@ -21,26 +21,25 @@ #include +#include "examples/cpp/cvrptw_lib.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "examples/cpp/cvrptw_lib.h" -#include "ortools/base/random.h" +using operations_research::ACMRandom; +using operations_research::GetSeed; using operations_research::IntervalVar; -using operations_research::RoutingModel; -using operations_research::RoutingSearchParameters; using operations_research::LocationContainer; using operations_research::RandomDemand; -using operations_research::GetSeed; +using operations_research::RoutingModel; +using operations_research::RoutingSearchParameters; using operations_research::StopServiceTimePlusTransition; -using operations_research::ACMRandom; using operations_research::StringAppendF; using operations_research::StringPrintf; @@ -54,7 +53,7 @@ const char* kTime = "Time"; const char* kCapacity = "Capacity"; int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK_LT(0, FLAGS_vrp_stops) << "Specify an instance size greater than 0."; CHECK_LT(0, FLAGS_vrp_orders_per_stop) << "Specify an instance size greater than 0."; @@ -138,9 +137,13 @@ int main(int argc, char** argv) { // An order has no service time iff it is at the same location as the // next order on the route. operations_research::IntVar* const is_null_duration = - solver->MakeElement([&locations, order](int64 index) { - return locations.SameLocationFromIndex(order, index); - }, routing.NextVar(order))->Var(); + solver + ->MakeElement( + [&locations, order](int64 index) { + return locations.SameLocationFromIndex(order, index); + }, + routing.NextVar(order)) + ->Var(); solver->AddConstraint( solver->MakeNonEquality(interval->PerformedExpr(), is_null_duration)); routing.AddIntervalToAssignment(interval); diff --git a/examples/cpp/dimacs_assignment.cc b/examples/cpp/dimacs_assignment.cc index a4186e82ff4..575bb01ab08 100644 --- a/examples/cpp/dimacs_assignment.cc +++ b/examples/cpp/dimacs_assignment.cc @@ -11,22 +11,20 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include -#include #include +#include #include -#include "ortools/base/commandlineflags.h" +#include "examples/cpp/parse_dimacs_assignment.h" +#include "examples/cpp/print_dimacs_assignment.h" +#include "ortools/algorithms/hungarian.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/algorithms/hungarian.h" -#include "examples/cpp/parse_dimacs_assignment.h" -#include "examples/cpp/print_dimacs_assignment.h" #include "ortools/graph/ebert_graph.h" #include "ortools/graph/linear_assignment.h" @@ -175,8 +173,8 @@ int SolveDimacsAssignment(int argc, char* argv[]) { static const char* const kUsageTemplate = "usage: %s "; -using ::operations_research::ForwardStarStaticGraph; using ::operations_research::ForwardStarGraph; +using ::operations_research::ForwardStarStaticGraph; using ::operations_research::SolveDimacsAssignment; using ::operations_research::StarGraph; using ::operations_research::StringPrintf; diff --git a/examples/cpp/dobble_ls.cc b/examples/cpp/dobble_ls.cc index 5ccd27eb5dd..279008c2c75 100644 --- a/examples/cpp/dobble_ls.cc +++ b/examples/cpp/dobble_ls.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // This problem is inspired by the Dobble game (aka Spot-It in the // USA). In this game, we have 57 cards, 57 symbols, and 8 symbols // per card. We want to assign symbols per card such that any two @@ -33,14 +32,13 @@ #include #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/map_util.h" +#include "ortools/base/random.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" -#include "ortools/base/random.h" DEFINE_int32(symbols_per_card, 8, "Number of symbols per card."); DEFINE_int32(ls_seed, 1, @@ -751,7 +749,7 @@ void SolveDobble(int num_cards, int num_symbols, int num_symbols_per_card) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); // These constants comes directly from the dobble game. // There are actually 55 cards, but we can create up to 57 cards. const int kSymbolsPerCard = FLAGS_symbols_per_card; diff --git a/examples/cpp/fap_parser.cc b/examples/cpp/fap_parser.cc index e0b20db307e..071ab497df2 100644 --- a/examples/cpp/fap_parser.cc +++ b/examples/cpp/fap_parser.cc @@ -18,12 +18,13 @@ #include #include #include "ortools/base/file.h" -#include "ortools/base/split.h" #include "ortools/base/map_util.h" +#include "ortools/base/split.h" namespace operations_research { -void ParseFileByLines(const std::string& filename, std::vector* lines) { +void ParseFileByLines(const std::string& filename, + std::vector* lines) { CHECK(lines != nullptr); std::string result; CHECK_OK(file::GetContents(filename, &result, file::Defaults())); @@ -40,7 +41,8 @@ void VariableParser::Parse() { std::vector lines; ParseFileByLines(filename_, &lines); for (const std::string& line : lines) { - std::vector tokens = absl::StrSplit(line, ' ', absl::SkipEmpty()); + std::vector tokens = + absl::StrSplit(line, ' ', absl::SkipEmpty()); if (tokens.empty()) { continue; } @@ -66,7 +68,8 @@ void DomainParser::Parse() { std::vector lines; ParseFileByLines(filename_, &lines); for (const std::string& line : lines) { - std::vector tokens = absl::StrSplit(line, ' ', absl::SkipEmpty()); + std::vector tokens = + absl::StrSplit(line, ' ', absl::SkipEmpty()); if (tokens.empty()) { continue; } @@ -96,7 +99,8 @@ void ConstraintParser::Parse() { std::vector lines; ParseFileByLines(filename_, &lines); for (const std::string& line : lines) { - std::vector tokens = absl::StrSplit(line, ' ', absl::SkipEmpty()); + std::vector tokens = + absl::StrSplit(line, ' ', absl::SkipEmpty()); if (tokens.empty()) { continue; } @@ -142,11 +146,13 @@ void ParametersParser::Parse() { ParseFileByLines(filename_, &lines); for (const std::string& line : lines) { if (objective) { - largest_token = largest_token || (line.find("largest") != std::string::npos); + largest_token = + largest_token || (line.find("largest") != std::string::npos); value_token = value_token || (line.find("value") != std::string::npos); number_token = number_token || (line.find("number") != std::string::npos); values_token = values_token || (line.find("values") != std::string::npos); - coefficient = coefficient || (line.find("coefficient") != std::string::npos); + coefficient = + coefficient || (line.find("coefficient") != std::string::npos); } if (coefficient) { @@ -214,8 +220,8 @@ void FindComponents(const std::vector& constraints, // also be included in the same component. const int component_index = in_component[variable_id1]; CHECK(gtl::ContainsKey(*components, component_index)); - gtl::InsertOrUpdate(&((*components)[component_index].variables), variable_id2, - variable2); + gtl::InsertOrUpdate(&((*components)[component_index].variables), + variable_id2, variable2); in_component[variable_id2] = component_index; (*components)[component_index].constraints.push_back(constraint); } else if (in_component[variable_id1] < 0 && @@ -224,8 +230,8 @@ void FindComponents(const std::vector& constraints, // also be included in the same component. const int component_index = in_component[variable_id2]; CHECK(gtl::ContainsKey(*components, component_index)); - gtl::InsertOrUpdate(&((*components)[component_index].variables), variable_id1, - variable1); + gtl::InsertOrUpdate(&((*components)[component_index].variables), + variable_id1, variable1); in_component[variable_id1] = component_index; (*components)[component_index].constraints.push_back(constraint); } else { @@ -241,23 +247,24 @@ void FindComponents(const std::vector& constraints, if (min_component_index != max_component_index) { // Update the component_index of maximum indexed component's variables. for (const auto& variable : - (*components)[max_component_index].variables) { + (*components)[max_component_index].variables) { int variable_id = variable.first; in_component[variable_id] = min_component_index; } // Insert all the variables of the maximum indexed component to the // variables of the minimum indexed component. - ((*components)[min_component_index]).variables.insert( - ((*components)[max_component_index]).variables.begin(), - ((*components)[max_component_index]).variables.end()); + ((*components)[min_component_index]) + .variables.insert( + ((*components)[max_component_index]).variables.begin(), + ((*components)[max_component_index]).variables.end()); // Insert all the constraints of the maximum indexed component to the // constraints of the minimum indexed component. - ((*components)[min_component_index]).constraints.insert( - ((*components)[min_component_index]).constraints.end(), - ((*components)[max_component_index]).constraints.begin(), - ((*components)[max_component_index]).constraints.end()); - (*components)[min_component_index] - .constraints.push_back(constraint); + ((*components)[min_component_index]) + .constraints.insert( + ((*components)[min_component_index]).constraints.end(), + ((*components)[max_component_index]).constraints.begin(), + ((*components)[max_component_index]).constraints.end()); + (*components)[min_component_index].constraints.push_back(constraint); // Delete the maximum indexed component from the components set. components->erase(max_component_index); } else { @@ -272,8 +279,10 @@ void FindComponents(const std::vector& constraints, int EvaluateConstraintImpact(const std::map& variables, const int max_weight_cost, const FapConstraint constraint) { - const FapVariable& variable1 = gtl::FindOrDie(variables, constraint.variable1); - const FapVariable& variable2 = gtl::FindOrDie(variables, constraint.variable2); + const FapVariable& variable1 = + gtl::FindOrDie(variables, constraint.variable1); + const FapVariable& variable2 = + gtl::FindOrDie(variables, constraint.variable2); const int degree1 = variable1.degree; const int degree2 = variable2.degree; const int max_degree = std::max(degree1, degree2); @@ -292,8 +301,8 @@ int EvaluateConstraintImpact(const std::map& variables, void ParseInstance(const std::string& data_directory, bool find_components, std::map* variables, - std::vector* constraints, std::string* objective, - std::vector* frequencies, + std::vector* constraints, + std::string* objective, std::vector* frequencies, std::unordered_map* components) { CHECK(variables != nullptr); CHECK(constraints != nullptr); @@ -315,9 +324,8 @@ void ParseInstance(const std::string& data_directory, bool find_components, ParametersParser cst(data_directory); cst.Parse(); - const int maximum_weight_cost = - *std::max_element((cst.constraint_weights()).begin(), - (cst.constraint_weights()).end()); + const int maximum_weight_cost = *std::max_element( + (cst.constraint_weights()).begin(), (cst.constraint_weights()).end()); // Make the variables of the instance. for (auto& it : *variables) { @@ -363,8 +371,8 @@ void ParseInstance(const std::string& data_directory, bool find_components, } } else { for (FapConstraint& constraint : *constraints) { - constraint.impact = EvaluateConstraintImpact( - *variables, maximum_weight_cost, constraint); + constraint.impact = + EvaluateConstraintImpact(*variables, maximum_weight_cost, constraint); } } } diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index 8b14ce806f1..33d0766a2db 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -19,20 +19,21 @@ #ifndef OR_TOOLS_EXAMPLES_FAP_PARSER_H_ #define OR_TOOLS_EXAMPLES_FAP_PARSER_H_ -#include #include #include +#include #include #include "ortools/base/logging.h" -#include "ortools/base/strtoint.h" -#include "ortools/base/split.h" #include "ortools/base/map_util.h" +#include "ortools/base/split.h" +#include "ortools/base/strtoint.h" namespace operations_research { // Takes a filename and a buffer and fills the lines buffer // with the lines of the file corresponding to the filename. -void ParseFileByLines(const std::string& filename, std::vector* lines); +void ParseFileByLines(const std::string& filename, + std::vector* lines); // The FapVariable struct represents a radio link of the // frequency assignment problem. @@ -244,8 +245,8 @@ int EvaluateConstraintImpact(const std::map& variables, // Function that parses an instance of frequency assignment problem. void ParseInstance(const std::string& data_directory, bool find_components, std::map* variables, - std::vector* constraints, std::string* objective, - std::vector* frequencies, + std::vector* constraints, + std::string* objective, std::vector* frequencies, std::unordered_map* components); } // namespace operations_research #endif // OR_TOOLS_EXAMPLES_FAP_PARSER_H_ diff --git a/examples/cpp/fap_utilities.cc b/examples/cpp/fap_utilities.cc index 4c492f2ae82..e7fcf01399b 100644 --- a/examples/cpp/fap_utilities.cc +++ b/examples/cpp/fap_utilities.cc @@ -20,8 +20,8 @@ #include #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/map_util.h" +#include "ortools/base/stringprintf.h" namespace operations_research { @@ -43,15 +43,13 @@ bool CheckConstraintSatisfaction( LOG(INFO) << " Violation of contraint between variable " << ct.variable1 << " and variable " << ct.variable2 << "."; LOG(INFO) << " Expected |" << var1 << " - " << var2 - << "| (= " << absolute_difference << ") > " << ct.value - << "."; + << "| (= " << absolute_difference << ") > " << ct.value << "."; status = false; } else if ((ct.operation == "=") && (absolute_difference != ct.value)) { LOG(INFO) << " Violation of contraint between variable " << ct.variable1 << " and variable " << ct.variable2 << "."; LOG(INFO) << " Expected |" << var1 << " - " << var2 - << "| (= " << absolute_difference << ") = " << ct.value - << "."; + << "| (= " << absolute_difference << ") = " << ct.value << "."; status = false; } } diff --git a/examples/cpp/fap_utilities.h b/examples/cpp/fap_utilities.h index e5432b7eaba..31cd25ddf3c 100644 --- a/examples/cpp/fap_utilities.h +++ b/examples/cpp/fap_utilities.h @@ -21,8 +21,8 @@ #include #include -#include "ortools/constraint_solver/constraint_solver.h" #include "examples/cpp/fap_parser.h" +#include "ortools/constraint_solver/constraint_solver.h" namespace operations_research { diff --git a/examples/cpp/flexible_jobshop.cc b/examples/cpp/flexible_jobshop.cc index 0aa46112bab..ef6bdca62ff 100644 --- a/examples/cpp/flexible_jobshop.cc +++ b/examples/cpp/flexible_jobshop.cc @@ -35,13 +35,12 @@ #include #include -#include "ortools/base/commandlineflags.h" +#include "examples/cpp/flexible_jobshop.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" -#include "examples/cpp/flexible_jobshop.h" #include "ortools/util/string_array.h" DEFINE_string(data_file, "", "A flexible shobshop problem (.fjs)."); @@ -84,8 +83,9 @@ void FlexibleJobshop(const FlexibleJobShopData& data) { for (int alt = 0; alt < task.machines.size(); ++alt) { const int machine_id = task.machines[alt]; const int duration = task.durations[alt]; - const std::string name = StringPrintf("J%dI%dA%dM%dD%d", task.job_id, - task_index, alt, machine_id, duration); + const std::string name = + StringPrintf("J%dI%dA%dM%dD%d", task.job_id, task_index, alt, + machine_id, duration); IntervalVar* const interval = solver.MakeFixedDurationIntervalVar( 0, horizon, duration, optional, name); jobs_to_tasks[job_id].back().intervals.push_back(interval); @@ -218,7 +218,7 @@ static const char kUsage[] = "Usage: see flags.\nThis program runs a simple flexible job shop" " optimization output besides the debug LOGs of the solver."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { gflags::SetUsageMessage(kUsage); gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_data_file.empty()) { diff --git a/examples/cpp/flexible_jobshop.h b/examples/cpp/flexible_jobshop.h index 0bda8e17272..8d9722452c7 100644 --- a/examples/cpp/flexible_jobshop.h +++ b/examples/cpp/flexible_jobshop.h @@ -36,13 +36,13 @@ #include #include +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/split.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" -#include "ortools/base/split.h" #include "ortools/util/string_array.h" -#include "ortools/base/filelineiter.h" namespace operations_research { // A FlexibleJobShopData parses data files and stores all data internally for diff --git a/examples/cpp/flow_api.cc b/examples/cpp/flow_api.cc index b125a32bf9a..5614d92f6e3 100644 --- a/examples/cpp/flow_api.cc +++ b/examples/cpp/flow_api.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/graph/ebert_graph.h" @@ -82,7 +81,7 @@ void MaxFeasibleFlow() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::MinCostFlowOn4x4Matrix(); operations_research::MaxFeasibleFlow(); return 0; diff --git a/examples/cpp/frequency_assignment_problem.cc b/examples/cpp/frequency_assignment_problem.cc index 6c6bb04035a..36b30ec45c4 100644 --- a/examples/cpp/frequency_assignment_problem.cc +++ b/examples/cpp/frequency_assignment_problem.cc @@ -51,14 +51,13 @@ #include #include -#include "ortools/base/commandlineflags.h" +#include "examples/cpp/fap_model_printer.h" +#include "examples/cpp/fap_parser.h" +#include "examples/cpp/fap_utilities.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/constraint_solver/constraint_solver.h" -#include "examples/cpp/fap_model_printer.h" -#include "examples/cpp/fap_parser.h" -#include "examples/cpp/fap_utilities.h" DEFINE_string(directory, "", "Specifies the directory of the data."); DEFINE_string(value_evaluator, "", @@ -854,7 +853,7 @@ void SolveProblem(const std::map& variables, } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK(!FLAGS_directory.empty()) << "Requires --directory="; diff --git a/examples/cpp/global_arith.cc b/examples/cpp/global_arith.cc index 66216e82754..b8e7ea3c645 100644 --- a/examples/cpp/global_arith.cc +++ b/examples/cpp/global_arith.cc @@ -11,9 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "examples/cpp/global_arith.h" #include "ortools/base/stl_util.h" #include "ortools/constraint_solver/constraint_solveri.h" -#include "examples/cpp/global_arith.h" namespace operations_research { @@ -36,12 +36,13 @@ class SubstitutionMap { } void ProcessAllSubstitutions(Callback3* const hook) { - for (std::unordered_map::const_iterator it = substitutions_.begin(); - it != substitutions_.end(); - ++it) { + for (std::unordered_map::const_iterator it = + substitutions_.begin(); + it != substitutions_.end(); ++it) { hook->Run(it->first, it->second.var_index, it->second.offset); } } + private: std::unordered_map substitutions_; }; @@ -57,18 +58,14 @@ struct Bounds { ub = std::min(ub, new_ub); } - void Intersect(const Bounds& other) { - Intersect(other.lb, other.ub); - } + void Intersect(const Bounds& other) { Intersect(other.lb, other.ub); } void Union(int64 new_lb, int64 new_ub) { lb = std::min(lb, new_lb); ub = std::max(ub, new_ub); } - void Union(const Bounds& other) { - Union(other.lb, other.ub); - } + void Union(const Bounds& other) { Union(other.lb, other.ub); } bool IsEqual(const Bounds& other) { return (ub == other.ub && lb == other.lb); @@ -90,7 +87,8 @@ class BoundsStore { : initial_bounds_(initial_bounds) {} void SetRange(int var_index, int64 lb, int64 ub) { - std::unordered_map::iterator it = modified_bounds_.find(var_index); + std::unordered_map::iterator it = + modified_bounds_.find(var_index); if (it == modified_bounds_.end()) { Bounds new_bounds(lb, ub); const Bounds& initial = (*initial_bounds_)[var_index]; @@ -103,9 +101,7 @@ class BoundsStore { } } - void Clear() { - modified_bounds_.clear(); - } + void Clear() { modified_bounds_.clear(); } const std::unordered_map& modified_bounds() const { return modified_bounds_; @@ -114,9 +110,9 @@ class BoundsStore { vector* initial_bounds() const { return initial_bounds_; } void Apply() { - for (std::unordered_map::const_iterator it = modified_bounds_.begin(); - it != modified_bounds_.end(); - ++it) { + for (std::unordered_map::const_iterator it = + modified_bounds_.begin(); + it != modified_bounds_.end(); ++it) { (*initial_bounds_)[it->first] = it->second; } } @@ -138,6 +134,7 @@ class ArithmeticConstraint { virtual void Replace(int to_replace, int var, int64 offset) = 0; virtual bool Deduce(ArithmeticPropagator* const propagator) const = 0; virtual string DebugString() const = 0; + private: const vector vars_; }; @@ -150,22 +147,19 @@ class ArithmeticPropagator : PropagationBaseObject { : PropagationBaseObject(solver), demon_(demon) {} void ReduceProblem() { - for (int constraint_index = 0; - constraint_index < constraints_.size(); + for (int constraint_index = 0; constraint_index < constraints_.size(); ++constraint_index) { if (constraints_[constraint_index]->Deduce(this)) { protected_constraints_.insert(constraint_index); } } - scoped_ptr > hook( - NewPermanentCallback(this, - &ArithmeticPropagator::ProcessOneSubstitution)); + scoped_ptr > hook(NewPermanentCallback( + this, &ArithmeticPropagator::ProcessOneSubstitution)); substitution_map_.ProcessAllSubstitutions(hook.get()); } void Post() { - for (int constraint_index = 0; - constraint_index < constraints_.size(); + for (int constraint_index = 0; constraint_index < constraints_.size(); ++constraint_index) { const vector& vars = constraints_[constraint_index]->vars(); for (int var_index = 0; var_index < vars.size(); ++var_index) { @@ -174,21 +168,15 @@ class ArithmeticPropagator : PropagationBaseObject { } } - void InitialPropagate() { + void InitialPropagate() {} - } - - void Update(int var_index) { - Enqueue(demon_); - } + void Update(int var_index) { Enqueue(demon_); } void AddConstraint(ArithmeticConstraint* const ct) { constraints_.push_back(ct); } - void AddVariable(int64 lb, int64 ub) { - bounds_.push_back(Bounds(lb, ub)); - } + void AddVariable(int64 lb, int64 ub) { bounds_.push_back(Bounds(lb, ub)); } const vector vars() const { return vars_; } @@ -212,8 +200,7 @@ class ArithmeticPropagator : PropagationBaseObject { } void ProcessOneSubstitution(int left_var, int right_var, int64 right_offset) { - for (int constraint_index = 0; - constraint_index < constraints_.size(); + for (int constraint_index = 0; constraint_index < constraints_.size(); ++constraint_index) { if (!ContainsKey(protected_constraints_, constraint_index)) { ArithmeticConstraint* const constraint = constraints_[constraint_index]; @@ -225,14 +212,15 @@ class ArithmeticPropagator : PropagationBaseObject { void PrintModel() { LOG(INFO) << "Vars:"; for (int i = 0; i < bounds_.size(); ++i) { - LOG(INFO) << " var<" << i << "> = [" << bounds_[i].lb - << " .. " << bounds_[i].ub << "]"; + LOG(INFO) << " var<" << i << "> = [" << bounds_[i].lb << " .. " + << bounds_[i].ub << "]"; } LOG(INFO) << "Constraints"; for (int i = 0; i < constraints_.size(); ++i) { LOG(INFO) << " " << constraints_[i]->DebugString(); } } + private: Demon* const demon_; vector vars_; @@ -256,14 +244,14 @@ class RowConstraint : public ArithmeticConstraint { coefficients_[var_index] = coefficient; } - virtual bool Propagate(BoundsStore* const store) { - return true; - } + virtual bool Propagate(BoundsStore* const store) { return true; } virtual void Replace(int to_replace, int var, int64 offset) { - std::unordered_map::iterator find_other = coefficients_.find(to_replace); + std::unordered_map::iterator find_other = + coefficients_.find(to_replace); if (find_other != coefficients_.end()) { - std::unordered_map::iterator find_var = coefficients_.find(var); + std::unordered_map::iterator find_var = + coefficients_.find(var); const int64 other_coefficient = find_other->second; if (lb_ != kint64min) { lb_ += other_coefficient * offset; @@ -308,16 +296,16 @@ class RowConstraint : public ArithmeticConstraint { virtual string DebugString() const { string output = "("; bool first = true; - for (std::unordered_map::const_iterator it = coefficients_.begin(); - it != coefficients_.end(); - ++it) { + for (std::unordered_map::const_iterator it = + coefficients_.begin(); + it != coefficients_.end(); ++it) { if (it->second != 0) { if (first) { first = false; if (it->second == 1) { output += StringPrintf("var<%d>", it->first); } else if (it->second == -1) { - output += StringPrintf("-var<%d>", it->first); + output += StringPrintf("-var<%d>", it->first); } else { output += StringPrintf("%lld*var<%d>", it->second, it->first); } @@ -343,6 +331,7 @@ class RowConstraint : public ArithmeticConstraint { } return output; } + private: std::unordered_map coefficients_; int64 lb_; @@ -357,9 +346,7 @@ class OrConstraint : public ArithmeticConstraint { virtual ~OrConstraint() {} - virtual bool Propagate(BoundsStore* const store) { - return true; - } + virtual bool Propagate(BoundsStore* const store) { return true; } virtual void Replace(int to_replace, int var, int64 offset) { left_->Replace(to_replace, var, offset); @@ -371,10 +358,10 @@ class OrConstraint : public ArithmeticConstraint { } virtual string DebugString() const { - return StringPrintf("Or(%s, %s)", - left_->DebugString().c_str(), + return StringPrintf("Or(%s, %s)", left_->DebugString().c_str(), right_->DebugString().c_str()); } + private: ArithmeticConstraint* const left_; ArithmeticConstraint* const right_; @@ -383,11 +370,9 @@ class OrConstraint : public ArithmeticConstraint { // ----- GlobalArithmeticConstraint ----- GlobalArithmeticConstraint::GlobalArithmeticConstraint(Solver* const solver) - : Constraint(solver), - propagator_(NULL) { + : Constraint(solver), propagator_(NULL) { propagator_.reset(new ArithmeticPropagator( - solver, - solver->MakeDelayedConstraintInitialPropagateCallback(this))); + solver, solver->MakeDelayedConstraintInitialPropagateCallback(this))); } GlobalArithmeticConstraint::~GlobalArithmeticConstraint() { STLDeleteElements(&constraints_); @@ -396,12 +381,9 @@ GlobalArithmeticConstraint::~GlobalArithmeticConstraint() { void GlobalArithmeticConstraint::Post() { const vector& vars = propagator_->vars(); for (int var_index = 0; var_index < vars.size(); ++var_index) { - Demon* const demon = - MakeConstraintDemon1(solver(), - this, - &GlobalArithmeticConstraint::Update, - "Update", - var_index); + Demon* const demon = MakeConstraintDemon1( + solver(), this, &GlobalArithmeticConstraint::Update, "Update", + var_index); vars[var_index]->WhenRange(demon); } LOG(INFO) << "----- Before reduction -----"; @@ -422,8 +404,7 @@ void GlobalArithmeticConstraint::Update(int var_index) { } ConstraintRef GlobalArithmeticConstraint::MakeScalProdGreaterOrEqualConstant( - const vector vars, - const vector coefficients, + const vector vars, const vector coefficients, int64 constant) { RowConstraint* const constraint = new RowConstraint(constant, kint64max); for (int index = 0; index < vars.size(); ++index) { @@ -433,8 +414,7 @@ ConstraintRef GlobalArithmeticConstraint::MakeScalProdGreaterOrEqualConstant( } ConstraintRef GlobalArithmeticConstraint::MakeScalProdLessOrEqualConstant( - const vector vars, - const vector coefficients, + const vector vars, const vector coefficients, int64 constant) { RowConstraint* const constraint = new RowConstraint(kint64min, constant); for (int index = 0; index < vars.size(); ++index) { @@ -444,8 +424,7 @@ ConstraintRef GlobalArithmeticConstraint::MakeScalProdLessOrEqualConstant( } ConstraintRef GlobalArithmeticConstraint::MakeScalProdEqualConstant( - const vector vars, - const vector coefficients, + const vector vars, const vector coefficients, int64 constant) { RowConstraint* const constraint = new RowConstraint(constant, constant); for (int index = 0; index < vars.size(); ++index) { @@ -455,8 +434,7 @@ ConstraintRef GlobalArithmeticConstraint::MakeScalProdEqualConstant( } ConstraintRef GlobalArithmeticConstraint::MakeSumGreaterOrEqualConstant( - const vector vars, - int64 constant) { + const vector vars, int64 constant) { RowConstraint* const constraint = new RowConstraint(constant, kint64max); for (int index = 0; index < vars.size(); ++index) { constraint->AddTerm(VarIndex(vars[index]), 1); @@ -483,9 +461,7 @@ ConstraintRef GlobalArithmeticConstraint::MakeSumEqualConstant( } ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint( - int64 lb, - const vector vars, - const vector coefficients, + int64 lb, const vector vars, const vector coefficients, int64 ub) { RowConstraint* const constraint = new RowConstraint(lb, ub); for (int index = 0; index < vars.size(); ++index) { @@ -495,34 +471,26 @@ ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint( } ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - int64 ub) { + IntVar* const v1, + int64 coeff1, + int64 ub) { RowConstraint* const constraint = new RowConstraint(lb, ub); constraint->AddTerm(VarIndex(v1), coeff1); return Store(constraint); } -ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - int64 ub) { +ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint( + int64 lb, IntVar* const v1, int64 coeff1, IntVar* const v2, int64 coeff2, + int64 ub) { RowConstraint* const constraint = new RowConstraint(lb, ub); - constraint->AddTerm(VarIndex(v1), coeff1); - constraint->AddTerm(VarIndex(v2), coeff2); - return Store(constraint); + constraint->AddTerm(VarIndex(v1), coeff1); + constraint->AddTerm(VarIndex(v2), coeff2); + return Store(constraint); } -ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - IntVar* const v3, - int64 coeff3, - int64 ub) { +ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint( + int64 lb, IntVar* const v1, int64 coeff1, IntVar* const v2, int64 coeff2, + IntVar* const v3, int64 coeff3, int64 ub) { RowConstraint* const constraint = new RowConstraint(lb, ub); constraint->AddTerm(VarIndex(v1), coeff1); constraint->AddTerm(VarIndex(v2), coeff2); @@ -530,16 +498,9 @@ ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, return Store(constraint); } -ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - IntVar* const v3, - int64 coeff3, - IntVar* const v4, - int64 coeff4, - int64 ub) { +ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint( + int64 lb, IntVar* const v1, int64 coeff1, IntVar* const v2, int64 coeff2, + IntVar* const v3, int64 coeff3, IntVar* const v4, int64 coeff4, int64 ub) { RowConstraint* const constraint = new RowConstraint(lb, ub); constraint->AddTerm(VarIndex(v1), coeff1); constraint->AddTerm(VarIndex(v2), coeff2); @@ -549,11 +510,9 @@ ConstraintRef GlobalArithmeticConstraint::MakeRowConstraint(int64 lb, } ConstraintRef GlobalArithmeticConstraint::MakeOrConstraint( - ConstraintRef left_ref, - ConstraintRef right_ref) { - OrConstraint* const constraint = - new OrConstraint(constraints_[left_ref.index()], - constraints_[right_ref.index()]); + ConstraintRef left_ref, ConstraintRef right_ref) { + OrConstraint* const constraint = new OrConstraint( + constraints_[left_ref.index()], constraints_[right_ref.index()]); return Store(constraint); } diff --git a/examples/cpp/global_arith.h b/examples/cpp/global_arith.h index 2732464f194..9aef60b4456 100644 --- a/examples/cpp/global_arith.h +++ b/examples/cpp/global_arith.h @@ -21,6 +21,7 @@ class ConstraintRef { public: ConstraintRef(int index) : index_(index) {} int index() const { return index_; } + private: const int index_; }; @@ -35,12 +36,10 @@ class GlobalArithmeticConstraint : public Constraint { void Update(int var_index); ConstraintRef MakeScalProdGreaterOrEqualConstant( - const vector vars, - const vector coefficients, + const vector vars, const vector coefficients, int64 constant); ConstraintRef MakeScalProdLessOrEqualConstant( - const vector vars, - const vector coefficients, + const vector vars, const vector coefficients, int64 constant); ConstraintRef MakeScalProdEqualConstant(const vector vars, const vector coefficients, @@ -51,42 +50,24 @@ class GlobalArithmeticConstraint : public Constraint { int64 constant); ConstraintRef MakeSumEqualConstant(const vector vars, int64 constant); - ConstraintRef MakeRowConstraint(int64 lb, - const vector vars, - const vector coefficients, - int64 ub); - ConstraintRef MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - int64 ub); - ConstraintRef MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - int64 ub); - ConstraintRef MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - IntVar* const v3, - int64 coeff3, - int64 ub); - ConstraintRef MakeRowConstraint(int64 lb, - IntVar* const v1, - int64 coeff1, - IntVar* const v2, - int64 coeff2, - IntVar* const v3, - int64 coeff3, - IntVar* const v4, - int64 coeff4, + ConstraintRef MakeRowConstraint(int64 lb, const vector vars, + const vector coefficients, int64 ub); + ConstraintRef MakeRowConstraint(int64 lb, IntVar* const v1, int64 coeff1, int64 ub); + ConstraintRef MakeRowConstraint(int64 lb, IntVar* const v1, int64 coeff1, + IntVar* const v2, int64 coeff2, int64 ub); + ConstraintRef MakeRowConstraint(int64 lb, IntVar* const v1, int64 coeff1, + IntVar* const v2, int64 coeff2, + IntVar* const v3, int64 coeff3, int64 ub); + ConstraintRef MakeRowConstraint(int64 lb, IntVar* const v1, int64 coeff1, + IntVar* const v2, int64 coeff2, + IntVar* const v3, int64 coeff3, + IntVar* const v4, int64 coeff4, int64 ub); ConstraintRef MakeOrConstraint(ConstraintRef left_constraint_index, ConstraintRef right_constraint_index); void Add(ConstraintRef constraint_index); + private: int VarIndex(IntVar* const var); ConstraintRef Store(ArithmeticConstraint* const constraint); diff --git a/examples/cpp/golomb.cc b/examples/cpp/golomb.cc index e55e496d358..d52cd4d11ae 100644 --- a/examples/cpp/golomb.cc +++ b/examples/cpp/golomb.cc @@ -26,7 +26,6 @@ #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -38,8 +37,7 @@ DEFINE_int32( size, 0, "Size of the problem. If equal to 0, will test several increasing sizes."); -static const int kBestSolutions[] = {0, 1, 3, 6, 11, 17, 25, - 34, 44, 55, 72, 85, +static const int kBestSolutions[] = {0, 1, 3, 6, 11, 17, 25, 34, 44, 55, 72, 85, // just for the optimistics ones, the rest: 106, 127, 151, 177, 199, 216, 246}; @@ -94,7 +92,7 @@ void GolombRuler(int size) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_size != 0) { operations_research::GolombRuler(FLAGS_size); } else { diff --git a/examples/cpp/integer_programming.cc b/examples/cpp/integer_programming.cc index 4c700ae523b..2ca53459b98 100644 --- a/examples/cpp/integer_programming.cc +++ b/examples/cpp/integer_programming.cc @@ -59,31 +59,31 @@ void RunIntegerProgrammingExample( } void RunAllExamples() { - #if defined(USE_GLPK) - LOG(INFO) << "---- Integer programming example with GLPK ----"; - RunIntegerProgrammingExample(MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING); - #endif - #if defined(USE_CBC) - LOG(INFO) << "---- Integer programming example with CBC ----"; - RunIntegerProgrammingExample(MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); - #endif - #if defined(USE_SCIP) - LOG(INFO) << "---- Integer programming example with SCIP ----"; - RunIntegerProgrammingExample(MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); - #endif - #if defined(USE_GUROBI) - LOG(INFO) << "---- Integer programming example with Gurobi ----"; - RunIntegerProgrammingExample(MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING); - #endif // USE_GUROBI - #if defined(USE_CPLEX) - LOG(INFO) << "---- Integer programming example with CPLEX ----"; - RunIntegerProgrammingExample(MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING); - #endif // USE_CPLEX +#if defined(USE_GLPK) + LOG(INFO) << "---- Integer programming example with GLPK ----"; + RunIntegerProgrammingExample(MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING); +#endif +#if defined(USE_CBC) + LOG(INFO) << "---- Integer programming example with CBC ----"; + RunIntegerProgrammingExample(MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); +#endif +#if defined(USE_SCIP) + LOG(INFO) << "---- Integer programming example with SCIP ----"; + RunIntegerProgrammingExample(MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); +#endif +#if defined(USE_GUROBI) + LOG(INFO) << "---- Integer programming example with Gurobi ----"; + RunIntegerProgrammingExample(MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING); +#endif // USE_GUROBI +#if defined(USE_CPLEX) + LOG(INFO) << "---- Integer programming example with CPLEX ----"; + RunIntegerProgrammingExample(MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING); +#endif // USE_CPLEX } } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::RunAllExamples(); return 0; } diff --git a/examples/cpp/jobshop.cc b/examples/cpp/jobshop.cc index 3a0972228de..8afd111d0f9 100644 --- a/examples/cpp/jobshop.cc +++ b/examples/cpp/jobshop.cc @@ -37,13 +37,11 @@ #include #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" DEFINE_string( diff --git a/examples/cpp/jobshop.h b/examples/cpp/jobshop.h index b1fccc601a7..7785eeedfad 100644 --- a/examples/cpp/jobshop.h +++ b/examples/cpp/jobshop.h @@ -37,12 +37,12 @@ #include #include +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/split.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" -#include "ortools/base/split.h" -#include "ortools/base/filelineiter.h" namespace operations_research { // ----- JobShopData ----- @@ -59,11 +59,7 @@ class JobShopData { int duration; }; - enum ProblemType { - UNDEFINED, - JSSP, - TAILLARD - }; + enum ProblemType { UNDEFINED, JSSP, TAILLARD }; enum TaillardState { START, diff --git a/examples/cpp/jobshop_earlytardy.cc b/examples/cpp/jobshop_earlytardy.cc index 5a3487b28ea..d0909c718e4 100644 --- a/examples/cpp/jobshop_earlytardy.cc +++ b/examples/cpp/jobshop_earlytardy.cc @@ -36,7 +36,8 @@ #include -#include "ortools/base/commandlineflags.h" +#include "examples/cpp/jobshop_earlytardy.h" +#include "examples/cpp/jobshop_ls.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -44,12 +45,9 @@ #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/linear_solver/linear_solver.h" #include "ortools/util/string_array.h" -#include "examples/cpp/jobshop_earlytardy.h" -#include "examples/cpp/jobshop_ls.h" DEFINE_string( - jet_file, - "", + jet_file, "", "Required: input file description the scheduling problem to solve, " "in our jet format:\n" " - the first line is \" \"\n" @@ -107,7 +105,7 @@ class TimePlacement : public DecisionBuilder { } } - // Adds the jobs precedence constraints. + // Adds the jobs precedence constraints. for (int j = 0; j < jobs_to_tasks_.size(); ++j) { for (int t = 0; t < jobs_to_tasks_[j].size() - 1; ++t) { IntervalVar* const first_task = jobs_to_tasks_[j][t]; @@ -146,10 +144,7 @@ class TimePlacement : public DecisionBuilder { // Creates penalty terms and objective. std::vector terms; - mp_solver_.MakeIntVarArray(jobs_to_tasks_.size(), - 0, - infinity, - "terms", + mp_solver_.MakeIntVarArray(jobs_to_tasks_.size(), 0, infinity, "terms", &terms); for (int j = 0; j < jobs_to_tasks_.size(); ++j) { mp_solver_.MutableObjective()->SetCoefficient(terms[j], 1.0); @@ -192,9 +187,7 @@ class TimePlacement : public DecisionBuilder { return NULL; } - virtual std::string DebugString() const { - return "TimePlacement"; - } + virtual std::string DebugString() const { return "TimePlacement"; } private: const EtJobShopData& data_; @@ -224,17 +217,11 @@ void EtJobShop(const EtJobShopData& data) { for (int task_index = 0; task_index < tasks.size(); ++task_index) { const Task& task = tasks[task_index]; CHECK_EQ(job_id, task.job_id); - const std::string name = StringPrintf("J%dM%dI%dD%d", - task.job_id, - task.machine_id, - task_index, - task.duration); - IntervalVar* const one_task = - solver.MakeFixedDurationIntervalVar(0, - horizon, - task.duration, - false, - name); + const std::string name = + StringPrintf("J%dM%dI%dD%d", task.job_id, task.machine_id, task_index, + task.duration); + IntervalVar* const one_task = solver.MakeFixedDurationIntervalVar( + 0, horizon, task.duration, false, name); jobs_to_tasks[task.job_id].push_back(one_task); machines_to_tasks[task.machine_id].push_back(one_task); } @@ -258,10 +245,8 @@ void EtJobShop(const EtJobShopData& data) { for (int job_id = 0; job_id < job_count; ++job_id) { const Job& job = data.GetJob(job_id); IntervalVar* const t = jobs_to_tasks[job_id][0]; - Constraint* const prec = - solver.MakeIntervalVarRelation(t, - Solver::STARTS_AFTER, - job.release_date); + Constraint* const prec = solver.MakeIntervalVarRelation( + t, Solver::STARTS_AFTER, job.release_date); solver.AddConstraint(prec); } @@ -270,11 +255,10 @@ void EtJobShop(const EtJobShopData& data) { const Job& job = data.GetJob(job_id); IntervalVar* const t = jobs_to_tasks[job_id][machine_count - 1]; IntVar* const penalty = - solver.MakeConvexPiecewiseExpr(t->EndExpr(), - job.early_cost, - job.due_date, - job.due_date, - job.tardy_cost)->Var(); + solver + .MakeConvexPiecewiseExpr(t->EndExpr(), job.early_cost, job.due_date, + job.due_date, job.tardy_cost) + ->Var(); penalties.push_back(penalty); } @@ -307,11 +291,11 @@ void EtJobShop(const EtJobShopData& data) { // conveniently done by fixing the objective variable to its // minimum value. DecisionBuilder* const obj_phase = - FLAGS_time_placement ? - solver.RevAlloc(new TimePlacement(data, all_sequences, jobs_to_tasks)) : - solver.MakePhase(objective_var, - Solver::CHOOSE_FIRST_UNBOUND, - Solver::ASSIGN_MIN_VALUE); + FLAGS_time_placement + ? solver.RevAlloc( + new TimePlacement(data, all_sequences, jobs_to_tasks)) + : solver.MakePhase(objective_var, Solver::CHOOSE_FIRST_UNBOUND, + Solver::ASSIGN_MIN_VALUE); if (FLAGS_use_ls) { Assignment* const first_solution = solver.MakeAssignment(); @@ -344,16 +328,13 @@ void EtJobShop(const EtJobShopData& data) { operators.push_back(swap_operator); LOG(INFO) << " - use shuffle operator with a max length of " << FLAGS_shuffle_length; - LocalSearchOperator* const shuffle_operator = - solver.RevAlloc(new ShuffleIntervals(all_sequences, - FLAGS_shuffle_length)); + LocalSearchOperator* const shuffle_operator = solver.RevAlloc( + new ShuffleIntervals(all_sequences, FLAGS_shuffle_length)); operators.push_back(shuffle_operator); LOG(INFO) << " - use free sub sequences of length " << FLAGS_sub_sequence_length << " lns operator"; - LocalSearchOperator* const lns_operator = - solver.RevAlloc(new SequenceLns(all_sequences, - FLAGS_lns_seed, - FLAGS_sub_sequence_length)); + LocalSearchOperator* const lns_operator = solver.RevAlloc(new SequenceLns( + all_sequences, FLAGS_lns_seed, FLAGS_sub_sequence_length)); operators.push_back(lns_operator); // Creates the local search decision builder. @@ -364,9 +345,8 @@ void EtJobShop(const EtJobShopData& data) { solver.MakeLimit(kint64max, FLAGS_lns_limit, kint64max, kint64max); DecisionBuilder* const random_sequence_phase = solver.MakePhase(all_sequences, Solver::CHOOSE_RANDOM_RANK_FORWARD); - DecisionBuilder* const ls_db = - solver.MakeSolveOnce(solver.Compose(random_sequence_phase, obj_phase), - ls_limit); + DecisionBuilder* const ls_db = solver.MakeSolveOnce( + solver.Compose(random_sequence_phase, obj_phase), ls_limit); LocalSearchPhaseParameters* const parameters = solver.MakeLocalSearchPhaseParameters(concat, ls_db); @@ -381,9 +361,10 @@ void EtJobShop(const EtJobShopData& data) { SearchMonitor* const search_log = solver.MakeSearchLog(kLogFrequency, objective_monitor); - SearchLimit* const limit = FLAGS_time_limit_in_ms > 0 ? - solver.MakeTimeLimit(FLAGS_time_limit_in_ms) : - NULL; + SearchLimit* const limit = + FLAGS_time_limit_in_ms > 0 + ? solver.MakeTimeLimit(FLAGS_time_limit_in_ms) + : NULL; // Search. solver.Solve(final_db, search_log, objective_monitor, limit); @@ -413,7 +394,7 @@ static const char kUsage[] = "Usage: see flags.\nThis program runs a simple job shop optimization " "output besides the debug LOGs of the solver."; -int main(int argc, char **argv) { +int main(int argc, char** argv) { FLAGS_log_prefix = false; gflags::SetUsageMessage(kUsage); gflags::ParseCommandLineFlags(&argc, &argv, true); @@ -421,14 +402,10 @@ int main(int argc, char **argv) { if (!FLAGS_jet_file.empty()) { data.LoadJetFile(FLAGS_jet_file); } else { - data.GenerateRandomData(FLAGS_machine_count, - FLAGS_job_count, - FLAGS_max_release_date, - FLAGS_max_early_cost, - FLAGS_max_tardy_cost, - FLAGS_max_duration, - FLAGS_scale_factor, - FLAGS_seed); + data.GenerateRandomData(FLAGS_machine_count, FLAGS_job_count, + FLAGS_max_release_date, FLAGS_max_early_cost, + FLAGS_max_tardy_cost, FLAGS_max_duration, + FLAGS_scale_factor, FLAGS_seed); } operations_research::EtJobShop(data); return 0; diff --git a/examples/cpp/jobshop_earlytardy.h b/examples/cpp/jobshop_earlytardy.h index 1584b1d5043..ed29071aaa4 100644 --- a/examples/cpp/jobshop_earlytardy.h +++ b/examples/cpp/jobshop_earlytardy.h @@ -39,13 +39,13 @@ #include +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/strtoint.h" #include "ortools/base/random.h" #include "ortools/base/split.h" -#include "ortools/base/filelineiter.h" +#include "ortools/base/stringprintf.h" +#include "ortools/base/strtoint.h" namespace operations_research { struct Task { @@ -57,10 +57,7 @@ struct Task { struct Job { Job(int r, int d, int ew, int tw) - : release_date(r), - due_date(d), - early_cost(ew), - tardy_cost(tw) {} + : release_date(r), due_date(d), early_cost(ew), tardy_cost(tw) {} int release_date; int due_date; int early_cost; @@ -70,10 +67,7 @@ struct Job { class EtJobShopData { public: - EtJobShopData() - : machine_count_(0), - job_count_(0), - horizon_(0) {} + EtJobShopData() : machine_count_(0), job_count_(0), horizon_(0) {} ~EtJobShopData() {} @@ -88,23 +82,14 @@ class EtJobShopData { } } - void GenerateRandomData(int machine_count, - int job_count, - int max_release_date, - int max_early_cost, - int max_tardy_cost, - int max_duration, - int scale_factor, - int seed) { - name_ = StringPrintf("EtJobshop(m%d-j%d-mrd%d-mew%d-mtw%d-md%d-sf%d-s%d)", - machine_count, - job_count, - max_release_date, - max_early_cost, - max_tardy_cost, - max_duration, - scale_factor, - seed); + void GenerateRandomData(int machine_count, int job_count, + int max_release_date, int max_early_cost, + int max_tardy_cost, int max_duration, + int scale_factor, int seed) { + name_ = + StringPrintf("EtJobshop(m%d-j%d-mrd%d-mew%d-mtw%d-md%d-sf%d-s%d)", + machine_count, job_count, max_release_date, max_early_cost, + max_tardy_cost, max_duration, scale_factor, seed); LOG(INFO) << "Generating random problem " << name_; ACMRandom random(seed); machine_count_ = machine_count; @@ -147,9 +132,7 @@ class EtJobShopData { int horizon() const { return horizon_; } // Returns the tasks of a job, ordered by precedence. - const Job& GetJob(int job_id) const { - return all_jobs_[job_id]; - } + const Job& GetJob(int job_id) const { return all_jobs_[job_id]; } private: void ProcessNewJetLine(const std::string& line) { @@ -163,8 +146,8 @@ class EtJobShopData { machine_count_ = atoi32(words[1]); CHECK_GT(machine_count_, 0); CHECK_GT(job_count_, 0); - LOG(INFO) << machine_count_ << " - machines and " - << job_count_ << " jobs"; + LOG(INFO) << machine_count_ << " - machines and " << job_count_ + << " jobs"; } else if (words.size() > 2 && machine_count_ != 0) { const int job_id = all_jobs_.size(); CHECK_EQ(words.size(), machine_count_ * 2 + 3); @@ -192,4 +175,4 @@ class EtJobShopData { std::vector all_jobs_; }; } // namespace operations_research -#endif // OR_TOOLS_EXAMPLES_JOBSHOP_EARLYTARDY_H_ +#endif // OR_TOOLS_EXAMPLES_JOBSHOP_EARLYTARDY_H_ diff --git a/examples/cpp/jobshop_ls.cc b/examples/cpp/jobshop_ls.cc index e2d33370c01..5186c1bec17 100644 --- a/examples/cpp/jobshop_ls.cc +++ b/examples/cpp/jobshop_ls.cc @@ -37,15 +37,14 @@ #include #include -#include "ortools/base/commandlineflags.h" +#include "examples/cpp/jobshop.h" +#include "ortools/base/bitmap.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/bitmap.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" -#include "examples/cpp/jobshop.h" DEFINE_string( data_file, "", diff --git a/examples/cpp/jobshop_ls.h b/examples/cpp/jobshop_ls.h index c917579a0dd..6455203195e 100644 --- a/examples/cpp/jobshop_ls.h +++ b/examples/cpp/jobshop_ls.h @@ -40,12 +40,12 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" +#include "ortools/base/split.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" -#include "ortools/base/split.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" -#include "ortools/base/random.h" namespace operations_research { // ----- Exchange 2 intervals on a sequence variable ----- diff --git a/examples/cpp/jobshop_sat.cc b/examples/cpp/jobshop_sat.cc index 48f16822f96..d118c391302 100644 --- a/examples/cpp/jobshop_sat.cc +++ b/examples/cpp/jobshop_sat.cc @@ -16,15 +16,14 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/logging.h" -#include "ortools/base/timer.h" -#include "google/protobuf/wrappers.pb.h" #include "google/protobuf/text_format.h" +#include "google/protobuf/wrappers.pb.h" +#include "ortools/base/commandlineflags.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/stringpiece_utils.h" #include "ortools/base/strutil.h" +#include "ortools/base/timer.h" #include "ortools/data/jobshop_scheduling.pb.h" #include "ortools/data/jobshop_scheduling_parser.h" #include "ortools/sat/cp_model.pb.h" @@ -56,7 +55,8 @@ int64 ComputeHorizon(const JsspInputProblem& problem) { int64 max_earliest_start = 0; for (const Job& job : problem.jobs()) { if (job.has_latest_end()) { - max_latest_end = std::max(max_latest_end, job.latest_end().value()); + max_latest_end = + std::max(max_latest_end, job.latest_end().value()); } else { max_latest_end = kint64max; } @@ -81,8 +81,8 @@ int64 ComputeHorizon(const JsspInputProblem& problem) { for (int i = 0; i < num_jobs; ++i) { int64 max_transition = 0; for (int j = 0; j < num_jobs; ++j) { - max_transition = - std::max(max_transition, matrix.transition_time(i * num_jobs + j)); + max_transition = std::max( + max_transition, matrix.transition_time(i * num_jobs + j)); } sum_of_transitions += max_transition; } @@ -446,7 +446,7 @@ void Solve(const JsspInputProblem& problem) { int main(int argc, char** argv) { base::SetFlag(&FLAGS_logtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Please supply a data file with --input="; } diff --git a/examples/cpp/linear_assignment_api.cc b/examples/cpp/linear_assignment_api.cc index cf6cfe697b6..a179960f5b5 100644 --- a/examples/cpp/linear_assignment_api.cc +++ b/examples/cpp/linear_assignment_api.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/graph/ebert_graph.h" @@ -67,7 +66,7 @@ void AnotherAssignment() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::AssignmentOn4x4Matrix(); operations_research::AnotherAssignment(); return 0; diff --git a/examples/cpp/linear_programming.cc b/examples/cpp/linear_programming.cc index 7e3743ce882..5067ceaa113 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -14,7 +14,6 @@ // // Linear programming example that shows how to use the API. -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/linear_solver/linear_solver.h" @@ -92,36 +91,36 @@ void RunLinearProgrammingExample( } void RunAllExamples() { - #if defined(USE_GLOP) +#if defined(USE_GLOP) LOG(INFO) << "---- Linear programming example with GLOP ----"; RunLinearProgrammingExample(MPSolver::GLOP_LINEAR_PROGRAMMING); - #endif // USE_GLOP - #if defined(USE_GLPK) +#endif // USE_GLOP +#if defined(USE_GLPK) LOG(INFO) << "---- Linear programming example with GLPK ----"; RunLinearProgrammingExample(MPSolver::GLPK_LINEAR_PROGRAMMING); - #endif // USE_GLPK - #if defined(USE_CLP) +#endif // USE_GLPK +#if defined(USE_CLP) LOG(INFO) << "---- Linear programming example with CLP ----"; RunLinearProgrammingExample(MPSolver::CLP_LINEAR_PROGRAMMING); - #endif // USE_CLP - #if defined(USE_SLM) +#endif // USE_CLP +#if defined(USE_SLM) LOG(INFO) << "---- Linear programming example with Sulum ----"; RunLinearProgrammingExample(MPSolver::SULUM_LINEAR_PROGRAMMING); - #endif // USE_SLM - #if defined(USE_GUROBI) +#endif // USE_SLM +#if defined(USE_GUROBI) LOG(INFO) << "---- Linear programming example with Gurobi ----"; RunLinearProgrammingExample(MPSolver::GUROBI_LINEAR_PROGRAMMING); - #endif // USE_GUROBI - #if defined(USE_CPLEX) +#endif // USE_GUROBI +#if defined(USE_CPLEX) LOG(INFO) << "---- Linear programming example with CPLEX ----"; RunLinearProgrammingExample(MPSolver::CPLEX_LINEAR_PROGRAMMING); - #endif // USE_CPLEX +#endif // USE_CPLEX } } // namespace operations_research int main(int argc, char** argv) { base::SetFlag(&FLAGS_alsologtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::RunAllExamples(); return 0; } diff --git a/examples/cpp/linear_solver_protocol_buffers.cc b/examples/cpp/linear_solver_protocol_buffers.cc index 509fc430763..341a2e76584 100644 --- a/examples/cpp/linear_solver_protocol_buffers.cc +++ b/examples/cpp/linear_solver_protocol_buffers.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include "ortools/base/commandlineflags.h" @@ -63,16 +62,16 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { MPModelRequest model_request; *model_request.mutable_model() = model_proto; - #if defined(USE_GLOP) +#if defined(USE_GLOP) if (type == MPSolver::GLOP_LINEAR_PROGRAMMING) { model_request.set_solver_type(MPModelRequest::GLOP_LINEAR_PROGRAMMING); } - #endif // USE_GLOP - #if defined(USE_CLP) +#endif // USE_GLOP +#if defined(USE_CLP) if (type == MPSolver::CLP_LINEAR_PROGRAMMING) { model_request.set_solver_type(MPModelRequest::CLP_LINEAR_PROGRAMMING); } - #endif // USE_CLP +#endif // USE_CLP MPSolutionResponse solution_response; MPSolver::SolveWithProto(model_request, &solution_response); @@ -88,19 +87,19 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) { } void RunAllExamples() { - #if defined(USE_GLOP) +#if defined(USE_GLOP) LOG(INFO) << "----- Running Max Example with GLOP -----"; BuildLinearProgrammingMaxExample(MPSolver::GLOP_LINEAR_PROGRAMMING); - #endif // USE_GLOP - #if defined(USE_CLP) +#endif // USE_GLOP +#if defined(USE_CLP) LOG(INFO) << "----- Running Max Example with Coin LP -----"; BuildLinearProgrammingMaxExample(MPSolver::CLP_LINEAR_PROGRAMMING); - #endif // USE_CLP +#endif // USE_CLP } } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::RunAllExamples(); return 0; } diff --git a/examples/cpp/ls_api.cc b/examples/cpp/ls_api.cc index 2d18dc068fc..be5f2ac2594 100644 --- a/examples/cpp/ls_api.cc +++ b/examples/cpp/ls_api.cc @@ -17,12 +17,12 @@ // Search with Filter approach. #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/map_util.h" +#include "ortools/base/random.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" -#include "ortools/base/random.h" namespace operations_research { class OneVarLns : public BaseLns { @@ -147,11 +147,7 @@ class SumFilter : public IntVarLocalSearchFilter { int64 sum_; }; -enum SolveType { - LNS, - LS, - LS_WITH_FILTER -}; +enum SolveType { LNS, LS, LS_WITH_FILTER }; void SolveProblem(SolveType solve_type) { Solver s("Sample"); @@ -201,7 +197,7 @@ void SolveProblem(SolveType solve_type) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::SolveProblem(operations_research::LNS); operations_research::SolveProblem(operations_research::LS); operations_research::SolveProblem(operations_research::LS_WITH_FILTER); diff --git a/examples/cpp/magic_square.cc b/examples/cpp/magic_square.cc index 5b6e3c10c11..128b557b4ed 100644 --- a/examples/cpp/magic_square.cc +++ b/examples/cpp/magic_square.cc @@ -19,7 +19,6 @@ // The problem is trivial for odd orders, but not for even orders. // We do not handle odd orders with the trivial method here. -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -149,7 +148,7 @@ void MagicSquare(int grid_size) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_size != 0) { operations_research::MagicSquare(FLAGS_size); } else { diff --git a/examples/cpp/model_util.cc b/examples/cpp/model_util.cc index 238abba7cc1..c92a6f5f2dc 100644 --- a/examples/cpp/model_util.cc +++ b/examples/cpp/model_util.cc @@ -11,24 +11,22 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" #include "ortools/base/recordio.h" -#include "ortools/base/join.h" +#include "ortools/base/status.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/model.pb.h" #include "ortools/constraint_solver/search_limit.pb.h" #include "ortools/util/graph_export.h" #include "ortools/util/string_array.h" -#include "ortools/base/status.h" DEFINE_string(input, "", "Input file of the problem."); DEFINE_string(output, "", "Output file when doing modifications."); @@ -68,16 +66,20 @@ static const char kRed[] = "#A52A2A"; // Creates node labels. std::string ExprLabel(int index) { return StringPrintf("expr_%i", index); } -std::string IntervalLabel(int index) { return StringPrintf("interval_%i", index); } +std::string IntervalLabel(int index) { + return StringPrintf("interval_%i", index); +} -std::string SequenceLabel(int index) { return StringPrintf("sequence_%i", index); } +std::string SequenceLabel(int index) { + return StringPrintf("sequence_%i", index); +} std::string ConstraintLabel(int index) { return StringPrintf("ct_%i", index); } // Scans argument to add links in the graph. template -void ExportLinks(const CpModel& model, const std::string& source, const T& proto, - GraphExporter* const exporter) { +void ExportLinks(const CpModel& model, const std::string& source, + const T& proto, GraphExporter* const exporter) { const std::string& arg_name = model.tags(proto.argument_index()); if (proto.type() == CpArgument::EXPRESSION) { exporter->WriteLink(source, ExprLabel(proto.integer_expression_index()), @@ -207,7 +209,8 @@ void ExportToGraphFile(const CpModel& proto, File* const file, const char kObjLabel[] = "obj"; if (proto.has_objective()) { - const std::string name = proto.objective().maximize() ? "Maximize" : "Minimize"; + const std::string name = + proto.objective().maximize() ? "Maximize" : "Minimize"; exporter->WriteNode(kObjLabel, name, "diamond", kRed); } @@ -348,10 +351,10 @@ int Run() { << JoinDebugStringPtr(primary_integer_variables, ", "); LOG(INFO) << "Secondary integer variables = " << JoinDebugStringPtr(secondary_integer_variables, ", "); - LOG(INFO) << "Sequence variables = " << JoinDebugStringPtr( - sequence_variables, ", "); - LOG(INFO) << "Interval variables = " << JoinDebugStringPtr( - interval_variables, ", "); + LOG(INFO) << "Sequence variables = " + << JoinDebugStringPtr(sequence_variables, ", "); + LOG(INFO) << "Interval variables = " + << JoinDebugStringPtr(interval_variables, ", "); } } @@ -395,7 +398,7 @@ int Run() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Filename not specified"; } diff --git a/examples/cpp/mps_driver.cc b/examples/cpp/mps_driver.cc index 044bb697bec..1d3cc3534f4 100644 --- a/examples/cpp/mps_driver.cc +++ b/examples/cpp/mps_driver.cc @@ -11,30 +11,28 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Driver for reading and solving files in the MPS format and in // the linear_solver.proto format. #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/logging.h" -#include "ortools/base/timer.h" -#include "ortools/base/file.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" #include "google/protobuf/text_format.h" +#include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" +#include "ortools/base/logging.h" +#include "ortools/base/status.h" #include "ortools/base/stringpiece_utils.h" #include "ortools/base/strutil.h" +#include "ortools/base/timer.h" #include "ortools/glop/lp_solver.h" #include "ortools/glop/parameters.pb.h" #include "ortools/lp_data/lp_print_utils.h" #include "ortools/lp_data/mps_reader.h" #include "ortools/lp_data/proto_utils.h" #include "ortools/util/proto_tools.h" -#include "ortools/base/status.h" DEFINE_bool(mps_dump_problem, false, "Dumps problem in readable form."); DEFINE_bool(mps_solve, true, "Solves problem."); @@ -50,17 +48,16 @@ DEFINE_string(params, "", "also specified, the --params will be merged onto " "them (i.e. in case of conflicts, --params wins)"); +using google::protobuf::TextFormat; using operations_research::FullProtocolMessageAsString; using operations_research::glop::GetProblemStatusString; using operations_research::glop::GlopParameters; using operations_research::glop::LinearProgram; using operations_research::glop::LPSolver; -using operations_research::glop::MPSReader; using operations_research::glop::MPModelProtoToLinearProgram; +using operations_research::glop::MPSReader; using operations_research::glop::ProblemStatus; using operations_research::glop::ToDouble; -using google::protobuf::TextFormat; - // Parse glop parameters from the flags --params_file and --params. void ReadGlopParameters(GlopParameters* parameters) { @@ -78,18 +75,16 @@ void ReadGlopParameters(GlopParameters* parameters) { } } - int main(int argc, char* argv[]) { gflags::ParseCommandLineFlags(&argc, &argv, true); GlopParameters parameters; ReadGlopParameters(¶meters); - LinearProgram linear_program; std::vector file_list; // Replace this with your favorite match function. - file_list.push_back(FLAGS_input); + file_list.push_back(FLAGS_input); for (int i = 0; i < file_list.size(); ++i) { const std::string& file_name = file_list[i]; MPSReader mps_reader; @@ -114,7 +109,6 @@ int main(int argc, char* argv[]) { solver.SetParameters(parameters); ProblemStatus solve_status = ProblemStatus::INIT; - std::string status_string; double objective_value; double solving_time_in_sec = 0; diff --git a/examples/cpp/multidim_knapsack.cc b/examples/cpp/multidim_knapsack.cc index a8bca5ef341..7f6a07b4551 100644 --- a/examples/cpp/multidim_knapsack.cc +++ b/examples/cpp/multidim_knapsack.cc @@ -18,15 +18,14 @@ #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/split.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" -#include "ortools/base/split.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/hybrid.h" -#include "ortools/base/filelineiter.h" DEFINE_string( data_file, "", @@ -300,10 +299,12 @@ void SolveKnapsack(MultiDimKnapsackData* const data) { SearchMonitor* const search_log = solver.MakeSearchLog(1000000, objective); monitors.push_back(search_log); } - DecisionBuilder* const db = solver.MakePhase( - assign, [data](int64 var, - int64 value) { return EvaluateItem(*data, var, value); }, - Solver::CHOOSE_STATIC_GLOBAL_BEST); + DecisionBuilder* const db = + solver.MakePhase(assign, + [data](int64 var, int64 value) { + return EvaluateItem(*data, var, value); + }, + Solver::CHOOSE_STATIC_GLOBAL_BEST); if (FLAGS_time_limit_in_ms != 0) { LOG(INFO) << "adding time limit of " << FLAGS_time_limit_in_ms << " ms"; SearchLimit* const limit = solver.MakeLimit( diff --git a/examples/cpp/network_routing.cc b/examples/cpp/network_routing.cc index 5a4dc9c787b..9fcfb55a467 100644 --- a/examples/cpp/network_routing.cc +++ b/examples/cpp/network_routing.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // This model solves a multicommodity mono-routing problem with // capacity constraints and a max usage cost structure. This means // that given a graph with capacity on edges, and a set of demands @@ -26,24 +25,23 @@ // A random problem generator is also included. +#include #include #include -#include #include #include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/random.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/graph/shortestpaths.h" #include "ortools/util/tuple_set.h" -#include "ortools/base/random.h" // ----- Data Generator ----- DEFINE_int32(clients, 0, @@ -770,11 +768,12 @@ class NetworkRoutingSolver { std::vector usage_costs; std::vector comfort_costs; for (int arc_index = 0; arc_index < num_arcs; ++arc_index) { - const int capacity = capacity_[arcs_data_.Value( - 2 * arc_index, 0)][arcs_data_.Value(2 * arc_index, 1)]; + const int capacity = capacity_[arcs_data_.Value(2 * arc_index, 0)] + [arcs_data_.Value(2 * arc_index, 1)]; IntVar* const usage_cost = - solver.MakeDiv(solver.MakeProd(vtraffic[arc_index], kOneThousand), - capacity) + solver + .MakeDiv(solver.MakeProd(vtraffic[arc_index], kOneThousand), + capacity) ->Var(); usage_costs.push_back(usage_cost); IntVar* const comfort_cost = solver.MakeIsGreaterCstVar( @@ -798,7 +797,7 @@ class NetworkRoutingSolver { // DecisionBuilder. Solver::IndexEvaluator2 eval_marginal_cost = [this, &usage_costs]( - int64 var, int64 value) { + int64 var, int64 value) { return EvaluateMarginalCost(usage_costs, var, value); }; @@ -916,7 +915,7 @@ class NetworkRoutingSolver { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::NetworkRoutingData data; operations_research::NetworkRoutingDataBuilder builder; builder.BuildModelFromParameters( diff --git a/examples/cpp/nqueens.cc b/examples/cpp/nqueens.cc index c2100cf1dd2..310294f8813 100644 --- a/examples/cpp/nqueens.cc +++ b/examples/cpp/nqueens.cc @@ -20,12 +20,11 @@ #include #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/map_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" DEFINE_bool(print, false, "If true, print one of the solution."); @@ -266,7 +265,7 @@ void NQueens(int size) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_size != 0) { operations_research::NQueens(FLAGS_size); } else { diff --git a/examples/cpp/nqueens2.cc b/examples/cpp/nqueens2.cc index 734e5afac6d..77018d914b6 100644 --- a/examples/cpp/nqueens2.cc +++ b/examples/cpp/nqueens2.cc @@ -17,7 +17,6 @@ // unique solutions: http://www.research.att.com/~njas/sequences/A000170 // distinct solutions: http://www.research.att.com/~njas/sequences/A002562 - #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -54,7 +53,7 @@ void NQueens(int size) { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::NQueens(FLAGS_size); return 0; } diff --git a/examples/cpp/opb_reader.h b/examples/cpp/opb_reader.h index 9daecc832f4..c74adfe6f39 100644 --- a/examples/cpp/opb_reader.h +++ b/examples/cpp/opb_reader.h @@ -19,12 +19,12 @@ #include #include +#include "ortools/base/filelineiter.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/strtoint.h" #include "ortools/base/split.h" +#include "ortools/base/strtoint.h" #include "ortools/sat/boolean_problem.pb.h" -#include "ortools/base/filelineiter.h" namespace operations_research { namespace sat { diff --git a/examples/cpp/parse_dimacs_assignment.cc b/examples/cpp/parse_dimacs_assignment.cc index 479d9fa931d..bb00d432cb3 100644 --- a/examples/cpp/parse_dimacs_assignment.cc +++ b/examples/cpp/parse_dimacs_assignment.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "examples/cpp/parse_dimacs_assignment.h" #include "ortools/base/commandlineflags.h" diff --git a/examples/cpp/parse_dimacs_assignment.h b/examples/cpp/parse_dimacs_assignment.h index 0a8608071f8..f3a78a39128 100644 --- a/examples/cpp/parse_dimacs_assignment.h +++ b/examples/cpp/parse_dimacs_assignment.h @@ -27,10 +27,10 @@ #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/logging.h" #include "ortools/graph/ebert_graph.h" #include "ortools/graph/linear_assignment.h" -#include "ortools/base/filelineiter.h" DECLARE_bool(assignment_maximize_cost); DECLARE_bool(assignment_optimize_layout); @@ -98,7 +98,8 @@ class DimacsAssignmentParser { // Implementation is below here. template -void DimacsAssignmentParser::ParseProblemLine(const std::string& line) { +void DimacsAssignmentParser::ParseProblemLine( + const std::string& line) { static const char* kIncorrectProblemLine = "Incorrect assignment problem line."; static const char* kAssignmentProblemType = "asn"; diff --git a/examples/cpp/pdptw.cc b/examples/cpp/pdptw.cc index 368b799d6cd..261c6c9d4d2 100644 --- a/examples/cpp/pdptw.cc +++ b/examples/cpp/pdptw.cc @@ -40,12 +40,11 @@ #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/strtoint.h" #include "ortools/base/file.h" -#include "ortools/base/split.h" #include "ortools/base/mathutil.h" +#include "ortools/base/split.h" +#include "ortools/base/stringprintf.h" +#include "ortools/base/strtoint.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" @@ -103,9 +102,10 @@ int64 Demand(const std::vector* const demands, } // Outputs a solution to the current model in a std::string. -std::string VerboseOutput(const RoutingModel& routing, const Assignment& assignment, - const Coordinates& coords, - const std::vector& service_times) { +std::string VerboseOutput(const RoutingModel& routing, + const Assignment& assignment, + const Coordinates& coords, + const std::vector& service_times) { std::string output; const RoutingDimension& time_dimension = routing.GetDimensionOrDie("time"); const RoutingDimension& load_dimension = routing.GetDimensionOrDie("demand"); @@ -148,8 +148,10 @@ std::string VerboseOutput(const RoutingModel& routing, const Assignment& assignm namespace { // An inefficient but convenient method to parse a whitespace-separated list -// of integers. Returns true iff the input std::string was entirely valid and parsed. -bool SafeParseInt64Array(const std::string& str, std::vector* parsed_int) { +// of integers. Returns true iff the input std::string was entirely valid and +// parsed. +bool SafeParseInt64Array(const std::string& str, + std::vector* parsed_int) { static const char kWhiteSpaces[] = " \t\n\v\f\r"; std::vector items = absl::StrSplit( str, absl::delimiter::AnyOf(kWhiteSpaces), absl::SkipEmpty()); @@ -304,7 +306,7 @@ bool LoadAndSolve(const std::string& pdp_file) { int main(int argc, char** argv) { base::SetFlag(&FLAGS_logtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (!operations_research::LoadAndSolve(FLAGS_pdp_file)) { LOG(INFO) << "Error solving " << FLAGS_pdp_file; } diff --git a/examples/cpp/print_dimacs_assignment.cc b/examples/cpp/print_dimacs_assignment.cc index 6b3197a3583..a109a52ccc9 100644 --- a/examples/cpp/print_dimacs_assignment.cc +++ b/examples/cpp/print_dimacs_assignment.cc @@ -23,10 +23,8 @@ namespace operations_research { -static void WriteOrDie(const char* buffer, - size_t item_size, - size_t buffer_length, - FILE* fp) { +static void WriteOrDie(const char* buffer, size_t item_size, + size_t buffer_length, FILE* fp) { size_t written = fwrite(buffer, item_size, buffer_length, fp); if (written != buffer_length) { fprintf(stderr, "Write failed.\n"); @@ -34,40 +32,31 @@ static void WriteOrDie(const char* buffer, } } - void PrintDimacsAssignmentProblem( const LinearSumAssignment& assignment, const TailArrayManager& tail_array_manager, const string& output_filename) { FILE* output = fopen(output_filename.c_str(), "w"); const ForwardStarGraph& graph(assignment.Graph()); - string output_line = StringPrintf("p asn %d %d\n", - graph.num_nodes(), - graph.num_arcs()); - WriteOrDie(output_line.c_str(), 1, output_line.length(), - output); + string output_line = + StringPrintf("p asn %d %d\n", graph.num_nodes(), graph.num_arcs()); + WriteOrDie(output_line.c_str(), 1, output_line.length(), output); - for (LinearSumAssignment::BipartiteLeftNodeIterator - node_it(assignment); - node_it.Ok(); - node_it.Next()) { + for (LinearSumAssignment::BipartiteLeftNodeIterator node_it( + assignment); + node_it.Ok(); node_it.Next()) { output_line = StringPrintf("n %d\n", node_it.Index() + 1); - WriteOrDie(output_line.c_str(), 1, output_line.length(), - output); + WriteOrDie(output_line.c_str(), 1, output_line.length(), output); } tail_array_manager.BuildTailArrayFromAdjacencyListsIfForwardGraph(); - for (ForwardStarGraph::ArcIterator arc_it(assignment.Graph()); - arc_it.Ok(); + for (ForwardStarGraph::ArcIterator arc_it(assignment.Graph()); arc_it.Ok(); arc_it.Next()) { ArcIndex arc = arc_it.Index(); - output_line = StringPrintf("a %d %d %lld\n", - graph.Tail(arc) + 1, - graph.Head(arc) + 1, - assignment.ArcCost(arc)); - WriteOrDie(output_line.c_str(), 1, output_line.length(), - output); + output_line = StringPrintf("a %d %d %lld\n", graph.Tail(arc) + 1, + graph.Head(arc) + 1, assignment.ArcCost(arc)); + WriteOrDie(output_line.c_str(), 1, output_line.length(), output); } } diff --git a/examples/cpp/print_dimacs_assignment.h b/examples/cpp/print_dimacs_assignment.h index b2a5dfa594f..6ffda492aca 100644 --- a/examples/cpp/print_dimacs_assignment.h +++ b/examples/cpp/print_dimacs_assignment.h @@ -21,12 +21,12 @@ #include #include +#include "ortools/base/file.h" #include "ortools/base/logging.h" +#include "ortools/base/status.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" #include "ortools/graph/ebert_graph.h" #include "ortools/graph/linear_assignment.h" -#include "ortools/base/status.h" namespace operations_research { diff --git a/examples/cpp/rcpsp_sat.cc b/examples/cpp/rcpsp_sat.cc index db08dc908e7..c2a06d7da74 100644 --- a/examples/cpp/rcpsp_sat.cc +++ b/examples/cpp/rcpsp_sat.cc @@ -13,7 +13,6 @@ #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/base/timer.h" @@ -275,7 +274,7 @@ void LoadAndSolve(const std::string& file_name) { int main(int argc, char** argv) { base::SetFlag(&FLAGS_logtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Please supply a data file with --input="; } diff --git a/examples/cpp/sat_cnf_reader.h b/examples/cpp/sat_cnf_reader.h index 08a27810d43..cc4e88286df 100644 --- a/examples/cpp/sat_cnf_reader.h +++ b/examples/cpp/sat_cnf_reader.h @@ -21,16 +21,16 @@ #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/strtoint.h" +#include "ortools/base/span.h" #include "ortools/base/split.h" #include "ortools/base/string_view.h" -#include "ortools/base/span.h" +#include "ortools/base/strtoint.h" #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/cp_model.pb.h" -#include "ortools/base/filelineiter.h" DEFINE_bool(wcnf_use_strong_slack, true, "If true, when we add a slack variable to reify a soft clause, we " @@ -196,8 +196,8 @@ class SatCnfReader { int64 StringPieceAtoi(absl::string_view input) { // Hack: data() is not null terminated, but we do know that it points - // inside a std::string where numbers are separated by " " and since atoi64 will - // stop at the first invalid char, this works. + // inside a std::string where numbers are separated by " " and since atoi64 + // will stop at the first invalid char, this works. return atoi64(input.data()); // NOLINT } diff --git a/examples/cpp/sat_runner.cc b/examples/cpp/sat_runner.cc index a7cfed9ee5f..f762d657d9d 100644 --- a/examples/cpp/sat_runner.cc +++ b/examples/cpp/sat_runner.cc @@ -18,17 +18,20 @@ #include #include +#include "examples/cpp/opb_reader.h" +#include "examples/cpp/sat_cnf_reader.h" +#include "google/protobuf/text_format.h" +#include "ortools/algorithms/sparse_permutation.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" +#include "ortools/base/status.h" +#include "ortools/base/stringpiece_utils.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" #include "ortools/base/timer.h" -#include "ortools/base/file.h" -#include "google/protobuf/text_format.h" -#include "ortools/base/join.h" -#include "ortools/base/stringpiece_utils.h" -#include "ortools/algorithms/sparse_permutation.h" #include "ortools/sat/boolean_problem.h" #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/cp_model.pb.h" @@ -36,12 +39,9 @@ #include "ortools/sat/drat_proof_handler.h" #include "ortools/sat/lp_utils.h" #include "ortools/sat/model.h" -#include "examples/cpp/opb_reader.h" #include "ortools/sat/optimization.h" #include "ortools/sat/pb_constraint.h" #include "ortools/sat/sat_base.h" -#include "examples/cpp/sat_cnf_reader.h" -#include "ortools/base/stringprintf.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/sat/sat_solver.h" #include "ortools/sat/simplification.h" @@ -49,7 +49,6 @@ #include "ortools/util/file_util.h" #include "ortools/util/sigint.h" #include "ortools/util/time_limit.h" -#include "ortools/base/status.h" DEFINE_string( input, "", @@ -114,7 +113,6 @@ DEFINE_bool(presolve, true, DEFINE_bool(probing, false, "If true, presolve the problem using probing."); - DEFINE_bool(use_cp_model, true, "Whether to interpret everything as a CpModelProto or " "to read by default a CpModelProto."); @@ -139,8 +137,8 @@ double GetScaledTrivialBestBound(const LinearBooleanProblem& problem) { return AddOffsetAndScaleObjectiveValue(problem, best_bound); } -void LoadBooleanProblem(const std::string& filename, LinearBooleanProblem* problem, - CpModelProto* cp_model) { +void LoadBooleanProblem(const std::string& filename, + LinearBooleanProblem* problem, CpModelProto* cp_model) { if (strings::EndsWith(filename, ".opb") || strings::EndsWith(filename, ".opb.bz2")) { OpbReader reader; @@ -175,7 +173,7 @@ void LoadBooleanProblem(const std::string& filename, LinearBooleanProblem* probl } std::string SolutionString(const LinearBooleanProblem& problem, - const std::vector& assignment) { + const std::vector& assignment) { std::string output; BooleanVariable limit(problem.original_num_variables()); for (BooleanVariable index(0); index < limit; ++index) { @@ -199,11 +197,11 @@ int Run() { // Parse the --params flag. if (!FLAGS_params.empty()) { - CHECK(google::protobuf::TextFormat::MergeFromString(FLAGS_params, ¶meters)) + CHECK(google::protobuf::TextFormat::MergeFromString(FLAGS_params, + ¶meters)) << FLAGS_params; } - // Initialize the solver. std::unique_ptr solver(new SatSolver()); solver->SetParameters(parameters); diff --git a/examples/cpp/shift_minimization_sat.cc b/examples/cpp/shift_minimization_sat.cc index 8d0b30e47df..b32b90432a1 100644 --- a/examples/cpp/shift_minimization_sat.cc +++ b/examples/cpp/shift_minimization_sat.cc @@ -33,11 +33,10 @@ #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/logging.h" -#include "ortools/base/strtoint.h" #include "ortools/base/filelineiter.h" +#include "ortools/base/logging.h" #include "ortools/base/split.h" +#include "ortools/base/strtoint.h" #include "ortools/sat/cp_constraints.h" #include "ortools/sat/cp_model_solver.h" #include "ortools/sat/integer_expr.h" @@ -331,7 +330,7 @@ void LoadAndSolve(const std::string& file_name) { int main(int argc, char** argv) { base::SetFlag(&FLAGS_logtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Please supply a data file with --input="; } diff --git a/examples/cpp/slitherlink.cc b/examples/cpp/slitherlink.cc index 1b536a67418..19dc406217a 100644 --- a/examples/cpp/slitherlink.cc +++ b/examples/cpp/slitherlink.cc @@ -1,48 +1,37 @@ #include -#include #include #include +#include #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/string_array.h" const std::vector> small = { - { 3, 2, -1, 3 }, - { -1, -1, -1, 2 }, - { 3, -1, -1, -1 }, - { 3, -1, 3, 1 } -}; + {3, 2, -1, 3}, {-1, -1, -1, 2}, {3, -1, -1, -1}, {3, -1, 3, 1}}; const std::vector> medium = { - { -1, 0, -1, 1, -1, -1, 1, -1 }, - { -1, 3, -1, -1, 2, 3, -1, 2 }, - { -1, -1, 0, -1, -1, -1, -1, 0 }, - { -1, 3, -1, -1, 0, -1, -1, -1 }, - { -1, -1, -1, 3, -1, -1, 0, -1 }, - { 1, -1, -1, -1, -1, 3, -1, -1 }, - { 3, -1, 1, 3, -1, -1, 3, -1 }, - { -1, 0, -1, -1, 3, -1, 3, -1 } -}; + {-1, 0, -1, 1, -1, -1, 1, -1}, {-1, 3, -1, -1, 2, 3, -1, 2}, + {-1, -1, 0, -1, -1, -1, -1, 0}, {-1, 3, -1, -1, 0, -1, -1, -1}, + {-1, -1, -1, 3, -1, -1, 0, -1}, {1, -1, -1, -1, -1, 3, -1, -1}, + {3, -1, 1, 3, -1, -1, 3, -1}, {-1, 0, -1, -1, 3, -1, 3, -1}}; const std::vector> big = { - { 3, -1, -1, -1, 2, -1, 1, -1, 1, 2 }, - { 1, -1, 0, -1, 3, -1, 2, 0, -1, -1 }, - { -1, 3, -1, -1, -1, -1, -1, -1, 3, -1 }, - { 2, 0, -1, 3, -1, 2, 3, -1, -1, -1 }, - { -1, -1, -1, 1, 1, 1, -1, -1, 3, 3 }, - { 2, 3, -1, -1, 2, 2, 3, -1, -1, -1 }, - { -1, -1, -1, 1, 2, -1, 2, -1, 3, 3 }, - { -1, 2, -1, -1, -1, -1, -1, -1, 2, -1 }, - { -1, -1, 1, 1, -1, 2, -1, 1, -1, 3 }, - { 3, 3, -1, 1, -1, 2, -1, -1, -1, 2 } -}; + {3, -1, -1, -1, 2, -1, 1, -1, 1, 2}, + {1, -1, 0, -1, 3, -1, 2, 0, -1, -1}, + {-1, 3, -1, -1, -1, -1, -1, -1, 3, -1}, + {2, 0, -1, 3, -1, 2, 3, -1, -1, -1}, + {-1, -1, -1, 1, 1, 1, -1, -1, 3, 3}, + {2, 3, -1, -1, 2, 2, 3, -1, -1, -1}, + {-1, -1, -1, 1, 2, -1, 2, -1, 3, 3}, + {-1, 2, -1, -1, -1, -1, -1, -1, 2, -1}, + {-1, -1, 1, 1, -1, 2, -1, 1, -1, 3}, + {3, 3, -1, 1, -1, 2, -1, -1, -1, 2}}; namespace operations_research { namespace { std::vector NeighboringArcs( - int i, int j, - const std::vector>& h_arcs, + int i, int j, const std::vector>& h_arcs, const std::vector>& v_arcs) { std::vector tmp; if (j > 0) { @@ -166,9 +155,7 @@ class GridSinglePath : public Constraint { GridSinglePath(Solver* const solver, const std::vector>& h_arcs, const std::vector>& v_arcs) - : Constraint(solver), - h_arcs_(h_arcs), - v_arcs_(v_arcs) {} + : Constraint(solver), h_arcs_(h_arcs), v_arcs_(v_arcs) {} ~GridSinglePath() {} @@ -251,7 +238,7 @@ class GridSinglePath : public Constraint { } if (visited_points.size() < possible_points.size()) { - for (const int point: visited_points) { + for (const int point : visited_points) { possible_points.erase(point); } // Loop on unreachable points and zero all neighboring arcs. @@ -338,15 +325,15 @@ void SlitherLink(const std::vector>& data) { for (int j = 0; j < num_columns; ++j) { const int value = data[i][j]; if (value != -1) { - std::vector square = { h_arcs[i][j], h_arcs[i + 1][j], - v_arcs[j][i], v_arcs[j + 1][i] }; + std::vector square = {h_arcs[i][j], h_arcs[i + 1][j], + v_arcs[j][i], v_arcs[j + 1][i]}; solver.AddConstraint(solver.MakeSumEquality(square, value)); } } } // Single loop: each node has a degree 0 or 2. - const std::vector zero_or_two = { 0, 2 }; + const std::vector zero_or_two = {0, 2}; for (int i = 0; i < num_rows + 1; ++i) { for (int j = 0; j < num_columns + 1; ++j) { const std::vector neighbors = @@ -405,7 +392,7 @@ void SlitherLink(const std::vector>& data) { } solver.EndSearch(); } -} // namespace operations_research +} // namespace operations_research int main() { std::cout << "Small problem" << std::endl; diff --git a/examples/cpp/solve.cc b/examples/cpp/solve.cc index 51b01348ab9..c45250516b2 100644 --- a/examples/cpp/solve.cc +++ b/examples/cpp/solve.cc @@ -19,12 +19,11 @@ #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/file.h" //#include "ortools/base/options.h" #include "ortools/base/stringpiece_utils.h" #include "ortools/linear_solver/linear_solver.h" @@ -204,7 +203,6 @@ void Run() { LOG(FATAL) << "Unsupported --dump_format: " << FLAGS_dump_format; } - // Create the solver, we use the name of the model as the solver name. MPSolver solver(model_proto.name(), type); solver.EnableOutput(); @@ -248,7 +246,6 @@ void Run() { printf("%-12s: %d x %d\n", "Dimension", solver.NumConstraints(), solver.NumVariables()); - // Solve. MPSolverParameters param; MPSolver::ResultStatus solve_status = MPSolver::NOT_SOLVED; @@ -318,7 +315,7 @@ void Run() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, /*remove_flags=*/true); + gflags::ParseCommandLineFlags(&argc, &argv, /*remove_flags=*/true); CHECK(!FLAGS_input.empty()) << "--input is required"; operations_research::Run(); } diff --git a/examples/cpp/sports_scheduling.cc b/examples/cpp/sports_scheduling.cc index 0fec194c30c..15bf9c55510 100644 --- a/examples/cpp/sports_scheduling.cc +++ b/examples/cpp/sports_scheduling.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Sports scheduling problem. // // We want to solve the problem of scheduling of team matches in a @@ -56,7 +55,6 @@ // // Usage: run this with --helpshort for a short usage manual. -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" diff --git a/examples/cpp/strawberry_fields_with_column_generation.cc b/examples/cpp/strawberry_fields_with_column_generation.cc index 83dbdcce367..22209456ba3 100644 --- a/examples/cpp/strawberry_fields_with_column_generation.cc +++ b/examples/cpp/strawberry_fields_with_column_generation.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Demonstration of column generation using LP toolkit. // // Column generation is the technique of generating columns (aka @@ -60,7 +59,6 @@ #include #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" @@ -443,8 +441,9 @@ class CoveringProblem { } std::string PrintGrid() const { - std::string output = StringPrintf("width = %d, height = %d, max_boxes = %d\n", - width_, height_, max_boxes_); + std::string output = + StringPrintf("width = %d, height = %d, max_boxes = %d\n", width_, + height_, max_boxes_); for (int y = 0; y < height_; ++y) { StringAppendF(&output, "%s\n", std::string(grid_ + width_ * y, width_).c_str()); @@ -458,7 +457,8 @@ class CoveringProblem { // of fractional boxes. std::string PrintCovering() const { static const double kTolerance = 1e-5; - std::string output = StringPrintf("cost = %lf\n", solver_->Objective().Value()); + std::string output = + StringPrintf("cost = %lf\n", solver_->Objective().Value()); std::unique_ptr display(new char[(width_ + 1) * height_ + 1]); for (int y = 0; y < height_; ++y) { memcpy(display.get() + y * (width_ + 1), grid_ + width_ * y, @@ -602,22 +602,22 @@ int main(int argc, char** argv) { usage += " --colgen_max_iterations max columns to generate\n"; usage += " --colgen_complete generate all columns at start\n"; - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::MPSolver::OptimizationProblemType solver_type; bool found = false; - #if defined(USE_GLOP) +#if defined(USE_GLOP) if (FLAGS_colgen_solver == "glop") { solver_type = operations_research::MPSolver::GLOP_LINEAR_PROGRAMMING; found = true; } - #endif // USE_GLOP - #if defined(USE_CLP) +#endif // USE_GLOP +#if defined(USE_CLP) if (FLAGS_colgen_solver == "clp") { solver_type = operations_research::MPSolver::CLP_LINEAR_PROGRAMMING; found = true; } - #endif // USE_CLP +#endif // USE_CLP if (!found) { LOG(ERROR) << "Unknown solver " << FLAGS_colgen_solver; return 1; diff --git a/examples/cpp/tsp.cc b/examples/cpp/tsp.cc index 015fe08a81a..ffb865e0cb3 100644 --- a/examples/cpp/tsp.cc +++ b/examples/cpp/tsp.cc @@ -27,17 +27,15 @@ #include +#include "google/protobuf/text_format.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "google/protobuf/text_format.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/random.h" #include "ortools/constraint_solver/routing.h" #include "ortools/constraint_solver/routing_enums.pb.h" #include "ortools/constraint_solver/routing_flags.h" -#include "ortools/base/random.h" DEFINE_int32(tsp_size, 10, "Size of Traveling Salesman Problem instance."); DEFINE_bool(tsp_use_random_matrix, true, "Use random cost matrix."); @@ -163,7 +161,7 @@ void Tsp() { } // namespace operations_research int main(int argc, char** argv) { - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); operations_research::Tsp(); return 0; } diff --git a/examples/cpp/weighted_tardiness_sat.cc b/examples/cpp/weighted_tardiness_sat.cc index 755a5ece16d..1bfdf139a0c 100644 --- a/examples/cpp/weighted_tardiness_sat.cc +++ b/examples/cpp/weighted_tardiness_sat.cc @@ -15,19 +15,18 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/commandlineflags.h" -#include "ortools/base/logging.h" -#include "ortools/base/timer.h" #include "google/protobuf/text_format.h" +#include "ortools/base/commandlineflags.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/numbers.h" #include "ortools/base/split.h" #include "ortools/base/strutil.h" +#include "ortools/base/timer.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_solver.h" #include "ortools/sat/model.h" -#include "ortools/base/filelineiter.h" DEFINE_string(input, "examples/data/weighted_tardiness/wt40.txt", "wt data file name."); @@ -305,7 +304,7 @@ void ParseAndSolve() { int main(int argc, char** argv) { base::SetFlag(&FLAGS_logtostderr, true); - gflags::ParseCommandLineFlags( &argc, &argv, true); + gflags::ParseCommandLineFlags(&argc, &argv, true); if (FLAGS_input.empty()) { LOG(FATAL) << "Please supply a data file with --input="; } diff --git a/ortools/algorithms/dynamic_partition.cc b/ortools/algorithms/dynamic_partition.cc index 6506c40a0e2..83a2e8f0c26 100644 --- a/ortools/algorithms/dynamic_partition.cc +++ b/ortools/algorithms/dynamic_partition.cc @@ -15,10 +15,9 @@ #include -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" #include "ortools/base/murmur.h" +#include "ortools/base/stringprintf.h" namespace operations_research { @@ -114,8 +113,8 @@ void DynamicPartition::Refine(const std::vector& distinguished_subset) { const int old_index = index_of_[element]; const int new_index = part_[part].end_index - num_distinguished_elements_in_part; - DCHECK_GE(new_index, old_index) << "Duplicate element given to Refine(): " - << element; + DCHECK_GE(new_index, old_index) + << "Duplicate element given to Refine(): " << element; // Perform the swap, keeping index_of_ up to date. index_of_[element] = new_index; index_of_[element_[new_index]] = old_index; diff --git a/ortools/algorithms/dynamic_partition.h b/ortools/algorithms/dynamic_partition.h index 82915e7ed4f..c02df507151 100644 --- a/ortools/algorithms/dynamic_partition.h +++ b/ortools/algorithms/dynamic_partition.h @@ -22,10 +22,10 @@ // (aka "elements") into disjoint equivalence classes (aka "parts"). // // SAFETY: -// Like std::vector crashes when used improperly, these classes are not "safe": -// most of their methods may crash if called with invalid arguments. The client -// code is responsible for using this class properly. A few DCHECKs() will help -// catch bugs, though. +// Like std::vector crashes when used improperly, these classes are not +// "safe": most of their methods may crash if called with invalid arguments. The +// client code is responsible for using this class properly. A few DCHECKs() +// will help catch bugs, though. #ifndef OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_ #define OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_ @@ -111,8 +111,8 @@ class DynamicPartition { // Prerequisite: NumParts() >= original_num_parts. void UndoRefineUntilNumPartsEqual(int original_num_parts); - // Dump the partition to a std::string. There might be different conventions for - // sorting the parts and the elements inside them. + // Dump the partition to a std::string. There might be different conventions + // for sorting the parts and the elements inside them. enum DebugStringSorting { // Elements are sorted within parts, and parts are then sorted // lexicographically. @@ -272,8 +272,8 @@ class MergingPartition { // *** Implementation of inline methods of the above classes. *** -inline DynamicPartition::IterablePart DynamicPartition::ElementsInPart(int i) - const { +inline DynamicPartition::IterablePart DynamicPartition::ElementsInPart( + int i) const { DCHECK_GE(i, 0); DCHECK_LT(i, NumParts()); return IterablePart(element_.begin() + part_[i].start_index, diff --git a/ortools/algorithms/find_graph_symmetries.cc b/ortools/algorithms/find_graph_symmetries.cc index 503e6020e80..4a1b590242c 100644 --- a/ortools/algorithms/find_graph_symmetries.cc +++ b/ortools/algorithms/find_graph_symmetries.cc @@ -17,18 +17,17 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" -#include "ortools/base/time_support.h" -#include "ortools/graph/iterators.h" -#include "ortools/graph/util.h" #include "ortools/algorithms/dense_doubly_linked_list.h" #include "ortools/algorithms/dynamic_partition.h" #include "ortools/algorithms/dynamic_permutation.h" #include "ortools/algorithms/sparse_permutation.h" #include "ortools/base/canonical_errors.h" +#include "ortools/base/commandlineflags.h" +#include "ortools/base/join.h" +#include "ortools/base/stringprintf.h" +#include "ortools/base/time_support.h" +#include "ortools/graph/iterators.h" +#include "ortools/graph/util.h" DEFINE_bool(minimize_permutation_support_size, false, "Tweak the algorithm to try and minimize the support size" @@ -40,7 +39,6 @@ namespace operations_research { using util::GraphIsSymmetric; - namespace { // Some routines used below. void SwapFrontAndBack(std::vector* v) { @@ -131,8 +129,9 @@ GraphSymmetryFinder::GraphSymmetryFinder(const Graph& graph, bool is_undirected) flattened_reverse_adj_lists_.assign(graph.num_arcs(), -1); for (const int node : graph.AllNodes()) { for (const int arc : graph.OutgoingArcs(node)) { - flattened_reverse_adj_lists_ - [reverse_adj_list_index_[graph.Head(arc) + /*shift*/ 1]++] = node; + flattened_reverse_adj_lists_[reverse_adj_list_index_[graph.Head(arc) + + /*shift*/ 1]++] = + node; } } // The last pass shifted reverse_adj_list_index, so it's now as we want it: @@ -408,7 +407,7 @@ util::Status GraphSymmetryFinder::FindSymmetries( int num_parts_before_refinement; InvariantDiveState(int node, int num_parts) - : invariant_node(node), num_parts_before_refinement(num_parts) {} + : invariant_node(node), num_parts_before_refinement(num_parts) {} }; std::vector invariant_dive_stack; // TODO(user): experiment with, and briefly describe the results of various @@ -958,8 +957,9 @@ bool GraphSymmetryFinder::ConfirmFullMatchOrFindNextMappingDecision( // We found loose ends, but none that mapped to its own root. Just pick // any valid image. *next_image_node = - *image_partition.ElementsInPart( - base_partition.PartOf(*next_base_node)).begin(); + *image_partition + .ElementsInPart(base_partition.PartOf(*next_base_node)) + .begin(); return false; } } diff --git a/ortools/algorithms/find_graph_symmetries.h b/ortools/algorithms/find_graph_symmetries.h index 0635c945bd8..bd6d3aace34 100644 --- a/ortools/algorithms/find_graph_symmetries.h +++ b/ortools/algorithms/find_graph_symmetries.h @@ -27,19 +27,18 @@ #include #include -#include "ortools/graph/graph.h" -#include "ortools/graph/iterators.h" #include "ortools/algorithms/dynamic_partition.h" #include "ortools/algorithms/dynamic_permutation.h" +#include "ortools/base/status.h" +#include "ortools/graph/graph.h" +#include "ortools/graph/iterators.h" #include "ortools/util/stats.h" #include "ortools/util/time_limit.h" -#include "ortools/base/status.h" namespace operations_research { class SparsePermutation; - class GraphSymmetryFinder { public: typedef ::util::StaticGraph<> Graph; @@ -116,8 +115,8 @@ class GraphSymmetryFinder { // In our use cases, we may call this in a scenario where the partition was // already partially refined on all parts #0...#K, then you should set // "first_unrefined_part_index" to K+1. - void RecursivelyRefinePartitionByAdjacency( - int first_unrefined_part_index, DynamicPartition* partition); + void RecursivelyRefinePartitionByAdjacency(int first_unrefined_part_index, + DynamicPartition* partition); // **** Methods below are public FOR TESTING ONLY. **** @@ -230,74 +229,51 @@ class GraphSymmetryFinder { // Temporary objects used by some of the class methods, and owned by the // class to avoid (costly) re-allocation. Their resting states are described // in the side comments; with N = NumNodes(). - DynamicPermutation tmp_dynamic_permutation_; // Identity(N) - mutable std::vector tmp_node_mask_; // [0..N-1] = false - std::vector tmp_degree_; // [0..N-1] = 0. - std::vector tmp_stack_; // Empty. + DynamicPermutation tmp_dynamic_permutation_; // Identity(N) + mutable std::vector tmp_node_mask_; // [0..N-1] = false + std::vector tmp_degree_; // [0..N-1] = 0. + std::vector tmp_stack_; // Empty. std::vector > tmp_nodes_with_degree_; // [0..N-1] = []. - MergingPartition tmp_partition_; // Reset(N). + MergingPartition tmp_partition_; // Reset(N). std::vector tmp_compatible_permutations_; // Empty. // Internal statistics, used for performance tuning and debugging. struct Stats : public StatsGroup { Stats() : StatsGroup("GraphSymmetryFinder"), - initialization_time( - "a Initialization", this), - initialization_refine_time( - "b ┗╸Refine", this), - invariant_dive_time( - "c Invariant Dive", this), - main_search_time( - "d Main Search", this), - invariant_unroll_time( - "e ┣╸Dive unroll", this), - permutation_output_time( - "f ┣╸Permutation output", this), - search_time( - "g ┗╸FindOneSuitablePermutation()", this), - search_time_fail( - "h ┣╸Fail", this), - search_time_success( - "i ┣╸Success", this), - initial_search_refine_time( - "j ┣╸Initial refine", this), - search_refine_time( - "k ┣╸Further refines", this), - quick_compatibility_time( - "l ┣╸Compatibility checks", this), - quick_compatibility_fail_time( - "m ┃ ┣╸Fail", this), - quick_compatibility_success_time( - "n ┃ ┗╸Success", this), + initialization_time("a Initialization", this), + initialization_refine_time("b ┗╸Refine", this), + invariant_dive_time("c Invariant Dive", this), + main_search_time("d Main Search", this), + invariant_unroll_time("e ┣╸Dive unroll", this), + permutation_output_time("f ┣╸Permutation output", this), + search_time("g ┗╸FindOneSuitablePermutation()", this), + search_time_fail("h ┣╸Fail", this), + search_time_success("i ┣╸Success", this), + initial_search_refine_time("j ┣╸Initial refine", this), + search_refine_time("k ┣╸Further refines", this), + quick_compatibility_time("l ┣╸Compatibility checks", this), + quick_compatibility_fail_time("m ┃ ┣╸Fail", this), + quick_compatibility_success_time("n ┃ ┗╸Success", this), dynamic_permutation_refinement_time( "o ┣╸Dynamic permutation refinement", this), map_election_std_time( "p ┣╸Mapping election / full match detection", this), - map_election_std_mapping_time( - "q ┃ ┣╸Mapping elected", this), - map_election_std_full_match_time( - "r ┃ ┗╸Full Match", this), - automorphism_test_time( - "s ┣╸[Upon full match] Automorphism check", this), - automorphism_test_fail_time( - "t ┃ ┣╸Fail", this), - automorphism_test_success_time( - "u ┃ ┗╸Success", this), - search_finalize_time( - "v ┣╸[Upon auto success] Finalization", this), + map_election_std_mapping_time("q ┃ ┣╸Mapping elected", this), + map_election_std_full_match_time("r ┃ ┗╸Full Match", this), + automorphism_test_time("s ┣╸[Upon full match] Automorphism check", + this), + automorphism_test_fail_time("t ┃ ┣╸Fail", this), + automorphism_test_success_time("u ┃ ┗╸Success", this), + search_finalize_time("v ┣╸[Upon auto success] Finalization", this), dynamic_permutation_undo_time( "w ┣╸[Upon auto fail, full] Dynamic permutation undo", this), map_reelection_time( "x ┣╸[Upon auto fail, partial] Mapping re-election", this), - non_singleton_search_time( - "y ┃ ┗╸Non-singleton search", this), - backtracking_time( - "z ┗╸Backtracking", this), - pruning_time( - "{ ┗╸Pruning", this), - search_depth( - "~ Search Stats: search_depth", this) {} + non_singleton_search_time("y ┃ ┗╸Non-singleton search", this), + backtracking_time("z ┗╸Backtracking", this), + pruning_time("{ ┗╸Pruning", this), + search_depth("~ Search Stats: search_depth", this) {} TimeDistribution initialization_time; TimeDistribution initialization_refine_time; diff --git a/ortools/algorithms/hungarian.cc b/ortools/algorithms/hungarian.cc index e46c8592a9b..8c819c15988 100644 --- a/ortools/algorithms/hungarian.cc +++ b/ortools/algorithms/hungarian.cc @@ -50,11 +50,7 @@ class HungarianOptimizer { private: typedef void (HungarianOptimizer::*Step)(); - typedef enum { - NONE, - PRIME, - STAR - } Mark; + typedef enum { NONE, PRIME, STAR } Mark; // Convert the final cost matrix into a set of assignments of agents -> tasks. // Returns the assignment in the two vectors passed as argument, the same as diff --git a/ortools/algorithms/hungarian.h b/ortools/algorithms/hungarian.h index a124bf3bef3..bee92381c71 100644 --- a/ortools/algorithms/hungarian.h +++ b/ortools/algorithms/hungarian.h @@ -41,16 +41,14 @@ namespace operations_research { // See IMPORTANT NOTE at the top of the file. -void MinimizeLinearAssignment( - const std::vector >& cost, - std::unordered_map* direct_assignment, - std::unordered_map* reverse_assignment); +void MinimizeLinearAssignment(const std::vector >& cost, + std::unordered_map* direct_assignment, + std::unordered_map* reverse_assignment); // See IMPORTANT NOTE at the top of the file. -void MaximizeLinearAssignment( - const std::vector >& cost, - std::unordered_map* direct_assignment, - std::unordered_map* reverse_assignment); +void MaximizeLinearAssignment(const std::vector >& cost, + std::unordered_map* direct_assignment, + std::unordered_map* reverse_assignment); } // namespace operations_research #endif // OR_TOOLS_ALGORITHMS_HUNGARIAN_H_ diff --git a/ortools/algorithms/hungarian_test.cc b/ortools/algorithms/hungarian_test.cc index 13c72b4de50..4758b8b86ad 100644 --- a/ortools/algorithms/hungarian_test.cc +++ b/ortools/algorithms/hungarian_test.cc @@ -3,11 +3,11 @@ #include "ortools/algorithms/hungarian.h" #include +#include "gtest/gtest.h" #include "ortools/base/integral_types.h" #include "ortools/base/macros.h" #include "ortools/base/map_util.h" #include "ortools/base/random.h" -#include "gtest/gtest.h" namespace operations_research { @@ -67,7 +67,7 @@ TEST(LinearAssignmentTest, NullMatrix) { #define MATRIX_TEST \ { \ - std::vector > cost(kMatrixHeight); \ + std::vector > cost(kMatrixHeight); \ for (int row = 0; row < kMatrixHeight; ++row) { \ cost[row].resize(kMatrixWidth); \ for (int col = 0; col < kMatrixWidth; ++col) { \ diff --git a/ortools/algorithms/knapsack_solver.cc b/ortools/algorithms/knapsack_solver.cc index a9059d97b96..2b0c370576e 100644 --- a/ortools/algorithms/knapsack_solver.cc +++ b/ortools/algorithms/knapsack_solver.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/algorithms/knapsack_solver.h" #include @@ -377,9 +376,10 @@ void KnapsackGenericSolver::GetLowerAndUpperBoundWhenItem(int item_id, *lower_bound = 0LL; *upper_bound = 0LL; } else { - *lower_bound = (HasOnePropagator()) ? propagators_[master_propagator_id_] - ->profit_lower_bound() - : 0LL; + *lower_bound = + (HasOnePropagator()) + ? propagators_[master_propagator_id_]->profit_lower_bound() + : 0LL; *upper_bound = GetAggregatedProfitUpperBound(); } @@ -530,8 +530,8 @@ void KnapsackGenericSolver::UpdateBestSolution() { if (best_solution_profit_ < profit_lower_bound) { best_solution_profit_ = profit_lower_bound; - propagators_[master_propagator_id_] - ->CopyCurrentStateToSolution(HasOnePropagator(), &best_solution_); + propagators_[master_propagator_id_]->CopyCurrentStateToSolution( + HasOnePropagator(), &best_solution_); } } @@ -567,7 +567,8 @@ class KnapsackBruteForceSolver : public BaseKnapsackSolver { DISALLOW_COPY_AND_ASSIGN(KnapsackBruteForceSolver); }; -KnapsackBruteForceSolver::KnapsackBruteForceSolver(const std::string& solver_name) +KnapsackBruteForceSolver::KnapsackBruteForceSolver( + const std::string& solver_name) : BaseKnapsackSolver(solver_name), num_items_(0), capacity_(0LL), @@ -1051,7 +1052,8 @@ class KnapsackMIPSolver : public BaseKnapsackSolver { }; KnapsackMIPSolver::KnapsackMIPSolver( - MPSolver::OptimizationProblemType problem_type, const std::string& solver_name) + MPSolver::OptimizationProblemType problem_type, + const std::string& solver_name) : BaseKnapsackSolver(solver_name), problem_type_(problem_type), profits_(), @@ -1137,18 +1139,18 @@ KnapsackSolver::KnapsackSolver(SolverType solver_type, case KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER: solver_.reset(new KnapsackGenericSolver(solver_name)); break; - #if defined(USE_CBC) +#if defined(USE_CBC) case KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER: solver_.reset(new KnapsackMIPSolver( MPSolver::CBC_MIXED_INTEGER_PROGRAMMING, solver_name)); break; - #endif // USE_CBC - #if defined(USE_SCIP) +#endif // USE_CBC +#if defined(USE_SCIP) case KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER: solver_.reset(new KnapsackMIPSolver( MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING, solver_name)); break; - #endif // USE_SCIP +#endif // USE_SCIP default: LOG(FATAL) << "Unknown knapsack solver type."; } @@ -1334,8 +1336,9 @@ void KnapsackSolver::InitReducedProblem( int64 KnapsackSolver::Solve() { return additional_profit_ + - ((is_problem_solved_) ? 0 : solver_->Solve(time_limit_.get(), - &is_solution_optimal_)); + ((is_problem_solved_) + ? 0 + : solver_->Solve(time_limit_.get(), &is_solution_optimal_)); } bool KnapsackSolver::BestSolutionContains(int item_id) const { diff --git a/ortools/algorithms/knapsack_solver.h b/ortools/algorithms/knapsack_solver.h index 6cc8dbf5dc7..cc9b9e77140 100644 --- a/ortools/algorithms/knapsack_solver.h +++ b/ortools/algorithms/knapsack_solver.h @@ -115,13 +115,13 @@ class KnapsackSolver { KNAPSACK_BRUTE_FORCE_SOLVER = 0, KNAPSACK_64ITEMS_SOLVER = 1, KNAPSACK_DYNAMIC_PROGRAMMING_SOLVER = 2, - #if defined(USE_CBC) +#if defined(USE_CBC) KNAPSACK_MULTIDIMENSION_CBC_MIP_SOLVER = 3, - #endif // USE_CBC +#endif // USE_CBC KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER = 5, - #if defined(USE_SCIP) +#if defined(USE_SCIP) KNAPSACK_MULTIDIMENSION_SCIP_MIP_SOLVER = 6, - #endif // USE_SCIP +#endif // USE_SCIP }; explicit KnapsackSolver(const std::string& solver_name); @@ -407,8 +407,8 @@ class KnapsackPropagator { // called with current state. // This method is useful when a propagator is able to find a better solution // than the blind instantiation to false of unbound items. - virtual void CopyCurrentStateToSolutionPropagator(std::vector* solution) - const = 0; + virtual void CopyCurrentStateToSolutionPropagator( + std::vector* solution) const = 0; const KnapsackState& state() const { return state_; } const std::vector& items() const { return items_; } diff --git a/ortools/algorithms/sparse_permutation.cc b/ortools/algorithms/sparse_permutation.cc index b85897c50c5..86edf2e612c 100644 --- a/ortools/algorithms/sparse_permutation.cc +++ b/ortools/algorithms/sparse_permutation.cc @@ -14,9 +14,8 @@ #include "ortools/algorithms/sparse_permutation.h" #include -#include "ortools/base/logging.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" namespace operations_research { diff --git a/ortools/algorithms/sparse_permutation.h b/ortools/algorithms/sparse_permutation.h index c9173274936..59e5db08112 100644 --- a/ortools/algorithms/sparse_permutation.h +++ b/ortools/algorithms/sparse_permutation.h @@ -103,7 +103,8 @@ struct SparsePermutation::Iterator { Iterator() {} Iterator(const std::vector::const_iterator& b, - const std::vector::const_iterator& e) : begin_(b), end_(e) {} + const std::vector::const_iterator& e) + : begin_(b), end_(e) {} std::vector::const_iterator begin() const { return begin_; } std::vector::const_iterator end() const { return end_; } diff --git a/ortools/base/accurate_sum.h b/ortools/base/accurate_sum.h index 392d101b311..dd9d984f6b0 100644 --- a/ortools/base/accurate_sum.h +++ b/ortools/base/accurate_sum.h @@ -11,8 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - - #ifndef OR_TOOLS_BASE_ACCURATE_SUM_H_ #define OR_TOOLS_BASE_ACCURATE_SUM_H_ diff --git a/ortools/base/callback.cc b/ortools/base/callback.cc index b11a9135c1e..37fcb5693e0 100644 --- a/ortools/base/callback.cc +++ b/ortools/base/callback.cc @@ -16,7 +16,8 @@ namespace operations_research { void CallbackUtils_::FailIsRepeatable(const char* name) { - LOG(FATAL) << "A " << name << " made with NewCallback() " - "is not a repeatable callback!"; + LOG(FATAL) << "A " << name + << " made with NewCallback() " + "is not a repeatable callback!"; } } // namespace operations_research diff --git a/ortools/base/callback.h b/ortools/base/callback.h index 9568236ee11..7990a2fc1b1 100644 --- a/ortools/base/callback.h +++ b/ortools/base/callback.h @@ -160,9 +160,9 @@ struct is_class_or_union { static small_ tester(void (U::*)()); template static big_ tester(...); - #ifndef SWIG +#ifndef SWIG static const bool value = sizeof(tester(0)) == sizeof(small_); - #endif // SWIG +#endif // SWIG }; template @@ -182,8 +182,9 @@ struct ConstRef { // ----- Callback specializations ----- -template ::value>::type> +template ::value>::type> class _ConstMemberResultCallback_0_0 : public ResultCallback { public: typedef ResultCallback base; @@ -219,8 +220,8 @@ class _ConstMemberResultCallback_0_0 : public ResultCallback { template class _ConstMemberResultCallback_0_0< - del, void, T, - typename c_enable_if::value>::type> : public Closure { + del, void, T, typename c_enable_if::value>::type> + : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)() const; @@ -267,8 +268,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)() const) { } #endif -template ::value>::type> +template ::value>::type> class _MemberResultCallback_0_0 : public ResultCallback { public: typedef ResultCallback base; @@ -304,8 +306,8 @@ class _MemberResultCallback_0_0 : public ResultCallback { template class _MemberResultCallback_0_0< - del, void, T, - typename c_enable_if::value>::type> : public Closure { + del, void, T, typename c_enable_if::value>::type> + : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)(); @@ -428,9 +430,9 @@ NewPermanentCallback(R (*function)()) { return new _FunctionResultCallback_0_0(function); } -template < - bool del, class R, class T, class P1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_1_0 : public ResultCallback { public: typedef ResultCallback base; @@ -468,8 +470,8 @@ class _ConstMemberResultCallback_1_0 : public ResultCallback { template class _ConstMemberResultCallback_1_0< - del, void, T, P1, - typename c_enable_if::value>::type> : public Closure { + del, void, T, P1, typename c_enable_if::value>::type> + : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)(P1) const; @@ -520,9 +522,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1) const, } #endif -template < - bool del, class R, class T, class P1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_1_0 : public ResultCallback { public: typedef ResultCallback base; @@ -560,8 +562,8 @@ class _MemberResultCallback_1_0 : public ResultCallback { template class _MemberResultCallback_1_0< - del, void, T, P1, - typename c_enable_if::value>::type> : public Closure { + del, void, T, P1, typename c_enable_if::value>::type> + : public Closure { public: typedef Closure base; typedef void (T::*MemberSignature)(P1); @@ -691,9 +693,9 @@ NewPermanentCallback(R (*function)(P1), typename ConstRef::type p1) { return new _FunctionResultCallback_1_0(function, p1); } -template < - bool del, class R, class T, class P1, class P2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_2_0 : public ResultCallback { public: typedef ResultCallback base; @@ -794,9 +796,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2) const, } #endif -template < - bool del, class R, class T, class P1, class P2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_2_0 : public ResultCallback { public: typedef ResultCallback base; @@ -983,9 +985,9 @@ NewPermanentCallback(R (*function)(P1, P2), typename ConstRef::type p1, return new _FunctionResultCallback_2_0(function, p1, p2); } -template < - bool del, class R, class T, class P1, class P2, class P3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_3_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1098,9 +1100,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3) const, } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_3_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1306,9 +1308,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3), typename ConstRef::type p1, p3); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_4_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1406,11 +1408,12 @@ class _ConstMemberResultCallback_4_0< #ifndef SWIG template -inline typename _ConstMemberResultCallback_4_0::base* -NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4) { +inline + typename _ConstMemberResultCallback_4_0::base* + NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { return new _ConstMemberResultCallback_4_0( obj, member, p1, p2, p3, p4); } @@ -1418,21 +1421,21 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, #ifndef SWIG template -inline typename _ConstMemberResultCallback_4_0::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, - typename ConstRef::type p1, - typename ConstRef::type p2, - typename ConstRef::type p3, - typename ConstRef::type p4) { +inline + typename _ConstMemberResultCallback_4_0::base* + NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { return new _ConstMemberResultCallback_4_0( obj, member, p1, p2, p3, p4); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_4_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1658,8 +1661,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4), } template ::value>::type> + class P5, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_5_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1792,8 +1796,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5) const, #endif template ::value>::type> + class P5, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_5_0 : public ResultCallback { public: typedef ResultCallback base; @@ -1898,12 +1903,12 @@ class _MemberResultCallback_5_0< #ifndef SWIG template -inline typename _MemberResultCallback_5_0::base* -NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4, - typename ConstRef::type p5) { +inline + typename _MemberResultCallback_5_0::base* + NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { return new _MemberResultCallback_5_0( obj, member, p1, p2, p3, p4, p5); } @@ -1912,14 +1917,14 @@ NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), #ifndef SWIG template -inline typename _MemberResultCallback_5_0::base* -NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), - typename ConstRef::type p1, - typename ConstRef::type p2, - typename ConstRef::type p3, - typename ConstRef::type p4, - typename ConstRef::type p5) { +inline + typename _MemberResultCallback_5_0::base* + NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, P5), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4, + typename ConstRef::type p5) { return new _MemberResultCallback_5_0( obj, member, p1, p2, p3, p4, p5); } @@ -1975,8 +1980,8 @@ class _FunctionResultCallback_5_0 : public ResultCallback { }; template -class _FunctionResultCallback_5_0 : public Closure { +class _FunctionResultCallback_5_0 + : public Closure { public: typedef Closure base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5); @@ -2044,8 +2049,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5), } template ::value>::type> + class P5, class P6, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_6_0 : public ResultCallback { public: typedef ResultCallback base; @@ -2163,8 +2169,9 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, P6) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_0< - true, R, T1, P1, P2, P3, P4, P5, P6>(obj, member, p1, p2, p3, p4, p5, p6); + return new _ConstMemberResultCallback_6_0(obj, member, p1, p2, p3, p4, p5, + p6); } #endif @@ -2185,8 +2192,9 @@ NewPermanentCallback( #endif template ::value>::type> + class P5, class P6, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_6_0 : public ResultCallback { public: typedef ResultCallback base; @@ -2380,8 +2388,8 @@ class _FunctionResultCallback_6_0 : public ResultCallback { }; template -class _FunctionResultCallback_6_0 : public Closure { +class _FunctionResultCallback_6_0 + : public Closure { public: typedef Closure base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6); @@ -2431,12 +2439,13 @@ class _FunctionResultCallback_6_0 -inline typename _FunctionResultCallback_6_0::base* -NewCallback(R (*function)(P1, P2, P3, P4, P5, P6), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4, - typename ConstRef::type p5, typename ConstRef::type p6) { +inline + typename _FunctionResultCallback_6_0::base* + NewCallback(R (*function)(P1, P2, P3, P4, P5, P6), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5, + typename ConstRef::type p6) { return new _FunctionResultCallback_6_0( function, p1, p2, p3, p4, p5, p6); } @@ -2455,9 +2464,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6), function, p1, p2, p3, p4, p5, p6); } -template < - bool del, class R, class T, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_0_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -2493,8 +2502,8 @@ class _ConstMemberResultCallback_0_1 : public ResultCallback1 { template class _ConstMemberResultCallback_0_1< - del, void, T, A1, typename c_enable_if::value>::type> : public Callback1 { + del, void, T, A1, typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(A1) const; @@ -2541,9 +2550,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(A1) const) { } #endif -template < - bool del, class R, class T, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_0_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -2578,9 +2587,9 @@ class _MemberResultCallback_0_1 : public ResultCallback1 { }; template -class _MemberResultCallback_0_1::value>::type> : public Callback1 { +class _MemberResultCallback_0_1< + del, void, T, A1, typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(A1); @@ -2703,9 +2712,9 @@ NewPermanentCallback(R (*function)(A1)) { return new _FunctionResultCallback_0_1(function); } -template < - bool del, class R, class T, class P1, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_1_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -2743,8 +2752,9 @@ class _ConstMemberResultCallback_1_1 : public ResultCallback1 { template class _ConstMemberResultCallback_1_1< - del, void, T, P1, A1, typename c_enable_if::value>::type> : public Callback1 { + del, void, T, P1, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, A1) const; @@ -2797,9 +2807,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1) const, } #endif -template < - bool del, class R, class T, class P1, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_1_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -2836,9 +2846,10 @@ class _MemberResultCallback_1_1 : public ResultCallback1 { }; template -class _MemberResultCallback_1_1::value>::type> : public Callback1 { +class _MemberResultCallback_1_1< + del, void, T, P1, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, A1); @@ -2968,9 +2979,9 @@ NewPermanentCallback(R (*function)(P1, A1), typename ConstRef::type p1) { return new _FunctionResultCallback_1_1(function, p1); } -template < - bool del, class R, class T, class P1, class P2, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_2_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3014,8 +3025,9 @@ class _ConstMemberResultCallback_2_1 : public ResultCallback1 { template class _ConstMemberResultCallback_2_1< - del, void, T, P1, P2, A1, typename c_enable_if::value>::type> : public Callback1 { + del, void, T, P1, P2, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, A1) const; @@ -3071,9 +3083,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1) const, } #endif -template < - bool del, class R, class T, class P1, class P2, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_2_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3116,9 +3128,10 @@ class _MemberResultCallback_2_1 : public ResultCallback1 { }; template -class _MemberResultCallback_2_1::value>::type> : public Callback1 { +class _MemberResultCallback_2_1< + del, void, T, P1, P2, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, A1); @@ -3212,8 +3225,8 @@ class _FunctionResultCallback_2_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_2_1 : public Callback1 { +class _FunctionResultCallback_2_1 + : public Callback1 { public: typedef Callback1 base; typedef void (*FunctionSignature)(P1, P2, A1); @@ -3262,9 +3275,9 @@ NewPermanentCallback(R (*function)(P1, P2, A1), typename ConstRef::type p1, p2); } -template < - bool del, class R, class T, class P1, class P2, class P3, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_3_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3311,8 +3324,9 @@ class _ConstMemberResultCallback_3_1 : public ResultCallback1 { template class _ConstMemberResultCallback_3_1< - del, void, T, P1, P2, P3, A1, typename c_enable_if::value>::type> : public Callback1 { + del, void, T, P1, P2, P3, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1) const; @@ -3356,11 +3370,11 @@ class _ConstMemberResultCallback_3_1< #ifndef SWIG template -inline typename _ConstMemberResultCallback_3_1::base* -NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3) { +inline + typename _ConstMemberResultCallback_3_1::base* + NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { return new _ConstMemberResultCallback_3_1( obj, member, p1, p2, p3); } @@ -3368,20 +3382,20 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, #ifndef SWIG template -inline typename _ConstMemberResultCallback_3_1::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, - typename ConstRef::type p1, - typename ConstRef::type p2, - typename ConstRef::type p3) { +inline + typename _ConstMemberResultCallback_3_1::base* + NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1) const, + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { return new _ConstMemberResultCallback_3_1( obj, member, p1, p2, p3); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class A1, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_3_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3427,9 +3441,10 @@ class _MemberResultCallback_3_1 : public ResultCallback1 { }; template -class _MemberResultCallback_3_1::value>::type> : public Callback1 { +class _MemberResultCallback_3_1< + del, void, T, P1, P2, P3, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1); @@ -3538,8 +3553,8 @@ class _FunctionResultCallback_3_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_3_1 : public Callback1 { +class _FunctionResultCallback_3_1 + : public Callback1 { public: typedef Callback1 base; typedef void (*FunctionSignature)(P1, P2, P3, A1); @@ -3594,8 +3609,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, A1), } template ::value>::type> + class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_4_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3646,8 +3662,8 @@ class _ConstMemberResultCallback_4_1 : public ResultCallback1 { template class _ConstMemberResultCallback_4_1< del, void, T, P1, P2, P3, P4, A1, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback1 { + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1) const; @@ -3721,8 +3737,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1) const, #endif template ::value>::type> + class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_4_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -3771,9 +3788,10 @@ class _MemberResultCallback_4_1 : public ResultCallback1 { }; template -class _MemberResultCallback_4_1::value>::type> : public Callback1 { +class _MemberResultCallback_4_1< + del, void, T, P1, P2, P3, P4, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1); @@ -3821,11 +3839,12 @@ class _MemberResultCallback_4_1 -inline typename _MemberResultCallback_4_1::base* -NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4) { +inline + typename _MemberResultCallback_4_1::base* + NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { return new _MemberResultCallback_4_1( obj, member, p1, p2, p3, p4); } @@ -3834,13 +3853,13 @@ NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), #ifndef SWIG template -inline typename _MemberResultCallback_4_1::base* -NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), - typename ConstRef::type p1, - typename ConstRef::type p2, - typename ConstRef::type p3, - typename ConstRef::type p4) { +inline + typename _MemberResultCallback_4_1::base* + NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, P4, A1), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { return new _MemberResultCallback_4_1( obj, member, p1, p2, p3, p4); } @@ -3893,8 +3912,8 @@ class _FunctionResultCallback_4_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_4_1 : public Callback1 { +class _FunctionResultCallback_4_1 + : public Callback1 { public: typedef Callback1 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, A1); @@ -3958,8 +3977,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1), } template ::value>::type> + class P5, class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_5_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -4014,8 +4034,8 @@ template class _ConstMemberResultCallback_5_1< del, void, T, P1, P2, P3, P4, P5, A1, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback1 { + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1) const; @@ -4072,8 +4092,9 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_1< - true, R, T1, P1, P2, P3, P4, P5, A1>(obj, member, p1, p2, p3, p4, p5); + return new _ConstMemberResultCallback_5_1(obj, member, p1, p2, p3, p4, + p5); } #endif @@ -4089,14 +4110,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_1< - false, R, T1, P1, P2, P3, P4, P5, A1>(obj, member, p1, p2, p3, p4, p5); + return new _ConstMemberResultCallback_5_1(obj, member, p1, p2, p3, p4, + p5); } #endif template ::value>::type> + class P5, class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_5_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -4149,9 +4172,10 @@ class _MemberResultCallback_5_1 : public ResultCallback1 { template -class _MemberResultCallback_5_1::value>::type> : public Callback1 { +class _MemberResultCallback_5_1< + del, void, T, P1, P2, P3, P4, P5, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1); @@ -4280,8 +4304,8 @@ class _FunctionResultCallback_5_1 : public ResultCallback1 { }; template -class _FunctionResultCallback_5_1 : public Callback1 { +class _FunctionResultCallback_5_1 + : public Callback1 { public: typedef Callback1 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1); @@ -4328,12 +4352,12 @@ class _FunctionResultCallback_5_1 -inline typename _FunctionResultCallback_5_1::base* -NewCallback(R (*function)(P1, P2, P3, P4, P5, A1), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4, - typename ConstRef::type p5) { +inline + typename _FunctionResultCallback_5_1::base* + NewCallback(R (*function)(P1, P2, P3, P4, P5, A1), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, typename ConstRef::type p4, + typename ConstRef::type p5) { return new _FunctionResultCallback_5_1( function, p1, p2, p3, p4, p5); } @@ -4352,8 +4376,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1), } template ::value>::type> + class P5, class P6, class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_6_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -4411,8 +4436,8 @@ template class _ConstMemberResultCallback_6_1< del, void, T, P1, P2, P3, P4, P5, P6, A1, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback1 { + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1) const; @@ -4488,15 +4513,16 @@ NewPermanentCallback( typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_1< - false, R, T1, P1, P2, P3, P4, P5, P6, A1>(obj, member, p1, p2, p3, p4, p5, - p6); + return new _ConstMemberResultCallback_6_1(obj, member, p1, p2, p3, p4, + p5, p6); } #endif template ::value>::type> + class P5, class P6, class A1, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_6_1 : public ResultCallback1 { public: typedef ResultCallback1 base; @@ -4552,9 +4578,10 @@ class _MemberResultCallback_6_1 : public ResultCallback1 { template -class _MemberResultCallback_6_1::value>::type> : public Callback1 { +class _MemberResultCallback_6_1< + del, void, T, P1, P2, P3, P4, P5, P6, A1, + typename c_enable_if::value>::type> + : public Callback1 { public: typedef Callback1 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1); @@ -4691,8 +4718,8 @@ class _FunctionResultCallback_6_1 : public ResultCallback1 { template -class _FunctionResultCallback_6_1 : public Callback1 { +class _FunctionResultCallback_6_1 + : public Callback1 { public: typedef Callback1 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1); @@ -4768,9 +4795,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1), function, p1, p2, p3, p4, p5, p6); } -template < - bool del, class R, class T, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_0_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -4806,8 +4833,9 @@ class _ConstMemberResultCallback_0_2 : public ResultCallback2 { template class _ConstMemberResultCallback_0_2< - del, void, T, A1, A2, typename c_enable_if::value>::type> : public Callback2 { + del, void, T, A1, A2, + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(A1, A2) const; @@ -4854,9 +4882,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2) const) { } #endif -template < - bool del, class R, class T, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_0_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -4892,8 +4920,9 @@ class _MemberResultCallback_0_2 : public ResultCallback2 { template class _MemberResultCallback_0_2< - del, void, T, A1, A2, typename c_enable_if::value>::type> : public Callback2 { + del, void, T, A1, A2, + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(A1, A2); @@ -4974,8 +5003,8 @@ class _FunctionResultCallback_0_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_0_2 : public Callback2 { +class _FunctionResultCallback_0_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(A1, A2); @@ -5017,9 +5046,9 @@ NewPermanentCallback(R (*function)(A1, A2)) { return new _FunctionResultCallback_0_2(function); } -template < - bool del, class R, class T, class P1, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_1_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5060,8 +5089,9 @@ class _ConstMemberResultCallback_1_2 : public ResultCallback2 { template class _ConstMemberResultCallback_1_2< - del, void, T, P1, A1, A2, typename c_enable_if::value>::type> : public Callback2 { + del, void, T, P1, A1, A2, + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, A1, A2) const; @@ -5114,9 +5144,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2) const, } #endif -template < - bool del, class R, class T, class P1, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_1_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5157,8 +5187,9 @@ class _MemberResultCallback_1_2 : public ResultCallback2 { template class _MemberResultCallback_1_2< - del, void, T, P1, A1, A2, typename c_enable_if::value>::type> : public Callback2 { + del, void, T, P1, A1, A2, + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, A1, A2); @@ -5247,8 +5278,8 @@ class _FunctionResultCallback_1_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_1_2 : public Callback2< - A1, A2> { +class _FunctionResultCallback_1_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, A1, A2); @@ -5293,9 +5324,9 @@ NewPermanentCallback(R (*function)(P1, A1, A2), return new _FunctionResultCallback_1_2(function, p1); } -template < - bool del, class R, class T, class P1, class P2, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_2_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5340,8 +5371,8 @@ class _ConstMemberResultCallback_2_2 : public ResultCallback2 { template class _ConstMemberResultCallback_2_2< del, void, T, P1, P2, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2) const; @@ -5382,10 +5413,11 @@ class _ConstMemberResultCallback_2_2< #ifndef SWIG template -inline typename _ConstMemberResultCallback_2_2::base* -NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, - typename ConstRef::type p1, typename ConstRef::type p2) { +inline + typename _ConstMemberResultCallback_2_2::base* + NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { return new _ConstMemberResultCallback_2_2( obj, member, p1, p2); } @@ -5393,19 +5425,19 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, #ifndef SWIG template -inline typename _ConstMemberResultCallback_2_2::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, - typename ConstRef::type p1, - typename ConstRef::type p2) { +inline + typename _ConstMemberResultCallback_2_2::base* + NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2) const, + typename ConstRef::type p1, + typename ConstRef::type p2) { return new _ConstMemberResultCallback_2_2( obj, member, p1, p2); } #endif -template < - bool del, class R, class T, class P1, class P2, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_2_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5450,8 +5482,8 @@ class _MemberResultCallback_2_2 : public ResultCallback2 { template class _MemberResultCallback_2_2< del, void, T, P1, P2, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2); @@ -5549,8 +5581,8 @@ class _FunctionResultCallback_2_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_2_2 : public Callback2< - A1, A2> { +class _FunctionResultCallback_2_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, P2, A1, A2); @@ -5602,8 +5634,9 @@ NewPermanentCallback(R (*function)(P1, P2, A1, A2), } template ::value>::type> + class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_3_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5651,8 +5684,8 @@ class _ConstMemberResultCallback_3_2 : public ResultCallback2 { template class _ConstMemberResultCallback_3_2< del, void, T, P1, P2, P3, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2) const; @@ -5722,8 +5755,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, A1, A2) const, #endif template ::value>::type> + class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_3_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5771,8 +5805,8 @@ class _MemberResultCallback_3_2 : public ResultCallback2 { template class _MemberResultCallback_3_2< del, void, T, P1, P2, P3, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2); @@ -5817,11 +5851,11 @@ class _MemberResultCallback_3_2< #ifndef SWIG template -inline typename _MemberResultCallback_3_2::base* -NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3) { +inline + typename _MemberResultCallback_3_2::base* + NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { return new _MemberResultCallback_3_2( obj, member, p1, p2, p3); } @@ -5830,12 +5864,12 @@ NewCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), #ifndef SWIG template -inline typename _MemberResultCallback_3_2::base* -NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), - typename ConstRef::type p1, - typename ConstRef::type p2, - typename ConstRef::type p3) { +inline + typename _MemberResultCallback_3_2::base* + NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, P3, A1, A2), + typename ConstRef::type p1, + typename ConstRef::type p2, + typename ConstRef::type p3) { return new _MemberResultCallback_3_2( obj, member, p1, p2, p3); } @@ -5885,8 +5919,8 @@ class _FunctionResultCallback_3_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_3_2 : public Callback2 { +class _FunctionResultCallback_3_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, P2, P3, A1, A2); @@ -5941,8 +5975,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2), } template ::value>::type> + class A1, class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_4_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -5994,8 +6029,8 @@ template class _ConstMemberResultCallback_4_2< del, void, T, P1, P2, P3, P4, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2) const; @@ -6070,8 +6105,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A1, class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_4_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -6123,8 +6159,8 @@ template class _MemberResultCallback_4_2< del, void, T, P1, P2, P3, P4, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2); @@ -6245,8 +6281,8 @@ class _FunctionResultCallback_4_2 : public ResultCallback2 { }; template -class _FunctionResultCallback_4_2 : public Callback2 { +class _FunctionResultCallback_4_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2); @@ -6290,11 +6326,12 @@ class _FunctionResultCallback_4_2 -inline typename _FunctionResultCallback_4_2::base* -NewCallback(R (*function)(P1, P2, P3, P4, A1, A2), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3, typename ConstRef::type p4) { +inline + typename _FunctionResultCallback_4_2::base* + NewCallback(R (*function)(P1, P2, P3, P4, A1, A2), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3, + typename ConstRef::type p4) { return new _FunctionResultCallback_4_2( function, p1, p2, p3, p4); } @@ -6312,8 +6349,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2), } template ::value>::type> + class P5, class A1, class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_5_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -6368,8 +6406,8 @@ template class _ConstMemberResultCallback_5_2< del, void, T, P1, P2, P3, P4, P5, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2) const; @@ -6426,8 +6464,9 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_2< - true, R, T1, P1, P2, P3, P4, P5, A1, A2>(obj, member, p1, p2, p3, p4, p5); + return new _ConstMemberResultCallback_5_2(obj, member, p1, p2, p3, p4, + p5); } #endif @@ -6450,8 +6489,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class P5, class A1, class A2, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_5_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -6506,8 +6546,8 @@ template class _MemberResultCallback_5_2< del, void, T, P1, P2, P3, P4, P5, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2); @@ -6637,8 +6677,8 @@ class _FunctionResultCallback_5_2 : public ResultCallback2 { template -class _FunctionResultCallback_5_2 : public Callback2 { +class _FunctionResultCallback_5_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2); @@ -6710,10 +6750,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2), function, p1, p2, p3, p4, p5); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_6_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -6771,8 +6811,8 @@ template class _ConstMemberResultCallback_6_2< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2) const; @@ -6849,16 +6889,16 @@ NewPermanentCallback( typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_2< - false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2>(obj, member, p1, p2, p3, p4, - p5, p6); + return new _ConstMemberResultCallback_6_2(obj, member, p1, p2, p3, + p4, p5, p6); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_6_2 : public ResultCallback2 { public: typedef ResultCallback2 base; @@ -6916,8 +6956,8 @@ template class _MemberResultCallback_6_2< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback2 { + typename c_enable_if::value>::type> + : public Callback2 { public: typedef Callback2 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2); @@ -7054,8 +7094,8 @@ class _FunctionResultCallback_6_2 : public ResultCallback2 { template -class _FunctionResultCallback_6_2 : public Callback2 { +class _FunctionResultCallback_6_2 + : public Callback2 { public: typedef Callback2 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2); @@ -7131,9 +7171,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2), A2>(function, p1, p2, p3, p4, p5, p6); } -template < - bool del, class R, class T, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_0_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7170,8 +7210,8 @@ class _ConstMemberResultCallback_0_3 : public ResultCallback3 { template class _ConstMemberResultCallback_0_3< del, void, T, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(A1, A2, A3) const; @@ -7220,9 +7260,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3) const) { } #endif -template < - bool del, class R, class T, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_0_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7259,8 +7299,8 @@ class _MemberResultCallback_0_3 : public ResultCallback3 { template class _MemberResultCallback_0_3< del, void, T, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(A1, A2, A3); @@ -7341,8 +7381,8 @@ class _FunctionResultCallback_0_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_0_3 : public Callback3< - A1, A2, A3> { +class _FunctionResultCallback_0_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(A1, A2, A3); @@ -7384,9 +7424,9 @@ NewPermanentCallback(R (*function)(A1, A2, A3)) { return new _FunctionResultCallback_0_3(function); } -template < - bool del, class R, class T, class P1, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_1_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7428,8 +7468,8 @@ class _ConstMemberResultCallback_1_3 : public ResultCallback3 { template class _ConstMemberResultCallback_1_3< del, void, T, P1, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3) const; @@ -7464,10 +7504,10 @@ class _ConstMemberResultCallback_1_3< #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_3::base* -NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, - typename ConstRef::type p1) { +inline + typename _ConstMemberResultCallback_1_3::base* + NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, + typename ConstRef::type p1) { return new _ConstMemberResultCallback_1_3( obj, member, p1); } @@ -7475,18 +7515,18 @@ NewCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, #ifndef SWIG template -inline typename _ConstMemberResultCallback_1_3::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, - typename ConstRef::type p1) { +inline + typename _ConstMemberResultCallback_1_3::base* + NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3) const, + typename ConstRef::type p1) { return new _ConstMemberResultCallback_1_3( obj, member, p1); } #endif -template < - bool del, class R, class T, class P1, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_1_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7528,8 +7568,8 @@ class _MemberResultCallback_1_3 : public ResultCallback3 { template class _MemberResultCallback_1_3< del, void, T, P1, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3); @@ -7618,8 +7658,8 @@ class _FunctionResultCallback_1_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_1_3 : public Callback3< - A1, A2, A3> { +class _FunctionResultCallback_1_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, A1, A2, A3); @@ -7666,8 +7706,9 @@ NewPermanentCallback(R (*function)(P1, A1, A2, A3), } template ::value>::type> + class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_2_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7712,8 +7753,8 @@ class _ConstMemberResultCallback_2_3 : public ResultCallback3 { template class _ConstMemberResultCallback_2_3< del, void, T, P1, P2, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3) const; @@ -7778,8 +7819,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, A1, A2, A3) const, #endif template ::value>::type> + class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_2_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -7824,8 +7866,8 @@ class _MemberResultCallback_2_3 : public ResultCallback3 { template class _MemberResultCallback_2_3< del, void, T, P1, P2, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3); @@ -7867,10 +7909,11 @@ class _MemberResultCallback_2_3< #ifndef SWIG template -inline typename _MemberResultCallback_2_3::base* -NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), - typename ConstRef::type p1, typename ConstRef::type p2) { +inline + typename _MemberResultCallback_2_3::base* + NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2) { return new _MemberResultCallback_2_3( obj, member, p1, p2); } @@ -7879,11 +7922,11 @@ NewCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), #ifndef SWIG template -inline typename _MemberResultCallback_2_3::base* -NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), - typename ConstRef::type p1, - typename ConstRef::type p2) { +inline + typename _MemberResultCallback_2_3::base* + NewPermanentCallback(T1* obj, R (T2::*member)(P1, P2, A1, A2, A3), + typename ConstRef::type p1, + typename ConstRef::type p2) { return new _MemberResultCallback_2_3( obj, member, p1, p2); } @@ -7930,8 +7973,8 @@ class _FunctionResultCallback_2_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_2_3 : public Callback3 { +class _FunctionResultCallback_2_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, P2, A1, A2, A3); @@ -7983,8 +8026,9 @@ NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3), } template ::value>::type> + class A2, class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_3_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8033,8 +8077,8 @@ template class _ConstMemberResultCallback_3_3< del, void, T, P1, P2, P3, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3) const; @@ -8105,8 +8149,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A2, class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_3_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8155,8 +8200,8 @@ template class _MemberResultCallback_3_3< del, void, T, P1, P2, P3, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3); @@ -8270,8 +8315,8 @@ class _FunctionResultCallback_3_3 : public ResultCallback3 { }; template -class _FunctionResultCallback_3_3 : public Callback3 { +class _FunctionResultCallback_3_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3); @@ -8312,11 +8357,11 @@ class _FunctionResultCallback_3_3 -inline typename _FunctionResultCallback_3_3::base* -NewCallback(R (*function)(P1, P2, P3, A1, A2, A3), - typename ConstRef::type p1, typename ConstRef::type p2, - typename ConstRef::type p3) { +inline + typename _FunctionResultCallback_3_3::base* + NewCallback(R (*function)(P1, P2, P3, A1, A2, A3), + typename ConstRef::type p1, typename ConstRef::type p2, + typename ConstRef::type p3) { return new _FunctionResultCallback_3_3( function, p1, p2, p3); } @@ -8333,8 +8378,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3), } template ::value>::type> + class A1, class A2, class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_4_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8386,8 +8432,8 @@ template class _ConstMemberResultCallback_4_3< del, void, T, P1, P2, P3, P4, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3) const; @@ -8456,14 +8502,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_3< - false, R, T1, P1, P2, P3, P4, A1, A2, A3>(obj, member, p1, p2, p3, p4); + return new _ConstMemberResultCallback_4_3(obj, member, p1, p2, p3, + p4); } #endif template ::value>::type> + class A1, class A2, class A3, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_4_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8515,8 +8563,8 @@ template class _MemberResultCallback_4_3< del, void, T, P1, P2, P3, P4, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3); @@ -8638,8 +8686,8 @@ class _FunctionResultCallback_4_3 : public ResultCallback3 { template -class _FunctionResultCallback_4_3 : public Callback3 { +class _FunctionResultCallback_4_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3); @@ -8706,10 +8754,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3), function, p1, p2, p3, p4); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_5_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8764,8 +8812,8 @@ template class _ConstMemberResultCallback_5_3< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3) const; @@ -8841,16 +8889,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_3< - false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3>(obj, member, p1, p2, p3, p4, - p5); + return new _ConstMemberResultCallback_5_3(obj, member, p1, p2, p3, + p4, p5); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_5_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -8905,8 +8953,8 @@ template class _MemberResultCallback_5_3< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3); @@ -9036,8 +9084,8 @@ class _FunctionResultCallback_5_3 : public ResultCallback3 { template -class _FunctionResultCallback_5_3 : public Callback3 { +class _FunctionResultCallback_5_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3); @@ -9109,10 +9157,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3), A3>(function, p1, p2, p3, p4, p5); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_6_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -9170,8 +9218,8 @@ template class _ConstMemberResultCallback_6_3< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3) const; @@ -9248,16 +9296,16 @@ NewPermanentCallback( typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_3< - false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2, A3>(obj, member, p1, p2, p3, - p4, p5, p6); + return new _ConstMemberResultCallback_6_3(obj, member, p1, p2, + p3, p4, p5, p6); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_6_3 : public ResultCallback3 { public: typedef ResultCallback3 base; @@ -9315,8 +9363,8 @@ template class _MemberResultCallback_6_3< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback3 { + typename c_enable_if::value>::type> + : public Callback3 { public: typedef Callback3 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); @@ -9453,8 +9501,8 @@ class _FunctionResultCallback_6_3 : public ResultCallback3 { template -class _FunctionResultCallback_6_3 : public Callback3 { +class _FunctionResultCallback_6_3 + : public Callback3 { public: typedef Callback3 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3); @@ -9532,9 +9580,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3), p6); } -template < - bool del, class R, class T, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_0_4 : public ResultCallback4 { public: @@ -9574,8 +9622,8 @@ class _ConstMemberResultCallback_0_4 template class _ConstMemberResultCallback_0_4< del, void, T, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(A1, A2, A3, A4) const; @@ -9608,9 +9656,9 @@ class _ConstMemberResultCallback_0_4< #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_4::base* -NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { +inline + typename _ConstMemberResultCallback_0_4::base* + NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { return new _ConstMemberResultCallback_0_4( obj, member); } @@ -9618,17 +9666,17 @@ NewCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { #ifndef SWIG template -inline typename _ConstMemberResultCallback_0_4::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { +inline + typename _ConstMemberResultCallback_0_4::base* + NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4) const) { return new _ConstMemberResultCallback_0_4( obj, member); } #endif -template < - bool del, class R, class T, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_0_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -9667,8 +9715,8 @@ class _MemberResultCallback_0_4 : public ResultCallback4 { template class _MemberResultCallback_0_4< del, void, T, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(A1, A2, A3, A4); @@ -9751,8 +9799,8 @@ class _FunctionResultCallback_0_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_0_4 : public Callback4 { +class _FunctionResultCallback_0_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(A1, A2, A3, A4); @@ -9795,8 +9843,9 @@ NewPermanentCallback(R (*function)(A1, A2, A3, A4)) { } template ::value>::type> + class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_1_4 : public ResultCallback4 { public: @@ -9839,8 +9888,8 @@ class _ConstMemberResultCallback_1_4 template class _ConstMemberResultCallback_1_4< del, void, T, P1, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4) const; @@ -9901,8 +9950,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(P1, A1, A2, A3, A4) const, #endif template ::value>::type> + class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_1_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -9944,8 +9994,8 @@ class _MemberResultCallback_1_4 : public ResultCallback4 { template class _MemberResultCallback_1_4< del, void, T, P1, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4); @@ -9984,10 +10034,10 @@ class _MemberResultCallback_1_4< #ifndef SWIG template -inline typename _MemberResultCallback_1_4::base* -NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), - typename ConstRef::type p1) { +inline + typename _MemberResultCallback_1_4::base* + NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), + typename ConstRef::type p1) { return new _MemberResultCallback_1_4( obj, member, p1); } @@ -9996,10 +10046,10 @@ NewCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), #ifndef SWIG template -inline typename _MemberResultCallback_1_4::base* -NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), - typename ConstRef::type p1) { +inline + typename _MemberResultCallback_1_4::base* + NewPermanentCallback(T1* obj, R (T2::*member)(P1, A1, A2, A3, A4), + typename ConstRef::type p1) { return new _MemberResultCallback_1_4( obj, member, p1); } @@ -10041,8 +10091,8 @@ class _FunctionResultCallback_1_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_1_4 : public Callback4 { +class _FunctionResultCallback_1_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(P1, A1, A2, A3, A4); @@ -10090,8 +10140,9 @@ NewPermanentCallback(R (*function)(P1, A1, A2, A3, A4), } template ::value>::type> + class A3, class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_2_4 : public ResultCallback4 { public: @@ -10138,8 +10189,8 @@ template class _ConstMemberResultCallback_2_4< del, void, T, P1, P2, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4) const; @@ -10205,8 +10256,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A3, class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_2_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -10252,8 +10304,8 @@ template class _MemberResultCallback_2_4< del, void, T, P1, P2, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4); @@ -10359,8 +10411,8 @@ class _FunctionResultCallback_2_4 : public ResultCallback4 { }; template -class _FunctionResultCallback_2_4 : public Callback4 { +class _FunctionResultCallback_2_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(P1, P2, A1, A2, A3, A4); @@ -10395,10 +10447,11 @@ class _FunctionResultCallback_2_4 -inline typename _FunctionResultCallback_2_4::base* -NewCallback(R (*function)(P1, P2, A1, A2, A3, A4), - typename ConstRef::type p1, typename ConstRef::type p2) { +inline + typename _FunctionResultCallback_2_4::base* + NewCallback(R (*function)(P1, P2, A1, A2, A3, A4), + typename ConstRef::type p1, + typename ConstRef::type p2) { return new _FunctionResultCallback_2_4( function, p1, p2); } @@ -10414,8 +10467,9 @@ NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3, A4), } template ::value>::type> + class A2, class A3, class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_3_4 : public ResultCallback4 { public: @@ -10465,8 +10519,8 @@ template class _ConstMemberResultCallback_3_4< del, void, T, P1, P2, P3, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4) const; @@ -10537,8 +10591,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A2, class A3, class A4, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_3_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -10587,8 +10642,8 @@ template class _MemberResultCallback_3_4< del, void, T, P1, P2, P3, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4); @@ -10703,8 +10758,8 @@ class _FunctionResultCallback_3_4 : public ResultCallback4 { template -class _FunctionResultCallback_3_4 : public Callback4 { +class _FunctionResultCallback_3_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4); @@ -10767,10 +10822,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4), function, p1, p2, p3); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_4_4 : public ResultCallback4 { public: @@ -10823,8 +10878,8 @@ template class _ConstMemberResultCallback_4_4< del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4) const; @@ -10878,8 +10933,9 @@ NewCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, A1, A2, A3, A4) const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_4< - true, R, T1, P1, P2, P3, P4, A1, A2, A3, A4>(obj, member, p1, p2, p3, p4); + return new _ConstMemberResultCallback_4_4(obj, member, p1, p2, p3, + p4); } #endif @@ -10900,10 +10956,10 @@ NewPermanentCallback(const T1* obj, } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_4_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -10955,8 +11011,8 @@ template class _MemberResultCallback_4_4< del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4); @@ -11078,8 +11134,8 @@ class _FunctionResultCallback_4_4 : public ResultCallback4 { template -class _FunctionResultCallback_4_4 : public Callback4 { +class _FunctionResultCallback_4_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4); @@ -11146,10 +11202,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4), A4>(function, p1, p2, p3, p4); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_5_4 : public ResultCallback4 { public: @@ -11205,8 +11261,8 @@ template class _ConstMemberResultCallback_5_4< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4) const; @@ -11282,16 +11338,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_4< - false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3, A4>(obj, member, p1, p2, p3, - p4, p5); + return new _ConstMemberResultCallback_5_4(obj, member, p1, p2, + p3, p4, p5); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_5_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -11346,8 +11402,8 @@ template class _MemberResultCallback_5_4< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); @@ -11478,8 +11534,8 @@ class _FunctionResultCallback_5_4 : public ResultCallback4 { template -class _FunctionResultCallback_5_4 : public Callback4 { +class _FunctionResultCallback_5_4 + : public Callback4 { public: typedef Callback4 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4); @@ -11551,10 +11607,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4), A3, A4>(function, p1, p2, p3, p4, p5); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_6_4 : public ResultCallback4 { public: @@ -11615,8 +11671,8 @@ template class _ConstMemberResultCallback_6_4< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, @@ -11695,16 +11751,16 @@ NewPermanentCallback( typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5, typename ConstRef::type p6) { - return new _ConstMemberResultCallback_6_4< - false, R, T1, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4>(obj, member, p1, p2, - p3, p4, p5, p6); + return new _ConstMemberResultCallback_6_4( + obj, member, p1, p2, p3, p4, p5, p6); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, class A4, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_6_4 : public ResultCallback4 { public: typedef ResultCallback4 base; @@ -11764,8 +11820,8 @@ template class _MemberResultCallback_6_4< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, - typename c_enable_if< - is_class_or_union::value>::type> : public Callback4 { + typename c_enable_if::value>::type> + : public Callback4 { public: typedef Callback4 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4); @@ -11982,8 +12038,9 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4), } template ::value>::type> + class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_0_5 : public ResultCallback5 { public: @@ -12024,8 +12081,8 @@ class _ConstMemberResultCallback_0_5 template class _ConstMemberResultCallback_0_5< del, void, T, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(A1, A2, A3, A4, A5) const; @@ -12079,8 +12136,9 @@ NewPermanentCallback(const T1* obj, R (T2::*member)(A1, A2, A3, A4, A5) const) { #endif template ::value>::type> + class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_0_5 : public ResultCallback5 { public: @@ -12121,8 +12179,8 @@ class _MemberResultCallback_0_5 template class _MemberResultCallback_0_5< del, void, T, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(A1, A2, A3, A4, A5); @@ -12156,9 +12214,9 @@ class _MemberResultCallback_0_5< #ifndef SWIG template -inline typename _MemberResultCallback_0_5::base* -NewCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { +inline + typename _MemberResultCallback_0_5::base* + NewCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { return new _MemberResultCallback_0_5(obj, member); } @@ -12167,9 +12225,9 @@ NewCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { #ifndef SWIG template -inline typename _MemberResultCallback_0_5::base* -NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { +inline + typename _MemberResultCallback_0_5::base* + NewPermanentCallback(T1* obj, R (T2::*member)(A1, A2, A3, A4, A5)) { return new _MemberResultCallback_0_5( obj, member); } @@ -12211,8 +12269,8 @@ class _FunctionResultCallback_0_5 }; template -class _FunctionResultCallback_0_5 : public Callback5 { +class _FunctionResultCallback_0_5 + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(A1, A2, A3, A4, A5); @@ -12256,8 +12314,9 @@ NewPermanentCallback(R (*function)(A1, A2, A3, A4, A5)) { } template ::value>::type> + class A4, class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_1_5 : public ResultCallback5 { public: @@ -12302,8 +12361,8 @@ template class _ConstMemberResultCallback_1_5< del, void, T, P1, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4, A5) const; @@ -12365,8 +12424,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A4, class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_1_5 : public ResultCallback5 { public: @@ -12411,8 +12471,8 @@ template class _MemberResultCallback_1_5< del, void, T, P1, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, A1, A2, A3, A4, A5); @@ -12513,8 +12573,8 @@ class _FunctionResultCallback_1_5 }; template -class _FunctionResultCallback_1_5 : public Callback5 { +class _FunctionResultCallback_1_5 + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(P1, A1, A2, A3, A4, A5); @@ -12547,10 +12607,10 @@ class _FunctionResultCallback_1_5 -inline typename _FunctionResultCallback_1_5::base* -NewCallback(R (*function)(P1, A1, A2, A3, A4, A5), - typename ConstRef::type p1) { +inline + typename _FunctionResultCallback_1_5::base* + NewCallback(R (*function)(P1, A1, A2, A3, A4, A5), + typename ConstRef::type p1) { return new _FunctionResultCallback_1_5( function, p1); } @@ -12565,8 +12625,9 @@ NewPermanentCallback(R (*function)(P1, A1, A2, A3, A4, A5), } template ::value>::type> + class A3, class A4, class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _ConstMemberResultCallback_2_5 : public ResultCallback5 { public: @@ -12614,8 +12675,8 @@ template class _ConstMemberResultCallback_2_5< del, void, T, P1, P2, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5) const; @@ -12681,8 +12742,9 @@ NewPermanentCallback(const T1* obj, #endif template ::value>::type> + class A3, class A4, class A5, + class OnlyIf = + typename c_enable_if::value>::type> class _MemberResultCallback_2_5 : public ResultCallback5 { public: @@ -12730,8 +12792,8 @@ template class _MemberResultCallback_2_5< del, void, T, P1, P2, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, A1, A2, A3, A4, A5); @@ -12840,8 +12902,8 @@ class _FunctionResultCallback_2_5 template -class _FunctionResultCallback_2_5 : public Callback5 { +class _FunctionResultCallback_2_5 + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(P1, P2, A1, A2, A3, A4, A5); @@ -12899,10 +12961,10 @@ NewPermanentCallback(R (*function)(P1, P2, A1, A2, A3, A4, A5), function, p1, p2); } -template < - bool del, class R, class T, class P1, class P2, class P3, class A1, - class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_3_5 : public ResultCallback5 { public: @@ -12953,8 +13015,8 @@ template class _ConstMemberResultCallback_3_5< del, void, T, P1, P2, P3, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5) const; @@ -13020,15 +13082,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3) { - return new _ConstMemberResultCallback_3_5< - false, R, T1, P1, P2, P3, A1, A2, A3, A4, A5>(obj, member, p1, p2, p3); + return new _ConstMemberResultCallback_3_5(obj, member, p1, p2, + p3); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class A1, - class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_3_5 : public ResultCallback5 { public: @@ -13079,8 +13142,8 @@ template class _MemberResultCallback_3_5< del, void, T, P1, P2, P3, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, A1, A2, A3, A4, A5); @@ -13197,8 +13260,8 @@ class _FunctionResultCallback_3_5 template -class _FunctionResultCallback_3_5 : public Callback5 { +class _FunctionResultCallback_3_5 + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(P1, P2, P3, A1, A2, A3, A4, A5); @@ -13261,10 +13324,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, A1, A2, A3, A4, A5), A5>(function, p1, p2, p3); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_4_5 : public ResultCallback5 { public: @@ -13318,8 +13381,8 @@ template class _ConstMemberResultCallback_4_5< del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5) const; @@ -13390,16 +13453,16 @@ NewPermanentCallback(const T1* obj, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4) { - return new _ConstMemberResultCallback_4_5< - false, R, T1, P1, P2, P3, P4, A1, A2, A3, A4, A5>(obj, member, p1, p2, p3, - p4); + return new _ConstMemberResultCallback_4_5(obj, member, p1, p2, + p3, p4); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_4_5 : public ResultCallback5 { public: @@ -13453,8 +13516,8 @@ template class _MemberResultCallback_4_5< del, void, T, P1, P2, P3, P4, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); @@ -13579,8 +13642,8 @@ class _FunctionResultCallback_4_5 template -class _FunctionResultCallback_4_5 : public Callback5 { +class _FunctionResultCallback_4_5 + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, A1, A2, A3, A4, A5); @@ -13647,10 +13710,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, A1, A2, A3, A4, A5), A4, A5>(function, p1, p2, p3, p4); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_5_5 : public ResultCallback5 { public: @@ -13709,8 +13772,8 @@ template class _ConstMemberResultCallback_5_5< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, @@ -13780,23 +13843,24 @@ template inline typename _ConstMemberResultCallback_5_5::base* -NewPermanentCallback(const T1* obj, R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, - A3, A4, A5) const, +NewPermanentCallback(const T1* obj, + R (T2::*member)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5) + const, typename ConstRef::type p1, typename ConstRef::type p2, typename ConstRef::type p3, typename ConstRef::type p4, typename ConstRef::type p5) { - return new _ConstMemberResultCallback_5_5< - false, R, T1, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5>(obj, member, p1, p2, - p3, p4, p5); + return new _ConstMemberResultCallback_5_5(obj, member, p1, + p2, p3, p4, p5); } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_5_5 : public ResultCallback5 { public: @@ -13855,8 +13919,8 @@ template class _MemberResultCallback_5_5< del, void, T, P1, P2, P3, P4, P5, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5); @@ -14066,10 +14130,10 @@ NewPermanentCallback(R (*function)(P1, P2, P3, P4, P5, A1, A2, A3, A4, A5), p5); } -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _ConstMemberResultCallback_6_5 : public ResultCallback5 { public: @@ -14132,8 +14196,8 @@ template class _ConstMemberResultCallback_6_5< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, @@ -14218,10 +14282,10 @@ NewPermanentCallback( } #endif -template < - bool del, class R, class T, class P1, class P2, class P3, class P4, - class P5, class P6, class A1, class A2, class A3, class A4, class A5, - class OnlyIf = typename c_enable_if::value>::type> +template ::value>::type> class _MemberResultCallback_6_5 : public ResultCallback5 { public: @@ -14283,8 +14347,8 @@ template class _MemberResultCallback_6_5< del, void, T, P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5, - typename c_enable_if::value>::type> : public Callback5 { + typename c_enable_if::value>::type> + : public Callback5 { public: typedef Callback5 base; typedef void (T::*MemberSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, @@ -14426,8 +14490,8 @@ class _FunctionResultCallback_6_5 template class _FunctionResultCallback_6_5 : public Callback5 { + A4, A5> + : public Callback5 { public: typedef Callback5 base; typedef void (*FunctionSignature)(P1, P2, P3, P4, P5, P6, A1, A2, A3, A4, A5); diff --git a/ortools/base/cleanup.h b/ortools/base/cleanup.h index b18775b7152..a02e1046d9c 100644 --- a/ortools/base/cleanup.h +++ b/ortools/base/cleanup.h @@ -23,8 +23,7 @@ template class Cleanup { public: template - explicit Cleanup(G&& f) - : f_(std::forward(f)) {} + explicit Cleanup(G&& f) : f_(std::forward(f)) {} ~Cleanup() { f_(); } private: diff --git a/ortools/base/file.cc b/ortools/base/file.cc index b4ab6163d0a..25305f53f2c 100644 --- a/ortools/base/file.cc +++ b/ortools/base/file.cc @@ -192,7 +192,8 @@ bool ReadFileToString(const absl::string_view& file_name, std::string* output) { return GetContents(file_name, output, file::Defaults()).ok(); } -bool WriteStringToFile(const std::string& data, const absl::string_view& file_name) { +bool WriteStringToFile(const std::string& data, + const absl::string_view& file_name) { return SetContents(file_name, data, file::Defaults()).ok(); } diff --git a/ortools/base/file.h b/ortools/base/file.h index 5b09af7ba5b..0dd48c7c686 100644 --- a/ortools/base/file.h +++ b/ortools/base/file.h @@ -14,18 +14,18 @@ #ifndef OR_TOOLS_BASE_FILE_H_ #define OR_TOOLS_BASE_FILE_H_ -#include #include +#include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "google/protobuf/io/tokenizer.h" #include "google/protobuf/descriptor.h" +#include "google/protobuf/io/tokenizer.h" #include "google/protobuf/message.h" #include "google/protobuf/text_format.h" -#include "ortools/base/string_view.h" +#include "ortools/base/integral_types.h" +#include "ortools/base/logging.h" #include "ortools/base/status.h" +#include "ortools/base/string_view.h" // This file defines some IO interfaces for compatibility with Google // IO specifications. @@ -64,8 +64,8 @@ class File { // Each line must be no more than max_length bytes. char* ReadLine(char* const output, uint64 max_length); - // Reads the whole file to a std::string, with a maximum length of 'max_length'. - // Returns the number of bytes read. + // Reads the whole file to a std::string, with a maximum length of + // 'max_length'. Returns the number of bytes read. int64 ReadToString(std::string* const line, uint64 max_length); // Writes "size" bytes of buff to file, buff should be pre-allocated. @@ -135,7 +135,8 @@ util::Status WriteString(File* file, const absl::string_view& contents, int flags); bool ReadFileToString(const absl::string_view& file_name, std::string* output); -bool WriteStringToFile(const std::string& data, const absl::string_view& file_name); +bool WriteStringToFile(const std::string& data, + const absl::string_view& file_name); bool ReadFileToProto(const absl::string_view& file_name, google::protobuf::Message* proto); void ReadFileToProtoOrDie(const absl::string_view& file_name, diff --git a/ortools/base/filelineiter.h b/ortools/base/filelineiter.h index 06746f35a1d..9342b6c4b32 100644 --- a/ortools/base/filelineiter.h +++ b/ortools/base/filelineiter.h @@ -18,19 +18,19 @@ // * The lines are separated by '\n' (which is removed by default) and have no // size limits. // * Consecutive '\n' result in empty lines being produced. -// * If not empty, the std::string after the last '\n' is produced as the last line. +// * If not empty, the std::string after the last '\n' is produced as the last +// line. // * Options are available to keep the trailing '\n' for each line, to remove // carriage-return chararters ('\r'), and to remove blank lines. #ifndef OR_TOOLS_BASE_FILELINEITER_H_ #define OR_TOOLS_BASE_FILELINEITER_H_ -#include "ortools/base/logging.h" #include "ortools/base/file.h" +#include "ortools/base/logging.h" #include "ortools/base/stringpiece_utils.h" #include "ortools/base/strutil.h" - // Implements the minimum interface for a range-based for loop iterator. class FileLineIterator { public: @@ -118,7 +118,6 @@ class FileLines { public: FileLines(const std::string& filename, int options) : options_(options) { if (!file::Open(filename, "r", &file_, file::Defaults()).ok()) return; - } explicit FileLines(const std::string& filename) diff --git a/ortools/base/hash.h b/ortools/base/hash.h index eee6fc753c4..a2d97def44d 100644 --- a/ortools/base/hash.h +++ b/ortools/base/hash.h @@ -14,7 +14,6 @@ #ifndef OR_TOOLS_BASE_HASH_H_ #define OR_TOOLS_BASE_HASH_H_ - #include #include #include diff --git a/ortools/base/inlined_vector.h b/ortools/base/inlined_vector.h index edf83885b86..061df2b563f 100644 --- a/ortools/base/inlined_vector.h +++ b/ortools/base/inlined_vector.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_BASE_INLINED_VECTOR_H_ #define OR_TOOLS_BASE_INLINED_VECTOR_H_ diff --git a/ortools/base/int_type.h b/ortools/base/int_type.h old mode 100755 new mode 100644 index e61a4d7ba22..2e89e3e64b3 --- a/ortools/base/int_type.h +++ b/ortools/base/int_type.h @@ -145,9 +145,9 @@ #define OR_TOOLS_BASE_INT_TYPE_H_ #include -#include #include #include // NOLINT +#include #include "ortools/base/macros.h" diff --git a/ortools/base/int_type_indexed_vector.h b/ortools/base/int_type_indexed_vector.h old mode 100755 new mode 100644 index 27cdc8f5c86..7702a2e3a77 --- a/ortools/base/int_type_indexed_vector.h +++ b/ortools/base/int_type_indexed_vector.h @@ -64,8 +64,8 @@ #include #include -#include "ortools/base/macros.h" #include "ortools/base/int_type.h" +#include "ortools/base/macros.h" // STL std::vector // ------------------------------------------------------------------ @@ -190,12 +190,12 @@ class ITIVector : protected std::vector { const ITIVector& y) { \ return x.get() op y.get(); \ } -ITIVECTOR_COMPARISON_OP(== ); // NOLINT -ITIVECTOR_COMPARISON_OP(!= ); // NOLINT -ITIVECTOR_COMPARISON_OP(< ); // NOLINT -ITIVECTOR_COMPARISON_OP(<= ); // NOLINT -ITIVECTOR_COMPARISON_OP(> ); // NOLINT -ITIVECTOR_COMPARISON_OP(>= ); // NOLINT +ITIVECTOR_COMPARISON_OP(==); // NOLINT +ITIVECTOR_COMPARISON_OP(!=); // NOLINT +ITIVECTOR_COMPARISON_OP(<); // NOLINT +ITIVECTOR_COMPARISON_OP(<=); // NOLINT +ITIVECTOR_COMPARISON_OP(>); // NOLINT +ITIVECTOR_COMPARISON_OP(>=); // NOLINT #undef ITIVECTOR_COMPARISON_OP template diff --git a/ortools/base/join.cc b/ortools/base/join.cc index a4709fde535..0935b2043ae 100644 --- a/ortools/base/join.cc +++ b/ortools/base/join.cc @@ -19,7 +19,9 @@ namespace absl { -void StrAppend(std::string* s, const AlphaNum& a) { s->append(a.data(), a.size()); } +void StrAppend(std::string* s, const AlphaNum& a) { + s->append(a.data(), a.size()); +} void StrAppend(std::string* s, const AlphaNum& a, const AlphaNum& b) { s->reserve(s->size() + a.size() + b.size()); s->append(a.data(), a.size()); @@ -106,7 +108,9 @@ void StrAppend(std::string* s, const AlphaNum& a, const AlphaNum& b, StrAppend(s, g, h, i, j, k, l, m); } -std::string StrCat(const AlphaNum& a) { return std::string(a.data(), a.size()); } +std::string StrCat(const AlphaNum& a) { + return std::string(a.data(), a.size()); +} std::string StrCat(const AlphaNum& a, const AlphaNum& b) { std::string out; StrAppend(&out, a, b); @@ -118,74 +122,74 @@ std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c) { return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d) { + const AlphaNum& d) { std::string out; StrAppend(&out, a, b, c, d); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e) { + const AlphaNum& d, const AlphaNum& e) { std::string out; StrAppend(&out, a, b, c, d, e); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f) { std::string out; StrAppend(&out, a, b, c, d, e, f); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g) { std::string out; StrAppend(&out, a, b, c, d, e, f, g); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h, i); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h, i, j); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h, i, j, k); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k, const AlphaNum& l) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k, const AlphaNum& l) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h, i, j, k, l); return out; } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k, const AlphaNum& l, - const AlphaNum& m) { + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k, const AlphaNum& l, + const AlphaNum& m) { std::string out; StrAppend(&out, a, b, c, d, e, f, g, h, i, j, k, l, m); return out; diff --git a/ortools/base/join.h b/ortools/base/join.h index f3bb705d679..934c03c44e2 100644 --- a/ortools/base/join.h +++ b/ortools/base/join.h @@ -14,8 +14,8 @@ #ifndef OR_TOOLS_BASE_JOIN_H_ #define OR_TOOLS_BASE_JOIN_H_ -#include #include +#include #include "ortools/base/basictypes.h" #include "ortools/base/integral_types.h" @@ -27,8 +27,8 @@ namespace absl { const int kFastToBufferSize = 32; // Writes output to the beginning of the given buffer. Returns a pointer to the -// end of the std::string (i.e. to the NUL char). Buffer must be at least 12 bytes. -// Not actually fast, but maybe someday! +// end of the std::string (i.e. to the NUL char). Buffer must be at least 12 +// bytes. Not actually fast, but maybe someday! template char* NumToBuffer(T i, char* buffer) { std::stringstream ss; @@ -63,10 +63,10 @@ struct AlphaNum { snprintf(digits, kFastToBufferSize, "%lf", f); piece.set(digits); } - AlphaNum(const char* c_str) : piece(c_str) {} // NOLINT(runtime/explicit) + AlphaNum(const char* c_str) : piece(c_str) {} // NOLINT(runtime/explicit) AlphaNum(const absl::string_view& pc) - : piece(pc) {} // NOLINT(runtime/explicit) - AlphaNum(const std::string& s) : piece(s) {} // NOLINT(runtime/explicit) + : piece(pc) {} // NOLINT(runtime/explicit) + AlphaNum(const std::string& s) : piece(s) {} // NOLINT(runtime/explicit) absl::string_view::size_type size() const { return piece.size(); } const char* data() const { return piece.data(); } @@ -82,37 +82,37 @@ std::string StrCat(const AlphaNum& a); std::string StrCat(const AlphaNum& a, const AlphaNum& b); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d); + const AlphaNum& d); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e); + const AlphaNum& d, const AlphaNum& e); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k, const AlphaNum& l); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k, const AlphaNum& l); std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, - const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, - const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, - const AlphaNum& j, const AlphaNum& k, const AlphaNum& l, - const AlphaNum& m); + const AlphaNum& d, const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, const AlphaNum& i, + const AlphaNum& j, const AlphaNum& k, const AlphaNum& l, + const AlphaNum& m); void StrAppend(std::string* s, const AlphaNum& a); void StrAppend(std::string* s, const AlphaNum& a, const AlphaNum& b); diff --git a/ortools/base/macros.h b/ortools/base/macros.h index 6ca24ebfe72..9423f8fbcd2 100644 --- a/ortools/base/macros.h +++ b/ortools/base/macros.h @@ -17,7 +17,7 @@ #include // for size_t. #if (defined(COMPILER_GCC3) || defined(OS_MACOSX)) && !defined(SWIG) -#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#define ATTRIBUTE_UNUSED __attribute__((__unused__)) #else // GCC #define ATTRIBUTE_UNUSED #endif // GCC @@ -49,10 +49,10 @@ const bool DEBUG_MODE = true; #endif template -char(&ArraySizeHelper(T(&array)[N]))[N]; +char (&ArraySizeHelper(T (&array)[N]))[N]; #ifndef COMPILER_MSVC template -char(&ArraySizeHelper(const T(&array)[N]))[N]; +char (&ArraySizeHelper(const T (&array)[N]))[N]; #endif #define arraysize(array) (sizeof(ArraySizeHelper(array))) diff --git a/ortools/base/murmur.h b/ortools/base/murmur.h index 8bb4b3b1f8c..8ddea1abaa5 100644 --- a/ortools/base/murmur.h +++ b/ortools/base/murmur.h @@ -23,6 +23,6 @@ namespace util_hash { inline uint64 MurmurHash64(const char *buf, const size_t len) { return ::operations_research::ThoroughHash(buf, len); } -} +} // namespace util_hash #endif // OR_TOOLS_BASE_MURMUR_H_ diff --git a/ortools/base/mutex.h b/ortools/base/mutex.h index 1a10433cbb6..ea0e4aa3712 100644 --- a/ortools/base/mutex.h +++ b/ortools/base/mutex.h @@ -15,7 +15,7 @@ #define OR_TOOLS_BASE_MUTEX_H_ #include // NOLINT -#include // NOLINT +#include // NOLINT #include "ortools/base/macros.h" diff --git a/ortools/base/protoutil.h b/ortools/base/protoutil.h index 69f1d4b3b5b..5c73ebc5cae 100644 --- a/ortools/base/protoutil.h +++ b/ortools/base/protoutil.h @@ -14,10 +14,10 @@ #ifndef OR_TOOLS_BASE_PROTOUTIL_H_ #define OR_TOOLS_BASE_PROTOUTIL_H_ -#include "ortools/base/time_support.h" #include "google/protobuf/duration.pb.h" #include "ortools/base/status.h" #include "ortools/base/statusor.h" +#include "ortools/base/time_support.h" namespace util_time { diff --git a/ortools/base/python-swig.h b/ortools/base/python-swig.h index 0672ec736e9..235e9d96dad 100644 --- a/ortools/base/python-swig.h +++ b/ortools/base/python-swig.h @@ -131,7 +131,7 @@ inline bool PyObjAs(PyObject* py, unsigned int* c) { } template <> -inline bool PyObjAs(PyObject* py, long* c) { // NOLINT +inline bool PyObjAs(PyObject* py, long* c) { // NOLINT long i = PyInt_AsLong(py); // NOLINT if (i == -1 && PyErr_Occurred()) return false; // Not a Python int. if (c) *c = i; @@ -140,7 +140,7 @@ inline bool PyObjAs(PyObject* py, long* c) { // NOLINT template <> inline bool PyObjAs(PyObject* py, long long* c) { // NOLINT - long long i; // NOLINT + long long i; // NOLINT #if PY_MAJOR_VERSION < 3 if (PyInt_Check(py)) { i = PyInt_AsLong(py); @@ -158,7 +158,7 @@ inline bool PyObjAs(PyObject* py, long long* c) { // NOLINT template <> inline bool PyObjAs(PyObject* py, unsigned long long* c) { // NOLINT - unsigned long long i; // NOLINT + unsigned long long i; // NOLINT #if PY_MAJOR_VERSION < 3 if (PyInt_Check(py)) { i = PyInt_AsUnsignedLongLongMask(py); @@ -223,7 +223,7 @@ inline int SwigPyIntOrLong_Check(PyObject* o) { #if PY_MAJOR_VERSION <= 2 || PyInt_Check(o) #endif - ); // NOLINT + ); // NOLINT } inline PyObject* SwigString_FromString(const std::string& s) { @@ -255,7 +255,7 @@ struct vector_pusher { template inline bool vector_input_helper(PyObject* seq, std::vector* out, bool (*convert)(PyObject*, T* const)) { - PyObject* item, *it = PyObject_GetIter(seq); + PyObject *item, *it = PyObject_GetIter(seq); if (!it) return false; T elem; while ((item = PyIter_Next(it))) { @@ -274,15 +274,15 @@ inline bool vector_input_helper(PyObject* seq, std::vector* out, template inline bool vector_input_wrap_helper(PyObject* seq, std::vector* out, swig_type_info* swig_Tp_type) { - PyObject* item, *it = PyObject_GetIter(seq); + PyObject *item, *it = PyObject_GetIter(seq); if (!it) { PyErr_SetString(PyExc_TypeError, "sequence expected"); return false; } typename vector_pusher::ptr elem; while ((item = PyIter_Next(it))) { - if (SWIG_ConvertPtr(item, reinterpret_cast(&elem), - swig_Tp_type, 0) == -1) { + if (SWIG_ConvertPtr(item, reinterpret_cast(&elem), swig_Tp_type, + 0) == -1) { Py_DECREF(it); it = PyObject_Repr(item); Py_DECREF(item); diff --git a/ortools/base/random.cc b/ortools/base/random.cc index 0f536e4ad54..224cb3b0660 100644 --- a/ortools/base/random.cc +++ b/ortools/base/random.cc @@ -79,7 +79,8 @@ int32 ACMRandom::HostnamePidTimeSeed() { } const int namelen = strlen(name); for (size_t i = 0; i < sizeof(uint32) * 3; ++i) { - name[namelen + i] = '\0'; // so we mix 0's once we get to end-of-std::string + name[namelen + i] = + '\0'; // so we mix 0's once we get to end-of-std::string } #if defined(__GNUC__) uint32 a = getpid(); diff --git a/ortools/base/recordio.cc b/ortools/base/recordio.cc index 7fcb089e8fd..1b03056253f 100644 --- a/ortools/base/recordio.cc +++ b/ortools/base/recordio.cc @@ -11,11 +11,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "ortools/base/recordio.h" #include #include #include #include "ortools/base/logging.h" -#include "ortools/base/recordio.h" namespace recordio { const int RecordWriter::kMagicNumber = 0x3ed7230a; diff --git a/ortools/base/span.h b/ortools/base/span.h index 72686784b19..27717c681c5 100644 --- a/ortools/base/span.h +++ b/ortools/base/span.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_BASE_SPAN_H_ #define OR_TOOLS_BASE_SPAN_H_ @@ -303,8 +302,8 @@ class Span { // The constructor for any class supplying 'data() const' that returns either // const T* or a less const-qualified version of it, and 'some_integral_type - // size() const'. google::protobuf::RepeatedField, std::string and (since C++11) - // std::vector and std::array are examples of this. See + // size() const'. google::protobuf::RepeatedField, std::string and (since + // C++11) std::vector and std::array are examples of this. See // span_internal.h for details. template > diff --git a/ortools/base/split.cc b/ortools/base/split.cc index 3bc9555e96c..7d1f9508228 100644 --- a/ortools/base/split.cc +++ b/ortools/base/split.cc @@ -27,7 +27,8 @@ namespace { // to 'result'. // // Note: For multi-character delimiters, this routine will split on *ANY* of -// the characters in the std::string, not the entire std::string as a single delimiter. +// the characters in the std::string, not the entire std::string as a single +// delimiter. // ---------------------------------------------------------------------- template static inline void InternalSplitStringUsingChar(const std::string& full, char c, @@ -73,22 +74,24 @@ static inline void InternalSplitStringUsing(const std::string& full, } // namespace -std::vector StrSplit(const std::string& full, char delim, int flags) { +std::vector StrSplit(const std::string& full, char delim, + int flags) { CHECK_EQ(absl::SkipEmpty(), flags); std::vector out; InternalSplitStringUsingChar(full, delim, &out); return out; } -std::vector StrSplit(const std::string& full, const char* delim, int flags) { +std::vector StrSplit(const std::string& full, const char* delim, + int flags) { CHECK_EQ(absl::SkipEmpty(), flags); std::vector out; InternalSplitStringUsing(full, delim, &out); return out; } -std::vector StrSplit(const std::string& full, const char* delim, - int64 flags) { +std::vector StrSplit(const std::string& full, + const char* delim, int64 flags) { CHECK_EQ(absl::SkipEmpty(), flags); std::vector out; InternalSplitStringUsing(full, delim, &out); diff --git a/ortools/base/split.h b/ortools/base/split.h index 1f344305dfa..6dad81744a2 100644 --- a/ortools/base/split.h +++ b/ortools/base/split.h @@ -26,9 +26,11 @@ namespace absl { inline int SkipEmpty() { return 0xDEADBEEF; } -std::vector StrSplit(const std::string& full, const char* delim, int flags); +std::vector StrSplit(const std::string& full, const char* delim, + int flags); -std::vector StrSplit(const std::string& full, char delim, int flags); +std::vector StrSplit(const std::string& full, char delim, + int flags); namespace delimiter { inline const char* AnyOf(const char* x) { return x; } diff --git a/ortools/base/status.h b/ortools/base/status.h index 4355bc4ae3a..366eb769718 100644 --- a/ortools/base/status.h +++ b/ortools/base/status.h @@ -15,8 +15,8 @@ #define OR_TOOLS_BASE_STATUS_H_ #include -#include "ortools/base/logging.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" namespace util { diff --git a/ortools/base/stringprintf.cc b/ortools/base/stringprintf.cc index a621349625c..95dcad9e212 100644 --- a/ortools/base/stringprintf.cc +++ b/ortools/base/stringprintf.cc @@ -20,17 +20,18 @@ #if !defined(_MSC_VER) #ifndef va_copy -# ifdef __va_copy -# define va_copy(d, s) __va_copy((d), (s)) -# else -# define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) -# endif +#ifdef __va_copy +#define va_copy(d, s) __va_copy((d), (s)) +#else +#define va_copy(d, s) memcpy(&(d), &(s), sizeof(va_list)) +#endif #endif #endif namespace operations_research { -void StringAppendV(std::string* const dst, const char* const format, va_list ap) { +void StringAppendV(std::string* const dst, const char* const format, + va_list ap) { // First try with a small fixed size buffer char space[1024]; diff --git a/ortools/base/sysinfo.cc b/ortools/base/sysinfo.cc index ffd3fc26479..b822e5eabd7 100644 --- a/ortools/base/sysinfo.cc +++ b/ortools/base/sysinfo.cc @@ -18,8 +18,8 @@ #include #include #elif defined(_MSC_VER) // WINDOWS -#include #include +#include #endif #include @@ -36,7 +36,7 @@ int64 GetProcessMemoryUsage() { mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, - (task_info_t) & t_info, &t_info_count)) { + (task_info_t)&t_info, &t_info_count)) { return -1; } int64 resident_memory = t_info.resident_size; @@ -69,7 +69,7 @@ int64 GetProcessMemoryUsage() { } return memory; } -#else // Unknown, returning 0. +#else // Unknown, returning 0. int64 GetProcessMemoryUsage() { return 0; } #endif diff --git a/ortools/base/thorough_hash.h b/ortools/base/thorough_hash.h index 090a91a9337..7ea108ef717 100644 --- a/ortools/base/thorough_hash.h +++ b/ortools/base/thorough_hash.h @@ -28,8 +28,8 @@ inline uint64 MixTwoUInt64(uint64 fp1, uint64 fp2) { return a + (~a >> 47); } -// This should be better (collision-wise) than the default hash, without -// being much slower. It never returns 0 or 1. +// This should be better (collision-wise) than the default hash, +// without being much slower. It never returns 0 or 1. inline uint64 ThoroughHash(const char* bytes, size_t len) { // Some big prime numer. uint64 fp = 0xa5b85c5e198ed849ULL; diff --git a/ortools/bop/bop_base.cc b/ortools/bop/bop_base.cc index 93c0f4b2f5a..5e2aaa574aa 100644 --- a/ortools/bop/bop_base.cc +++ b/ortools/bop/bop_base.cc @@ -26,8 +26,7 @@ namespace bop { using ::operations_research::LinearBooleanProblem; BopOptimizerBase::BopOptimizerBase(const std::string& name) - : name_(name), - stats_(name) { + : name_(name), stats_(name) { SCOPED_TIME_STAT(&stats_); } diff --git a/ortools/bop/bop_fs.cc b/ortools/bop/bop_fs.cc index 3d05f649379..304f56ecb3a 100644 --- a/ortools/bop/bop_fs.cc +++ b/ortools/bop/bop_fs.cc @@ -16,11 +16,11 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" #include "google/protobuf/text_format.h" -#include "ortools/base/stl_util.h" #include "ortools/algorithms/sparse_permutation.h" +#include "ortools/base/commandlineflags.h" +#include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/glop/lp_solver.h" #include "ortools/lp_data/lp_print_utils.h" #include "ortools/sat/boolean_problem.h" @@ -204,7 +204,6 @@ BopOptimizerBase::Status GuidedSatFirstSolutionGenerator::Optimize( return BopOptimizerBase::CONTINUE; } - //------------------------------------------------------------------------------ // BopRandomFirstSolutionGenerator //------------------------------------------------------------------------------ @@ -404,8 +403,9 @@ BopOptimizerBase::Status LinearRelaxation::SynchronizeIfNeeded( constraint_index, StringPrintf((clause.a.IsPositive() ? "%s" : "not(%s)"), lp_model_.GetVariableName(col_a).c_str()) + - " or " + StringPrintf((clause.b.IsPositive() ? "%s" : "not(%s)"), - lp_model_.GetVariableName(col_b).c_str())); + " or " + + StringPrintf((clause.b.IsPositive() ? "%s" : "not(%s)"), + lp_model_.GetVariableName(col_b).c_str())); lp_model_.SetCoefficient(constraint_index, col_a, coefficient_a); lp_model_.SetCoefficient(constraint_index, col_b, coefficient_b); lp_model_.SetConstraintBounds(constraint_index, rhs, glop::kInfinity); diff --git a/ortools/bop/bop_fs.h b/ortools/bop/bop_fs.h index 662ea769a26..794a5f88e5d 100644 --- a/ortools/bop/bop_fs.h +++ b/ortools/bop/bop_fs.h @@ -17,11 +17,12 @@ #include #include "ortools/base/basictypes.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/random.h" #include "ortools/bop/bop_base.h" #include "ortools/bop/bop_parameters.pb.h" #include "ortools/bop/bop_solution.h" @@ -31,7 +32,6 @@ #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/sat_solver.h" #include "ortools/util/time_limit.h" -#include "ortools/base/random.h" namespace operations_research { namespace bop { @@ -70,7 +70,6 @@ class GuidedSatFirstSolutionGenerator : public BopOptimizerBase { std::unique_ptr sat_solver_; }; - // This class implements an optimizer that tries various random search // strategies, each with a really low conflict limit. It can be used to generate // a first solution or to improve an existing one. diff --git a/ortools/bop/bop_lns.cc b/ortools/bop/bop_lns.cc index 3b79278ca6b..7b6ee02d6a3 100644 --- a/ortools/bop/bop_lns.cc +++ b/ortools/bop/bop_lns.cc @@ -17,11 +17,11 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" #include "google/protobuf/text_format.h" #include "ortools/base/cleanup.h" +#include "ortools/base/commandlineflags.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/glop/lp_solver.h" #include "ortools/lp_data/lp_print_utils.h" #include "ortools/sat/boolean_problem.h" @@ -127,10 +127,11 @@ BopOptimizerBase::Status BopCompleteLNSOptimizer::Optimize( CHECK(sat_solver_ != nullptr); const double initial_dt = sat_solver_->deterministic_time(); - auto advance_dt = ::operations_research::util::MakeCleanup([initial_dt, this, &time_limit]() { - time_limit->AdvanceDeterministicTime(sat_solver_->deterministic_time() - - initial_dt); - }); + auto advance_dt = ::operations_research::util::MakeCleanup( + [initial_dt, this, &time_limit]() { + time_limit->AdvanceDeterministicTime(sat_solver_->deterministic_time() - + initial_dt); + }); // Set the parameters for this run. // TODO(user): Because of this, we actually loose the perfect continuity @@ -239,8 +240,8 @@ BopOptimizerBase::Status BopAdaptiveLNSOptimizer::Optimize( // Set-up a sat_propagator_ cleanup task to catch all the exit cases. const double initial_dt = sat_propagator_->deterministic_time(); - auto sat_propagator_cleanup = - ::operations_research::util::MakeCleanup([initial_dt, this, &learned_info, &time_limit]() { + auto sat_propagator_cleanup = ::operations_research::util::MakeCleanup( + [initial_dt, this, &learned_info, &time_limit]() { if (!sat_propagator_->IsModelUnsat()) { sat_propagator_->SetAssumptionLevel(0); sat_propagator_->RestoreSolverToAssumptionLevel(); diff --git a/ortools/bop/bop_lns.h b/ortools/bop/bop_lns.h index 3080781af7a..2965b64a5c7 100644 --- a/ortools/bop/bop_lns.h +++ b/ortools/bop/bop_lns.h @@ -18,11 +18,12 @@ #include #include "ortools/base/basictypes.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/random.h" #include "ortools/bop/bop_base.h" #include "ortools/bop/bop_parameters.pb.h" #include "ortools/bop/bop_solution.h" @@ -33,7 +34,6 @@ #include "ortools/sat/sat_solver.h" #include "ortools/util/stats.h" #include "ortools/util/time_limit.h" -#include "ortools/base/random.h" namespace operations_research { namespace bop { diff --git a/ortools/bop/bop_ls.cc b/ortools/bop/bop_ls.cc index a06b66ab33d..7a394bb071c 100644 --- a/ortools/bop/bop_ls.cc +++ b/ortools/bop/bop_ls.cc @@ -13,7 +13,6 @@ #include "ortools/bop/bop_ls.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/stringprintf.h" #include "ortools/bop/bop_util.h" #include "ortools/sat/boolean_problem.h" @@ -88,7 +87,8 @@ BopOptimizerBase::Status LocalSearchOptimizer::Optimize( // the ls? note that this is minor. sat_wrapper_.ExtractLearnedInfo(learned_info); if (assignment_iterator_->BetterSolutionHasBeenFound()) { - // TODO(user): simply use std::vector instead of a BopSolution internally. + // TODO(user): simply use std::vector instead of a BopSolution + // internally. learned_info->solution = assignment_iterator_->LastReferenceAssignment(); return BopOptimizerBase::SOLUTION_FOUND; } @@ -792,7 +792,8 @@ bool LocalSearchAssignmentIterator::NextAssignment() { // All nodes have been explored. if (search_nodes_.empty()) { - VLOG(1) << std::string(27, ' ') + "LS " << max_num_decisions_ << " finished." + VLOG(1) << std::string(27, ' ') + "LS " << max_num_decisions_ + << " finished." << " #explored:" << num_nodes_ << " #stored:" << transposition_table_.size() << " #skipped:" << num_skipped_nodes_; diff --git a/ortools/bop/bop_ls.h b/ortools/bop/bop_ls.h index a0ea35ae177..d30e3dbb46f 100644 --- a/ortools/bop/bop_ls.h +++ b/ortools/bop/bop_ls.h @@ -31,12 +31,12 @@ #include #include "ortools/base/hash.h" +#include "ortools/base/random.h" #include "ortools/bop/bop_base.h" #include "ortools/bop/bop_solution.h" #include "ortools/bop/bop_types.h" #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/sat_solver.h" -#include "ortools/base/random.h" namespace operations_research { namespace bop { @@ -481,7 +481,7 @@ class OneFlipConstraintRepairer { // on most promising variables first. void SortTermsOfEachConstraints(int num_variables); - ITIVector > + ITIVector> by_constraint_matrix_; const AssignmentAndConstraintFeasibilityMaintainer& maintainer_; const sat::VariablesAssignment& sat_assignment_; diff --git a/ortools/bop/bop_portfolio.cc b/ortools/bop/bop_portfolio.cc index bd3954c101e..7ed9c8c7f29 100644 --- a/ortools/bop/bop_portfolio.cc +++ b/ortools/bop/bop_portfolio.cc @@ -13,9 +13,8 @@ #include "ortools/bop/bop_portfolio.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/bop/bop_fs.h" #include "ortools/bop/bop_lns.h" #include "ortools/bop/bop_ls.h" @@ -410,7 +409,8 @@ void OptimizerSelector::SetOptimizerRunnability(OptimizerIndex optimizer_index, run_infos_[info_positions_[optimizer_index]].runnable = runnable; } -std::string OptimizerSelector::PrintStats(OptimizerIndex optimizer_index) const { +std::string OptimizerSelector::PrintStats( + OptimizerIndex optimizer_index) const { const RunInfo& info = run_infos_[info_positions_[optimizer_index]]; return absl::StrFormat( " %40s : %3d/%-3d (%6.2f%%) Total gain: %6d Total Dtime: %0.3f " diff --git a/ortools/bop/bop_solver.cc b/ortools/bop/bop_solver.cc index 63e04e40013..2bb3fb454b3 100644 --- a/ortools/bop/bop_solver.cc +++ b/ortools/bop/bop_solver.cc @@ -16,10 +16,10 @@ #include #include -#include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" #include "google/protobuf/text_format.h" +#include "ortools/base/commandlineflags.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/bop/bop_fs.h" #include "ortools/bop/bop_lns.h" #include "ortools/bop/bop_ls.h" @@ -172,8 +172,9 @@ double BopSolver::GetScaledBestBound() const { } double BopSolver::GetScaledGap() const { - return 100.0 * std::abs(problem_state_.solution().GetScaledCost() - - GetScaledBestBound()) / + return 100.0 * + std::abs(problem_state_.solution().GetScaledCost() - + GetScaledBestBound()) / std::abs(problem_state_.solution().GetScaledCost()); } diff --git a/ortools/bop/bop_solver.h b/ortools/bop/bop_solver.h index c6cddb5423f..51a55c04b2f 100644 --- a/ortools/bop/bop_solver.h +++ b/ortools/bop/bop_solver.h @@ -40,11 +40,11 @@ #include #include "ortools/base/basictypes.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/bop/bop_base.h" #include "ortools/bop/bop_parameters.pb.h" #include "ortools/bop/bop_solution.h" diff --git a/ortools/bop/integral_solver.cc b/ortools/bop/integral_solver.cc index 8b2d4e44dfd..ae83178ba1e 100644 --- a/ortools/bop/integral_solver.cc +++ b/ortools/bop/integral_solver.cc @@ -24,12 +24,12 @@ namespace bop { using operations_research::glop::ColIndex; using operations_research::glop::DenseRow; using operations_research::glop::Fractional; +using operations_research::glop::kInfinity; using operations_research::glop::LinearProgram; using operations_research::glop::LPDecomposer; +using operations_research::glop::RowIndex; using operations_research::glop::SparseColumn; using operations_research::glop::SparseMatrix; -using operations_research::glop::RowIndex; -using operations_research::glop::kInfinity; namespace { // TODO(user): Use an existing one or move it to util. @@ -1020,8 +1020,9 @@ void RunOneBop(const BopParameters& parameters, int problem_index, const int local_num_variables = std::max(1, problem.num_variables().value()); NestedTimeLimit subproblem_time_limit( - time_limit, std::max(time_per_variable * local_num_variables, - parameters.decomposed_problem_min_time_in_seconds()), + time_limit, + std::max(time_per_variable * local_num_variables, + parameters.decomposed_problem_min_time_in_seconds()), deterministic_time_per_variable * local_num_variables); *status = InternalSolve(problem, parameters, local_initial_solution, @@ -1066,7 +1067,6 @@ BopSolveStatus IntegralSolver::SolveWithTimeLimit( // happens, we will simply change the target of this pointer. LinearProgram const* lp = &linear_problem; - BopSolveStatus status; if (lp->num_variables() >= parameters_.decomposer_num_variables_threshold()) { LPDecomposer decomposer; @@ -1082,13 +1082,13 @@ BopSolveStatus IntegralSolver::SolveWithTimeLimit( Fractional(0.0)); std::vector best_bounds(num_sub_problems, Fractional(0.0)); std::vector statuses(num_sub_problems, - BopSolveStatus::INVALID_PROBLEM); + BopSolveStatus::INVALID_PROBLEM); - for (int i = 0; i < num_sub_problems; ++i) { - RunOneBop(parameters_, i, initial_solution, time_limit, &decomposer, - &(variable_values[i]), &(objective_values[i]), - &(best_bounds[i]), &(statuses[i])); - } + for (int i = 0; i < num_sub_problems; ++i) { + RunOneBop(parameters_, i, initial_solution, time_limit, &decomposer, + &(variable_values[i]), &(objective_values[i]), + &(best_bounds[i]), &(statuses[i])); + } // Aggregate results. status = BopSolveStatus::OPTIMAL_SOLUTION_FOUND; diff --git a/ortools/bop/integral_solver.h b/ortools/bop/integral_solver.h index c05740a1afd..71cf7398a57 100644 --- a/ortools/bop/integral_solver.h +++ b/ortools/bop/integral_solver.h @@ -47,8 +47,7 @@ class IntegralSolver { // TODO(user): Change the API to accept a partial solution instead since the // underlying solver supports it. BopSolveStatus Solve(const glop::LinearProgram& linear_problem, - const glop::DenseRow& initial_solution) - MUST_USE_RESULT; + const glop::DenseRow& initial_solution) MUST_USE_RESULT; BopSolveStatus SolveWithTimeLimit(const glop::LinearProgram& linear_problem, const glop::DenseRow& initial_solution, TimeLimit* time_limit) MUST_USE_RESULT; diff --git a/ortools/constraint_solver/ac4_mdd_reset_table.cc b/ortools/constraint_solver/ac4_mdd_reset_table.cc index 077579bdcac..8ae84be143b 100644 --- a/ortools/constraint_solver/ac4_mdd_reset_table.cc +++ b/ortools/constraint_solver/ac4_mdd_reset_table.cc @@ -14,11 +14,11 @@ #include #include #include +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -29,10 +29,10 @@ namespace operations_research { namespace { /** -* Creation of Mdd, from Yap & al, "An Mdd-based Generalized Arc Consistency -* Algorithm for Positive and Negative Table Constraints and Some Global -* Constraints" -*/ + * Creation of Mdd, from Yap & al, "An Mdd-based Generalized Arc Consistency + * Algorithm for Positive and Negative Table Constraints and Some Global + * Constraints" + */ // Mdd_compression class Mdd { @@ -252,7 +252,7 @@ class MddFactory { } Mdd* ReCount(Mdd* T) { - std::vector *v1, *v2, *tmp; + std::vector*v1, *v2, *tmp; int nb = 0; std::vector visited(getNbInstance()); @@ -283,7 +283,7 @@ class MddFactory { } void Draw(Mdd* T) { - std::vector *v1, *v2, *tmp; + std::vector*v1, *v2, *tmp; std::cout << "digraph G{\n"; std::vector visited(getNbInstance()); v1 = new std::vector(); @@ -1088,15 +1088,15 @@ class MddTableVar { } void ComputeDeltaDomain(std::vector* delta) { -// nouvelle version, Pour Laurent, il utilise des bitset et -// recupère donc les valeurs supprimer / modifier en parcourant -// le plus petit ensemble des deux. -// Ici j'ai besoin pour voir directement itérer ensuite sur les -// Bon/Mauvais rapidement (en prenant donc le plus petit ensemble -// des deux) -// Idée 1) utilisé un sparseSet pour mon domain. il permetra -// de soit supprimer les valeurs supprimées, soit de reset -// et de remetre les valeur postive. + // nouvelle version, Pour Laurent, il utilise des bitset et + // recupère donc les valeurs supprimer / modifier en parcourant + // le plus petit ensemble des deux. + // Ici j'ai besoin pour voir directement itérer ensuite sur les + // Bon/Mauvais rapidement (en prenant donc le plus petit ensemble + // des deux) + // Idée 1) utilisé un sparseSet pour mon domain. il permetra + // de soit supprimer les valeurs supprimées, soit de reset + // et de remetre les valeur postive. #define NEWDELTA diff --git a/ortools/constraint_solver/ac4r_table.cc b/ortools/constraint_solver/ac4r_table.cc index 95f3d4a958c..c9767709a55 100644 --- a/ortools/constraint_solver/ac4r_table.cc +++ b/ortools/constraint_solver/ac4r_table.cc @@ -11,11 +11,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/int_type.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -121,8 +121,7 @@ class TableVar { value_index++) { tuples_per_value_[value_index] = new RevIntSet(column.NumTuplesContainingValueIndex(value_index), - shared_positions_.get(), - column.NumTuples()); + shared_positions_.get(), column.NumTuples()); active_values_.Insert(solver_, value_index); } } diff --git a/ortools/constraint_solver/alldiff_cst.cc b/ortools/constraint_solver/alldiff_cst.cc index 722cf205a27..35d02d4743a 100644 --- a/ortools/constraint_solver/alldiff_cst.cc +++ b/ortools/constraint_solver/alldiff_cst.cc @@ -146,8 +146,8 @@ class RangeBipartiteMatching { : solver_(solver), size_(size), intervals_(new Interval[size + 1]), - min_sorted_(new Interval* [size]), - max_sorted_(new Interval* [size]), + min_sorted_(new Interval*[size]), + max_sorted_(new Interval*[size]), bounds_(new int64[2 * size + 2]), tree_(new int[2 * size + 2]), diff_(new int64[2 * size + 2]), @@ -340,8 +340,8 @@ class RangeBipartiteMatching { Solver* const solver_; const int size_; std::unique_ptr intervals_; - std::unique_ptr min_sorted_; - std::unique_ptr max_sorted_; + std::unique_ptr min_sorted_; + std::unique_ptr max_sorted_; // bounds_[1..active_size_] hold set of min & max in the n intervals_ // while bounds_[0] and bounds_[active_size_ + 1] allow sentinels. std::unique_ptr bounds_; diff --git a/ortools/constraint_solver/assignment.cc b/ortools/constraint_solver/assignment.cc index 234f6581fa4..28bd0a0735d 100644 --- a/ortools/constraint_solver/assignment.cc +++ b/ortools/constraint_solver/assignment.cc @@ -11,21 +11,19 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include #include +#include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/file.h" -#include "ortools/base/recordio.h" -#include "ortools/base/join.h" +#include "ortools/base/hash.h" +#include "ortools/base/integral_types.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/recordio.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/assignment.pb.h" #include "ortools/constraint_solver/constraint_solver.h" @@ -505,7 +503,7 @@ template void RealLoad(const AssignmentProto& assignment_proto, Container* const container, int (AssignmentProto::*GetSize)() const, - const Proto& (AssignmentProto::*GetElem)(int) const) { + const Proto& (AssignmentProto::*GetElem)(int)const) { bool fast_load = (container->Size() == (assignment_proto.*GetSize)()); for (int i = 0; fast_load && i < (assignment_proto.*GetSize)(); ++i) { Element* const element = container->MutableElement(i); @@ -848,20 +846,20 @@ void Assignment::SetSequence(const SequenceVar* const var, const std::vector& forward_sequence, const std::vector& backward_sequence, const std::vector& unperformed) { - sequence_var_container_.MutableElement(var) - ->SetSequence(forward_sequence, backward_sequence, unperformed); + sequence_var_container_.MutableElement(var)->SetSequence( + forward_sequence, backward_sequence, unperformed); } void Assignment::SetForwardSequence(const SequenceVar* const var, const std::vector& forward_sequence) { - sequence_var_container_.MutableElement(var) - ->SetForwardSequence(forward_sequence); + sequence_var_container_.MutableElement(var)->SetForwardSequence( + forward_sequence); } void Assignment::SetBackwardSequence( const SequenceVar* const var, const std::vector& backward_sequence) { - sequence_var_container_.MutableElement(var) - ->SetBackwardSequence(backward_sequence); + sequence_var_container_.MutableElement(var)->SetBackwardSequence( + backward_sequence); } void Assignment::SetUnperformed(const SequenceVar* const var, diff --git a/ortools/constraint_solver/collect_variables.cc b/ortools/constraint_solver/collect_variables.cc index dd1e5cf5964..3947f7fd3e4 100644 --- a/ortools/constraint_solver/collect_variables.cc +++ b/ortools/constraint_solver/collect_variables.cc @@ -11,10 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include #include +#include #include #include "ortools/base/integral_types.h" diff --git a/ortools/constraint_solver/constraint_solver.cc b/ortools/constraint_solver/constraint_solver.cc index bc45320e3d0..70b4c87cd7e 100644 --- a/ortools/constraint_solver/constraint_solver.cc +++ b/ortools/constraint_solver/constraint_solver.cc @@ -26,18 +26,18 @@ #include "ortools/base/random.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" -#include "ortools/base/recordio.h" -#include "zlib.h" #include "ortools/base/map_util.h" +#include "ortools/base/recordio.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/model.pb.h" #include "ortools/util/tuple_set.h" +#include "zlib.h" // These flags are used to set the fields in the DefaultSolverParameters proto. DEFINE_bool(cp_trace_propagation, false, @@ -525,7 +525,6 @@ class TrailPacker { DISALLOW_COPY_AND_ASSIGN(TrailPacker); }; - template class NoCompressionTrailPacker : public TrailPacker { public: @@ -596,8 +595,8 @@ class CompressedTrail { : block_size_(block_size), blocks_(nullptr), free_blocks_(nullptr), - data_(new addrval[ block_size ]), - buffer_(new addrval[ block_size ]), + data_(new addrval[block_size]), + buffer_(new addrval[block_size]), buffer_used_(false), current_(0), size_(0) { @@ -1344,7 +1343,6 @@ class BalancingDecision : public Decision { Decision* Solver::MakeFailDecision() { return fail_decision_.get(); } - // ------------------ Solver class ----------------- // These magic numbers are there to make sure we pop the correct @@ -1370,7 +1368,8 @@ void CheckSolverParameters(const ConstraintSolverParameters& parameters) { } } // namespace -Solver::Solver(const std::string& name, const ConstraintSolverParameters& parameters) +Solver::Solver(const std::string& name, + const ConstraintSolverParameters& parameters) : name_(name), parameters_(parameters), random_(ACMRandom::DeterministicSeed()), @@ -1471,22 +1470,19 @@ std::string Solver::DebugString() const { out += "PROBLEM_INFEASIBLE"; break; } - StringAppendF(&out, ", branches = %" GG_LL_FORMAT "d, fails = %" GG_LL_FORMAT - "d, decisions = %" GG_LL_FORMAT - "d, delayed demon runs = %" GG_LL_FORMAT - "d, var demon runs = %" GG_LL_FORMAT - "d, normal demon runs = %" GG_LL_FORMAT - "d, Run time = %" GG_LL_FORMAT "d ms)", - branches_, fails_, decisions_, demon_runs_[DELAYED_PRIORITY], - demon_runs_[VAR_PRIORITY], demon_runs_[NORMAL_PRIORITY], - wall_time()); + StringAppendF( + &out, + ", branches = %" GG_LL_FORMAT "d, fails = %" GG_LL_FORMAT + "d, decisions = %" GG_LL_FORMAT "d, delayed demon runs = %" GG_LL_FORMAT + "d, var demon runs = %" GG_LL_FORMAT + "d, normal demon runs = %" GG_LL_FORMAT "d, Run time = %" GG_LL_FORMAT + "d ms)", + branches_, fails_, decisions_, demon_runs_[DELAYED_PRIORITY], + demon_runs_[VAR_PRIORITY], demon_runs_[NORMAL_PRIORITY], wall_time()); return out; } -int64 Solver::MemoryUsage() { - return GetProcessMemoryUsage(); -} - +int64 Solver::MemoryUsage() { return GetProcessMemoryUsage(); } int64 Solver::wall_time() const { return timer_->GetInMs(); } @@ -2451,7 +2447,8 @@ std::string Solver::GetName(const PropagationBaseObject* object) { return empty_name_; } -void Solver::SetName(const PropagationBaseObject* object, const std::string& name) { +void Solver::SetName(const PropagationBaseObject* object, + const std::string& name) { if (parameters_.store_names() && GetName(object).compare(name) != 0) { // in particular if name.empty() propagation_object_names_[object] = name; @@ -2732,15 +2729,16 @@ void ModelVisitor::VisitIntegerVariable(const IntVar* const variable, } void ModelVisitor::VisitIntegerVariable(const IntVar* const variable, - const std::string& operation, int64 value, - IntVar* const delegate) { + const std::string& operation, + int64 value, IntVar* const delegate) { if (delegate != nullptr) { delegate->Accept(this); } } void ModelVisitor::VisitIntervalVariable(const IntervalVar* const variable, - const std::string& operation, int64 value, + const std::string& operation, + int64 value, IntervalVar* const delegate) { if (delegate != nullptr) { delegate->Accept(this); @@ -2753,7 +2751,8 @@ void ModelVisitor::VisitSequenceVariable(const SequenceVar* const variable) { } } -void ModelVisitor::VisitIntegerArgument(const std::string& arg_name, int64 value) {} +void ModelVisitor::VisitIntegerArgument(const std::string& arg_name, + int64 value) {} void ModelVisitor::VisitIntegerArrayArgument(const std::string& arg_name, const std::vector& values) { @@ -3165,7 +3164,9 @@ class LocalSearchMonitorMaster : public LocalSearchMonitor { // events. void Install() override { SearchMonitor::Install(); } - std::string DebugString() const override { return "LocalSearchMonitorMaster"; } + std::string DebugString() const override { + return "LocalSearchMonitorMaster"; + } private: std::vector monitors_; diff --git a/ortools/constraint_solver/constraint_solver.h b/ortools/constraint_solver/constraint_solver.h index 03254d39bb4..8c5b1a7b873 100644 --- a/ortools/constraint_solver/constraint_solver.h +++ b/ortools/constraint_solver/constraint_solver.h @@ -65,32 +65,31 @@ #define OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVER_H_ #include -#include -#include #include #include #include +#include +#include #include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/map_util.h" +#include "ortools/base/random.h" #include "ortools/base/stringprintf.h" #include "ortools/base/sysinfo.h" #include "ortools/base/timer.h" -#include "ortools/base/map_util.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/solver_parameters.pb.h" #include "ortools/util/piecewise_linear_function.h" #include "ortools/util/sorted_interval_list.h" #include "ortools/util/tuple_set.h" -#include "ortools/base/random.h" class File; - namespace operations_research { class Assignment; @@ -1029,9 +1028,12 @@ class Solver { std::vector* const interval_variables); ConstraintBuilder GetConstraintBuilder(const std::string& tag) const; - IntegerExpressionBuilder GetIntegerExpressionBuilder(const std::string& tag) const; - IntervalVariableBuilder GetIntervalVariableBuilder(const std::string& tag) const; - SequenceVariableBuilder GetSequenceVariableBuilder(const std::string& tag) const; + IntegerExpressionBuilder GetIntegerExpressionBuilder( + const std::string& tag) const; + IntervalVariableBuilder GetIntervalVariableBuilder( + const std::string& tag) const; + SequenceVariableBuilder GetSequenceVariableBuilder( + const std::string& tag) const; #endif // SWIG #if !defined(SWIG) @@ -1048,7 +1050,6 @@ class Solver { // Current memory usage in bytes static int64 MemoryUsage(); - // The wall_time() in ms since the creation of the solver. int64 wall_time() const; @@ -1593,7 +1594,8 @@ class Solver { Constraint* MakeSortingConstraint(const std::vector& vars, const std::vector& sorted); // TODO(user): Add void MakeSortedArray(const std::vector& vars, - // std::vector* const sorted); + // std::vector* const + // sorted); // Creates a constraint that enforces that left is lexicographically less // than right. @@ -1765,7 +1767,7 @@ class Solver { // Compatibility layer for python API. Constraint* MakeAllowedAssignments( const std::vector& vars, - const std::vector >& raw_tuples) { + const std::vector>& raw_tuples) { IntTupleSet tuples(vars.size()); tuples.InsertAll(raw_tuples); return MakeAllowedAssignments(vars, tuples); @@ -1773,7 +1775,7 @@ class Solver { Constraint* MakeTransitionConstraint( const std::vector& vars, - const std::vector >& raw_transitions, + const std::vector>& raw_transitions, int64 initial_state, const std::vector& final_states) { IntTupleSet transitions(3); transitions.InsertAll(raw_transitions); @@ -1847,7 +1849,8 @@ class Solver { // Creates a performed interval var with a fixed duration. The duration must // be greater than 0. IntervalVar* MakeFixedDurationIntervalVar(IntVar* const start_variable, - int64 duration, const std::string& name); + int64 duration, + const std::string& name); // Creates an interval var with a fixed duration, and performed var. // The duration must be greater than 0. @@ -2392,7 +2395,6 @@ class Solver { SearchMonitor* MakeSearchLog(int branch_period, OptimizeVar* const opt_var, std::function display_callback); - // ----- Search Trace ------ // Creates a search monitor that will trace precisely the behavior of the @@ -3109,7 +3111,8 @@ class Solver { // Registers a constraint builder. void RegisterBuilder(const std::string& tag, ConstraintBuilder builder); // Registers an integer expression builder. - void RegisterBuilder(const std::string& tag, IntegerExpressionBuilder builder); + void RegisterBuilder(const std::string& tag, + IntegerExpressionBuilder builder); // Registers an interval variable builder. void RegisterBuilder(const std::string& tag, IntervalVariableBuilder builder); // Registers a sequence variable builder. @@ -3143,8 +3146,10 @@ class Solver { const std::string name_; const ConstraintSolverParameters parameters_; - std::unordered_map propagation_object_names_; - std::unordered_map cast_information_; + std::unordered_map + propagation_object_names_; + std::unordered_map + cast_information_; std::unordered_set cast_constraints_; const std::string empty_name_; std::unique_ptr queue_; @@ -3186,7 +3191,8 @@ class Solver { int num_int_vars_; // Support for model loading. - std::unordered_map expression_builders_; + std::unordered_map + expression_builders_; std::unordered_map constraint_builders_; std::unordered_map interval_builders_; std::unordered_map sequence_builders_; @@ -4969,8 +4975,8 @@ class AssignmentContainer { } E* MutableElement(const V* const var) { E* const element = MutableElementOrNull(var); - DCHECK(element != nullptr) << "Unknown variable " << var->DebugString() - << " in solution"; + DCHECK(element != nullptr) + << "Unknown variable " << var->DebugString() << " in solution"; return element; } E* MutableElementOrNull(const V* const var) { @@ -4982,8 +4988,8 @@ class AssignmentContainer { } const E& Element(const V* const var) const { const E* const element = ElementPtrOrNull(var); - DCHECK(element != nullptr) << "Unknown variable " << var->DebugString() - << " in solution"; + DCHECK(element != nullptr) + << "Unknown variable " << var->DebugString() << " in solution"; return *element; } const E* ElementPtrOrNull(const V* const var) const { @@ -5024,7 +5030,8 @@ class AssignmentContainer { // but also how the map is hashed (e.g., number of buckets). This is not // what we want. for (const E& element : container.elements_) { - const int position = gtl::FindWithDefault(elements_map_, element.Var(), -1); + const int position = + gtl::FindWithDefault(elements_map_, element.Var(), -1); if (position < 0 || elements_[position] != element) { return false; } @@ -5360,13 +5367,13 @@ class Pack : public Constraint { const int bins_; std::vector dims_; std::unique_ptr unprocessed_; - std::vector > forced_; - std::vector > removed_; + std::vector> forced_; + std::vector> removed_; std::vector holes_; uint64 stamp_; Demon* demon_; - std::vector > to_set_; - std::vector > to_unset_; + std::vector> to_set_; + std::vector> to_unset_; bool in_process_; }; diff --git a/ortools/constraint_solver/constraint_solveri.h b/ortools/constraint_solver/constraint_solveri.h index 4538a28684b..65f3e5b7612 100644 --- a/ortools/constraint_solver/constraint_solveri.h +++ b/ortools/constraint_solver/constraint_solveri.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Collection of objects used to extend the Constraint Solver library. // // This file contains a set of objects that simplifies writing extensions @@ -54,19 +53,19 @@ #include #include #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" +#include "ortools/base/map_util.h" #include "ortools/base/sysinfo.h" #include "ortools/base/timer.h" -#include "ortools/base/join.h" -#include "ortools/base/map_util.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/model.pb.h" #include "ortools/util/bitset.h" @@ -88,7 +87,8 @@ class CPIntervalVariableProto; // and subclasses of BaseIntExpr. Variables are stateful objects that // provide a rich API (remove values, WhenBound...). On the other hand, // subclasses of BaseIntExpr represent range-only stateless objects. -// That is, std::min(A + B) is recomputed each time as std::min(A) + std::min(B). +// That is, std::min(A + B) is recomputed each time as std::min(A) + +// std::min(B). // // Furthermore, sometimes, the propagation on an expression is not complete, // and Min(), Max() are not monotonic with respect to SetMin() and SetMax(). @@ -555,7 +555,8 @@ std::string ParameterDebugString(P* param) { template class CallMethod1 : public Demon { public: - CallMethod1(T* const ct, void (T::*method)(P), const std::string& name, P param1) + CallMethod1(T* const ct, void (T::*method)(P), const std::string& name, + P param1) : constraint_(ct), method_(method), name_(name), param1_(param1) {} ~CallMethod1() override {} @@ -600,9 +601,9 @@ class CallMethod2 : public Demon { std::string DebugString() const override { return absl::StrCat(absl::StrCat("CallMethod_", name_), - absl::StrCat("(", constraint_->DebugString()), - absl::StrCat(", ", ParameterDebugString(param1_)), - absl::StrCat(", ", ParameterDebugString(param2_), ")")); + absl::StrCat("(", constraint_->DebugString()), + absl::StrCat(", ", ParameterDebugString(param1_)), + absl::StrCat(", ", ParameterDebugString(param2_), ")")); } private: @@ -641,10 +642,10 @@ class CallMethod3 : public Demon { std::string DebugString() const override { return absl::StrCat(absl::StrCat("CallMethod_", name_), - absl::StrCat("(", constraint_->DebugString()), - absl::StrCat(", ", ParameterDebugString(param1_)), - absl::StrCat(", ", ParameterDebugString(param2_)), - absl::StrCat(", ", ParameterDebugString(param3_), ")")); + absl::StrCat("(", constraint_->DebugString()), + absl::StrCat(", ", ParameterDebugString(param1_)), + absl::StrCat(", ", ParameterDebugString(param2_)), + absl::StrCat(", ", ParameterDebugString(param3_), ")")); } private: @@ -698,7 +699,8 @@ class DelayedCallMethod0 : public Demon { template Demon* MakeDelayedConstraintDemon0(Solver* const s, T* const ct, - void (T::*method)(), const std::string& name) { + void (T::*method)(), + const std::string& name) { return s->RevAlloc(new DelayedCallMethod0(ct, method, name)); } @@ -733,8 +735,8 @@ class DelayedCallMethod1 : public Demon { template Demon* MakeDelayedConstraintDemon1(Solver* const s, T* const ct, - void (T::*method)(P), const std::string& name, - P param1) { + void (T::*method)(P), + const std::string& name, P param1) { return s->RevAlloc(new DelayedCallMethod1(ct, method, name, param1)); } @@ -742,8 +744,8 @@ Demon* MakeDelayedConstraintDemon1(Solver* const s, T* const ct, template class DelayedCallMethod2 : public Demon { public: - DelayedCallMethod2(T* const ct, void (T::*method)(P, Q), const std::string& name, - P param1, Q param2) + DelayedCallMethod2(T* const ct, void (T::*method)(P, Q), + const std::string& name, P param1, Q param2) : constraint_(ct), method_(method), name_(name), @@ -762,9 +764,9 @@ class DelayedCallMethod2 : public Demon { std::string DebugString() const override { return absl::StrCat(absl::StrCat("DelayedCallMethod_", name_), - absl::StrCat("(", constraint_->DebugString()), - absl::StrCat(", ", ParameterDebugString(param1_)), - absl::StrCat(", ", ParameterDebugString(param2_), ")")); + absl::StrCat("(", constraint_->DebugString()), + absl::StrCat(", ", ParameterDebugString(param1_)), + absl::StrCat(", ", ParameterDebugString(param2_), ")")); } private: @@ -777,8 +779,9 @@ class DelayedCallMethod2 : public Demon { template Demon* MakeDelayedConstraintDemon2(Solver* const s, T* const ct, - void (T::*method)(P, Q), const std::string& name, - P param1, Q param2) { + void (T::*method)(P, Q), + const std::string& name, P param1, + Q param2) { return s->RevAlloc( new DelayedCallMethod2(ct, method, name, param1, param2)); } @@ -2007,14 +2010,16 @@ class ArgumentHolder { bool HasIntegerVariableArrayArgument(const std::string& arg_name) const; // Getters. - int64 FindIntegerArgumentWithDefault(const std::string& arg_name, int64 def) const; + int64 FindIntegerArgumentWithDefault(const std::string& arg_name, + int64 def) const; int64 FindIntegerArgumentOrDie(const std::string& arg_name) const; const std::vector& FindIntegerArrayArgumentOrDie( const std::string& arg_name) const; const IntTupleSet& FindIntegerMatrixArgumentOrDie( const std::string& arg_name) const; - IntExpr* FindIntegerExpressionArgumentOrDie(const std::string& arg_name) const; + IntExpr* FindIntegerExpressionArgumentOrDie( + const std::string& arg_name) const; const std::vector& FindIntegerVariableArrayArgumentOrDie( const std::string& arg_name) const; @@ -2026,9 +2031,12 @@ class ArgumentHolder { std::unordered_map integer_expression_argument_; std::unordered_map interval_argument_; std::unordered_map sequence_argument_; - std::unordered_map > integer_variable_array_argument_; - std::unordered_map > interval_array_argument_; - std::unordered_map > sequence_array_argument_; + std::unordered_map > + integer_variable_array_argument_; + std::unordered_map > + interval_array_argument_; + std::unordered_map > + sequence_array_argument_; }; // Model Parser @@ -2069,7 +2077,8 @@ class ModelParser : public ModelVisitor { void VisitIntegerExpressionArgument(const std::string& arg_name, IntExpr* const argument) override; void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override; + const std::string& arg_name, + const std::vector& arguments) override; // Visit interval argument. void VisitIntervalArgument(const std::string& arg_name, IntervalVar* const argument) override; @@ -2114,7 +2123,6 @@ class CpModelLoader { // Returns the number of stored interval variables. int NumIntervalVariables() const { return intervals_.size(); } - #if !defined(SWIG) // Internal, do not use. diff --git a/ortools/constraint_solver/constraints.cc b/ortools/constraint_solver/constraints.cc index 15e0c6355d0..2428687bc9c 100644 --- a/ortools/constraint_solver/constraints.cc +++ b/ortools/constraint_solver/constraints.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -20,9 +19,9 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/saturated_arithmetic.h" diff --git a/ortools/constraint_solver/count_cst.cc b/ortools/constraint_solver/count_cst.cc index 9e4d7321c6a..8ea2dea229d 100644 --- a/ortools/constraint_solver/count_cst.cc +++ b/ortools/constraint_solver/count_cst.cc @@ -19,10 +19,9 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/string_array.h" diff --git a/ortools/constraint_solver/default_search.cc b/ortools/constraint_solver/default_search.cc index 3314f00ec22..0f7082acf26 100644 --- a/ortools/constraint_solver/default_search.cc +++ b/ortools/constraint_solver/default_search.cc @@ -11,13 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include -#include #include #include #include +#include #include #include @@ -27,12 +26,12 @@ #include "ortools/base/macros.h" #include "ortools/base/stringprintf.h" +#include "ortools/base/random.h" #include "ortools/base/stl_util.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/cached_log.h" #include "ortools/util/string_array.h" -#include "ortools/base/random.h" DEFINE_int32(cp_impact_divider, 10, "Divider for continuous update."); @@ -145,7 +144,9 @@ class FindVar : public DecisionVisitor { Operation operation() const { return operation_; } - std::string DebugString() const override { return "FindVar decision visitor"; } + std::string DebugString() const override { + return "FindVar decision visitor"; + } private: IntVar* var_; @@ -622,7 +623,9 @@ class ImpactRecorder : public SearchMonitor { InitVarImpacts* without_split() { return &without_splits_; } InitVarImpactsWithSplits* with_splits() { return &with_splits_; } - std::string DebugString() const override { return "FirstRunVariableContainers"; } + std::string DebugString() const override { + return "FirstRunVariableContainers"; + } private: const std::function update_impact_callback_; @@ -639,7 +642,7 @@ class ImpactRecorder : public SearchMonitor { // original_min_[i] + j to variable i. std::vector > impacts_; std::vector original_min_; - std::unique_ptr domain_iterators_; + std::unique_ptr domain_iterators_; int64 init_count_; const DefaultPhaseParameters::DisplayLevel display_level_; int current_var_; diff --git a/ortools/constraint_solver/demon_profiler.cc b/ortools/constraint_solver/demon_profiler.cc index 16ee268beab..d0671accf1e 100644 --- a/ortools/constraint_solver/demon_profiler.cc +++ b/ortools/constraint_solver/demon_profiler.cc @@ -11,26 +11,25 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include -#include #include +#include #include #include +#include "ortools/base/file.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/status.h" +#include "ortools/base/stl_util.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" #include "ortools/base/time_support.h" -#include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/demon_profiler.pb.h" -#include "ortools/base/status.h" namespace operations_research { namespace { @@ -269,7 +268,8 @@ class DemonProfiler : public PropagationMonitor { if (file::Open(filename, "w", &file, file::Defaults()).ok()) { file::WriteString(file, model, file::Defaults()).IgnoreError(); std::vector to_sort; - for (std::unordered_map::const_iterator it = + for (std::unordered_map::const_iterator it = constraint_map_.begin(); it != constraint_map_.end(); ++it) { const Constraint* const ct = it->first; @@ -423,7 +423,8 @@ class DemonProfiler : public PropagationMonitor { const int64 start_time_ns_; std::unordered_map constraint_map_; std::unordered_map demon_map_; - std::unordered_map > demons_per_constraint_; + std::unordered_map > + demons_per_constraint_; }; void Solver::ExportProfilingOverview(const std::string& filename) { diff --git a/ortools/constraint_solver/deviation.cc b/ortools/constraint_solver/deviation.cc index 70c30cf83d9..610b4b2d2a0 100644 --- a/ortools/constraint_solver/deviation.cc +++ b/ortools/constraint_solver/deviation.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -20,8 +19,8 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/mathutil.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/util/string_array.h" diff --git a/ortools/constraint_solver/diffn.cc b/ortools/constraint_solver/diffn.cc index d726b6b258f..d269a3e55d1 100644 --- a/ortools/constraint_solver/diffn.cc +++ b/ortools/constraint_solver/diffn.cc @@ -15,17 +15,16 @@ #include #include +#include "ortools/base/hash.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/string_array.h" - namespace operations_research { // Diffn constraint, Non overlapping boxs. namespace { diff --git a/ortools/constraint_solver/element.cc b/ortools/constraint_solver/element.cc index e9b18d52248..747671adba5 100644 --- a/ortools/constraint_solver/element.cc +++ b/ortools/constraint_solver/element.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -20,10 +19,9 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/range_minimum_query.h" @@ -419,23 +417,23 @@ void RangeMinimumQueryExprElement::Range(int64* mi, int64* ma) { *ma = max_rmq_.GetMinimumFromRange(range_min, range_max); } -#define UPDATE_RMQ_BASE_ELEMENT_INDEX_BOUNDS(test) \ - const std::vector& values = min_rmq_.array(); \ - int64 index_min = IndexMin(); \ - int64 index_max = IndexMax(); \ - int64 value = values[index_min]; \ - while (index_min < index_max && (test)) { \ - index_min++; \ - value = values[index_min]; \ - } \ - if (index_min == index_max && (test)) { \ - solver()->Fail(); \ - } \ - value = values[index_max]; \ - while (index_max >= index_min && (test)) { \ - index_max--; \ - value = values[index_max]; \ - } \ +#define UPDATE_RMQ_BASE_ELEMENT_INDEX_BOUNDS(test) \ + const std::vector& values = min_rmq_.array(); \ + int64 index_min = IndexMin(); \ + int64 index_max = IndexMax(); \ + int64 value = values[index_min]; \ + while (index_min < index_max && (test)) { \ + index_min++; \ + value = values[index_min]; \ + } \ + if (index_min == index_max && (test)) { \ + solver()->Fail(); \ + } \ + value = values[index_max]; \ + while (index_max >= index_min && (test)) { \ + index_max--; \ + value = values[index_max]; \ + } \ index_->SetRange(index_min, index_max); void RangeMinimumQueryExprElement::SetMin(int64 m) { @@ -1331,7 +1329,7 @@ void IntExprEvaluatorElementCt::UpdateExpr() { namespace { std::string StringifyEvaluatorBare(const Solver::Int64ToIntVar& evaluator, - int64 range_start, int64 range_end) { + int64 range_start, int64 range_end) { std::string out; for (int64 i = range_start; i < range_end; ++i) { if (i != range_start) { @@ -1344,7 +1342,7 @@ std::string StringifyEvaluatorBare(const Solver::Int64ToIntVar& evaluator, } std::string StringifyInt64ToIntVar(const Solver::Int64ToIntVar& evaluator, - int64 range_begin, int64 range_end) { + int64 range_begin, int64 range_end) { std::string out; if (range_end - range_begin > 10) { out = StringPrintf( @@ -1770,8 +1768,9 @@ IntExpr* Solver::MakeIndexExpression(const std::vector& vars, if (cache != nullptr) { return cache->Var(); } else { - const std::string name = StringPrintf("Index(%s, %" GG_LL_FORMAT "d)", - JoinNamePtr(vars, ", ").c_str(), value); + const std::string name = + StringPrintf("Index(%s, %" GG_LL_FORMAT "d)", + JoinNamePtr(vars, ", ").c_str(), value); IntVar* const index = MakeIntVar(0, vars.size() - 1, name); AddConstraint(MakeIndexOfConstraint(vars, index, value)); model_cache_->InsertVarArrayConstantExpression( diff --git a/ortools/constraint_solver/expr_array.cc b/ortools/constraint_solver/expr_array.cc index be694417b9b..a6b98d98a34 100644 --- a/ortools/constraint_solver/expr_array.cc +++ b/ortools/constraint_solver/expr_array.cc @@ -20,10 +20,10 @@ #include #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/mathutil.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" @@ -63,7 +63,8 @@ class TreeArrayConstraint : public CastConstraint { target_var_->DebugString().c_str()); } - void AcceptInternal(const std::string& name, ModelVisitor* const visitor) const { + void AcceptInternal(const std::string& name, + ModelVisitor* const visitor) const { visitor->BeginVisitConstraint(name, this); visitor->VisitIntegerVariableArrayArgument(ModelVisitor::kVarsArgument, vars_); @@ -283,7 +284,9 @@ class SumConstraint : public TreeArrayConstraint { target_var_->SetRange(RootMin(), RootMax()); } - std::string DebugString() const override { return DebugStringInternal("Sum"); } + std::string DebugString() const override { + return DebugStringInternal("Sum"); + } void Accept(ModelVisitor* const visitor) const override { AcceptInternal(ModelVisitor::kSumEqual, visitor); @@ -593,7 +596,9 @@ class SafeSumConstraint : public TreeArrayConstraint { target_var_->SetRange(RootMin(), RootMax()); } - std::string DebugString() const override { return DebugStringInternal("Sum"); } + std::string DebugString() const override { + return DebugStringInternal("Sum"); + } void Accept(ModelVisitor* const visitor) const override { AcceptInternal(ModelVisitor::kSumEqual, visitor); @@ -773,7 +778,9 @@ class MinConstraint : public TreeArrayConstraint { MinVarChanged(); } - std::string DebugString() const override { return DebugStringInternal("Min"); } + std::string DebugString() const override { + return DebugStringInternal("Min"); + } void Accept(ModelVisitor* const visitor) const override { AcceptInternal(ModelVisitor::kMinEqual, visitor); @@ -1051,7 +1058,9 @@ class MaxConstraint : public TreeArrayConstraint { MaxVarChanged(); } - std::string DebugString() const override { return DebugStringInternal("Max"); } + std::string DebugString() const override { + return DebugStringInternal("Max"); + } void Accept(ModelVisitor* const visitor) const override { AcceptInternal(ModelVisitor::kMaxEqual, visitor); @@ -2486,7 +2495,8 @@ class ExprLinearizer : public ModelParser { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { Top()->SetIntegerVariableArrayArgument(arg_name, arguments); } @@ -3117,9 +3127,9 @@ IntExpr* MakeScalProdAux(Solver* solver, const std::vector& vars, if (AreAllPositive(coefs)) { if (vars.size() > 8) { return solver->MakeSum( - solver->RegisterIntExpr( - solver->RevAlloc( - new PositiveBooleanScalProd(solver, vars, coefs))) + solver + ->RegisterIntExpr(solver->RevAlloc( + new PositiveBooleanScalProd(solver, vars, coefs))) ->Var(), constant); } else { diff --git a/ortools/constraint_solver/expr_cst.cc b/ortools/constraint_solver/expr_cst.cc index e027b7f6652..2f6bd8be294 100644 --- a/ortools/constraint_solver/expr_cst.cc +++ b/ortools/constraint_solver/expr_cst.cc @@ -21,11 +21,10 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/saturated_arithmetic.h" diff --git a/ortools/constraint_solver/expressions.cc b/ortools/constraint_solver/expressions.cc index 70382d18128..235ab9b1fab 100644 --- a/ortools/constraint_solver/expressions.cc +++ b/ortools/constraint_solver/expressions.cc @@ -11,23 +11,22 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include -#include #include #include +#include #include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/stl_util.h" #include "ortools/base/mathutil.h" +#include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" @@ -448,10 +447,11 @@ class DomainIntVar : public IntVar { if (variable_->Bound()) { return solver()->MakeIntConst(1); } else { - const std::string vname = variable_->HasName() ? variable_->name() - : variable_->DebugString(); - const std::string bname = StringPrintf("Watch<%s == %" GG_LL_FORMAT "d>", - vname.c_str(), value); + const std::string vname = variable_->HasName() + ? variable_->name() + : variable_->DebugString(); + const std::string bname = StringPrintf( + "Watch<%s == %" GG_LL_FORMAT "d>", vname.c_str(), value); IntVar* const boolvar = solver()->MakeBoolVar(bname); watchers_.UnsafeRevInsert(value, boolvar); if (posted_.Switched()) { @@ -681,10 +681,11 @@ class DomainIntVar : public IntVar { if (variable_->Bound()) { return solver()->MakeIntConst(1); } else { - const std::string vname = variable_->HasName() ? variable_->name() - : variable_->DebugString(); - const std::string bname = StringPrintf("Watch<%s == %" GG_LL_FORMAT "d>", - vname.c_str(), value); + const std::string vname = variable_->HasName() + ? variable_->name() + : variable_->DebugString(); + const std::string bname = StringPrintf( + "Watch<%s == %" GG_LL_FORMAT "d>", vname.c_str(), value); IntVar* const boolvar = solver()->MakeBoolVar(bname); RevInsert(index, boolvar); if (posted_.Switched()) { @@ -936,10 +937,11 @@ class DomainIntVar : public IntVar { if (variable_->Min() >= value) { return solver()->MakeIntConst(1); } else { - const std::string vname = variable_->HasName() ? variable_->name() - : variable_->DebugString(); - const std::string bname = StringPrintf("Watch<%s >= %" GG_LL_FORMAT "d>", - vname.c_str(), value); + const std::string vname = variable_->HasName() + ? variable_->name() + : variable_->DebugString(); + const std::string bname = StringPrintf( + "Watch<%s >= %" GG_LL_FORMAT "d>", vname.c_str(), value); IntVar* const boolvar = solver()->MakeBoolVar(bname); watchers_.UnsafeRevInsert(value, boolvar); if (posted_.Switched()) { @@ -1176,10 +1178,11 @@ class DomainIntVar : public IntVar { if (variable_->Min() >= value) { return solver()->MakeIntConst(1); } else { - const std::string vname = variable_->HasName() ? variable_->name() - : variable_->DebugString(); - const std::string bname = StringPrintf("Watch<%s >= %" GG_LL_FORMAT "d>", - vname.c_str(), value); + const std::string vname = variable_->HasName() + ? variable_->name() + : variable_->DebugString(); + const std::string bname = StringPrintf( + "Watch<%s >= %" GG_LL_FORMAT "d>", vname.c_str(), value); IntVar* const boolvar = solver()->MakeBoolVar(bname); RevInsert(value - offset_, boolvar); if (posted_.Switched()) { @@ -1322,7 +1325,8 @@ class DomainIntVar : public IntVar { }; // ----- Main Class ----- - DomainIntVar(Solver* const s, int64 vmin, int64 vmax, const std::string& name); + DomainIntVar(Solver* const s, int64 vmin, int64 vmax, + const std::string& name); DomainIntVar(Solver* const s, const std::vector& sorted_values, const std::string& name); ~DomainIntVar() override; @@ -1723,9 +1727,9 @@ class SimpleBitSet : public DomainIntVar::BitSet { std::string DebugString() const override { std::string out; - SStringPrintf(&out, - "SimpleBitSet(%" GG_LL_FORMAT "d..%" GG_LL_FORMAT "d : ", - omin_, omax_); + SStringPrintf( + &out, "SimpleBitSet(%" GG_LL_FORMAT "d..%" GG_LL_FORMAT "d : ", omin_, + omax_); for (int i = 0; i < bsize_; ++i) { StringAppendF(&out, "%llx", bits_[i]); } @@ -2260,8 +2264,9 @@ void DomainIntVar::SetMin(int64 m) { } else { CheckOldMin(); const int64 new_min = - (bits_ == nullptr ? m : bits_->ComputeNewMin(m, min_.Value(), - max_.Value())); + (bits_ == nullptr + ? m + : bits_->ComputeNewMin(m, min_.Value(), max_.Value())); min_.SetValue(solver(), new_min); if (min_.Value() > max_.Value()) { solver()->Fail(); @@ -2283,8 +2288,9 @@ void DomainIntVar::SetMax(int64 m) { } else { CheckOldMax(); const int64 new_max = - (bits_ == nullptr ? m : bits_->ComputeNewMax(m, min_.Value(), - max_.Value())); + (bits_ == nullptr + ? m + : bits_->ComputeNewMax(m, min_.Value(), max_.Value())); max_.SetValue(solver(), new_max); if (min_.Value() > max_.Value()) { solver()->Fail(); @@ -2313,8 +2319,9 @@ void DomainIntVar::SetRange(int64 mi, int64 ma) { if (mi > min_.Value()) { CheckOldMin(); const int64 new_min = - (bits_ == nullptr ? mi : bits_->ComputeNewMin(mi, min_.Value(), - max_.Value())); + (bits_ == nullptr + ? mi + : bits_->ComputeNewMin(mi, min_.Value(), max_.Value())); min_.SetValue(solver(), new_min); } if (min_.Value() > ma) { @@ -2323,8 +2330,9 @@ void DomainIntVar::SetRange(int64 mi, int64 ma) { if (ma < max_.Value()) { CheckOldMax(); const int64 new_max = - (bits_ == nullptr ? ma : bits_->ComputeNewMax(ma, min_.Value(), - max_.Value())); + (bits_ == nullptr + ? ma + : bits_->ComputeNewMax(ma, min_.Value(), max_.Value())); max_.SetValue(solver(), new_max); } if (min_.Value() > max_.Value()) { @@ -4922,20 +4930,24 @@ class DivIntExpr : public BaseIntExpr { // Due to VS 2015 cl.exe limitation, it is impossible to create locals // (e.g. denom_min, denom_max) - // Once VS 2015 will be not supported please remove this comment and the associated commit. + // Once VS 2015 will be not supported please remove this comment and the + // associated commit. int64 Min() const override { if (denom_->Min() == 0 && denom_->Max() == 0) { - return kint64max; // TODO(user): Check this convention. + return kint64max; // TODO(user): Check this convention. } else if (denom_->Min() >= 0) { // Denominator strictly positive. DCHECK_GT(denom_->Max(), 0); const int64 num_min = num_->Min(); const int64 adjusted_denom_min = (denom_->Min() == 0) ? 1 : denom_->Min(); - return num_min >= 0 ? num_min / denom_->Max() : num_min / adjusted_denom_min; + return num_min >= 0 ? num_min / denom_->Max() + : num_min / adjusted_denom_min; } else if (denom_->Max() <= 0) { // Denominator strictly negative. DCHECK_LT(denom_->Min(), 0); const int64 num_max = num_->Max(); - const int64 adjusted_denom_max = (denom_->Max() == 0) ? -1 : denom_->Max(); - return num_max >= 0 ? num_max / adjusted_denom_max : num_max / denom_->Min(); + const int64 adjusted_denom_max = + (denom_->Max() == 0) ? -1 : denom_->Max(); + return num_max >= 0 ? num_max / adjusted_denom_max + : num_max / denom_->Min(); } else { // Denominator across 0. return std::min(num_->Min(), -num_->Max()); } @@ -4943,24 +4955,26 @@ class DivIntExpr : public BaseIntExpr { // Due to VS 2015 cl.exe limitation, it is impossible to create locals // (e.g. denom_min, denom_max) - // Once VS 2015 will be not supported please remove this comment and the associated commit. + // Once VS 2015 will be not supported please remove this comment and the + // associated commit. int64 Max() const override { - if (denom_->Min() == 0 && denom_->Max() == 0) { - return kint64min; // TODO(user): Check this convention. - } else if (denom_->Min() >= 0) { // Denominator strictly positive. - DCHECK_GT(denom_->Max(), 0); - const int64 num_max = num_->Max(); - const int64 adjusted_denom_min = denom_->Min() == 0 ? 1 : denom_->Min(); - return num_max >= 0 ? num_max / adjusted_denom_min : num_max / denom_->Max(); - } else if (denom_->Max() <= 0) { // Denominator strictly negative. - DCHECK_LT(denom_->Min(), 0); - const int64 num_min = num_->Min(); - const int64 adjusted_denom_max = denom_->Max() == 0 ? -1 : denom_->Max(); - return num_min >= 0 ? num_min / denom_->Min() - : -num_min / -adjusted_denom_max; - } else { // Denominator across 0. - return std::max(num_->Max(), -num_->Min()); - } + if (denom_->Min() == 0 && denom_->Max() == 0) { + return kint64min; // TODO(user): Check this convention. + } else if (denom_->Min() >= 0) { // Denominator strictly positive. + DCHECK_GT(denom_->Max(), 0); + const int64 num_max = num_->Max(); + const int64 adjusted_denom_min = denom_->Min() == 0 ? 1 : denom_->Min(); + return num_max >= 0 ? num_max / adjusted_denom_min + : num_max / denom_->Max(); + } else if (denom_->Max() <= 0) { // Denominator strictly negative. + DCHECK_LT(denom_->Min(), 0); + const int64 num_min = num_->Min(); + const int64 adjusted_denom_max = denom_->Max() == 0 ? -1 : denom_->Max(); + return num_min >= 0 ? num_min / denom_->Min() + : -num_min / -adjusted_denom_max; + } else { // Denominator across 0. + return std::max(num_->Max(), -num_->Min()); + } } void AdjustDenominator() { @@ -6477,7 +6491,8 @@ IntVar* Solver::MakeIntVar(const std::vector& values) { return MakeIntVar(values, ""); } -IntVar* Solver::MakeIntVar(const std::vector& values, const std::string& name) { +IntVar* Solver::MakeIntVar(const std::vector& values, + const std::string& name) { return MakeIntVar(ToInt64Vector(values), name); } @@ -6518,7 +6533,8 @@ std::string IndexedName(const std::string& prefix, int index, int max_index) { } // namespace void Solver::MakeIntVarArray(int var_count, int64 vmin, int64 vmax, - const std::string& name, std::vector* vars) { + const std::string& name, + std::vector* vars) { for (int i = 0; i < var_count; ++i) { vars->push_back(MakeIntVar(vmin, vmax, IndexedName(name, i, var_count))); } diff --git a/ortools/constraint_solver/gcc.cc b/ortools/constraint_solver/gcc.cc index 2cfd877321c..63b7918d60a 100644 --- a/ortools/constraint_solver/gcc.cc +++ b/ortools/constraint_solver/gcc.cc @@ -18,16 +18,15 @@ // Joint Conference on Artificial Intelligence (IJCAI 03), Acapulco, // Mexico, pages 245-250, 2003. - +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/vector_map.h" @@ -249,9 +248,9 @@ class GccConstraint : public Constraint { virtual void InitialPropagate() { // Sets the range. for (Index i(0); i < size_; ++i) { - variables_[i] - ->SetRange(first_domain_value_, - first_domain_value_ + max_occurrences_.size() - 1); + variables_[i]->SetRange( + first_domain_value_, + first_domain_value_ + max_occurrences_.size() - 1); } // Removes value with max card = 0; std::vector to_remove; @@ -292,11 +291,9 @@ class GccConstraint : public Constraint { // filterLower{Min,Max} and // filterUpper{Min,Max} do not check for this case. if ((lower_sum_.Sum(lower_sum_.MinValue(), - sorted_by_min_[0]->min_value - 1) > - 0) || + sorted_by_min_[0]->min_value - 1) > 0) || (lower_sum_.Sum(sorted_by_max_[size_ - 1]->max_value + 1, - lower_sum_.MaxValue()) > - 0)) { + lower_sum_.MaxValue()) > 0)) { solver()->Fail(); } @@ -307,8 +304,8 @@ class GccConstraint : public Constraint { if (has_changed) { for (Index i(0); i < size_; ++i) { - variables_[i] - ->SetRange(intervals_[i].min_value, intervals_[i].max_value); + variables_[i]->SetRange(intervals_[i].min_value, + intervals_[i].max_value); } } } @@ -719,16 +716,16 @@ Constraint* MakeGcc(Solver* const solver, const std::vector& vars, int64 first_domain_value, const std::vector& min_occurrences, const std::vector& max_occurrences) { - return solver->RevAlloc(new GccConstraint( - solver, vars, first_domain_value, min_occurrences.size(), min_occurrences, - max_occurrences)); + return solver->RevAlloc(new GccConstraint(solver, vars, first_domain_value, + min_occurrences.size(), + min_occurrences, max_occurrences)); } Constraint* MakeGcc(Solver* const solver, const std::vector& vars, int64 offset, const std::vector& min_occurrences, const std::vector& max_occurrences) { - return solver->RevAlloc( - new GccConstraint(solver, vars, offset, min_occurrences.size(), - min_occurrences, max_occurrences)); + return solver->RevAlloc(new GccConstraint(solver, vars, offset, + min_occurrences.size(), + min_occurrences, max_occurrences)); } } // namespace operations_research diff --git a/ortools/constraint_solver/graph_constraints.cc b/ortools/constraint_solver/graph_constraints.cc index 8fb9fe9762f..92eb5a73661 100644 --- a/ortools/constraint_solver/graph_constraints.cc +++ b/ortools/constraint_solver/graph_constraints.cc @@ -19,11 +19,9 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/saturated_arithmetic.h" @@ -458,8 +456,9 @@ class Circuit : public Constraint { const int new_start = starts_.Value(index); starts_.SetValue(s, new_end, new_start); ends_.SetValue(s, new_start, new_end); - lengths_.SetValue(s, new_start, lengths_.Value(new_start) + - lengths_.Value(destination)); + lengths_.SetValue( + s, new_start, + lengths_.Value(new_start) + lengths_.Value(destination)); if (sub_circuit_) { // You are creating the only path. Nexts can no longer loop upon itself. nexts_[destination]->RemoveValue(destination); diff --git a/ortools/constraint_solver/hybrid.cc b/ortools/constraint_solver/hybrid.cc index 74c9e981e3a..303427cf7b3 100644 --- a/ortools/constraint_solver/hybrid.cc +++ b/ortools/constraint_solver/hybrid.cc @@ -11,13 +11,12 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/constraint_solver/hybrid.h" #include #include -#include #include +#include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" @@ -36,17 +35,17 @@ DEFINE_bool(verbose_simplex_call, false, namespace operations_research { namespace { inline MPSolver::OptimizationProblemType LpSolverForCp() { - #if defined(USE_GUROBI) +#if defined(USE_GUROBI) return MPSolver::GUROBI_LINEAR_PROGRAMMING; - #elif defined(USE_CLP) +#elif defined(USE_CLP) return MPSolver::CLP_LINEAR_PROGRAMMING; - #elif defined(USE_GLPK) +#elif defined(USE_GLPK) return MPSolver::CLP_LINEAR_PROGRAMMING; - #elif defined(USE_SULUM) +#elif defined(USE_SULUM) return MPSolver::SULUM_LINEAR_PROGRAMMING; - #else +#else LOG(FATAL) << "No suitable linear programming solver available."; - #endif +#endif } class SimplexConnection : public SearchMonitor { @@ -132,7 +131,9 @@ class Linearizer : public ModelParser { ~Linearizer() override {} // Begin/End visit element. - void BeginVisitModel(const std::string& solver_name) override { BeginVisit(true); } + void BeginVisitModel(const std::string& solver_name) override { + BeginVisit(true); + } void EndVisitModel(const std::string& solver_name) override { EndVisit(); } @@ -163,7 +164,9 @@ class Linearizer : public ModelParser { } EndVisit(); } - void BeginVisitExtension(const std::string& type) override { BeginVisit(true); } + void BeginVisitExtension(const std::string& type) override { + BeginVisit(true); + } void EndVisitExtension(const std::string& type) override { if (IS_TYPE(type, kObjectiveExtension)) { VisitObjective(); @@ -256,7 +259,8 @@ class Linearizer : public ModelParser { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { if (DoVisit()) { Top()->SetIntegerVariableArrayArgument(arg_name, arguments); for (int i = 0; i < arguments.size(); ++i) { @@ -496,7 +500,8 @@ class Linearizer : public ModelParser { Top()->FindIntegerArgumentOrDie(ModelVisitor::kMaximizeArgument); *objective_ = const_cast(Top()->FindIntegerExpressionArgumentOrDie( - ModelVisitor::kExpressionArgument))->Var(); + ModelVisitor::kExpressionArgument)) + ->Var(); MPObjective* const objective = mp_solver_->MutableObjective(); objective->SetCoefficient(Translated(*objective_), 1.0); objective->SetOptimizationDirection(*maximize_); diff --git a/ortools/constraint_solver/interval.cc b/ortools/constraint_solver/interval.cc index 0ffdcb037fe..80c044f369b 100644 --- a/ortools/constraint_solver/interval.cc +++ b/ortools/constraint_solver/interval.cc @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/saturated_arithmetic.h" @@ -739,7 +738,8 @@ class PerformedVar : public BooleanVar { class FixedDurationIntervalVar : public BaseIntervalVar { public: FixedDurationIntervalVar(Solver* const s, int64 start_min, int64 start_max, - int64 duration, bool optional, const std::string& name); + int64 duration, bool optional, + const std::string& name); // Unperformed interval. FixedDurationIntervalVar(Solver* const s, const std::string& name); ~FixedDurationIntervalVar() override {} @@ -1231,10 +1231,8 @@ class StartVarPerformedIntervalVar : public IntervalVar { }; // TODO(user): Take care of overflows. -StartVarPerformedIntervalVar::StartVarPerformedIntervalVar(Solver* const s, - IntVar* const var, - int64 duration, - const std::string& name) +StartVarPerformedIntervalVar::StartVarPerformedIntervalVar( + Solver* const s, IntVar* const var, int64 duration, const std::string& name) : IntervalVar(s, name), start_var_(var), duration_(duration) {} int64 StartVarPerformedIntervalVar::StartMin() const { @@ -1737,8 +1735,9 @@ std::string FixedInterval::DebugString() const { } else { out = "IntervalVar(start = "; } - StringAppendF(&out, "%" GG_LL_FORMAT "d, duration = %" GG_LL_FORMAT - "d, performed = true)", + StringAppendF(&out, + "%" GG_LL_FORMAT "d, duration = %" GG_LL_FORMAT + "d, performed = true)", start_, duration_); return out; } diff --git a/ortools/constraint_solver/io.cc b/ortools/constraint_solver/io.cc index 9b4c8692a7b..f7d50644e8b 100644 --- a/ortools/constraint_solver/io.cc +++ b/ortools/constraint_solver/io.cc @@ -11,22 +11,21 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include -#include #include #include +#include #include #include #include "ortools/base/callback.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/model.pb.h" @@ -119,7 +118,8 @@ class FirstPassVisitor : public ModelVisitor { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { for (int i = 0; i < arguments.size(); ++i) { VisitSubArgument(arguments[i]); } @@ -406,8 +406,10 @@ class ArgumentHolder { std::unordered_map interval_argument_; std::unordered_map sequence_argument_; std::unordered_map> integer_array_argument_; - std::unordered_map>> integer_matrix_argument_; - std::unordered_map> integer_variable_array_argument_; + std::unordered_map>> + integer_matrix_argument_; + std::unordered_map> + integer_variable_array_argument_; std::unordered_map> interval_array_argument_; std::unordered_map> sequence_array_argument_; }; @@ -530,7 +532,8 @@ class SecondPassVisitor : public ModelVisitor { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { std::vector indices; for (int i = 0; i < arguments.size(); ++i) { indices.push_back(FindExpressionIndexOrDie(arguments[i])); @@ -2514,8 +2517,9 @@ bool Solver::LoadModelWithSearchMonitors( } if (model_proto.has_objective()) { const CpObjective& objective_proto = model_proto.objective(); - IntVar* const objective_var = model_loader_->IntegerExpression( - objective_proto.objective_index())->Var(); + IntVar* const objective_var = + model_loader_->IntegerExpression(objective_proto.objective_index()) + ->Var(); const bool maximize = objective_proto.maximize(); const int64 step = objective_proto.step(); OptimizeVar* const objective = @@ -2533,7 +2537,8 @@ bool Solver::UpgradeModel(CpModel* const proto) { return true; } -void Solver::RegisterBuilder(const std::string& tag, ConstraintBuilder builder) { +void Solver::RegisterBuilder(const std::string& tag, + ConstraintBuilder builder) { gtl::InsertOrDie(&constraint_builders_, tag, builder); } diff --git a/ortools/constraint_solver/local_search.cc b/ortools/constraint_solver/local_search.cc index bfdb971f760..f54d6132988 100644 --- a/ortools/constraint_solver/local_search.cc +++ b/ortools/constraint_solver/local_search.cc @@ -11,33 +11,32 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include -#include #include #include #include #include #include #include +#include +#include #include #include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/random.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/graph/hamiltonian_path.h" #include "ortools/util/saturated_arithmetic.h" -#include "ortools/base/random.h" DEFINE_int32(cp_local_search_sync_frequency, 16, "Frequency of checks for better solutions in the solution pool."); @@ -1029,7 +1028,9 @@ class RelocateAndMakeActiveOperator : public BaseInactiveNodeToPathOperator { MakeActive(GetInactiveNode(), before_node_to_move); } - std::string DebugString() const override { return "RelocateAndMakeActiveOpertor"; } + std::string DebugString() const override { + return "RelocateAndMakeActiveOpertor"; + } }; // ----- MakeActiveAndRelocate ----- @@ -1144,7 +1145,9 @@ class MakeChainInactiveOperator : public PathOperator { return MakeChainInactive(BaseNode(0), BaseNode(1)); } - std::string DebugString() const override { return "MakeChainInactiveOperator"; } + std::string DebugString() const override { + return "MakeChainInactiveOperator"; + } protected: bool OnSamePathAsPreviousBase(int64 base_index) override { @@ -1216,7 +1219,9 @@ class ExtendedSwapActiveOperator : public BaseInactiveNodeToPathOperator { ~ExtendedSwapActiveOperator() override {} bool MakeNeighbor() override; - std::string DebugString() const override { return "ExtendedSwapActiveOperator"; } + std::string DebugString() const override { + return "ExtendedSwapActiveOperator"; + } }; bool ExtendedSwapActiveOperator::MakeNeighbor() { @@ -1960,8 +1965,8 @@ LocalSearchOperator* MakeLocalSearchOperator( #define MAKE_LOCAL_SEARCH_OPERATOR(OperatorClass) \ template <> \ LocalSearchOperator* MakeLocalSearchOperator( \ - Solver * solver, const std::vector& vars, \ - const std::vector& secondary_vars, \ + Solver * solver, const std::vector& vars, \ + const std::vector& secondary_vars, \ std::function start_empty_path_class) { \ return solver->RevAlloc(new OperatorClass( \ vars, secondary_vars, std::move(start_empty_path_class))); \ @@ -2981,7 +2986,9 @@ class LocalSearchPhaseParameters : public BaseObject { limit_(limit), filters_(filters) {} ~LocalSearchPhaseParameters() override {} - std::string DebugString() const override { return "LocalSearchPhaseParameters"; } + std::string DebugString() const override { + return "LocalSearchPhaseParameters"; + } SolutionPool* solution_pool() const { return solution_pool_; } LocalSearchOperator* ls_operator() const { return ls_operator_; } diff --git a/ortools/constraint_solver/model_cache.cc b/ortools/constraint_solver/model_cache.cc index 1dc1224dd3b..00ef1af9357 100644 --- a/ortools/constraint_solver/model_cache.cc +++ b/ortools/constraint_solver/model_cache.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include @@ -89,7 +88,7 @@ void Double(C*** array_ptr, int* size_ptr) { C** const old_cell_array = *array_ptr; const int old_size = *size_ptr; (*size_ptr) *= 2; - (*array_ptr) = new C* [(*size_ptr)]; + (*array_ptr) = new C*[(*size_ptr)]; memset(*array_ptr, 0, (*size_ptr) * sizeof(**array_ptr)); for (int i = 0; i < old_size; ++i) { C* tmp = old_cell_array[i]; @@ -110,7 +109,7 @@ template class Cache1 { public: Cache1() - : array_(new Cell* [FLAGS_cache_initial_size]), + : array_(new Cell*[FLAGS_cache_initial_size]), size_(FLAGS_cache_initial_size), num_items_(0) { memset(array_, 0, sizeof(*array_) * size_); @@ -198,7 +197,7 @@ template class Cache2 { public: Cache2() - : array_(new Cell* [FLAGS_cache_initial_size]), + : array_(new Cell*[FLAGS_cache_initial_size]), size_(FLAGS_cache_initial_size), num_items_(0) { memset(array_, 0, sizeof(*array_) * size_); @@ -287,7 +286,7 @@ template class Cache3 { public: Cache3() - : array_(new Cell* [FLAGS_cache_initial_size]), + : array_(new Cell*[FLAGS_cache_initial_size]), size_(FLAGS_cache_initial_size), num_items_(0) { memset(array_, 0, sizeof(*array_) * size_); @@ -564,8 +563,8 @@ class NonReversibleCache : public ModelCache { !FLAGS_cp_disable_cache && var_constant_constant_constraints_[type]->Find(var, value1, value2) == nullptr) { - var_constant_constant_constraints_[type] - ->UnsafeInsert(var, value1, value2, ct); + var_constant_constant_constraints_[type]->UnsafeInsert(var, value1, + value2, ct); } } @@ -691,10 +690,11 @@ class NonReversibleCache : public ModelCache { DCHECK_GE(type, 0); DCHECK_LT(type, EXPR_EXPR_CONSTANT_EXPRESSION_MAX); if (solver()->state() == Solver::OUTSIDE_SEARCH && - !FLAGS_cp_disable_cache && expr_expr_constant_expressions_[type]->Find( - var1, var2, constant) == nullptr) { - expr_expr_constant_expressions_[type] - ->UnsafeInsert(var1, var2, constant, expression); + !FLAGS_cp_disable_cache && + expr_expr_constant_expressions_[type]->Find(var1, var2, constant) == + nullptr) { + expr_expr_constant_expressions_[type]->UnsafeInsert(var1, var2, constant, + expression); } } @@ -720,8 +720,8 @@ class NonReversibleCache : public ModelCache { !FLAGS_cp_disable_cache && var_constant_constant_expressions_[type]->Find(var, value1, value2) == nullptr) { - var_constant_constant_expressions_[type] - ->UnsafeInsert(var, value1, value2, expression); + var_constant_constant_expressions_[type]->UnsafeInsert( + var, value1, value2, expression); } } @@ -747,8 +747,8 @@ class NonReversibleCache : public ModelCache { if (solver()->state() == Solver::OUTSIDE_SEARCH && !FLAGS_cp_disable_cache && var_constant_array_expressions_[type]->Find(var, values) == nullptr) { - var_constant_array_expressions_[type] - ->UnsafeInsert(var, values, expression); + var_constant_array_expressions_[type]->UnsafeInsert(var, values, + expression); } } @@ -794,8 +794,8 @@ class NonReversibleCache : public ModelCache { if (solver()->state() != Solver::IN_SEARCH && var_array_constant_array_expressions_[type]->Find(vars, values) == nullptr) { - var_array_constant_array_expressions_[type] - ->UnsafeInsert(vars, values, expression); + var_array_constant_array_expressions_[type]->UnsafeInsert(vars, values, + expression); } } @@ -817,8 +817,8 @@ class NonReversibleCache : public ModelCache { DCHECK_LT(type, VAR_ARRAY_CONSTANT_EXPRESSION_MAX); if (solver()->state() != Solver::IN_SEARCH && var_array_constant_expressions_[type]->Find(vars, value) == nullptr) { - var_array_constant_expressions_[type] - ->UnsafeInsert(vars, value, expression); + var_array_constant_expressions_[type]->UnsafeInsert(vars, value, + expression); } } diff --git a/ortools/constraint_solver/nogoods.cc b/ortools/constraint_solver/nogoods.cc index d88c7f73501..d4005530ebd 100644 --- a/ortools/constraint_solver/nogoods.cc +++ b/ortools/constraint_solver/nogoods.cc @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/util/string_array.h" @@ -42,11 +41,7 @@ NoGood* NoGoodManager::MakeNoGood() { return new NoGood(); } class NoGoodTerm { public: - enum TermStatus { - ALWAYS_TRUE, - ALWAYS_FALSE, - UNDECIDED - }; + enum TermStatus { ALWAYS_TRUE, ALWAYS_FALSE, UNDECIDED }; NoGoodTerm() {} virtual ~NoGoodTerm() {} @@ -121,8 +116,12 @@ bool NoGood::Apply(Solver* const solver) { NoGoodTerm* first_undecided = nullptr; for (int i = 0; i < terms_.size(); ++i) { switch (terms_[i]->Evaluate()) { - case NoGoodTerm::ALWAYS_TRUE: { break; } - case NoGoodTerm::ALWAYS_FALSE: { return false; } + case NoGoodTerm::ALWAYS_TRUE: { + break; + } + case NoGoodTerm::ALWAYS_FALSE: { + return false; + } case NoGoodTerm::UNDECIDED: { if (first_undecided == nullptr) { first_undecided = terms_[i]; diff --git a/ortools/constraint_solver/pack.cc b/ortools/constraint_solver/pack.cc index e8f94bbfbc8..e282788a8fd 100644 --- a/ortools/constraint_solver/pack.cc +++ b/ortools/constraint_solver/pack.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Packing constraints #include @@ -22,10 +21,9 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" @@ -260,8 +258,8 @@ void Pack::InitialPropagate() { StringPrintf("InitialProgateDimension(%s)", dims_[dim_index]->DebugString().c_str())); } - dims_[dim_index] - ->InitialPropagateUnassigned(data->assigned(), data->unassigned()); + dims_[dim_index]->InitialPropagateUnassigned(data->assigned(), + data->unassigned()); dims_[dim_index]->EndInitialPropagate(); if (need_context) { solver()->GetPropagationMonitor()->PopContext(); @@ -293,8 +291,8 @@ void Pack::Propagate() { solver()->GetPropagationMonitor()->PushContext(StringPrintf( "ProgateDimension(%s)", dims_[dim_index]->DebugString().c_str())); } - dims_[dim_index] - ->Propagate(bin_index, forced_[bin_index], removed_[bin_index]); + dims_[dim_index]->Propagate(bin_index, forced_[bin_index], + removed_[bin_index]); if (need_context) { solver()->GetPropagationMonitor()->PopContext(); } @@ -487,8 +485,9 @@ void Pack::AssignAllRemainingItems() { int var_index = unprocessed_->GetFirstBit(bins_, 0); while (var_index != -1 && var_index < vars_.size()) { SetAssigned(var_index); - var_index = var_index == vars_.size() - 1 ? -1 : unprocessed_->GetFirstBit( - bins_, var_index + 1); + var_index = var_index == vars_.size() - 1 + ? -1 + : unprocessed_->GetFirstBit(bins_, var_index + 1); } } @@ -496,8 +495,9 @@ void Pack::UnassignAllRemainingItems() { int var_index = unprocessed_->GetFirstBit(bins_, 0); while (var_index != -1 && var_index < vars_.size()) { SetUnassigned(var_index); - var_index = var_index == vars_.size() - 1 ? -1 : unprocessed_->GetFirstBit( - bins_, var_index + 1); + var_index = var_index == vars_.size() - 1 + ? -1 + : unprocessed_->GetFirstBit(bins_, var_index + 1); } } @@ -894,7 +894,9 @@ class DimensionWeightedSumEqVar : public Dimension { ~DimensionWeightedSumEqVar() override {} - std::string DebugString() const override { return "DimensionWeightedSumEqVar"; } + std::string DebugString() const override { + return "DimensionWeightedSumEqVar"; + } void Post() override { for (int i = 0; i < bins_count_; ++i) { diff --git a/ortools/constraint_solver/resource.cc b/ortools/constraint_solver/resource.cc index c2b4de62533..3ec30252920 100644 --- a/ortools/constraint_solver/resource.cc +++ b/ortools/constraint_solver/resource.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // This file contains implementations of several resource constraints. // The implemented constraints are: // * Disjunctive: forces a set of intervals to be non-overlapping @@ -22,21 +21,20 @@ // on a set of interval variables. #include -#include #include #include +#include #include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" -#include "ortools/base/stl_util.h" #include "ortools/base/mathutil.h" +#include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" @@ -546,7 +544,9 @@ class EdgeFinderAndDetectablePrecedences { EdgeFinderAndDetectablePrecedences(Solver* const solver, const std::vector& intervals, bool mirror, bool strict); - ~EdgeFinderAndDetectablePrecedences() { gtl::STLDeleteElements(&by_start_min_); } + ~EdgeFinderAndDetectablePrecedences() { + gtl::STLDeleteElements(&by_start_min_); + } int64 size() const { return by_start_min_.size(); } IntervalVar* interval(int index) { return by_start_min_[index]->interval; } void UpdateEst(); @@ -563,8 +563,8 @@ class EdgeFinderAndDetectablePrecedences { // use them must first sort them in the right order. // All of these vectors store the same set of objects. Therefore, at - // destruction time, gtl::STLDeleteElements should be called on only one of them. - // It does not matter which one. + // destruction time, gtl::STLDeleteElements should be called on only one of + // them. It does not matter which one. ThetaTree theta_tree_; std::vector by_end_min_; @@ -2364,7 +2364,8 @@ class VariableDemandCumulativeConstraint : public Constraint { VariableDemandCumulativeConstraint(Solver* const s, const std::vector& intervals, const std::vector& demands, - IntVar* const capacity, const std::string& name) + IntVar* const capacity, + const std::string& name) : Constraint(s), capacity_(capacity), intervals_(intervals), @@ -2462,7 +2463,8 @@ class VariableDemandCumulativeConstraint : public Constraint { if (high_demand_intervals.size() >= 2) { // If there are less than 2 such intervals, the constraint would do // nothing - const std::string seq_name = absl::StrCat(name(), "-HighDemandSequence"); + const std::string seq_name = + absl::StrCat(name(), "-HighDemandSequence"); constraint = solver()->MakeStrictDisjunctiveConstraint( high_demand_intervals, seq_name); } @@ -2607,7 +2609,8 @@ Constraint* Solver::MakeCumulative(const std::vector& intervals, Constraint* Solver::MakeCumulative(const std::vector& intervals, const std::vector& demands, - IntVar* const capacity, const std::string& name) { + IntVar* const capacity, + const std::string& name) { CHECK_EQ(intervals.size(), demands.size()); for (int i = 0; i < intervals.size(); ++i) { CHECK_GE(demands[i], 0); @@ -2618,7 +2621,8 @@ Constraint* Solver::MakeCumulative(const std::vector& intervals, Constraint* Solver::MakeCumulative(const std::vector& intervals, const std::vector& demands, - IntVar* const capacity, const std::string& name) { + IntVar* const capacity, + const std::string& name) { return MakeCumulative(intervals, ToInt64Vector(demands), capacity, name); } @@ -2644,7 +2648,8 @@ Constraint* Solver::MakeCumulative(const std::vector& intervals, Constraint* Solver::MakeCumulative(const std::vector& intervals, const std::vector& demands, - IntVar* const capacity, const std::string& name) { + IntVar* const capacity, + const std::string& name) { CHECK_EQ(intervals.size(), demands.size()); for (int i = 0; i < intervals.size(); ++i) { CHECK_GE(demands[i]->Min(), 0); diff --git a/ortools/constraint_solver/routing.cc b/ortools/constraint_solver/routing.cc index e440201048c..a6564244a68 100644 --- a/ortools/constraint_solver/routing.cc +++ b/ortools/constraint_solver/routing.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/constraint_solver/routing.h" #include @@ -22,21 +21,21 @@ #include #include +#include "google/protobuf/text_format.h" #include "ortools/base/callback.h" #include "ortools/base/casts.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "google/protobuf/text_format.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/thorough_hash.h" -#include "ortools/base/hash.h" -#include "ortools/constraint_solver/routing_neighborhoods.h" #include "ortools/constraint_solver/model.pb.h" -#include "ortools/base/join.h" #include "ortools/constraint_solver/routing_enums.pb.h" +#include "ortools/constraint_solver/routing_neighborhoods.h" #include "ortools/graph/connectivity.h" #include "ortools/graph/linear_assignment.h" #include "ortools/util/saturated_arithmetic.h" @@ -649,7 +648,7 @@ RoutingModelParameters RoutingModel::DefaultModelParameters() { parameters.mutable_solver_parameters(); *solver_parameters = Solver::DefaultSolverParameters(); solver_parameters->set_compress_trail( - ConstraintSolverParameters::COMPRESS_WITH_ZLIB); + ConstraintSolverParameters::COMPRESS_WITH_ZLIB); parameters.set_reduce_vehicle_cost_model(true); return parameters; } @@ -693,7 +692,8 @@ RoutingSearchParameters RoutingModel::DefaultSearchParameters() { "use_light_propagation: true " "fingerprint_arc_cost_evaluators: true "; RoutingSearchParameters parameters; - if (!google::protobuf::TextFormat::ParseFromString(kSearchParameters, ¶meters)) { + if (!google::protobuf::TextFormat::ParseFromString(kSearchParameters, + ¶meters)) { LOG(ERROR) << "Unsupported default search parameters: " << kSearchParameters; } @@ -807,10 +807,9 @@ bool RoutingModel::InitializeDimensionInternal( } } -bool RoutingModel::AddConstantDimensionWithSlack(int64 value, int64 capacity, - int64 slack_max, - bool fix_start_cumul_to_zero, - const std::string& dimension_name) { +bool RoutingModel::AddConstantDimensionWithSlack( + int64 value, int64 capacity, int64 slack_max, bool fix_start_cumul_to_zero, + const std::string& dimension_name) { return AddDimension( ConstantEvaluator::MakeNodeEvaluatorCallback(value, solver_.get()), slack_max, capacity, fix_start_cumul_to_zero, dimension_name); @@ -953,7 +952,8 @@ bool RoutingModel::AddDimensionDependentDimensionWithVehicleCapacity( bool RoutingModel::AddDimensionDependentDimensionWithVehicleCapacity( NodeEvaluator2* pure_transits, VariableNodeEvaluator2* dependent_transits, const RoutingDimension* base_dimension, int64 slack_max, - int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string& name) { + int64 vehicle_capacity, bool fix_start_cumul_to_zero, + const std::string& name) { std::vector pure_evaluators(vehicles_, pure_transits); std::vector transit_evaluators(vehicles_, dependent_transits); @@ -999,7 +999,7 @@ bool RoutingModel::HasDimension(const std::string& dimension_name) const { RoutingModel::DimensionIndex RoutingModel::GetDimensionIndex( const std::string& dimension_name) const { return gtl::FindWithDefault(dimension_name_to_index_, dimension_name, - kNoDimension); + kNoDimension); } const RoutingDimension& RoutingModel::GetDimensionOrDie( @@ -1104,12 +1104,11 @@ uint64 RoutingModel::GetFingerprintOfEvaluator( } } const int row_num_bytes = row_size * sizeof(int64); - const uint64 fprint = ThoroughHash( - reinterpret_cast(row.get()), row_num_bytes); + const uint64 fprint = + ThoroughHash(reinterpret_cast(row.get()), row_num_bytes); // MixTwoUInt64 never returns 0. - evaluator_fprint = evaluator_fprint != 0 - ? MixTwoUInt64(evaluator_fprint, fprint) - : fprint; + evaluator_fprint = + evaluator_fprint != 0 ? MixTwoUInt64(evaluator_fprint, fprint) : fprint; } return evaluator_fprint; } @@ -1173,7 +1172,8 @@ void RoutingModel::ComputeCostClasses( // we can avoid to: we detect duplicate evaluators, for example, and if // there's only one evaluator callback used, we don't bother computing its // fingerprint. - if (!gtl::FindCopy(evaluator_to_fprint, uncached_evaluator, &evaluator_fprint)) { + if (!gtl::FindCopy(evaluator_to_fprint, uncached_evaluator, + &evaluator_fprint)) { evaluator_fprint = all_evaluators_equal ? kAllEquivalentEvaluatorFprint @@ -1182,8 +1182,8 @@ void RoutingModel::ComputeCostClasses( parameters.fingerprint_arc_cost_evaluators()); evaluator_to_fprint[uncached_evaluator] = evaluator_fprint; } - NodeEvaluator2** cached_evaluator = - >l::LookupOrInsert(&fprint_to_cached_evaluator, evaluator_fprint, nullptr); + NodeEvaluator2** cached_evaluator = >l::LookupOrInsert( + &fprint_to_cached_evaluator, evaluator_fprint, nullptr); if (*cached_evaluator == nullptr) { *cached_evaluator = NewCachedCallback(uncached_evaluator); } @@ -1303,8 +1303,8 @@ void RoutingModel::ComputeVehicleClasses() { vehicle_class.unvisitable_nodes_fprint = ThoroughHash( nodes_unvisitability_bitmask.get(), nodes_unvisitability_num_bytes); const VehicleClassIndex num_vehicle_classes(vehicle_classes_.size()); - const VehicleClassIndex vehicle_class_index = - gtl::LookupOrInsert(&vehicle_class_map, vehicle_class, num_vehicle_classes); + const VehicleClassIndex vehicle_class_index = gtl::LookupOrInsert( + &vehicle_class_map, vehicle_class, num_vehicle_classes); if (vehicle_class_index == num_vehicle_classes) { // New vehicle class vehicle_classes_.push_back(vehicle_class); } @@ -1644,7 +1644,8 @@ class RoutingModelInspector : public ModelVisitor { for (int node = 0; node < model_->Size(); ++node) { const int component = same_vehicle_components_.GetClassRepresentative(node); - if (gtl::InsertIfNotPresent(&component_indices, component, component_index)) { + if (gtl::InsertIfNotPresent(&component_indices, component, + component_index)) { ++component_index; } } @@ -1666,12 +1667,12 @@ class RoutingModelInspector : public ModelVisitor { void VisitIntegerExpressionArgument(const std::string& type_name, IntExpr* const expr) override { gtl::FindWithDefault(expr_inspectors_, type_name, - [](const IntExpr* expr) {})(expr); + [](const IntExpr* expr) {})(expr); } void VisitIntegerArrayArgument(const std::string& arg_name, const std::vector& values) override { gtl::FindWithDefault(array_inspectors_, arg_name, - [](const std::vector& int_array) {})(values); + [](const std::vector& int_array) {})(values); } private: @@ -1689,10 +1690,14 @@ class RoutingModelInspector : public ModelVisitor { expr_inspectors_[kRightArgument] = [this](const IntExpr* expr) { right_ = expr; }; - array_inspectors_[kStartsArgument] = [this]( - const std::vector& int_array) { starts_argument_ = int_array; }; - array_inspectors_[kEndsArgument] = [this]( - const std::vector& int_array) { ends_argument_ = int_array; }; + array_inspectors_[kStartsArgument] = + [this](const std::vector& int_array) { + starts_argument_ = int_array; + }; + array_inspectors_[kEndsArgument] = + [this](const std::vector& int_array) { + ends_argument_ = int_array; + }; constraint_inspectors_[kNotMember] = [this]() { std::pair dim_index; if (gtl::FindCopy(cumul_to_dim_indices_, expr_, &dim_index)) { @@ -2429,7 +2434,6 @@ class RouteConstructor { std::vector node_to_vehicle_class_index_; }; - void GetVehicleClasses(const RoutingModel& model, std::vector* vehicle_classes) { vehicle_classes->clear(); @@ -3807,19 +3811,21 @@ LocalSearchOperator* RoutingModel::CreateMakeInactiveOperator() { : vehicle_vars_, \ vehicle_start_class_callback_); -#define CP_ROUTING_ADD_CALLBACK_OPERATOR(operator_type, cp_operator_type) \ - if (CostsAreHomogeneousAcrossVehicles()) { \ - local_search_operators_[operator_type] = solver_->MakeOperator( \ - nexts_, [this](int64 i, int64 j, \ - int64 k) { return GetArcCostForVehicle(i, j, k); }, \ - Solver::cp_operator_type); \ - } else { \ - local_search_operators_[operator_type] = \ - solver_->MakeOperator(nexts_, vehicle_vars_, \ - [this](int64 i, int64 j, int64 k) { \ - return GetArcCostForVehicle(i, j, k); \ - }, \ - Solver::cp_operator_type); \ +#define CP_ROUTING_ADD_CALLBACK_OPERATOR(operator_type, cp_operator_type) \ + if (CostsAreHomogeneousAcrossVehicles()) { \ + local_search_operators_[operator_type] = \ + solver_->MakeOperator(nexts_, \ + [this](int64 i, int64 j, int64 k) { \ + return GetArcCostForVehicle(i, j, k); \ + }, \ + Solver::cp_operator_type); \ + } else { \ + local_search_operators_[operator_type] = \ + solver_->MakeOperator(nexts_, vehicle_vars_, \ + [this](int64 i, int64 j, int64 k) { \ + return GetArcCostForVehicle(i, j, k); \ + }, \ + Solver::cp_operator_type); \ } void RoutingModel::CreateNeighborhoodOperators() { @@ -4106,8 +4112,9 @@ void RoutingModel::CreateFirstSolutionDecisionBuilders( first_solution_filtered_decision_builders_ [FirstSolutionStrategy::PATH_CHEAPEST_ARC] = solver_->RevAlloc( new EvaluatorCheapestAdditionFilteredDecisionBuilder( - this, NewPermanentCallback( - this, &RoutingModel::GetArcCostForFirstSolution), + this, + NewPermanentCallback(this, + &RoutingModel::GetArcCostForFirstSolution), GetOrCreateFeasibilityFilters())); first_solution_decision_builders_ [FirstSolutionStrategy::PATH_CHEAPEST_ARC] = @@ -4463,7 +4470,7 @@ RoutingModel::NewCachedStateDependentCallback( const int size = node_to_index_.size(); VariableNodeEvaluator2* cached_evaluator = nullptr; if (!gtl::FindCopy(cached_state_dependent_callbacks_, callback, - &cached_evaluator)) { + &cached_evaluator)) { cached_evaluator = new StateDependentRoutingCache(callback, size); cached_state_dependent_callbacks_[callback] = cached_evaluator; owned_state_dependent_callbacks_.insert(callback); @@ -4504,7 +4511,8 @@ int64 RoutingModel::GetCost(int64 i, int64 j, int64 v) { int64 RoutingModel::GetVehicleClassCost(int64 i, int64 j, int64 c) { return GetArcCostForClass(i, j, c); } -void RoutingModel::SetDimensionTransitCost(const std::string& name, int64 coeff) { +void RoutingModel::SetDimensionTransitCost(const std::string& name, + int64 coeff) { GetMutableDimension(name)->SetSpanCostCoefficientForAllVehicles(coeff); } int64 RoutingModel::GetDimensionTransitCost(const std::string& name) const { @@ -4524,15 +4532,17 @@ int64 RoutingModel::GetTransitValue(const std::string& dimension_name, int64 from_index, int64 to_index, int64 vehicle) const { DimensionIndex dimension_index(-1); - if (gtl::FindCopy(dimension_name_to_index_, dimension_name, &dimension_index)) { + if (gtl::FindCopy(dimension_name_to_index_, dimension_name, + &dimension_index)) { return dimensions_[dimension_index]->GetTransitValue(from_index, to_index, vehicle); } else { return 0; } } -void RoutingModel::SetCumulVarSoftUpperBound(NodeIndex node, const std::string& name, - int64 ub, int64 coeff) { +void RoutingModel::SetCumulVarSoftUpperBound(NodeIndex node, + const std::string& name, int64 ub, + int64 coeff) { GetMutableDimension(name)->SetCumulVarSoftUpperBound(node, ub, coeff); } bool RoutingModel::HasCumulVarSoftUpperBound(NodeIndex node, @@ -4554,17 +4564,17 @@ int64 RoutingModel::GetCumulVarSoftUpperBoundCoefficient( : 0; } void RoutingModel::SetStartCumulVarSoftUpperBound(int vehicle, - const std::string& name, int64 ub, - int64 coeff) { + const std::string& name, + int64 ub, int64 coeff) { GetMutableDimension(name)->SetStartCumulVarSoftUpperBound(vehicle, ub, coeff); } -bool RoutingModel::HasStartCumulVarSoftUpperBound(int vehicle, - const std::string& name) const { +bool RoutingModel::HasStartCumulVarSoftUpperBound( + int vehicle, const std::string& name) const { return HasDimension(name) && GetDimensionOrDie(name).HasStartCumulVarSoftUpperBound(vehicle); } -int64 RoutingModel::GetStartCumulVarSoftUpperBound(int vehicle, - const std::string& name) const { +int64 RoutingModel::GetStartCumulVarSoftUpperBound( + int vehicle, const std::string& name) const { return HasDimension(name) ? GetDimensionOrDie(name).GetStartCumulVarSoftUpperBound(vehicle) : kint64max; @@ -4576,7 +4586,8 @@ int64 RoutingModel::GetStartCumulVarSoftUpperBoundCoefficient( .GetStartCumulVarSoftUpperBoundCoefficient(vehicle) : 0; } -void RoutingModel::SetEndCumulVarSoftUpperBound(int vehicle, const std::string& name, +void RoutingModel::SetEndCumulVarSoftUpperBound(int vehicle, + const std::string& name, int64 ub, int64 coeff) { GetMutableDimension(name)->SetEndCumulVarSoftUpperBound(vehicle, ub, coeff); } @@ -4585,8 +4596,8 @@ bool RoutingModel::HasEndCumulVarSoftUpperBound(int vehicle, return HasDimension(name) && GetDimensionOrDie(name).HasEndCumulVarSoftUpperBound(vehicle); } -int64 RoutingModel::GetEndCumulVarSoftUpperBound(int vehicle, - const std::string& name) const { +int64 RoutingModel::GetEndCumulVarSoftUpperBound( + int vehicle, const std::string& name) const { return HasDimension(name) ? GetDimensionOrDie(name).GetEndCumulVarSoftUpperBound(vehicle) : kint64max; diff --git a/ortools/constraint_solver/routing.h b/ortools/constraint_solver/routing.h index 89a08d7224f..4413df0b7e8 100644 --- a/ortools/constraint_solver/routing.h +++ b/ortools/constraint_solver/routing.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // The vehicle routing library lets one model and solve generic vehicle routing // problems ranging from the Traveling Salesman Problem to more complex // problems such as the Capacitated Vehicle Routing Problem with Time Windows. @@ -167,12 +166,14 @@ #include #include +#include "ortools/base/adjustable_priority_queue-inl.h" +#include "ortools/base/adjustable_priority_queue.h" #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/routing_parameters.pb.h" @@ -180,9 +181,6 @@ #include "ortools/graph/graph.h" #include "ortools/util/range_query_function.h" #include "ortools/util/sorted_interval_list.h" -#include "ortools/base/adjustable_priority_queue-inl.h" -#include "ortools/base/adjustable_priority_queue.h" - namespace operations_research { @@ -356,9 +354,9 @@ class RoutingModel { // Constructor taking a vector of (start node, end node) pairs for each // vehicle route. Used to model multiple depots. RoutingModel(int nodes, int vehicles, - const std::vector >& start_end); + const std::vector>& start_end); RoutingModel(int nodes, int vehicles, - const std::vector >& start_end, + const std::vector>& start_end, const RoutingModelParameters& parameters); // Constructor taking vectors of start nodes and end nodes for each // vehicle route. Used to model multiple depots. @@ -422,7 +420,8 @@ class RoutingModel { bool fix_start_cumul_to_zero, const std::string& name); bool AddConstantDimension(int64 value, int64 capacity, - bool fix_start_cumul_to_zero, const std::string& name) { + bool fix_start_cumul_to_zero, + const std::string& name) { return AddConstantDimensionWithSlack(value, capacity, 0, fix_start_cumul_to_zero, name); } @@ -434,7 +433,8 @@ class RoutingModel { // Returns false if a dimension with the same name has already been created // (and doesn't create the new dimension). bool AddVectorDimension(std::vector values, int64 capacity, - bool fix_start_cumul_to_zero, const std::string& name); + bool fix_start_cumul_to_zero, + const std::string& name); // Creates a dimension where the transit variable is constrained to be // equal to 'values[i][next(i)]' for node i; 'capacity' is the upper bound of // the cumul variables. 'name' is the name used to reference the dimension; @@ -442,7 +442,7 @@ class RoutingModel { // model. // Returns false if a dimension with the same name has already been created // (and doesn't create the new dimension). - bool AddMatrixDimension(std::vector > values, + bool AddMatrixDimension(std::vector> values, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name); #if !defined(SWIG) @@ -477,7 +477,8 @@ class RoutingModel { bool AddDimensionDependentDimensionWithVehicleCapacity( NodeEvaluator2* pure_transits, VariableNodeEvaluator2* dependent_transits, const RoutingDimension* base_dimension, int64 slack_max, - int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string& name); + int64 vehicle_capacity, bool fix_start_cumul_to_zero, + const std::string& name); // Creates a cached StateDependentTransit from an std::function. static RoutingModel::StateDependentTransit MakeStateDependentTransit( const std::function& f, int64 domain_start, @@ -489,10 +490,12 @@ class RoutingModel { // Returns true if a dimension exists for a given dimension name. bool HasDimension(const std::string& dimension_name) const; // Returns a dimension from its name. Dies if the dimension does not exist. - const RoutingDimension& GetDimensionOrDie(const std::string& dimension_name) const; + const RoutingDimension& GetDimensionOrDie( + const std::string& dimension_name) const; // Returns a dimension from its name. Returns nullptr if the dimension does // not exist. - RoutingDimension* GetMutableDimension(const std::string& dimension_name) const; + RoutingDimension* GetMutableDimension( + const std::string& dimension_name) const; // Set the given dimension as "primary constrained". As of August 2013, this // is only used by ArcIsMoreConstrainedThanArc(). // "dimension" must be the name of an existing dimension, or be empty, in @@ -501,7 +504,8 @@ class RoutingModel { DCHECK(dimension_name.empty() || HasDimension(dimension_name)); primary_constrained_dimension_ = dimension_name; } - // Get the primary constrained dimension, or an empty std::string if it is unset. + // Get the primary constrained dimension, or an empty std::string if it is + // unset. const std::string& GetPrimaryConstrainedDimension() const { return primary_constrained_dimension_; } @@ -573,7 +577,7 @@ class RoutingModel { // indices: a disjunction is "perfect" when its variables do not appear in // any other disjunction. Each pair is sorted (lowest variable index first), // and the output vector is also sorted (lowest pairs first). - std::vector > GetPerfectBinaryDisjunctions() const; + std::vector> GetPerfectBinaryDisjunctions() const; // SPECIAL: Makes the solver ignore all the disjunctions whose active // variables are all trivially zero (i.e. Max() == 0), by setting their // max_cardinality to 0. @@ -720,8 +724,8 @@ class RoutingModel { // vehicle and deactivates other nodes. // An assignment containing the locks can be obtained by calling // PreAssignment(). - bool ApplyLocksToAllVehicles( - const std::vector >& locks, bool close_routes); + bool ApplyLocksToAllVehicles(const std::vector>& locks, + bool close_routes); // Returns an assignment used to fix some of the variables of the problem. // In practice, this assignment locks partial routes of the problem. This // can be used in the context of locking the parts of the routes which have @@ -746,7 +750,7 @@ class RoutingModel { // considerable amount of time, especially when using dimensions // with slack. Assignment* ReadAssignmentFromRoutes( - const std::vector >& routes, + const std::vector>& routes, bool ignore_inactive_nodes); // Fills an assignment from a specification of the routes of the // vehicles. The routes are specified as lists of nodes that appear @@ -765,7 +769,7 @@ class RoutingModel { // loaded. However, such assignment still might not be a valid // solution to the routing problem due to more complex constraints; // it is advisible to call solver()->CheckSolution() afterwards. - bool RoutesToAssignment(const std::vector >& routes, + bool RoutesToAssignment(const std::vector>& routes, bool ignore_inactive_nodes, bool close_routes, Assignment* const assignment) const; // Converts the solution in the given assignment to routes for all vehicles. @@ -773,7 +777,7 @@ class RoutingModel { // vehicles end with an end node for that vehicle). void AssignmentToRoutes( const Assignment& assignment, - std::vector >* const routes) const; + std::vector>* const routes) const; // Returns a compacted version of the given assignment, in which all vehicles // with id lower or equal to some N have non-empty routes, and all vehicles // with id greater than N have empty routes. Does not take ownership of the @@ -922,8 +926,9 @@ class RoutingModel { // feasible intervals of the CumulVar for dimension "dimension_to_print" // at each step of the routes. // If "dimension_to_print" is omitted, all dimensions will be printed. - std::string DebugOutputAssignment(const Assignment& solution_assignment, - const std::string& dimension_to_print) const; + std::string DebugOutputAssignment( + const Assignment& solution_assignment, + const std::string& dimension_to_print) const; // Returns the underlying constraint solver. Can be used to add extra // constraints and/or modify search algoithms. @@ -984,7 +989,8 @@ class RoutingModel { int64 GetTransitValue(const std::string& d, int64 from, int64 to, int64 vehicle) const; #ifndef SWIG - const std::vector& CumulVars(const std::string& dimension_name) const; + const std::vector& CumulVars( + const std::string& dimension_name) const; #endif // All the methods below are replaced by public methods with the same name // on the RoutingDimension class. See those. @@ -994,11 +1000,13 @@ class RoutingModel { void SetCumulVarSoftUpperBound(NodeIndex, const std::string&, int64, int64); bool HasCumulVarSoftUpperBound(NodeIndex, const std::string&) const; int64 GetCumulVarSoftUpperBound(NodeIndex, const std::string&) const; - int64 GetCumulVarSoftUpperBoundCoefficient(NodeIndex, const std::string&) const; + int64 GetCumulVarSoftUpperBoundCoefficient(NodeIndex, + const std::string&) const; void SetStartCumulVarSoftUpperBound(int, const std::string&, int64, int64); bool HasStartCumulVarSoftUpperBound(int, const std::string&) const; int64 GetStartCumulVarSoftUpperBound(int, const std::string&) const; - int64 GetStartCumulVarSoftUpperBoundCoefficient(int, const std::string&) const; + int64 GetStartCumulVarSoftUpperBoundCoefficient(int, + const std::string&) const; void SetEndCumulVarSoftUpperBound(int, const std::string&, int64, int64); bool HasEndCumulVarSoftUpperBound(int, const std::string&) const; int64 GetEndCumulVarSoftUpperBound(int, const std::string&) const; @@ -1100,7 +1108,7 @@ class RoutingModel { // Internal methods. void Initialize(); void SetStartEnd( - const std::vector >& start_end); + const std::vector>& start_end); void AddDisjunctionInternal(const std::vector& nodes, int64 penalty, int64 max_cardinality); void AddNoCycleConstraintInternal(); @@ -1269,15 +1277,15 @@ class RoutingModel { cached_state_dependent_callbacks_; // Disjunctions ITIVector disjunctions_; - std::vector > node_to_disjunctions_; + std::vector> node_to_disjunctions_; // Same vehicle costs - std::vector > same_vehicle_costs_; + std::vector> same_vehicle_costs_; // Pickup and delivery NodePairs pickup_delivery_pairs_; // Same vehicle group to which a node belongs. std::vector same_vehicle_group_; // Same vehicle node groups. - std::vector > same_vehicle_groups_; + std::vector> same_vehicle_groups_; // Index management std::vector index_to_node_; ITIVector node_to_index_; @@ -1649,7 +1657,8 @@ class RoutingDimension { class SelfBased {}; RoutingDimension(RoutingModel* model, std::vector vehicle_capacities, - const std::string& name, const RoutingDimension* base_dimension); + const std::string& name, + const RoutingDimension* base_dimension); RoutingDimension(RoutingModel* model, std::vector vehicle_capacities, const std::string& name, SelfBased); void Initialize( @@ -1721,14 +1730,13 @@ class RoutingDimension { DISALLOW_COPY_AND_ASSIGN(RoutingDimension); }; - #ifndef SWIG // Class to arrange nodes by by their distance and their angles from the // depot. Used in the Sweep first solution heuristic. class SweepArranger { public: explicit SweepArranger(const ITIVector >& points); + std::pair>& points); virtual ~SweepArranger() {} void ArrangeNodes(std::vector* nodes); void SetSectors(int sectors) { sectors_ = sectors; } @@ -1875,8 +1883,8 @@ class CheapestInsertionFilteredDecisionBuilder // if penalty callback is null or if the node cannot be unperformed. int64 GetUnperformedValue(int64 node_to_insert) const; - std::unique_ptr > evaluator_; - std::unique_ptr > penalty_evaluator_; + std::unique_ptr> evaluator_; + std::unique_ptr> penalty_evaluator_; }; // Filter-based decision builder which builds a solution by inserting @@ -2045,7 +2053,7 @@ class EvaluatorCheapestAdditionFilteredDecisionBuilder // Next nodes are sorted according to the current evaluator. void SortPossibleNexts(int64 from, std::vector* sorted_nexts) override; - std::unique_ptr > evaluator_; + std::unique_ptr> evaluator_; }; // A CheapestAdditionFilteredDecisionBuilder where the notion of 'cheapest arc' diff --git a/ortools/constraint_solver/routing_neighborhoods.h b/ortools/constraint_solver/routing_neighborhoods.h index e01fdc523a9..07d2b63e2a0 100644 --- a/ortools/constraint_solver/routing_neighborhoods.h +++ b/ortools/constraint_solver/routing_neighborhoods.h @@ -189,7 +189,9 @@ class NodePairSwapActiveOperator : public PathWithPreviousNodesOperator { bool MakeNextNeighbor(Assignment* delta, Assignment* deltadelta) override; bool MakeNeighbor() override; - std::string DebugString() const override { return "NodePairSwapActiveOperator"; } + std::string DebugString() const override { + return "NodePairSwapActiveOperator"; + } private: void OnNodeInitialization() override; @@ -216,7 +218,9 @@ class PairNodeSwapActiveOperator : public PathOperator { bool MakeNextNeighbor(Assignment* delta, Assignment* deltadelta) override; bool MakeNeighbor() override; - std::string DebugString() const override { return "PairNodeSwapActiveOperator"; } + std::string DebugString() const override { + return "PairNodeSwapActiveOperator"; + } protected: bool OnSamePathAsPreviousBase(int64 base_index) override { diff --git a/ortools/constraint_solver/routing_search.cc b/ortools/constraint_solver/routing_search.cc index d461169bd16..de184d828c8 100644 --- a/ortools/constraint_solver/routing_search.cc +++ b/ortools/constraint_solver/routing_search.cc @@ -99,18 +99,18 @@ class NodeDisjunctionFilter : public RoutingLocalSearchFilter { !IsVarSynced(index) || (Value(index) == index) != is_inactive; if (active_state_changed) { if (!is_inactive) { - ++gtl::LookupOrInsert(&disjunction_active_deltas, disjunction_index, - 0); + ++gtl::LookupOrInsert(&disjunction_active_deltas, + disjunction_index, 0); if (IsVarSynced(index)) { --gtl::LookupOrInsert(&disjunction_inactive_deltas, - disjunction_index, 0); + disjunction_index, 0); } } else { - ++gtl::LookupOrInsert(&disjunction_inactive_deltas, disjunction_index, - 0); + ++gtl::LookupOrInsert(&disjunction_inactive_deltas, + disjunction_index, 0); if (IsVarSynced(index)) { - --gtl::LookupOrInsert(&disjunction_active_deltas, disjunction_index, - 0); + --gtl::LookupOrInsert(&disjunction_active_deltas, + disjunction_index, 0); } } } @@ -1058,7 +1058,8 @@ bool PathCumulFilter::FinalizeAcceptPath() { // Delta max end is lower than the current solution one. // If the path supporting the current max end has been modified, we need // to check all paths to find the largest max end. - if (!gtl::ContainsKey(delta_paths_, current_max_end_.cumul_value_support)) { + if (!gtl::ContainsKey(delta_paths_, + current_max_end_.cumul_value_support)) { new_max_end = current_max_end_.cumul_value; } else { for (int i = 0; i < current_max_end_.path_values.size(); ++i) { @@ -1090,7 +1091,8 @@ bool PathCumulFilter::FinalizeAcceptPath() { // Delta min start is greater than the current solution one. // If the path supporting the current min start has been modified, we need // to check all paths to find the smallest min start. - if (!gtl::ContainsKey(delta_paths_, current_min_start_.cumul_value_support)) { + if (!gtl::ContainsKey(delta_paths_, + current_min_start_.cumul_value_support)) { new_min_start = current_min_start_.cumul_value; } else { for (int i = 0; i < current_min_start_.path_values.size(); ++i) { diff --git a/ortools/constraint_solver/routing_types.h b/ortools/constraint_solver/routing_types.h index 70ab6b1582b..f8add68ebcf 100644 --- a/ortools/constraint_solver/routing_types.h +++ b/ortools/constraint_solver/routing_types.h @@ -17,8 +17,8 @@ #include #include #include "ortools/base/callback.h" -#include "ortools/base/integral_types.h" #include "ortools/base/int_type.h" +#include "ortools/base/integral_types.h" namespace operations_research { diff --git a/ortools/constraint_solver/sat_constraint.h b/ortools/constraint_solver/sat_constraint.h index c467eb52821..44049b3b709 100644 --- a/ortools/constraint_solver/sat_constraint.h +++ b/ortools/constraint_solver/sat_constraint.h @@ -31,8 +31,8 @@ #include #include -#include "ortools/base/map_util.h" #include "ortools/base/hash.h" +#include "ortools/base/map_util.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/sat/sat_solver.h" diff --git a/ortools/constraint_solver/sched_constraints.cc b/ortools/constraint_solver/sched_constraints.cc index 2310a0d602f..76b9524d9f2 100644 --- a/ortools/constraint_solver/sched_constraints.cc +++ b/ortools/constraint_solver/sched_constraints.cc @@ -36,11 +36,7 @@ namespace operations_research { namespace { class TreeArrayConstraint : public Constraint { public: - enum PerformedStatus { - UNPERFORMED, - PERFORMED, - UNDECIDED - }; + enum PerformedStatus { UNPERFORMED, PERFORMED, UNDECIDED }; TreeArrayConstraint(Solver* const solver, const std::vector& vars, @@ -70,7 +66,8 @@ class TreeArrayConstraint : public Constraint { target_var_->DebugString().c_str()); } - void AcceptInternal(const std::string& name, ModelVisitor* const visitor) const { + void AcceptInternal(const std::string& name, + ModelVisitor* const visitor) const { visitor->BeginVisitConstraint(name, this); visitor->VisitIntervalArrayArgument(ModelVisitor::kIntervalsArgument, vars_); diff --git a/ortools/constraint_solver/sched_search.cc b/ortools/constraint_solver/sched_search.cc index 41213c18679..b5c4c281e97 100644 --- a/ortools/constraint_solver/sched_search.cc +++ b/ortools/constraint_solver/sched_search.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include @@ -37,7 +36,8 @@ int64 IndexToValue(int64 index) { return index + 1; } SequenceVar::SequenceVar(Solver* const s, const std::vector& intervals, - const std::vector& nexts, const std::string& name) + const std::vector& nexts, + const std::string& name) : PropagationBaseObject(s), intervals_(intervals), nexts_(nexts), diff --git a/ortools/constraint_solver/search.cc b/ortools/constraint_solver/search.cc index 4144923aaad..e09f7776953 100644 --- a/ortools/constraint_solver/search.cc +++ b/ortools/constraint_solver/search.cc @@ -11,34 +11,33 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include -#include #include #include #include #include +#include #include #include +#include "ortools/base/bitmap.h" #include "ortools/base/casts.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/timer.h" -#include "ortools/base/join.h" -#include "ortools/base/bitmap.h" #include "ortools/base/map_util.h" +#include "ortools/base/random.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" +#include "ortools/base/timer.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/search_limit.pb.h" #include "ortools/util/string_array.h" -#include "ortools/base/random.h" DEFINE_bool(cp_use_sparse_gls_penalties, false, "Use sparse implementation to store Guided Local Search penalties"); @@ -128,17 +127,19 @@ bool SearchLog::AtSolution() { } } std::string log; - StringAppendF(&log, "Solution #%d (%stime = %" GG_LL_FORMAT - "d ms, branches = %" GG_LL_FORMAT - "d," - " failures = %" GG_LL_FORMAT "d, depth = %d", + StringAppendF(&log, + "Solution #%d (%stime = %" GG_LL_FORMAT + "d ms, branches = %" GG_LL_FORMAT + "d," + " failures = %" GG_LL_FORMAT "d, depth = %d", nsol_++, obj_str.c_str(), timer_->GetInMs(), solver()->branches(), solver()->failures(), depth); if (solver()->neighbors() != 0) { - StringAppendF(&log, ", neighbors = %" GG_LL_FORMAT - "d, filtered neighbors = %" GG_LL_FORMAT - "d," - " accepted neighbors = %" GG_LL_FORMAT "d", + StringAppendF(&log, + ", neighbors = %" GG_LL_FORMAT + "d, filtered neighbors = %" GG_LL_FORMAT + "d," + " accepted neighbors = %" GG_LL_FORMAT "d", solver()->neighbors(), solver()->filtered_neighbors(), solver()->accepted_neighbors()); } @@ -158,17 +159,18 @@ bool SearchLog::AtSolution() { void SearchLog::BeginFail() { Maintain(); } void SearchLog::NoMoreSolutions() { - std::string buffer = StringPrintf("Finished search tree (time = %" GG_LL_FORMAT - "d ms, branches = %" GG_LL_FORMAT - "d," - " failures = %" GG_LL_FORMAT "d", - timer_->GetInMs(), solver()->branches(), - solver()->failures()); + std::string buffer = StringPrintf( + "Finished search tree (time = %" GG_LL_FORMAT + "d ms, branches = %" GG_LL_FORMAT + "d," + " failures = %" GG_LL_FORMAT "d", + timer_->GetInMs(), solver()->branches(), solver()->failures()); if (solver()->neighbors() != 0) { - StringAppendF(&buffer, ", neighbors = %" GG_LL_FORMAT - "d, filtered neighbors = %" GG_LL_FORMAT - "d," - " accepted neigbors = %" GG_LL_FORMAT "d", + StringAppendF(&buffer, + ", neighbors = %" GG_LL_FORMAT + "d, filtered neighbors = %" GG_LL_FORMAT + "d," + " accepted neigbors = %" GG_LL_FORMAT "d", solver()->neighbors(), solver()->filtered_neighbors(), solver()->accepted_neighbors()); } @@ -190,10 +192,10 @@ void SearchLog::RefuteDecision(Decision* const decision) { } void SearchLog::OutputDecision() { - std::string buffer = StringPrintf("%" GG_LL_FORMAT "d branches, %" GG_LL_FORMAT - "d ms, %" GG_LL_FORMAT "d failures", - solver()->branches(), timer_->GetInMs(), - solver()->failures()); + std::string buffer = StringPrintf( + "%" GG_LL_FORMAT "d branches, %" GG_LL_FORMAT "d ms, %" GG_LL_FORMAT + "d failures", + solver()->branches(), timer_->GetInMs(), solver()->failures()); if (min_right_depth_ != kint32max && max_depth_ != 0) { const int depth = solver()->SearchDepth(); StringAppendF(&buffer, ", tree pos=%d/%d/%d minref=%d max=%d", @@ -204,9 +206,10 @@ void SearchLog::OutputDecision() { } if (obj_ != nullptr && objective_min_ != kint64max && objective_max_ != kint64min) { - StringAppendF(&buffer, ", objective minimum = %" GG_LL_FORMAT - "d" - ", objective maximum = %" GG_LL_FORMAT "d", + StringAppendF(&buffer, + ", objective minimum = %" GG_LL_FORMAT + "d" + ", objective maximum = %" GG_LL_FORMAT "d", objective_min_, objective_max_); } const int progress = solver()->TopProgressPercent(); @@ -244,22 +247,22 @@ void SearchLog::OutputLine(const std::string& line) { std::string SearchLog::MemoryUsage() { static const int64 kDisplayThreshold = 2; - static const int64 kKiloByte = 1024; - static const int64 kMegaByte = kKiloByte * kKiloByte; - static const int64 kGigaByte = kMegaByte * kKiloByte; - const int64 memory_usage = Solver::MemoryUsage(); - if (memory_usage > kDisplayThreshold * kGigaByte) { - return StringPrintf("memory used = %.2lf GB", - memory_usage * 1.0 / kGigaByte); - } else if (memory_usage > kDisplayThreshold * kMegaByte) { - return StringPrintf("memory used = %.2lf MB", - memory_usage * 1.0 / kMegaByte); - } else if (memory_usage > kDisplayThreshold * kKiloByte) { - return StringPrintf("memory used = %2lf KB", - memory_usage * 1.0 / kKiloByte); - } else { - return StringPrintf("memory used = %" GG_LL_FORMAT "d", memory_usage); - } + static const int64 kKiloByte = 1024; + static const int64 kMegaByte = kKiloByte * kKiloByte; + static const int64 kGigaByte = kMegaByte * kKiloByte; + const int64 memory_usage = Solver::MemoryUsage(); + if (memory_usage > kDisplayThreshold * kGigaByte) { + return StringPrintf("memory used = %.2lf GB", + memory_usage * 1.0 / kGigaByte); + } else if (memory_usage > kDisplayThreshold * kMegaByte) { + return StringPrintf("memory used = %.2lf MB", + memory_usage * 1.0 / kMegaByte); + } else if (memory_usage > kDisplayThreshold * kKiloByte) { + return StringPrintf("memory used = %2lf KB", + memory_usage * 1.0 / kKiloByte); + } else { + return StringPrintf("memory used = %" GG_LL_FORMAT "d", memory_usage); + } } SearchMonitor* Solver::MakeSearchLog(int branch_period) { @@ -271,14 +274,15 @@ SearchMonitor* Solver::MakeSearchLog(int branch_period, IntVar* const var) { return RevAlloc(new SearchLog(this, nullptr, var, nullptr, branch_period)); } -SearchMonitor* Solver::MakeSearchLog(int branch_period, - std::function display_callback) { +SearchMonitor* Solver::MakeSearchLog( + int branch_period, std::function display_callback) { return RevAlloc(new SearchLog(this, nullptr, nullptr, std::move(display_callback), branch_period)); } -SearchMonitor* Solver::MakeSearchLog(int branch_period, IntVar* const var, - std::function display_callback) { +SearchMonitor* Solver::MakeSearchLog( + int branch_period, IntVar* const var, + std::function display_callback) { return RevAlloc(new SearchLog(this, nullptr, var, std::move(display_callback), branch_period)); } @@ -289,14 +293,13 @@ SearchMonitor* Solver::MakeSearchLog(int branch_period, new SearchLog(this, opt_var, nullptr, nullptr, branch_period)); } -SearchMonitor* Solver::MakeSearchLog(int branch_period, - OptimizeVar* const opt_var, - std::function display_callback) { +SearchMonitor* Solver::MakeSearchLog( + int branch_period, OptimizeVar* const opt_var, + std::function display_callback) { return RevAlloc(new SearchLog(this, opt_var, nullptr, std::move(display_callback), branch_period)); } - // ---------- Search Trace ---------- namespace { class SearchTrace : public SearchMonitor { @@ -1899,7 +1902,7 @@ std::string SelectValueName(Solver::IntValueStrategy val_str) { } std::string BuildHeuristicsName(Solver::IntVarStrategy var_str, - Solver::IntValueStrategy val_str) { + Solver::IntValueStrategy val_str) { return ChooseVariableName(var_str) + "_" + SelectValueName(val_str); } } // namespace @@ -1972,11 +1975,11 @@ DecisionBuilder* Solver::MakePhase(const std::vector& vars, CHECK(var_evaluator != nullptr); CheapestVarSelector* const var_selector = RevAlloc(new CheapestVarSelector(std::move(var_evaluator))); - Solver::VariableIndexSelector choose_variable = [var_selector]( - Solver* solver, const std::vector& vars, int first_unbound, - int last_unbound) { - return var_selector->Choose(solver, vars, first_unbound, last_unbound); - }; + Solver::VariableIndexSelector choose_variable = + [var_selector](Solver* solver, const std::vector& vars, + int first_unbound, int last_unbound) { + return var_selector->Choose(solver, vars, first_unbound, last_unbound); + }; Solver::VariableValueSelector select_value = BaseAssignVariables::MakeValueSelector(this, val_str); const std::string name = "ChooseCheapestVariable_" + SelectValueName(val_str); @@ -1991,8 +1994,10 @@ DecisionBuilder* Solver::MakePhase(const std::vector& vars, BaseAssignVariables::MakeVariableSelector(this, vars, var_str); CheapestValueSelector* const value_selector = RevAlloc(new CheapestValueSelector(std::move(value_evaluator), nullptr)); - Solver::VariableValueSelector select_value = [value_selector]( - const IntVar* var, int64 id) { return value_selector->Select(var, id); }; + Solver::VariableValueSelector select_value = + [value_selector](const IntVar* var, int64 id) { + return value_selector->Select(var, id); + }; const std::string name = ChooseVariableName(var_str) + "_SelectCheapestValue"; return BaseAssignVariables::MakePhase(this, vars, choose_variable, select_value, name, @@ -2006,8 +2011,10 @@ DecisionBuilder* Solver::MakePhase( BaseAssignVariables::MakeVariableSelector(this, vars, var_str); BestValueByComparisonSelector* const value_selector = RevAlloc( new BestValueByComparisonSelector(std::move(var_val1_val2_comparator))); - Solver::VariableValueSelector select_value = [value_selector]( - const IntVar* var, int64 id) { return value_selector->Select(var, id); }; + Solver::VariableValueSelector select_value = + [value_selector](const IntVar* var, int64 id) { + return value_selector->Select(var, id); + }; return BaseAssignVariables::MakePhase(this, vars, choose_variable, select_value, "CheapestValue", BaseAssignVariables::ASSIGN); @@ -2018,15 +2025,17 @@ DecisionBuilder* Solver::MakePhase(const std::vector& vars, Solver::IndexEvaluator2 value_evaluator) { CheapestVarSelector* const var_selector = RevAlloc(new CheapestVarSelector(std::move(var_evaluator))); - Solver::VariableIndexSelector choose_variable = [var_selector]( - Solver* solver, const std::vector& vars, int first_unbound, - int last_unbound) { - return var_selector->Choose(solver, vars, first_unbound, last_unbound); - }; + Solver::VariableIndexSelector choose_variable = + [var_selector](Solver* solver, const std::vector& vars, + int first_unbound, int last_unbound) { + return var_selector->Choose(solver, vars, first_unbound, last_unbound); + }; CheapestValueSelector* value_selector = RevAlloc(new CheapestValueSelector(std::move(value_evaluator), nullptr)); - Solver::VariableValueSelector select_value = [value_selector]( - const IntVar* var, int64 id) { return value_selector->Select(var, id); }; + Solver::VariableValueSelector select_value = + [value_selector](const IntVar* var, int64 id) { + return value_selector->Select(var, id); + }; return BaseAssignVariables::MakePhase(this, vars, choose_variable, select_value, "CheapestValue", BaseAssignVariables::ASSIGN); @@ -2040,8 +2049,10 @@ DecisionBuilder* Solver::MakePhase(const std::vector& vars, BaseAssignVariables::MakeVariableSelector(this, vars, var_str); CheapestValueSelector* value_selector = RevAlloc(new CheapestValueSelector( std::move(value_evaluator), std::move(tie_breaker))); - Solver::VariableValueSelector select_value = [value_selector]( - const IntVar* var, int64 id) { return value_selector->Select(var, id); }; + Solver::VariableValueSelector select_value = + [value_selector](const IntVar* var, int64 id) { + return value_selector->Select(var, id); + }; return BaseAssignVariables::MakePhase(this, vars, choose_variable, select_value, "CheapestValue", BaseAssignVariables::ASSIGN); @@ -2053,15 +2064,17 @@ DecisionBuilder* Solver::MakePhase(const std::vector& vars, Solver::IndexEvaluator1 tie_breaker) { CheapestVarSelector* const var_selector = RevAlloc(new CheapestVarSelector(std::move(var_evaluator))); - Solver::VariableIndexSelector choose_variable = [var_selector]( - Solver* solver, const std::vector& vars, int first_unbound, - int last_unbound) { - return var_selector->Choose(solver, vars, first_unbound, last_unbound); - }; + Solver::VariableIndexSelector choose_variable = + [var_selector](Solver* solver, const std::vector& vars, + int first_unbound, int last_unbound) { + return var_selector->Choose(solver, vars, first_unbound, last_unbound); + }; CheapestValueSelector* value_selector = RevAlloc(new CheapestValueSelector( std::move(value_evaluator), std::move(tie_breaker))); - Solver::VariableValueSelector select_value = [value_selector]( - const IntVar* var, int64 id) { return value_selector->Select(var, id); }; + Solver::VariableValueSelector select_value = + [value_selector](const IntVar* var, int64 id) { + return value_selector->Select(var, id); + }; return BaseAssignVariables::MakePhase(this, vars, choose_variable, select_value, "CheapestValue", BaseAssignVariables::ASSIGN); @@ -3173,12 +3186,11 @@ void SimulatedAnnealing::ApplyDecision(Decision* const d) { if (d == s->balancing_decision()) { return; } - #if defined(_MSC_VER) || defined(__ANDROID__) - const int64 energy_bound = Temperature() * log(rand_.RndFloat()) / - log(2.0L); - #else - const int64 energy_bound = Temperature() * log2(rand_.RndFloat()); - #endif +#if defined(_MSC_VER) || defined(__ANDROID__) + const int64 energy_bound = Temperature() * log(rand_.RndFloat()) / log(2.0L); +#else + const int64 energy_bound = Temperature() * log2(rand_.RndFloat()); +#endif if (maximize_) { const int64 bound = (current_ > kint64min) ? current_ + step_ + energy_bound : current_; @@ -3257,7 +3269,7 @@ class GuidedLocalSearchPenaltiesTable : public GuidedLocalSearchPenalties { void Reset() override; private: - std::vector > penalties_; + std::vector> penalties_; bool has_values_; }; @@ -3544,7 +3556,7 @@ int64 GuidedLocalSearch::Evaluate(const Assignment* delta, // Penalize all the most expensive arcs (var, value) according to their utility: // utility(i, j) = cost(i, j) / (1 + penalty(i, j)) bool GuidedLocalSearch::LocalOptimum() { - std::vector > utility(vars_.size()); + std::vector> utility(vars_.size()); for (int i = 0; i < vars_.size(); ++i) { if (!assignment_.Bound(vars_[i])) { // Never synced with a solution, problem infeasible. @@ -4562,9 +4574,9 @@ class SymmetryManager : public SearchMonitor { private: const std::vector visitors_; - std::vector > clauses_; - std::vector > decisions_; - std::vector > directions_; + std::vector> clauses_; + std::vector> decisions_; + std::vector> directions_; }; // ----- Symmetry Breaker ----- diff --git a/ortools/constraint_solver/softgcc.cc b/ortools/constraint_solver/softgcc.cc index 679ec093397..d0c07deed03 100644 --- a/ortools/constraint_solver/softgcc.cc +++ b/ortools/constraint_solver/softgcc.cc @@ -14,14 +14,14 @@ #include #include "ortools/base/stringprintf.h" -#include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/constraint_solver.h" +#include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/string_array.h" #include "ortools/util/vector_map.h" namespace operations_research { namespace { -class SoftGCC : public Constraint{ +class SoftGCC : public Constraint { public: static const int64 kUnassigned = kint64min; enum FlowType { UF, OF }; @@ -32,12 +32,9 @@ class SoftGCC : public Constraint{ // in x and viol(vi) = max(0, card_mins_i]-ci, ci-card_max_[i]) // i.e. viol(vi) is the shortage or excess wrt the prescribed // cardinalities. - SoftGCC(Solver* const solver, - const std::vector& vars, - int64 min_value, - const std::vector& card_mins, - const std::vector& card_max, - IntVar* const violation_var) + SoftGCC(Solver* const solver, const std::vector& vars, + int64 min_value, const std::vector& card_mins, + const std::vector& card_max, IntVar* const violation_var) : Constraint(solver), vars_(vars), min_value_(min_value), @@ -100,7 +97,7 @@ class SoftGCC : public Constraint{ } virtual void InitialPropagate() { - for (int64 k = 0; k < vars_.size() ; k++) { + for (int64 k = 0; k < vars_.size(); k++) { if (under_variable_match_[k] != kUnassigned) { if (!vars_[k]->Contains(under_variable_match_[k])) { Unassign(k, UF); @@ -123,7 +120,7 @@ class SoftGCC : public Constraint{ // Prune upper bound of violation if all variables are bound. bool all_bound = true; - for (int64 i = 0 ; i < vars_.size(); i++) { + for (int64 i = 0; i < vars_.size(); i++) { if (!vars_[i]->Bound()) { all_bound = false; break; @@ -134,7 +131,6 @@ class SoftGCC : public Constraint{ } } - void ComputeRangeOfValues() { const int64 prev_min_value = min_value_; const int64 prev_max_value = max_value_; @@ -160,23 +156,23 @@ class SoftGCC : public Constraint{ sum_card_min_ = 0; - for (int64 i = 0 ; i < prev_num_values; i++) { + for (int64 i = 0; i < prev_num_values; i++) { if (card_mins_[i] > 0) { - new_card_mins[i + delta] = card_mins_[i] ; + new_card_mins[i + delta] = card_mins_[i]; sum_card_min_ += card_mins_[i]; } } - for (int64 i = 0 ; i < prev_num_values; i++) { + for (int64 i = 0; i < prev_num_values; i++) { if (card_max_[i] < vars_.size()) { - new_card_max[i + delta] = card_max_[i] ; + new_card_max[i + delta] = card_max_[i]; } } card_mins_.swap(new_card_mins); card_max_.swap(new_card_max); } else { sum_card_min_ = 0; - for (int64 i = 0 ; i < num_values_; i++) { + for (int64 i = 0; i < num_values_; i++) { if (card_mins_[i] > 0) { sum_card_min_ += card_mins_[i]; } @@ -190,11 +186,11 @@ class SoftGCC : public Constraint{ overflow_.reset(NewIntArray(num_values_)); // first variable matched - under_value_match_.reset(new int64 [num_values_]); - over_value_match_.reset(new int64 [num_values_]); + under_value_match_.reset(new int64[num_values_]); + over_value_match_.reset(new int64[num_values_]); for (int64 k = 0; k < num_values_; k++) { under_value_match_[k] = kUnassigned; // unmatched - over_value_match_[k] = kUnassigned; // unmatched + over_value_match_[k] = kUnassigned; // unmatched } // next variable matched @@ -202,7 +198,7 @@ class SoftGCC : public Constraint{ over_next_match_.reset(new int64[vars_.size()]); for (int64 k = 0; k < vars_.size(); k++) { under_next_match_[k] = kUnassigned; // no next - over_next_match_[k] = kUnassigned; // no next + over_next_match_[k] = kUnassigned; // no next } // previous variable matched @@ -210,15 +206,15 @@ class SoftGCC : public Constraint{ over_previous_match_.reset(new int64[vars_.size()]); for (int64 k = 0; k < vars_.size(); k++) { under_previous_match_[k] = kUnassigned; // no prev - over_previous_match_[k] = kUnassigned; // no prev + over_previous_match_[k] = kUnassigned; // no prev } // variable assignment - under_variable_match_.reset(new int64 [vars_.size()]); - over_variable_match_.reset(new int64 [vars_.size()]); - for (int64 k = 0 ; k < vars_.size(); k++) { - under_variable_match_[k] = kUnassigned; // unmatched - over_variable_match_[k] = kUnassigned; // unmatched + under_variable_match_.reset(new int64[vars_.size()]); + over_variable_match_.reset(new int64[vars_.size()]); + for (int64 k = 0; k < vars_.size(); k++) { + under_variable_match_[k] = kUnassigned; // unmatched + over_variable_match_[k] = kUnassigned; // unmatched } variable_seen_.reset(new int64[vars_.size()]); @@ -257,7 +253,7 @@ class SoftGCC : public Constraint{ prev = under_previous_match_.get(); value_match = under_value_match_.get(); under_total_flow_++; - } else { // OF + } else { // OF flow = overflow_.get(); var_match = over_variable_match_.get(); next = over_next_match_.get(); @@ -300,7 +296,7 @@ class SoftGCC : public Constraint{ next = under_next_match_.get(); prev = under_previous_match_.get(); value_match = under_value_match_.get(); - } else { // OF + } else { // OF flow = overflow_.get(); var_match = over_variable_match_.get(); next = over_next_match_.get(); @@ -308,7 +304,7 @@ class SoftGCC : public Constraint{ value_match = over_value_match_.get(); } - if (var_match[k] != kUnassigned) { // this guy is assigned; must be removed + if (var_match[k] != kUnassigned) { // this guy is assigned; must be removed if (ft == UF) { under_total_flow_--; } else { @@ -317,13 +313,13 @@ class SoftGCC : public Constraint{ int64 w = var_match[k]; flow[w - min_value_]--; - if (value_match[w - min_value_] == k) { // first in the list + if (value_match[w - min_value_] == k) { // first in the list int64 nk = next[k]; value_match[w - min_value_] = nk; if (nk != kUnassigned) { - prev[nk] = kUnassigned; // nk is now first + prev[nk] = kUnassigned; // nk is now first } - } else { // not first + } else { // not first int64 pk = prev[k]; int64 nk = next[k]; next[pk] = nk; @@ -364,13 +360,12 @@ class SoftGCC : public Constraint{ int64 ViolationValue() { int64 buf = FindBestUnderflow(); int64 bof = FindBestOverflow(); - return buf+bof; + return buf + bof; } // Computes and returns the best under flow. int64 FindBestUnderflow() { - for (int64 k = 0; - k < vars_.size() && under_total_flow_ < vars_.size(); + for (int64 k = 0; k < vars_.size() && under_total_flow_ < vars_.size(); k++) { if (under_variable_match_[k] == kUnassigned) { magic_++; @@ -390,15 +385,14 @@ class SoftGCC : public Constraint{ overflow_[i - min_value_] = underflow_[i - min_value_]; over_value_match_[i - min_value_] = under_value_match_[i - min_value_]; } - for (int64 k = 0; k < vars_.size() ; k++) { + for (int64 k = 0; k < vars_.size(); k++) { over_variable_match_[k] = under_variable_match_[k]; over_next_match_[k] = under_next_match_[k]; over_previous_match_[k] = under_previous_match_[k]; } over_total_flow_ = under_total_flow_; - for (int64 k = 0; - k < vars_.size() && over_total_flow_ < vars_.size(); + for (int64 k = 0; k < vars_.size() && over_total_flow_ < vars_.size(); k++) { if (over_variable_match_[k] == kUnassigned) { magic_++; @@ -411,9 +405,8 @@ class SoftGCC : public Constraint{ // Finds augmenting path from variable i which is currently not // matched (true if found a path, false otherwise). bool FindAugmentingPath(int64 k, FlowType ft) { - int64* const var_match = (ft == UF) ? - under_variable_match_.get() : - over_variable_match_.get(); + int64* const var_match = + (ft == UF) ? under_variable_match_.get() : over_variable_match_.get(); if (variable_seen_[k] != magic_) { variable_seen_[k] = magic_; @@ -428,8 +421,7 @@ class SoftGCC : public Constraint{ } } else { for (int64 v = var_min; v <= var_max; v++) { - if (var_match[k] != v && - vars_[k]->Contains(v) && + if (var_match[k] != v && vars_[k]->Contains(v) && FindAugmentingPathValue(v, ft)) { Assign(k, v, ft); return true; @@ -455,7 +447,7 @@ class SoftGCC : public Constraint{ next = under_next_match_.get(); value_match = under_value_match_.get(); capa = card_mins_.data(); - } else { // OF + } else { // OF flow = overflow_.get(); next = over_next_match_.get(); value_match = over_value_match_.get(); @@ -493,7 +485,7 @@ class SoftGCC : public Constraint{ num_vars_in_component_.resize(component_ + 1); for (int64 k = 0; k < vars_.size(); k++) { - if (var_match[k] == kUnassigned ) { + if (var_match[k] == kUnassigned) { num_vars_in_component_[variable_component_[k]]++; } } @@ -517,8 +509,8 @@ class SoftGCC : public Constraint{ stack_.reset(NewIntArray(vars_.size() + num_values_ + 1)); type_.reset(NewIntArray(vars_.size() + num_values_ + 1)); - is_var_always_matched_in_underflow_ .reset(new bool[vars_.size()]); - is_var_always_matched_in_overflow_ .reset(new bool[vars_.size()]); + is_var_always_matched_in_underflow_.reset(new bool[vars_.size()]); + is_var_always_matched_in_overflow_.reset(new bool[vars_.size()]); for (int k = 0; k < size; ++k) { is_var_always_matched_in_underflow_[k] = false; @@ -527,12 +519,12 @@ class SoftGCC : public Constraint{ } void InitScc() { - for (int64 k = 0 ; k < vars_.size(); k++) { + for (int64 k = 0; k < vars_.size(); k++) { variable_component_[k] = 0; variable_dfs_[k] = 0; variable_high_[k] = 0; } - for (int64 k = 0 ; k < num_values_; k++) { + for (int64 k = 0; k < num_values_; k++) { value_component_[k] = 0; value_dfs_[k] = 0; value_high_[k] = 0; @@ -550,16 +542,14 @@ class SoftGCC : public Constraint{ void FindScc(FlowType ft) { InitScc(); for (int64 k = 0; k < vars_.size(); k++) { - if (variable_dfs_[k] == 0) - FindSccVar(k, ft); + if (variable_dfs_[k] == 0) FindSccVar(k, ft); } } void FindSccVar(int64 k, FlowType ft) { // First variable matched to the value. - int64* var_match = (ft == UF) ? - under_variable_match_.get() : - over_variable_match_.get(); + int64* var_match = + (ft == UF) ? under_variable_match_.get() : over_variable_match_.get(); variable_dfs_[k] = dfs_--; variable_high_[k] = variable_dfs_[k]; @@ -648,9 +638,8 @@ class SoftGCC : public Constraint{ void FindSccValue(int64 v, FlowType ft) { // First variable matched to the value. - int64* value_match = (ft == UF) ? - under_value_match_.get() : - over_value_match_.get(); + int64* value_match = + (ft == UF) ? under_value_match_.get() : over_value_match_.get(); // First variable matched to the value. const int64* const capa = (ft == UF) ? card_mins_.data() : card_max_.data(); // First variable matched to the value. @@ -691,7 +680,7 @@ class SoftGCC : public Constraint{ value_high_[v - min_value_] = sink_high_; } } else if ((sink_dfs_ > value_dfs_[v - min_value_]) && - (sink_component_ == 0)) { + (sink_component_ == 0)) { if (sink_dfs_ > value_high_[v - min_value_]) { value_high_[v - min_value_] = sink_dfs_; } @@ -720,9 +709,8 @@ class SoftGCC : public Constraint{ void FindSccSink(FlowType ft) { // First variable matched to the value. - int64* const var_match = (ft == UF) ? - under_variable_match_.get() : - over_variable_match_.get(); + int64* const var_match = + (ft == UF) ? under_variable_match_.get() : over_variable_match_.get(); // First variable matched to the value. int64* const flow = (ft == UF) ? underflow_.get() : overflow_.get(); @@ -746,7 +734,7 @@ class SoftGCC : public Constraint{ sink_high_ = value_high_[w - min_value_]; } } else if ((value_dfs_[w - min_value_] > sink_dfs_) && - (value_component_[w - min_value_] == 0)) { + (value_component_[w - min_value_] == 0)) { if (value_dfs_[w - min_value_] > sink_high_) { sink_high_ = value_dfs_[w - min_value_]; } @@ -765,7 +753,7 @@ class SoftGCC : public Constraint{ sink_high_ = variable_high_[i]; } } else if ((variable_dfs_[i] > sink_dfs_) && - (variable_component_[i] == 0)) { + (variable_component_[i] == 0)) { if (variable_dfs_[i] > sink_high_) { sink_high_ = variable_dfs_[i]; } @@ -791,7 +779,6 @@ class SoftGCC : public Constraint{ } } while (true); } - } void Prune(int64 min_violation) { @@ -824,12 +811,12 @@ class SoftGCC : public Constraint{ for (int64 w = var_min; w <= var_max; w++) { if (under_variable_match_[k] != w && over_variable_match_[k] != w) { if ((under_variable_component_[k] != - under_value_component_[w - min_value_] && + under_value_component_[w - min_value_] && (card_mins_[w - min_value_] > 0 || is_var_always_matched_in_underflow_[k])) && (variable_component_[k] != value_component_[w - min_value_] && (card_max_[w - min_value_] > 0 || - is_var_always_matched_in_overflow_[k])) ) { + is_var_always_matched_in_overflow_[k]))) { vars_[k]->RemoveValue(w); } } @@ -846,7 +833,7 @@ class SoftGCC : public Constraint{ for (int64 w = var_min; w <= var_max; w++) { if (under_variable_match_[k] != w && over_variable_match_[k] != w) { if (under_variable_component_[k] != - under_value_component_[w - min_value_] && + under_value_component_[w - min_value_] && (card_mins_[w - min_value_] > 0 || is_var_always_matched_in_underflow_[k])) { vars_[k]->RemoveValue(w); @@ -874,9 +861,7 @@ class SoftGCC : public Constraint{ } } - virtual std::string DebugString() const { - return "SoftGCC"; - } + virtual std::string DebugString() const { return "SoftGCC"; } virtual void Accept(ModelVisitor* const visitor) const { visitor->BeginVisitConstraint(ModelVisitor::kGlobalCardinality, this); @@ -906,37 +891,37 @@ class SoftGCC : public Constraint{ IntVar* const violation_var_; int64 sum_card_min_; - //for each value, the quantity of flow into this value + // for each value, the quantity of flow into this value std::unique_ptr underflow_; - //for each variable, the value it is matched to + // for each variable, the value it is matched to std::unique_ptr under_variable_match_; - //first variable matched to the value + // first variable matched to the value std::unique_ptr under_value_match_; - //total flow + // total flow int64 under_total_flow_; - //next variable matched + // next variable matched std::unique_ptr under_next_match_; - //previous variable matched + // previous variable matched std::unique_ptr under_previous_match_; - //for each value, the quantity of flow into this value + // for each value, the quantity of flow into this value std::unique_ptr overflow_; - //for each variable, the value it is matched to + // for each variable, the value it is matched to std::unique_ptr over_variable_match_; - //first variable matched to the value + // first variable matched to the value std::unique_ptr over_value_match_; - //total flow + // total flow int64 over_total_flow_; - //next variable matched + // next variable matched std::unique_ptr over_next_match_; - //previous variable matched + // previous variable matched std::unique_ptr over_previous_match_; - //flags for the dfs_ if the var nodes have been visited + // flags for the dfs_ if the var nodes have been visited std::unique_ptr variable_seen_; - //flags for the dfs_ if the val nodes have been visited + // flags for the dfs_ if the val nodes have been visited std::unique_ptr value_seen_; - //magic_ used for the flag in _variable_seen_ and _value_seen_ + // magic_ used for the flag in _variable_seen_ and _value_seen_ int64 magic_; int64 dfs_; int64 component_; @@ -960,32 +945,20 @@ class SoftGCC : public Constraint{ }; } // namespace - -Constraint* MakeSoftGcc(Solver* const solver, - const std::vector& vars, - int64 min_value, - const std::vector& card_mins, +Constraint* MakeSoftGcc(Solver* const solver, const std::vector& vars, + int64 min_value, const std::vector& card_mins, const std::vector& card_max, IntVar* const violation_var) { - return solver->RevAlloc(new SoftGCC(solver, - vars, - min_value, - card_mins, - card_max, - violation_var)); + return solver->RevAlloc( + new SoftGCC(solver, vars, min_value, card_mins, card_max, violation_var)); } -Constraint* MakeSoftGcc(Solver* const solver, - const std::vector& vars, - int64 min_value, - const std::vector& card_mins, +Constraint* MakeSoftGcc(Solver* const solver, const std::vector& vars, + int64 min_value, const std::vector& card_mins, const std::vector& card_max, IntVar* const violation_var) { - return solver->RevAlloc(new SoftGCC(solver, - vars, - min_value, + return solver->RevAlloc(new SoftGCC(solver, vars, min_value, ToInt64Vector(card_mins), - ToInt64Vector(card_max), - violation_var)); + ToInt64Vector(card_max), violation_var)); } } // namespace operations_research diff --git a/ortools/constraint_solver/table.cc b/ortools/constraint_solver/table.cc index 67c2f3d967c..4c51e3c9d1b 100644 --- a/ortools/constraint_solver/table.cc +++ b/ortools/constraint_solver/table.cc @@ -15,18 +15,17 @@ // This file implements the table constraints. #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/constraint_solver/sat_constraint.h" @@ -1141,7 +1140,7 @@ class SmallCompactPositiveTableConstraint : public BasePositiveTableConstraint { }; bool HasCompactDomains(const std::vector& vars) { - return true; // Always assume compact table. + return true; // Always assume compact table. } // ---------- Deterministic Finite Automaton ---------- diff --git a/ortools/constraint_solver/timetabling.cc b/ortools/constraint_solver/timetabling.cc index c7a201c1309..09debdf92ba 100644 --- a/ortools/constraint_solver/timetabling.cc +++ b/ortools/constraint_solver/timetabling.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include "ortools/base/integral_types.h" diff --git a/ortools/constraint_solver/trace.cc b/ortools/constraint_solver/trace.cc index 0fe92cce73b..3a0cb19c81c 100644 --- a/ortools/constraint_solver/trace.cc +++ b/ortools/constraint_solver/trace.cc @@ -11,21 +11,19 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" @@ -581,7 +579,9 @@ class PrintTrace : public PropagationMonitor { PopDelayedInfo(); } - void PushContext(const std::string& context) override { PushDelayedInfo(context); } + void PushContext(const std::string& context) override { + PushDelayedInfo(context); + } void PopContext() override { PopDelayedInfo(); } diff --git a/ortools/constraint_solver/tree_monitor.cc b/ortools/constraint_solver/tree_monitor.cc index 0f36e337315..036eaf919d4 100644 --- a/ortools/constraint_solver/tree_monitor.cc +++ b/ortools/constraint_solver/tree_monitor.cc @@ -11,28 +11,27 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include #include #include #include #include #include +#include #include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" +#include +#include #include "ortools/base/file.h" +#include "ortools/base/hash.h" +#include "ortools/base/integral_types.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" -#include -#include #include "ortools/util/xml_helper.h" namespace operations_research { @@ -50,8 +49,8 @@ struct NaturalLess { ++start; } - // If one std::string is the substring of another, then the shorter std::string is - // smaller. + // If one std::string is the substring of another, then the shorter + // std::string is smaller. if (start == length) { return s1.length() < s2.length(); } @@ -86,7 +85,8 @@ struct NaturalLess { } }; -bool CompareStringsUsingNaturalLess(const std::string& s1, const std::string& s2) { +bool CompareStringsUsingNaturalLess(const std::string& s1, + const std::string& s2) { return NaturalLess()(s1, s2); } @@ -101,7 +101,6 @@ const char* kConfigXml = " \n" ""; - class TreeNode; // TreeDecisionVisitor is used to gain access to the variables and values @@ -183,13 +182,16 @@ class TreeMonitor : public SearchMonitor { typedef std::unordered_map IntVarMap; TreeMonitor(Solver* const solver, const IntVar* const* vars, int size, - const std::string& filename_tree, const std::string& filename_visualizer); + const std::string& filename_tree, + const std::string& filename_visualizer); TreeMonitor(Solver* const solver, const IntVar* const* vars, int size, - std::string* const tree_xml, std::string* const visualization_xml); + std::string* const tree_xml, + std::string* const visualization_xml); TreeMonitor(Solver* const solver, const IntVar* const* vars, int size, - const std::string& filename_config, const std::string& filename_tree, + const std::string& filename_config, + const std::string& filename_tree, const std::string& filename_visualizer); TreeMonitor(Solver* const solver, const IntVar* const* vars, int size, @@ -252,12 +254,7 @@ class TreeMonitor : public SearchMonitor { class TreeNode { public: typedef std::map, NaturalLess> DomainMap; - enum TreeNodeType { - ROOT, - TRY, - FAIL, - SOLUTION - }; + enum TreeNodeType { ROOT, TRY, FAIL, SOLUTION }; TreeNode(TreeNode* parent, int id) : cycles_(1), id_(id), name_(""), node_type_(TRY), parent_(parent) {} @@ -314,8 +311,9 @@ class TreeNode { // Adds a new child, initializes it and returns the corresponding pointer. bool AddChild(int id, const std::string& name, - std::unordered_map const& last_value, bool is_final_node, - TreeMonitor::IntVarMap const& vars, TreeNode** child) { + std::unordered_map const& last_value, + bool is_final_node, TreeMonitor::IntVarMap const& vars, + TreeNode** child) { CHECK(child != nullptr); if (!is_final_node) { @@ -390,8 +388,8 @@ class TreeNode { if (node_type_ == FAIL) { visualization_writer->StartElement("failed"); visualization_writer->AddAttribute("index", name); - visualization_writer->AddAttribute("value", - absl::StrCat(parent_->branch_value(0))); + visualization_writer->AddAttribute( + "value", absl::StrCat(parent_->branch_value(0))); visualization_writer->EndElement(); // failed } else if (node_type_ == TRY) { visualization_writer->StartElement("focus"); @@ -440,7 +438,8 @@ class TreeNode { const std::vector* const domain_values = gtl::FindOrNull(domain, name_); if (domain_values) { - tree_writer->AddAttribute("size", absl::StrCat(domain_values->size())); + tree_writer->AddAttribute("size", + absl::StrCat(domain_values->size())); } else { tree_writer->AddAttribute("size", "unknown"); } @@ -719,15 +718,15 @@ void TreeMonitor::ExitSearch() { LOG(INFO) << "Failed to gain write access to file: " << filename_tree_; } - if(!filename_config_.empty()) { + if (!filename_config_.empty()) { std::ofstream file_config_(filename_config_.c_str()); if (file_config_.is_open()) { file_config_ << kConfigXml; file_config_.close(); } else { - LOG(INFO) << "Failed to gain write access to file: " << - filename_config_; + LOG(INFO) << "Failed to gain write access to file: " + << filename_config_; } } } else { @@ -747,8 +746,9 @@ void TreeMonitor::ExitSearch() { std::string TreeMonitor::StripSpecialCharacters(std::string attribute) { // Numbers, characters, dashes, underscored, brackets, colons, slashes, // periods, question marks, and parentheses are allowed - const char* kAllowedCharacters = "0123456789abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ_-[]:/.?()"; + const char* kAllowedCharacters = + "0123456789abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ_-[]:/.?()"; std::set character_set; diff --git a/ortools/constraint_solver/utilities.cc b/ortools/constraint_solver/utilities.cc index c85845fde46..b6fcf671f52 100644 --- a/ortools/constraint_solver/utilities.cc +++ b/ortools/constraint_solver/utilities.cc @@ -11,18 +11,16 @@ // See the License for the specific language governing permissions and // limitations under the License. - +#include #include #include -#include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" @@ -438,7 +436,8 @@ class PrintModelVisitor : public ModelVisitor { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { LOG(INFO) << Spaces() << arg_name << ": ["; Increase(); for (int i = 0; i < arguments.size(); ++i) { @@ -624,7 +623,8 @@ class ModelStatisticsVisitor : public ModelVisitor { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { for (int i = 0; i < arguments.size(); ++i) { VisitSubArgument(arguments[i]); } @@ -707,7 +707,8 @@ class ModelStatisticsVisitor : public ModelVisitor { class VariableDegreeVisitor : public ModelVisitor { public: - explicit VariableDegreeVisitor(std::unordered_map* const map) + explicit VariableDegreeVisitor( + std::unordered_map* const map) : map_(map) {} ~VariableDegreeVisitor() override {} @@ -755,7 +756,8 @@ class VariableDegreeVisitor : public ModelVisitor { } void VisitIntegerVariableArrayArgument( - const std::string& arg_name, const std::vector& arguments) override { + const std::string& arg_name, + const std::vector& arguments) override { for (int i = 0; i < arguments.size(); ++i) { VisitSubArgument(arguments[i]); } diff --git a/ortools/constraint_solver/visitor.cc b/ortools/constraint_solver/visitor.cc index 79515e04e23..c5ab3ae5531 100644 --- a/ortools/constraint_solver/visitor.cc +++ b/ortools/constraint_solver/visitor.cc @@ -11,11 +11,10 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include +#include #include #include -#include #include #include "ortools/base/integral_types.h" @@ -35,7 +34,8 @@ void ArgumentHolder::SetTypeName(const std::string& type_name) { type_name_ = type_name; } -void ArgumentHolder::SetIntegerArgument(const std::string& arg_name, int64 value) { +void ArgumentHolder::SetIntegerArgument(const std::string& arg_name, + int64 value) { integer_argument_[arg_name] = value; } @@ -46,7 +46,8 @@ void ArgumentHolder::SetIntegerArrayArgument(const std::string& arg_name, void ArgumentHolder::SetIntegerMatrixArgument(const std::string& arg_name, const IntTupleSet& values) { - std::pair to_insert = std::make_pair(arg_name, values); + std::pair to_insert = + std::make_pair(arg_name, values); matrix_argument_.insert(to_insert); } @@ -90,12 +91,13 @@ bool ArgumentHolder::HasIntegerVariableArrayArgument( return gtl::ContainsKey(integer_variable_array_argument_, arg_name); } -int64 ArgumentHolder::FindIntegerArgumentWithDefault(const std::string& arg_name, - int64 def) const { +int64 ArgumentHolder::FindIntegerArgumentWithDefault( + const std::string& arg_name, int64 def) const { return gtl::FindWithDefault(integer_argument_, arg_name, def); } -int64 ArgumentHolder::FindIntegerArgumentOrDie(const std::string& arg_name) const { +int64 ArgumentHolder::FindIntegerArgumentOrDie( + const std::string& arg_name) const { return gtl::FindOrDie(integer_argument_, arg_name); } @@ -162,14 +164,15 @@ void ModelParser::VisitIntegerVariable(const IntVar* const variable, } void ModelParser::VisitIntegerVariable(const IntVar* const variable, - const std::string& operation, int64 value, - IntVar* const delegate) { + const std::string& operation, + int64 value, IntVar* const delegate) { delegate->Accept(this); // Usual place for parsing. } void ModelParser::VisitIntervalVariable(const IntervalVar* const variable, - const std::string& operation, int64 value, + const std::string& operation, + int64 value, IntervalVar* const delegate) { if (delegate != nullptr) { delegate->Accept(this); @@ -182,7 +185,8 @@ void ModelParser::VisitSequenceVariable(const SequenceVar* const variable) { } // Integer arguments -void ModelParser::VisitIntegerArgument(const std::string& arg_name, int64 value) { +void ModelParser::VisitIntegerArgument(const std::string& arg_name, + int64 value) { Top()->SetIntegerArgument(arg_name, value); } diff --git a/ortools/data/jobshop_scheduling_parser.cc b/ortools/data/jobshop_scheduling_parser.cc index b0d6758a546..2e5e6503a41 100644 --- a/ortools/data/jobshop_scheduling_parser.cc +++ b/ortools/data/jobshop_scheduling_parser.cc @@ -15,14 +15,14 @@ #include "math.h" +#include "google/protobuf/wrappers.pb.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/split.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" -#include "google/protobuf/wrappers.pb.h" -#include "ortools/base/split.h" #include "ortools/data/jobshop_scheduling.pb.h" -#include "ortools/base/filelineiter.h" DEFINE_int64(jssp_scaling_up_factor, 100000L, "Scaling factor for floating point penalties."); diff --git a/ortools/data/rcpsp_parser.cc b/ortools/data/rcpsp_parser.cc index 78b0d010b02..75fa52623ee 100644 --- a/ortools/data/rcpsp_parser.cc +++ b/ortools/data/rcpsp_parser.cc @@ -13,12 +13,12 @@ #include "ortools/data/rcpsp_parser.h" -#include "ortools/base/strtoint.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/numbers.h" #include "ortools/base/split.h" #include "ortools/base/stringpiece_utils.h" +#include "ortools/base/strtoint.h" #include "ortools/data/rcpsp.pb.h" -#include "ortools/base/filelineiter.h" using ::absl::delimiter::AnyOf; diff --git a/ortools/data/set_covering_parser.cc b/ortools/data/set_covering_parser.cc index 279caa228db..56cb98d4465 100644 --- a/ortools/data/set_covering_parser.cc +++ b/ortools/data/set_covering_parser.cc @@ -13,10 +13,10 @@ #include "ortools/data/set_covering_parser.h" -#include "ortools/base/strtoint.h" +#include "ortools/base/filelineiter.h" #include "ortools/base/numbers.h" #include "ortools/base/split.h" -#include "ortools/base/filelineiter.h" +#include "ortools/base/strtoint.h" namespace operations_research { namespace scp { @@ -39,7 +39,8 @@ bool ScpParser::LoadProblem(const std::string& filename, Format format, return section_ == END; } -void ScpParser::ProcessLine(const std::string& line, Format format, ScpData* data) { +void ScpParser::ProcessLine(const std::string& line, Format format, + ScpData* data) { line_++; const std::vector words = absl::StrSplit(line, AnyOf(" :\t\r"), absl::SkipEmpty()); diff --git a/ortools/flatzinc/checker.cc b/ortools/flatzinc/checker.cc index df7744b298f..23070661a9a 100644 --- a/ortools/flatzinc/checker.cc +++ b/ortools/flatzinc/checker.cc @@ -1033,7 +1033,7 @@ bool CheckSymmetricAllDifferent( using CallMap = std::unordered_map< std::string, std::function)>>; + std::function)>>; CallMap CreateCallMap() { CallMap m; diff --git a/ortools/flatzinc/constraints.cc b/ortools/flatzinc/constraints.cc index f72446b1f1d..402c5f0de0e 100644 --- a/ortools/flatzinc/constraints.cc +++ b/ortools/flatzinc/constraints.cc @@ -16,9 +16,9 @@ #include #include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/hash.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/flatzinc/flatzinc_constraints.h" @@ -2171,8 +2171,9 @@ void ExtractIntLinNe(fz::SolverData* data, fz::Constraint* ct) { std::vector coeffs; int64 rhs = 0; ParseLongIntLin(data, ct, &vars, &coeffs, &rhs); - AddConstraint(solver, ct, solver->MakeNonEquality( - solver->MakeScalProd(vars, coeffs), rhs)); + AddConstraint( + solver, ct, + solver->MakeNonEquality(solver->MakeScalProd(vars, coeffs), rhs)); } } diff --git a/ortools/flatzinc/cp_model_fz_solver.cc b/ortools/flatzinc/cp_model_fz_solver.cc index c7b24b7bba5..b8d2648b269 100644 --- a/ortools/flatzinc/cp_model_fz_solver.cc +++ b/ortools/flatzinc/cp_model_fz_solver.cc @@ -15,12 +15,12 @@ #include -#include "ortools/base/timer.h" #include "google/protobuf/text_format.h" -#include "ortools/base/split.h" -#include "ortools/base/stringpiece_utils.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" +#include "ortools/base/split.h" +#include "ortools/base/stringpiece_utils.h" +#include "ortools/base/timer.h" #include "ortools/flatzinc/checker.h" #include "ortools/flatzinc/logging.h" #include "ortools/sat/cp_constraints.h" @@ -768,7 +768,8 @@ std::string SolutionString( } } else { const int bound_size = output.bounds.size(); - std::string result = absl::StrCat(output.name, " = array", bound_size, "d("); + std::string result = + absl::StrCat(output.name, " = array", bound_size, "d("); for (int i = 0; i < bound_size; ++i) { if (output.bounds[i].max_value != 0) { absl::StrAppend(&result, output.bounds[i].min_value, "..", @@ -891,7 +892,7 @@ void SolveFzWithCpModelProto(const fz::Model& fz_model, // set in m.parameters. sat::SatParameters flag_parameters; CHECK(google::protobuf::TextFormat::ParseFromString(FLAGS_cp_sat_params, - &flag_parameters)) + &flag_parameters)) << FLAGS_cp_sat_params; m.parameters.MergeFrom(flag_parameters); if (p.all_solutions && !m.proto.has_objective()) { @@ -899,8 +900,8 @@ void SolveFzWithCpModelProto(const fz::Model& fz_model, m.parameters.set_enumerate_all_solutions(true); } if (!p.free_search) { - m.parameters.set_search_branching(SatParameters::FIXED_SEARCH); - } + m.parameters.set_search_branching(SatParameters::FIXED_SEARCH); + } if (p.time_limit_in_ms > 0) { m.parameters.set_max_time_in_seconds(p.time_limit_in_ms * 1e-3); diff --git a/ortools/flatzinc/flatzinc_constraints.cc b/ortools/flatzinc/flatzinc_constraints.cc index 9720b6804a2..e13cf671a94 100644 --- a/ortools/flatzinc/flatzinc_constraints.cc +++ b/ortools/flatzinc/flatzinc_constraints.cc @@ -17,7 +17,6 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/flatzinc/logging.h" #include "ortools/util/string_array.h" @@ -155,7 +154,8 @@ class FixedModulo : public Constraint { std::string DebugString() const override { return absl::StrFormat("(%s %% %s == %" GG_LL_FORMAT "d)", - var_->DebugString().c_str(), mod_->DebugString().c_str(), residual_); + var_->DebugString().c_str(), + mod_->DebugString().c_str(), residual_); } private: @@ -914,7 +914,8 @@ Constraint* MakeFixedModulo(Solver* const s, IntVar* const var, } IntervalVar* MakePerformedIntervalVar(Solver* const solver, IntVar* const start, - IntVar* const duration, const std::string& n) { + IntVar* const duration, + const std::string& n) { CHECK(start != nullptr); CHECK(duration != nullptr); return solver->RegisterIntervalVar(solver->RevAlloc( diff --git a/ortools/flatzinc/flatzinc_constraints.h b/ortools/flatzinc/flatzinc_constraints.h index 4c19b168538..980885e369c 100644 --- a/ortools/flatzinc/flatzinc_constraints.h +++ b/ortools/flatzinc/flatzinc_constraints.h @@ -58,7 +58,8 @@ Constraint* MakeFixedModulo(Solver* const s, IntVar* const var, // Creates a performed interval variable with the given start and duration // variables. IntervalVar* MakePerformedIntervalVar(Solver* const solver, IntVar* const start, - IntVar* const duration, const std::string& n); + IntVar* const duration, + const std::string& n); // Creates a n-dimensional constraints that enforces that k boxes (n dimension) // do not overlap in space. diff --git a/ortools/flatzinc/fz.cc b/ortools/flatzinc/fz.cc index 083057819d5..754d8805a9c 100644 --- a/ortools/flatzinc/fz.cc +++ b/ortools/flatzinc/fz.cc @@ -27,9 +27,8 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/timer.h" #include "ortools/base/threadpool.h" -#include "ortools/base/commandlineflags.h" +#include "ortools/base/timer.h" #include "ortools/flatzinc/cp_model_fz_solver.h" #include "ortools/flatzinc/logging.h" #include "ortools/flatzinc/model.h" diff --git a/ortools/flatzinc/logging.cc b/ortools/flatzinc/logging.cc index 3f32e68e1b4..2225b45f29b 100644 --- a/ortools/flatzinc/logging.cc +++ b/ortools/flatzinc/logging.cc @@ -20,4 +20,3 @@ DEFINE_bool(fz_verbose, false, "Print verbose logging information from the flatzinc interpreter."); DEFINE_bool(fz_debug, false, "Print debug logging information from the flatzinc interpreter."); - diff --git a/ortools/flatzinc/model.cc b/ortools/flatzinc/model.cc index 76195fa846d..a95669b9e02 100644 --- a/ortools/flatzinc/model.cc +++ b/ortools/flatzinc/model.cc @@ -17,13 +17,10 @@ #include #include -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/base/join.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/flatzinc/logging.h" namespace operations_research { @@ -585,8 +582,8 @@ IntegerVariable* Argument::VarAt(int pos) const { // ----- IntegerVariable ----- -IntegerVariable::IntegerVariable(const std::string& name_, const Domain& domain_, - bool temporary_) +IntegerVariable::IntegerVariable(const std::string& name_, + const Domain& domain_, bool temporary_) : name(name_), domain(domain_), defining_constraint(nullptr), @@ -636,8 +633,9 @@ std::string IntegerVariable::DebugString() const { std::string Constraint::DebugString() const { const std::string strong = strong_propagation ? "strong propagation" : ""; const std::string presolve_status_str = - active ? "" : (presolve_propagation_done ? "[propagated during presolve]" - : "[removed during presolve]"); + active ? "" + : (presolve_propagation_done ? "[propagated during presolve]" + : "[removed during presolve]"); const std::string target = target_variable != nullptr ? StringPrintf(" => %s", target_variable->name.c_str()) @@ -822,7 +820,8 @@ std::string SolutionOutputSpecs::Bounds::DebugString() const { } SolutionOutputSpecs SolutionOutputSpecs::SingleVariable( - const std::string& name, IntegerVariable* variable, bool display_as_boolean) { + const std::string& name, IntegerVariable* variable, + bool display_as_boolean) { SolutionOutputSpecs result; result.name = name; result.variable = variable; @@ -866,8 +865,8 @@ Model::~Model() { gtl::STLDeleteElements(&constraints_); } -IntegerVariable* Model::AddVariable(const std::string& name, const Domain& domain, - bool defined) { +IntegerVariable* Model::AddVariable(const std::string& name, + const Domain& domain, bool defined) { IntegerVariable* const var = new IntegerVariable(name, domain, defined); variables_.push_back(var); return var; @@ -881,8 +880,9 @@ IntegerVariable* Model::AddConstant(int64 value) { return var; } -void Model::AddConstraint(const std::string& id, std::vector arguments, - bool is_domain, IntegerVariable* defines) { +void Model::AddConstraint(const std::string& id, + std::vector arguments, bool is_domain, + IntegerVariable* defines) { Constraint* const constraint = new Constraint(id, std::move(arguments), is_domain, defines); constraints_.push_back(constraint); @@ -891,7 +891,8 @@ void Model::AddConstraint(const std::string& id, std::vector arguments } } -void Model::AddConstraint(const std::string& id, std::vector arguments) { +void Model::AddConstraint(const std::string& id, + std::vector arguments) { AddConstraint(id, std::move(arguments), false, nullptr); } diff --git a/ortools/flatzinc/model.h b/ortools/flatzinc/model.h index 98b3fd006ed..7ee499b6e97 100644 --- a/ortools/flatzinc/model.h +++ b/ortools/flatzinc/model.h @@ -141,7 +141,8 @@ struct IntegerVariable { private: friend class Model; - IntegerVariable(const std::string& name_, const Domain& domain_, bool temporary_); + IntegerVariable(const std::string& name_, const Domain& domain_, + bool temporary_); }; // An argument is either an integer value, an integer domain, a @@ -200,8 +201,8 @@ struct Argument { // A constraint has a type, some arguments, and a few tags. Typically, a // Constraint is on the heap, and owned by the global Model object. struct Constraint { - Constraint(const std::string& t, std::vector args, bool strong_propag, - IntegerVariable* target) + Constraint(const std::string& t, std::vector args, + bool strong_propag, IntegerVariable* target) : type(t), arguments(std::move(args)), target_variable(target), diff --git a/ortools/flatzinc/parser.tab.cc b/ortools/flatzinc/parser.tab.cc index f807dc6ec6f..126ca3c0e2b 100644 --- a/ortools/flatzinc/parser.tab.cc +++ b/ortools/flatzinc/parser.tab.cc @@ -71,42 +71,40 @@ /* Pull parsers. */ #define YYPULL 1 - /* Substitute the variable and function names. */ -#define yyparse orfz_parse -#define yylex orfz_lex -#define yyerror orfz_error -#define yydebug orfz_debug -#define yynerrs orfz_nerrs - +#define yyparse orfz_parse +#define yylex orfz_lex +#define yyerror orfz_error +#define yydebug orfz_debug +#define yynerrs orfz_nerrs /* Copy the first part of user declarations. */ #line 73 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:339 */ -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif +#ifndef YY_NULLPTR +#if defined __cplusplus && 201103L <= __cplusplus +#define YY_NULLPTR nullptr +#else +#define YY_NULLPTR 0 +#endif +#endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 +#undef YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE 1 +#define YYERROR_VERBOSE 1 #endif /* In a future release of Bison, this section will be replaced by #include "parser.tab.hh". */ #ifndef YY_ORFZ_ORTOOLS_FLATZINC_PARSER_TAB_HH_INCLUDED -# define YY_ORFZ_ORTOOLS_FLATZINC_PARSER_TAB_HH_INCLUDED +#define YY_ORFZ_ORTOOLS_FLATZINC_PARSER_TAB_HH_INCLUDED /* Debug traces. */ #ifndef YYDEBUG -# define YYDEBUG 1 +#define YYDEBUG 1 #endif #if YYDEBUG extern int orfz_debug; @@ -131,36 +129,34 @@ typedef operations_research::fz::LexerInfo YYSTYPE; /* Token type. */ #ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - ARRAY = 258, - BOOL = 259, - CONSTRAINT = 260, - FLOAT = 261, - INT = 262, - MAXIMIZE = 263, - MINIMIZE = 264, - OF = 265, - PREDICATE = 266, - SATISFY = 267, - SET = 268, - SOLVE = 269, - VAR = 270, - DOTDOT = 271, - COLONCOLON = 272, - IVALUE = 273, - SVALUE = 274, - IDENTIFIER = 275, - DVALUE = 276 - }; +#define YYTOKENTYPE +enum yytokentype { + ARRAY = 258, + BOOL = 259, + CONSTRAINT = 260, + FLOAT = 261, + INT = 262, + MAXIMIZE = 263, + MINIMIZE = 264, + OF = 265, + PREDICATE = 266, + SATISFY = 267, + SET = 268, + SOLVE = 269, + VAR = 270, + DOTDOT = 271, + COLONCOLON = 272, + IVALUE = 273, + SVALUE = 274, + IDENTIFIER = 275, + DVALUE = 276 +}; #endif /* Value type. */ - - -int orfz_parse (operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner); +int orfz_parse(operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, void* scanner); #endif /* !YY_ORFZ_ORTOOLS_FLATZINC_PARSER_TAB_HH_INCLUDED */ @@ -181,15 +177,15 @@ using operations_research::fz::Domain; using operations_research::fz::IntegerVariable; using operations_research::fz::Lookup; using operations_research::fz::Model; -using operations_research::fz::SolutionOutputSpecs; using operations_research::fz::ParserContext; +using operations_research::fz::SolutionOutputSpecs; using operations_research::fz::VariableRefOrValue; using operations_research::fz::VariableRefOrValueArray; #line 177 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:359 */ #ifdef short -# undef short +#undef short #endif #ifdef YYTYPE_UINT8 @@ -217,636 +213,566 @@ typedef short int yytype_int16; #endif #ifndef YYSIZE_T -# ifdef __SIZE_TYPE__ -# define YYSIZE_T __SIZE_TYPE__ -# elif defined size_t -# define YYSIZE_T size_t -# elif ! defined YYSIZE_T -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# else -# define YYSIZE_T unsigned int -# endif +#ifdef __SIZE_TYPE__ +#define YYSIZE_T __SIZE_TYPE__ +#elif defined size_t +#define YYSIZE_T size_t +#elif !defined YYSIZE_T +#include /* INFRINGES ON USER NAME SPACE */ +#define YYSIZE_T size_t +#else +#define YYSIZE_T unsigned int +#endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM ((YYSIZE_T)-1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include /* INFRINGES ON USER NAME SPACE */ -# define YY_(Msgid) dgettext ("bison-runtime", Msgid) -# endif -# endif -# ifndef YY_ -# define YY_(Msgid) Msgid -# endif +#if defined YYENABLE_NLS && YYENABLE_NLS +#if ENABLE_NLS +#include /* INFRINGES ON USER NAME SPACE */ +#define YY_(Msgid) dgettext("bison-runtime", Msgid) +#endif +#endif +#ifndef YY_ +#define YY_(Msgid) Msgid +#endif #endif #ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif +#if (defined __GNUC__ && \ + (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) || \ + defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +#define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#else +#define YY_ATTRIBUTE(Spec) /* empty */ +#endif #endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#define YY_ATTRIBUTE_PURE YY_ATTRIBUTE((__pure__)) #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif +#if !defined _Noreturn && \ + (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +#if defined _MSC_VER && 1200 <= _MSC_VER +#define _Noreturn __declspec(noreturn) +#else +#define _Noreturn YY_ATTRIBUTE((__noreturn__)) +#endif #endif /* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +#if !defined lint || defined __GNUC__ +#define YYUSE(E) ((void)(E)) #else -# define YYUSE(E) /* empty */ +#define YYUSE(E) /* empty */ #endif #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") \ + _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +#define YY_IGNORE_MAYBE_UNINITIALIZED_END _Pragma("GCC diagnostic pop") #else -# define YY_INITIAL_VALUE(Value) Value +#define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +#define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif - -#if ! defined yyoverflow || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ -# ifdef YYSTACK_USE_ALLOCA -# if YYSTACK_USE_ALLOCA -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# elif defined __BUILTIN_VA_ARG_INCR -# include /* INFRINGES ON USER NAME SPACE */ -# elif defined _AIX -# define YYSTACK_ALLOC __alloca -# elif defined _MSC_VER -# include /* INFRINGES ON USER NAME SPACE */ -# define alloca _alloca -# else -# define YYSTACK_ALLOC alloca -# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS -# include /* INFRINGES ON USER NAME SPACE */ - /* Use EXIT_SUCCESS as a witness for stdlib.h. */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's 'empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# ifndef YYSTACK_ALLOC_MAXIMUM - /* The OS might guarantee only one guard page at the bottom of the stack, - and a page size can be as small as 4096 bytes. So we cannot safely - invoke alloca (N) if N exceeds 4096. Use a slightly smaller number - to allow for a few compiler-allocated temporary stack slots. */ -# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ -# endif -# else -# define YYSTACK_ALLOC YYMALLOC -# define YYSTACK_FREE YYFREE -# ifndef YYSTACK_ALLOC_MAXIMUM -# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM -# endif -# if (defined __cplusplus && ! defined EXIT_SUCCESS \ - && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) -# include /* INFRINGES ON USER NAME SPACE */ -# ifndef EXIT_SUCCESS -# define EXIT_SUCCESS 0 -# endif -# endif -# ifndef YYMALLOC -# define YYMALLOC malloc -# if ! defined malloc && ! defined EXIT_SUCCESS -void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# ifndef YYFREE -# define YYFREE free -# if ! defined free && ! defined EXIT_SUCCESS -void free (void *); /* INFRINGES ON USER NAME SPACE */ -# endif -# endif -# endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ +#ifdef YYSTACK_USE_ALLOCA +#if YYSTACK_USE_ALLOCA +#ifdef __GNUC__ +#define YYSTACK_ALLOC __builtin_alloca +#elif defined __BUILTIN_VA_ARG_INCR +#include /* INFRINGES ON USER NAME SPACE */ +#elif defined _AIX +#define YYSTACK_ALLOC __alloca +#elif defined _MSC_VER +#include /* INFRINGES ON USER NAME SPACE */ +#define alloca _alloca +#else +#define YYSTACK_ALLOC alloca +#if !defined _ALLOCA_H && !defined EXIT_SUCCESS +#include /* INFRINGES ON USER NAME SPACE */ +/* Use EXIT_SUCCESS as a witness for stdlib.h. */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#endif +#endif +#endif +#ifdef YYSTACK_ALLOC +/* Pacify GCC's 'empty if-body' warning. */ +#define YYSTACK_FREE(Ptr) \ + do { /* empty */ \ + ; \ + } while (0) +#ifndef YYSTACK_ALLOC_MAXIMUM +/* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +#define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +#endif +#else +#define YYSTACK_ALLOC YYMALLOC +#define YYSTACK_FREE YYFREE +#ifndef YYSTACK_ALLOC_MAXIMUM +#define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +#endif +#if (defined __cplusplus && !defined EXIT_SUCCESS && \ + !((defined YYMALLOC || defined malloc) && \ + (defined YYFREE || defined free))) +#include /* INFRINGES ON USER NAME SPACE */ +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#endif +#ifndef YYMALLOC +#define YYMALLOC malloc +#if !defined malloc && !defined EXIT_SUCCESS +void* malloc(YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#ifndef YYFREE +#define YYFREE free +#if !defined free && !defined EXIT_SUCCESS +void free(void*); /* INFRINGES ON USER NAME SPACE */ +#endif +#endif +#endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined yyoverflow \ - && (! defined __cplusplus \ - || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) +#if (!defined yyoverflow && \ + (!defined __cplusplus || \ + (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ -union yyalloc -{ +union yyalloc { yytype_int16 yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +#define YYSTACK_GAP_MAXIMUM (sizeof(union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) +#define YYSTACK_BYTES(N) \ + ((N) * (sizeof(yytype_int16) + sizeof(YYSTYPE)) + YYSTACK_GAP_MAXIMUM) -# define YYCOPY_NEEDED 1 +#define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ -# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) +#define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do { \ + YYSIZE_T yynewbytes; \ + YYCOPY(&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof(*yyptr); \ + } while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ -# ifndef YYCOPY -# if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) -# else -# define YYCOPY(Dst, Src, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ - while (0) -# endif -# endif +#ifndef YYCOPY +#if defined __GNUC__ && 1 < __GNUC__ +#define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy(Dst, Src, (Count) * sizeof(*(Src))) +#else +#define YYCOPY(Dst, Src, Count) \ + do { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) (Dst)[yyi] = (Src)[yyi]; \ + } while (0) +#endif +#endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 3 +#define YYFINAL 3 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 271 +#define YYLAST 271 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 32 +#define YYNTOKENS 32 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 32 +#define YYNNTS 32 /* YYNRULES -- Number of rules. */ -#define YYNRULES 96 +#define YYNRULES 96 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 223 +#define YYNSTATES 223 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 276 +#define YYUNDEFTOK 2 +#define YYMAXUTOK 276 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + ((unsigned int)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 23, 24, 2, 2, 25, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 26, 22, - 2, 29, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 27, 2, 28, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 30, 2, 31, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21 -}; +static const yytype_uint8 yytranslate[] = { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 23, 24, 2, 2, 25, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 22, + 2, 29, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 27, 2, 28, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 30, 2, 31, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; #if YYDEBUG - /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = -{ - 0, 103, 103, 110, 114, 115, 120, 123, 124, 127, - 128, 129, 130, 133, 134, 137, 138, 145, 146, 149, - 168, 183, 194, 209, 220, 246, 279, 349, 350, 353, - 354, 355, 358, 362, 368, 369, 382, 400, 401, 402, - 403, 410, 411, 412, 413, 420, 421, 428, 429, 430, - 433, 434, 437, 438, 439, 444, 445, 448, 449, 450, - 455, 456, 457, 462, 463, 467, 468, 474, 478, 484, - 485, 488, 515, 516, 519, 520, 521, 522, 523, 528, - 559, 576, 601, 610, 614, 617, 618, 621, 622, 623, - 624, 634, 643, 649, 664, 672, 681 -}; +/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ +static const yytype_uint16 yyrline[] = { + 0, 103, 103, 110, 114, 115, 120, 123, 124, 127, 128, 129, 130, 133, + 134, 137, 138, 145, 146, 149, 168, 183, 194, 209, 220, 246, 279, 349, + 350, 353, 354, 355, 358, 362, 368, 369, 382, 400, 401, 402, 403, 410, + 411, 412, 413, 420, 421, 428, 429, 430, 433, 434, 437, 438, 439, 444, + 445, 448, 449, 450, 455, 456, 457, 462, 463, 467, 468, 474, 478, 484, + 485, 488, 515, 516, 519, 520, 521, 522, 523, 528, 559, 576, 601, 610, + 614, 617, 618, 621, 622, 623, 624, 634, 643, 649, 664, 672, 681}; #endif #if YYDEBUG || YYERROR_VERBOSE || 1 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "ARRAY", "BOOL", "CONSTRAINT", "FLOAT", - "INT", "MAXIMIZE", "MINIMIZE", "OF", "PREDICATE", "SATISFY", "SET", - "SOLVE", "VAR", "DOTDOT", "COLONCOLON", "IVALUE", "SVALUE", "IDENTIFIER", - "DVALUE", "';'", "'('", "')'", "','", "':'", "'['", "']'", "'='", "'{'", - "'}'", "$accept", "model", "predicates", "predicate", - "predicate_arguments", "predicate_argument", "predicate_array_argument", - "predicate_ints", "variable_or_constant_declarations", - "variable_or_constant_declaration", "optional_var_or_value", - "optional_var_or_value_array", "var_or_value_array", "var_or_value", - "int_domain", "set_domain", "float_domain", "domain", "integers", - "integer", "floats", "float", "const_literal", "const_literals", - "constraints", "constraint", "arguments", "argument", "annotations", - "annotation_arguments", "annotation", "solve", YY_NULLPTR -}; +static const char* const yytname[] = {"$end", + "error", + "$undefined", + "ARRAY", + "BOOL", + "CONSTRAINT", + "FLOAT", + "INT", + "MAXIMIZE", + "MINIMIZE", + "OF", + "PREDICATE", + "SATISFY", + "SET", + "SOLVE", + "VAR", + "DOTDOT", + "COLONCOLON", + "IVALUE", + "SVALUE", + "IDENTIFIER", + "DVALUE", + "';'", + "'('", + "')'", + "','", + "':'", + "'['", + "']'", + "'='", + "'{'", + "'}'", + "$accept", + "model", + "predicates", + "predicate", + "predicate_arguments", + "predicate_argument", + "predicate_array_argument", + "predicate_ints", + "variable_or_constant_declarations", + "variable_or_constant_declaration", + "optional_var_or_value", + "optional_var_or_value_array", + "var_or_value_array", + "var_or_value", + "int_domain", + "set_domain", + "float_domain", + "domain", + "integers", + "integer", + "floats", + "float", + "const_literal", + "const_literals", + "constraints", + "constraint", + "arguments", + "argument", + "annotations", + "annotation_arguments", + "annotation", + "solve", + YY_NULLPTR}; #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 59, 40, 41, 44, 58, 91, 93, 61, - 123, 125 -}; -# endif +static const yytype_uint16 yytoknum[] = { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, + 59, 40, 41, 44, 58, 91, 93, 61, 123, 125}; +#endif #define YYPACT_NINF -182 -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-182))) +#define yypact_value_is_default(Yystate) (!!((Yystate) == (-182))) #define YYTABLE_NINF -19 -#define yytable_value_is_error(Yytable_value) \ - 0 - - /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -static const yytype_int16 yypact[] = -{ - -182, 49, 7, -182, -15, 67, 114, 20, -182, 95, - -182, 99, -182, -182, -182, 136, 76, 122, 141, 11, - 154, -182, -182, -182, 143, 130, 40, 157, 12, 151, - 160, 158, -182, 155, 118, -182, -182, 161, 163, -182, - 162, 164, 165, 76, 156, 166, 159, 171, -182, -182, - 172, 11, 169, -182, -182, 175, 11, -182, -182, 167, - 125, -182, -182, 27, 168, -182, 40, 176, 177, 179, - 120, -182, 170, -182, 22, 80, 80, 80, -182, 121, - 174, 184, 173, -182, 182, -182, -182, 178, -182, -182, - 59, -182, 75, 187, -182, 180, -182, 93, 11, 131, - -182, -182, -182, 188, -182, 96, 121, -182, 198, 190, - 199, -182, 200, 150, -182, 195, 185, -182, 34, -182, - 196, 197, -182, 186, -182, 31, -182, 128, -182, 80, - 201, 121, 202, 84, -182, -182, -182, 56, 60, -182, - 203, 204, -182, 129, -182, 189, 205, 150, -182, -182, - 207, -182, -182, 147, 206, 121, -182, 76, 192, 76, - 209, 210, 211, -182, 212, -182, -182, 213, -182, -182, - -182, -182, 216, 208, 217, 218, 219, 224, -182, -182, - 225, -182, 226, -182, -182, -182, -182, -182, 74, 85, - 87, 91, 220, 221, 222, 223, -182, 97, 75, 64, - 104, -182, 133, -182, 137, 227, -182, -182, 138, -182, - -182, 139, -182, 75, -182, 214, 153, -182, -182, -182, - 228, -182, -182 -}; - - /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - Performed when YYTABLE does not specify something else to do. Zero - means the default is an error. */ -static const yytype_uint8 yydefact[] = -{ - 5, 0, 0, 1, 0, 0, 0, 70, 4, 0, - 3, 0, 37, 45, 38, 0, 0, 0, 0, 0, - 0, 47, 48, 49, 0, 0, 0, 0, 0, 0, - 0, 0, 52, 53, 0, 51, 17, 0, 0, 84, - 0, 0, 0, 0, 0, 8, 0, 0, 41, 42, - 0, 0, 0, 39, 46, 0, 0, 40, 84, 0, - 0, 69, 2, 0, 0, 6, 0, 0, 0, 0, - 0, 84, 0, 50, 0, 0, 0, 0, 94, 0, - 16, 0, 0, 13, 0, 7, 9, 0, 43, 44, - 28, 54, 0, 74, 76, 79, 75, 0, 0, 0, - 73, 96, 95, 88, 89, 90, 0, 83, 0, 0, - 0, 10, 0, 0, 25, 60, 65, 64, 0, 19, - 0, 0, 34, 35, 82, 0, 33, 0, 84, 0, - 0, 0, 0, 0, 86, 15, 14, 0, 0, 27, - 0, 0, 63, 0, 77, 0, 0, 0, 81, 78, - 71, 72, 87, 0, 0, 0, 93, 0, 0, 0, - 0, 0, 0, 61, 0, 62, 80, 0, 32, 91, - 92, 85, 0, 0, 0, 0, 0, 0, 66, 36, - 0, 11, 0, 84, 84, 84, 12, 84, 0, 0, - 0, 31, 0, 0, 0, 0, 26, 0, 0, 0, - 0, 21, 0, 68, 0, 58, 57, 23, 0, 56, - 30, 0, 20, 0, 24, 0, 0, 22, 29, 67, - 0, 55, 59 -}; - - /* YYPGOTO[NTERM-NUM]. */ -static const yytype_int16 yypgoto[] = -{ - -182, -182, -182, -182, 191, -182, -182, 108, -182, -182, - -182, -182, 25, -107, 88, 89, 92, -7, -50, 215, - -182, 13, -181, -182, -182, -182, -182, -72, -56, 100, - -76, -182 -}; - - /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = -{ - -1, 1, 2, 6, 44, 45, 82, 83, 7, 20, - 114, 196, 125, 126, 21, 22, 23, 46, 34, 35, - 208, 209, 119, 204, 25, 40, 99, 100, 60, 133, - 134, 41 -}; - - /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule whose - number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int16 yytable[] = -{ - 24, 70, 74, 107, 101, 102, 139, 8, 4, 29, - -18, -18, -18, -18, -18, 90, 48, 203, 5, 49, - -18, -18, -18, 11, 12, -18, 13, 14, -18, 32, - 50, 33, 219, 15, 80, 16, 64, -18, 17, 79, - 168, 18, 51, 42, 12, 81, 13, 14, 127, 3, - 19, 92, 32, 15, 33, 43, 147, 151, 17, 148, - 12, 18, 13, 14, 12, 142, 13, 14, 143, 15, - 19, 157, 150, 15, 17, 159, 79, 18, 17, 171, - 12, 18, 13, 14, 205, 206, 19, 9, 113, 15, - 19, 79, 207, 115, 17, 116, 117, 18, 93, 94, - 95, 96, 79, 192, 79, 118, 19, 97, 79, 155, - 98, 122, 156, 123, 193, 32, 194, 33, 26, 131, - 195, 124, 122, 132, 123, 201, 27, 188, 189, 190, - 158, 191, 210, 76, 77, 38, 10, 78, 30, 103, - 104, 105, 79, 56, 39, 56, 28, 202, 106, 57, - 172, 89, 174, 56, 56, 128, 129, 31, 56, 149, - 165, 212, 213, 216, 147, 214, 217, 218, 122, 37, - 123, 169, 155, 205, 206, 47, 36, 52, 53, 54, - 65, 58, 55, 59, 61, 67, 62, 68, 69, 71, - 75, 66, 63, 72, 84, 87, 86, 88, 91, 108, - 109, 110, 111, 120, 130, 80, 112, 121, 136, 137, - 138, 140, 141, 146, 144, 145, 135, 166, 173, 152, - 154, 163, 164, 167, 79, 211, 160, 161, 181, 221, - 162, 153, 220, 0, 170, 175, 176, 177, 183, 184, - 178, 179, 180, 182, 185, 186, 187, 197, 198, 199, - 200, 0, 0, 0, 215, 0, 222, 85, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 73 -}; - -static const yytype_int16 yycheck[] = -{ - 7, 51, 58, 79, 76, 77, 113, 22, 1, 16, - 3, 4, 5, 6, 7, 71, 4, 198, 11, 7, - 13, 14, 15, 3, 4, 18, 6, 7, 21, 18, - 18, 20, 213, 13, 7, 15, 43, 30, 18, 17, - 147, 21, 30, 3, 4, 18, 6, 7, 98, 0, - 30, 29, 18, 13, 20, 15, 25, 129, 18, 28, - 4, 21, 6, 7, 4, 31, 6, 7, 118, 13, - 30, 15, 128, 13, 18, 15, 17, 21, 18, 155, - 4, 21, 6, 7, 20, 21, 30, 20, 29, 13, - 30, 17, 28, 18, 18, 20, 21, 21, 18, 19, - 20, 21, 17, 29, 17, 30, 30, 27, 17, 25, - 30, 18, 28, 20, 29, 18, 29, 20, 23, 23, - 29, 28, 18, 27, 20, 28, 27, 183, 184, 185, - 137, 187, 28, 8, 9, 5, 22, 12, 16, 18, - 19, 20, 17, 25, 14, 25, 10, 197, 27, 31, - 157, 31, 159, 25, 25, 24, 25, 16, 25, 31, - 31, 28, 25, 25, 25, 28, 28, 28, 18, 26, - 20, 24, 25, 20, 21, 18, 22, 26, 18, 21, - 24, 20, 27, 20, 22, 26, 22, 16, 16, 20, - 23, 25, 27, 18, 26, 18, 20, 18, 28, 25, - 16, 28, 20, 16, 16, 7, 28, 27, 18, 10, - 10, 16, 27, 27, 18, 18, 108, 28, 26, 18, - 18, 18, 18, 18, 17, 200, 138, 138, 20, 216, - 138, 131, 18, -1, 28, 26, 26, 26, 20, 20, - 28, 28, 26, 26, 20, 20, 20, 27, 27, 27, - 27, -1, -1, -1, 27, -1, 28, 66, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 56 -}; - - /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = -{ - 0, 33, 34, 0, 1, 11, 35, 40, 22, 20, - 22, 3, 4, 6, 7, 13, 15, 18, 21, 30, - 41, 46, 47, 48, 49, 56, 23, 27, 10, 49, - 16, 16, 18, 20, 50, 51, 22, 26, 5, 14, - 57, 63, 3, 15, 36, 37, 49, 18, 4, 7, - 18, 30, 26, 18, 21, 27, 25, 31, 20, 20, - 60, 22, 22, 27, 49, 24, 25, 26, 16, 16, - 50, 20, 18, 51, 60, 23, 8, 9, 12, 17, - 7, 18, 38, 39, 26, 36, 20, 18, 18, 31, - 60, 28, 29, 18, 19, 20, 21, 27, 30, 58, - 59, 59, 59, 18, 19, 20, 27, 62, 25, 16, - 28, 20, 28, 29, 42, 18, 20, 21, 30, 54, - 16, 27, 18, 20, 28, 44, 45, 50, 24, 25, - 16, 23, 27, 61, 62, 39, 18, 10, 10, 45, - 16, 27, 31, 50, 18, 18, 27, 25, 28, 31, - 60, 59, 18, 61, 18, 25, 28, 15, 49, 15, - 46, 47, 48, 18, 18, 31, 28, 18, 45, 24, - 28, 62, 49, 26, 49, 26, 26, 26, 28, 28, - 26, 20, 26, 20, 20, 20, 20, 20, 60, 60, - 60, 60, 29, 29, 29, 29, 43, 27, 27, 27, - 27, 28, 50, 54, 55, 20, 21, 28, 52, 53, - 28, 44, 28, 25, 28, 27, 25, 28, 28, 54, - 18, 53, 28 -}; - - /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = -{ - 0, 32, 33, 34, 34, 34, 35, 36, 36, 37, - 37, 37, 37, 38, 38, 39, 39, 40, 40, 41, - 41, 41, 41, 41, 41, 41, 41, 42, 42, 43, - 43, 43, 44, 44, 45, 45, 45, 46, 46, 46, - 46, 47, 47, 47, 47, 48, 48, 49, 49, 49, - 50, 50, 51, 51, 51, 52, 52, 53, 53, 53, - 54, 54, 54, 54, 54, 54, 54, 55, 55, 56, - 56, 57, 58, 58, 59, 59, 59, 59, 59, 59, - 59, 59, 59, 60, 60, 61, 61, 62, 62, 62, - 62, 62, 62, 62, 63, 63, 63 -}; - - /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = -{ - 0, 2, 5, 3, 3, 0, 5, 3, 1, 3, - 4, 8, 9, 1, 3, 3, 1, 3, 0, 6, - 15, 14, 15, 14, 15, 6, 13, 2, 0, 4, - 3, 0, 3, 1, 1, 1, 4, 1, 1, 3, - 3, 3, 3, 5, 5, 1, 3, 1, 1, 1, - 3, 1, 1, 1, 4, 3, 1, 1, 1, 4, - 1, 3, 3, 2, 1, 1, 4, 3, 1, 3, - 0, 6, 3, 1, 1, 1, 1, 3, 3, 1, - 4, 3, 2, 3, 0, 3, 1, 3, 1, 1, - 1, 4, 4, 3, 3, 4, 4 -}; - - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab - - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (context, model, ok, scanner, YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) +#define yytable_value_is_error(Yytable_value) 0 + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const yytype_int16 yypact[] = { + -182, 49, 7, -182, -15, 67, 114, 20, -182, 95, -182, 99, + -182, -182, -182, 136, 76, 122, 141, 11, 154, -182, -182, -182, + 143, 130, 40, 157, 12, 151, 160, 158, -182, 155, 118, -182, + -182, 161, 163, -182, 162, 164, 165, 76, 156, 166, 159, 171, + -182, -182, 172, 11, 169, -182, -182, 175, 11, -182, -182, 167, + 125, -182, -182, 27, 168, -182, 40, 176, 177, 179, 120, -182, + 170, -182, 22, 80, 80, 80, -182, 121, 174, 184, 173, -182, + 182, -182, -182, 178, -182, -182, 59, -182, 75, 187, -182, 180, + -182, 93, 11, 131, -182, -182, -182, 188, -182, 96, 121, -182, + 198, 190, 199, -182, 200, 150, -182, 195, 185, -182, 34, -182, + 196, 197, -182, 186, -182, 31, -182, 128, -182, 80, 201, 121, + 202, 84, -182, -182, -182, 56, 60, -182, 203, 204, -182, 129, + -182, 189, 205, 150, -182, -182, 207, -182, -182, 147, 206, 121, + -182, 76, 192, 76, 209, 210, 211, -182, 212, -182, -182, 213, + -182, -182, -182, -182, 216, 208, 217, 218, 219, 224, -182, -182, + 225, -182, 226, -182, -182, -182, -182, -182, 74, 85, 87, 91, + 220, 221, 222, 223, -182, 97, 75, 64, 104, -182, 133, -182, + 137, 227, -182, -182, 138, -182, -182, 139, -182, 75, -182, 214, + 153, -182, -182, -182, 228, -182, -182}; + +/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE does not specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = { + 5, 0, 0, 1, 0, 0, 0, 70, 4, 0, 3, 0, 37, 45, 38, 0, 0, 0, 0, + 0, 0, 47, 48, 49, 0, 0, 0, 0, 0, 0, 0, 0, 52, 53, 0, 51, 17, 0, + 0, 84, 0, 0, 0, 0, 0, 8, 0, 0, 41, 42, 0, 0, 0, 39, 46, 0, 0, + 40, 84, 0, 0, 69, 2, 0, 0, 6, 0, 0, 0, 0, 0, 84, 0, 50, 0, 0, + 0, 0, 94, 0, 16, 0, 0, 13, 0, 7, 9, 0, 43, 44, 28, 54, 0, 74, 76, + 79, 75, 0, 0, 0, 73, 96, 95, 88, 89, 90, 0, 83, 0, 0, 0, 10, 0, 0, + 25, 60, 65, 64, 0, 19, 0, 0, 34, 35, 82, 0, 33, 0, 84, 0, 0, 0, 0, + 0, 86, 15, 14, 0, 0, 27, 0, 0, 63, 0, 77, 0, 0, 0, 81, 78, 71, 72, + 87, 0, 0, 0, 93, 0, 0, 0, 0, 0, 0, 61, 0, 62, 80, 0, 32, 91, 92, + 85, 0, 0, 0, 0, 0, 0, 66, 36, 0, 11, 0, 84, 84, 84, 12, 84, 0, 0, + 0, 31, 0, 0, 0, 0, 26, 0, 0, 0, 0, 21, 0, 68, 0, 58, 57, 23, 0, + 56, 30, 0, 20, 0, 24, 0, 0, 22, 29, 67, 0, 55, 59}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int16 yypgoto[] = { + -182, -182, -182, -182, 191, -182, -182, 108, -182, -182, -182, + -182, 25, -107, 88, 89, 92, -7, -50, 215, -182, 13, + -181, -182, -182, -182, -182, -72, -56, 100, -76, -182}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int16 yydefgoto[] = { + -1, 1, 2, 6, 44, 45, 82, 83, 7, 20, 114, 196, 125, 126, 21, 22, + 23, 46, 34, 35, 208, 209, 119, 204, 25, 40, 99, 100, 60, 133, 134, 41}; + +/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule whose + number is the opposite. If YYTABLE_NINF, syntax error. */ +static const yytype_int16 yytable[] = { + 24, 70, 74, 107, 101, 102, 139, 8, 4, 29, -18, -18, -18, -18, -18, + 90, 48, 203, 5, 49, -18, -18, -18, 11, 12, -18, 13, 14, -18, 32, + 50, 33, 219, 15, 80, 16, 64, -18, 17, 79, 168, 18, 51, 42, 12, + 81, 13, 14, 127, 3, 19, 92, 32, 15, 33, 43, 147, 151, 17, 148, + 12, 18, 13, 14, 12, 142, 13, 14, 143, 15, 19, 157, 150, 15, 17, + 159, 79, 18, 17, 171, 12, 18, 13, 14, 205, 206, 19, 9, 113, 15, + 19, 79, 207, 115, 17, 116, 117, 18, 93, 94, 95, 96, 79, 192, 79, + 118, 19, 97, 79, 155, 98, 122, 156, 123, 193, 32, 194, 33, 26, 131, + 195, 124, 122, 132, 123, 201, 27, 188, 189, 190, 158, 191, 210, 76, 77, + 38, 10, 78, 30, 103, 104, 105, 79, 56, 39, 56, 28, 202, 106, 57, + 172, 89, 174, 56, 56, 128, 129, 31, 56, 149, 165, 212, 213, 216, 147, + 214, 217, 218, 122, 37, 123, 169, 155, 205, 206, 47, 36, 52, 53, 54, + 65, 58, 55, 59, 61, 67, 62, 68, 69, 71, 75, 66, 63, 72, 84, + 87, 86, 88, 91, 108, 109, 110, 111, 120, 130, 80, 112, 121, 136, 137, + 138, 140, 141, 146, 144, 145, 135, 166, 173, 152, 154, 163, 164, 167, 79, + 211, 160, 161, 181, 221, 162, 153, 220, 0, 170, 175, 176, 177, 183, 184, + 178, 179, 180, 182, 185, 186, 187, 197, 198, 199, 200, 0, 0, 0, 215, + 0, 222, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 73}; + +static const yytype_int16 yycheck[] = { + 7, 51, 58, 79, 76, 77, 113, 22, 1, 16, 3, 4, 5, 6, 7, 71, + 4, 198, 11, 7, 13, 14, 15, 3, 4, 18, 6, 7, 21, 18, 18, 20, + 213, 13, 7, 15, 43, 30, 18, 17, 147, 21, 30, 3, 4, 18, 6, 7, + 98, 0, 30, 29, 18, 13, 20, 15, 25, 129, 18, 28, 4, 21, 6, 7, + 4, 31, 6, 7, 118, 13, 30, 15, 128, 13, 18, 15, 17, 21, 18, 155, + 4, 21, 6, 7, 20, 21, 30, 20, 29, 13, 30, 17, 28, 18, 18, 20, + 21, 21, 18, 19, 20, 21, 17, 29, 17, 30, 30, 27, 17, 25, 30, 18, + 28, 20, 29, 18, 29, 20, 23, 23, 29, 28, 18, 27, 20, 28, 27, 183, + 184, 185, 137, 187, 28, 8, 9, 5, 22, 12, 16, 18, 19, 20, 17, 25, + 14, 25, 10, 197, 27, 31, 157, 31, 159, 25, 25, 24, 25, 16, 25, 31, + 31, 28, 25, 25, 25, 28, 28, 28, 18, 26, 20, 24, 25, 20, 21, 18, + 22, 26, 18, 21, 24, 20, 27, 20, 22, 26, 22, 16, 16, 20, 23, 25, + 27, 18, 26, 18, 20, 18, 28, 25, 16, 28, 20, 16, 16, 7, 28, 27, + 18, 10, 10, 16, 27, 27, 18, 18, 108, 28, 26, 18, 18, 18, 18, 18, + 17, 200, 138, 138, 20, 216, 138, 131, 18, -1, 28, 26, 26, 26, 20, 20, + 28, 28, 26, 26, 20, 20, 20, 27, 27, 27, 27, -1, -1, -1, 27, -1, + 28, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = { + 0, 33, 34, 0, 1, 11, 35, 40, 22, 20, 22, 3, 4, 6, 7, 13, 15, 18, 21, + 30, 41, 46, 47, 48, 49, 56, 23, 27, 10, 49, 16, 16, 18, 20, 50, 51, 22, 26, + 5, 14, 57, 63, 3, 15, 36, 37, 49, 18, 4, 7, 18, 30, 26, 18, 21, 27, 25, + 31, 20, 20, 60, 22, 22, 27, 49, 24, 25, 26, 16, 16, 50, 20, 18, 51, 60, 23, + 8, 9, 12, 17, 7, 18, 38, 39, 26, 36, 20, 18, 18, 31, 60, 28, 29, 18, 19, + 20, 21, 27, 30, 58, 59, 59, 59, 18, 19, 20, 27, 62, 25, 16, 28, 20, 28, 29, + 42, 18, 20, 21, 30, 54, 16, 27, 18, 20, 28, 44, 45, 50, 24, 25, 16, 23, 27, + 61, 62, 39, 18, 10, 10, 45, 16, 27, 31, 50, 18, 18, 27, 25, 28, 31, 60, 59, + 18, 61, 18, 25, 28, 15, 49, 15, 46, 47, 48, 18, 18, 31, 28, 18, 45, 24, 28, + 62, 49, 26, 49, 26, 26, 26, 28, 28, 26, 20, 26, 20, 20, 20, 20, 20, 60, 60, + 60, 60, 29, 29, 29, 29, 43, 27, 27, 27, 27, 28, 50, 54, 55, 20, 21, 28, 52, + 53, 28, 44, 28, 25, 28, 27, 25, 28, 28, 54, 18, 53, 28}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = { + 0, 32, 33, 34, 34, 34, 35, 36, 36, 37, 37, 37, 37, 38, 38, 39, 39, + 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 42, 42, 43, 43, 43, 44, 44, + 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 48, 48, 49, 49, 49, 50, + 50, 51, 51, 51, 52, 52, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 55, + 55, 56, 56, 57, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 60, 60, + 61, 61, 62, 62, 62, 62, 62, 62, 62, 63, 63, 63}; + +/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = { + 0, 2, 5, 3, 3, 0, 5, 3, 1, 3, 4, 8, 9, 1, 3, 3, 1, 3, 0, 6, + 15, 14, 15, 14, 15, 6, 13, 2, 0, 4, 3, 0, 3, 1, 1, 1, 4, 1, 1, 3, + 3, 3, 3, 5, 5, 1, 3, 1, 1, 1, 3, 1, 1, 1, 4, 3, 1, 1, 1, 4, + 1, 3, 3, 2, 1, 1, 4, 3, 1, 3, 0, 6, 3, 1, 1, 1, 1, 3, 3, 1, + 4, 3, 2, 3, 0, 3, 1, 3, 1, 1, 1, 4, 4, 3, 3, 4, 4}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK(yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } else { \ + yyerror(context, model, ok, scanner, \ + YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - - +#define YYTERROR 1 +#define YYERRCODE 256 /* Enable debugging if requested. */ #if YYDEBUG -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif +#ifndef YYFPRINTF +#include /* INFRINGES ON USER NAME SPACE */ +#define YYFPRINTF fprintf +#endif -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) +#define YYDPRINTF(Args) \ + do { \ + if (yydebug) YYFPRINTF Args; \ + } while (0) /* This macro is provided for backward compatibility. */ #ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#define YY_LOCATION_PRINT(File, Loc) ((void)0) #endif - -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yy_symbol_print (stderr, \ - Type, Value, context, model, ok, scanner); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ + do { \ + if (yydebug) { \ + YYFPRINTF(stderr, "%s ", Title); \ + yy_symbol_print(stderr, Type, Value, context, model, ok, scanner); \ + YYFPRINTF(stderr, "\n"); \ + } \ + } while (0) /*----------------------------------------. | Print this symbol's value on YYOUTPUT. | `----------------------------------------*/ -static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner) -{ - FILE *yyo = yyoutput; - YYUSE (yyo); - YYUSE (context); - YYUSE (model); - YYUSE (ok); - YYUSE (scanner); - if (!yyvaluep) - return; -# ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - YYUSE (yytype); +static void yy_symbol_value_print( + FILE* yyoutput, int yytype, YYSTYPE const* const yyvaluep, + operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, void* scanner) { + FILE* yyo = yyoutput; + YYUSE(yyo); + YYUSE(context); + YYUSE(model); + YYUSE(ok); + YYUSE(scanner); + if (!yyvaluep) return; +#ifdef YYPRINT + if (yytype < YYNTOKENS) YYPRINT(yyoutput, yytoknum[yytype], *yyvaluep); +#endif + YYUSE(yytype); } - /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ -static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner) -{ - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - - yy_symbol_value_print (yyoutput, yytype, yyvaluep, context, model, ok, scanner); - YYFPRINTF (yyoutput, ")"); +static void yy_symbol_print(FILE* yyoutput, int yytype, + YYSTYPE const* const yyvaluep, + operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, + void* scanner) { + YYFPRINTF(yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", + yytname[yytype]); + + yy_symbol_value_print(yyoutput, yytype, yyvaluep, context, model, ok, + scanner); + YYFPRINTF(yyoutput, ")"); } /*------------------------------------------------------------------. @@ -854,69 +780,62 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, ope | TOP (included). | `------------------------------------------------------------------*/ -static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) -{ - YYFPRINTF (stderr, "Stack now"); - for (; yybottom <= yytop; yybottom++) - { - int yybot = *yybottom; - YYFPRINTF (stderr, " %d", yybot); - } - YYFPRINTF (stderr, "\n"); +static void yy_stack_print(yytype_int16* yybottom, yytype_int16* yytop) { + YYFPRINTF(stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) { + int yybot = *yybottom; + YYFPRINTF(stderr, " %d", yybot); + } + YYFPRINTF(stderr, "\n"); } -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - +#define YY_STACK_PRINT(Bottom, Top) \ + do { \ + if (yydebug) yy_stack_print((Bottom), (Top)); \ + } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule, operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner) -{ +static void yy_reduce_print(yytype_int16* yyssp, YYSTYPE* yyvsp, int yyrule, + operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, + void* scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, + yylno); /* The symbols being reduced. */ - for (yyi = 0; yyi < yynrhs; yyi++) - { - YYFPRINTF (stderr, " $%d = ", yyi + 1); - yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , context, model, ok, scanner); - YYFPRINTF (stderr, "\n"); - } + for (yyi = 0; yyi < yynrhs; yyi++) { + YYFPRINTF(stderr, " $%d = ", yyi + 1); + yy_symbol_print(stderr, yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]), context, model, ok, + scanner); + YYFPRINTF(stderr, "\n"); + } } -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, Rule, context, model, ok, scanner); \ -} while (0) +#define YY_REDUCE_PRINT(Rule) \ + do { \ + if (yydebug) \ + yy_reduce_print(yyssp, yyvsp, Rule, context, model, ok, scanner); \ + } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) +#define YYDPRINTF(Args) +#define YY_SYMBOL_PRINT(Title, Type, Value, Location) +#define YY_STACK_PRINT(Bottom, Top) +#define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ - /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH -# define YYINITDEPTH 200 +#define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only @@ -927,49 +846,42 @@ int yydebug; evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 +#define YYMAXDEPTH 10000 #endif - #if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else +#ifndef yystrlen +#if defined __GLIBC__ && defined _STRING_H +#define yystrlen strlen +#else /* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) -{ +static YYSIZE_T yystrlen(const char* yystr) { YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; + for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } -# endif -# endif +#endif +#endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else +#ifndef yystpcpy +#if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +#define yystpcpy stpcpy +#else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; +static char* yystpcpy(char* yydest, const char* yysrc) { + char* yyd = yydest; + const char* yys = yysrc; - while ((*yyd++ = *yys++) != '\0') - continue; + while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } -# endif -# endif +#endif +#endif -# ifndef yytnamerr +#ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string @@ -977,45 +889,36 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } +static YYSIZE_T yytnamerr(char* yyres, const char* yystr) { + if (*yystr == '"') { + YYSIZE_T yyn = 0; + char const* yyp = yystr; + + for (;;) switch (*++yyp) { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes:; + } - if (! yyres) - return yystrlen (yystr); + if (!yyres) return yystrlen(yystr); - return yystpcpy (yyres, yystr) - yyres; + return yystpcpy(yyres, yystr) - yyres; } -# endif +#endif /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message about the unexpected token YYTOKEN for the state stack whose top is @@ -1025,17 +928,15 @@ yytnamerr (char *yyres, const char *yystr) not large enough to hold the message. In that case, also set *YYMSG_ALLOC to the required number of bytes. Return 2 if the required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); +static int yysyntax_error(YYSIZE_T* yymsg_alloc, char** yymsg, + yytype_int16* yyssp, int yytoken) { + YYSIZE_T yysize0 = yytnamerr(YY_NULLPTR, yytname[yytoken]); YYSIZE_T yysize = yysize0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; + const char* yyformat = YY_NULLPTR; /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + char const* yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per "expected"). */ int yycount = 0; @@ -1063,91 +964,80 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, one exception: it will still contain any token that will not be accepted due to an error action in a later state. */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } + if (yytoken != YYEMPTY) { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default(yyn)) { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR && + !yytable_value_is_error(yytable[yyx + yyn])) { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr(YY_NULLPTR, yytname[yyx]); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } } } + } - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } + switch (yycount) { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, + YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; + YYSIZE_T yysize1 = yysize + yystrlen(yyformat); + if (!(yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; yysize = yysize1; } - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } + if (*yymsg_alloc < yysize) { + *yymsg_alloc = 2 * yysize; + if (!(yysize <= *yymsg_alloc && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ { - char *yyp = *yymsg; + char* yyp = *yymsg; int yyi = 0; while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) { + yyp += yytnamerr(yyp, yyarg[yyi++]); + yyformat += 2; + } else { + yyp++; + yyformat++; + } } return 0; } @@ -1157,68 +1047,63 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, | Release the memory associated to this symbol. | `-----------------------------------------------*/ -static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner) -{ - YYUSE (yyvaluep); - YYUSE (context); - YYUSE (model); - YYUSE (ok); - YYUSE (scanner); - if (!yymsg) - yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); +static void yydestruct(const char* yymsg, int yytype, YYSTYPE* yyvaluep, + operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, + void* scanner) { + YYUSE(yyvaluep); + YYUSE(context); + YYUSE(model); + YYUSE(ok); + YYUSE(scanner); + if (!yymsg) yymsg = "Deleting"; + YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + YYUSE(yytype); YY_IGNORE_MAYBE_UNINITIALIZED_END } - - - /*----------. | yyparse. | `----------*/ -int -yyparse (operations_research::fz::ParserContext* context, operations_research::fz::Model* model, bool* ok, void* scanner) -{ -/* The lookahead symbol. */ -int yychar; +int yyparse(operations_research::fz::ParserContext* context, + operations_research::fz::Model* model, bool* ok, void* scanner) { + /* The lookahead symbol. */ + int yychar; + /* The semantic value of the lookahead symbol. */ + /* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ + YY_INITIAL_VALUE(static YYSTYPE yyval_default;) + YYSTYPE yylval YY_INITIAL_VALUE(= yyval_default); -/* The semantic value of the lookahead symbol. */ -/* Default value used for initialization, for pacifying older GCCs - or non-GCC compilers. */ -YY_INITIAL_VALUE (static YYSTYPE yyval_default;) -YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); + /* Number of syntax errors so far. */ + int yynerrs; - /* Number of syntax errors so far. */ - int yynerrs; + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; - int yystate; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16* yyss; + yytype_int16* yyssp; - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE* yyvs; + YYSTYPE* yyvsp; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; - - YYSIZE_T yystacksize; + YYSIZE_T yystacksize; int yyn; int yyresult; @@ -1231,11 +1116,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; - char *yymsg = yymsgbuf; + char* yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif -#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ @@ -1245,7 +1130,7 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yyvsp = yyvs = yyvsa; yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); + YYDPRINTF((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; @@ -1253,82 +1138,73 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: + /*------------------------------------------------------------. + | yynewstate -- Push a new state, which is found in yystate. | + `------------------------------------------------------------*/ +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: +yysetstate: *yyssp = yystate; - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + if (yyss + yystacksize - 1 <= yyssp) { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE* yyvs1 = yyvs; + yytype_int16* yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow(YY_("memory exhausted"), &yyss1, yysize * sizeof(*yyssp), + &yyvs1, yysize * sizeof(*yyvsp), &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } #else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif +#ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +#else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; + + { + yytype_int16* yyss1 = yyss; + union yyalloc* yyptr = + (union yyalloc*)YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize)); + if (!yyptr) goto yyexhaustedlab; + YYSTACK_RELOCATE(yyss_alloc, yyss); + YYSTACK_RELOCATE(yyvs_alloc, yyvs); +#undef YYSTACK_RELOCATE + if (yyss1 != yyssa) YYSTACK_FREE(yyss1); + } +#endif #endif /* no yyoverflow */ - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YYDPRINTF((stderr, "Stack size increased to %lu\n", + (unsigned long int)yystacksize)); - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } + if (yyss + yystacksize - 1 <= yyssp) YYABORT; + } - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YYDPRINTF((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) - YYACCEPT; + if (yystate == YYFINAL) YYACCEPT; goto yybackup; @@ -1342,50 +1218,41 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; - if (yypact_value_is_default (yyn)) - goto yydefault; + if (yypact_value_is_default(yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, scanner); - } + if (yychar == YYEMPTY) { + YYDPRINTF((stderr, "Reading a token: ")); + yychar = yylex(&yylval, scanner); + } - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } + if (yychar <= YYEOF) { + yychar = yytoken = YYEOF; + YYDPRINTF((stderr, "Now at end of input.\n")); + } else { + yytoken = YYTRANSLATE(yychar); + YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc); + } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yytable_value_is_error (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } + if (yyn <= 0) { + if (yytable_value_is_error(yyn)) goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } /* Count tokens shifted since error; after three, turn off error status. */ - if (yyerrstatus) - yyerrstatus--; + if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ - YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; @@ -1397,17 +1264,14 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); goto yynewstate; - /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; + if (yyn == 0) goto yyerrlab; goto yyreduce; - /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ @@ -1423,880 +1287,1013 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - + yyval = yyvsp[1 - yylen]; - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 4: + YY_REDUCE_PRINT(yyn); + switch (yyn) { + case 4: #line 114 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { yyerrok; } + { + yyerrok; + } #line 1423 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 19: + case 19: #line 149 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // Declaration of a (named) constant: we simply register it in the - // parser's context, and don't store it in the model. - const Domain& domain = (yyvsp[-5].domain); - const std::string& identifier = (yyvsp[-3].string_value); - const Domain& assignment = (yyvsp[0].domain); - std::vector* const annotations = (yyvsp[-2].annotations); - - - if (!assignment.HasOneValue()) { - // TODO(lperron): Check that the assignment is included in the domain. - context->domain_map[identifier] = assignment; - } else { - const int64 value = assignment.values.front(); - CHECK(domain.Contains(value)); - context->integer_map[identifier] = value; - } - delete annotations; -} + // Declaration of a (named) constant: we simply register it in the + // parser's context, and don't store it in the model. + const Domain& domain = (yyvsp[-5].domain); + const std::string& identifier = (yyvsp[-3].string_value); + const Domain& assignment = (yyvsp[0].domain); + std::vector* const annotations = (yyvsp[-2].annotations); + + if (!assignment.HasOneValue()) { + // TODO(lperron): Check that the assignment is included in the domain. + context->domain_map[identifier] = assignment; + } else { + const int64 value = assignment.values.front(); + CHECK(domain.Contains(value)); + context->integer_map[identifier] = value; + } + delete annotations; + } #line 1447 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 20: + case 20: #line 169 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-4].annotations); - // Declaration of a (named) constant array. See rule right above. - CHECK_EQ((yyvsp[-12].integer_value), 1) << "Only [1..n] array are supported here."; - const int64 num_constants = (yyvsp[-10].integer_value); - const std::string& identifier = (yyvsp[-5].string_value); - const std::vector* const assignments = (yyvsp[-1].integers); - CHECK(assignments != nullptr); - CHECK_EQ(num_constants, assignments->size()); - // TODO(lperron): CHECK all values within domain. - context->integer_array_map[identifier] = *assignments; - delete assignments; - delete annotations; -} + std::vector* const annotations = (yyvsp[-4].annotations); + // Declaration of a (named) constant array. See rule right above. + CHECK_EQ((yyvsp[-12].integer_value), 1) + << "Only [1..n] array are supported here."; + const int64 num_constants = (yyvsp[-10].integer_value); + const std::string& identifier = (yyvsp[-5].string_value); + const std::vector* const assignments = (yyvsp[-1].integers); + CHECK(assignments != nullptr); + CHECK_EQ(num_constants, assignments->size()); + // TODO(lperron): CHECK all values within domain. + context->integer_array_map[identifier] = *assignments; + delete assignments; + delete annotations; + } #line 1466 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 21: + case 21: #line 184 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-3].annotations); - // Declaration of a (named) constant array. See rule right above. - CHECK_EQ((yyvsp[-11].integer_value), 1) << "Only [1..n] array are supported here."; - const int64 num_constants = (yyvsp[-9].integer_value); - CHECK_EQ(num_constants, 0) << "Empty arrays should have a size of 0"; - const std::string& identifier = (yyvsp[-4].string_value); - context->integer_array_map[identifier] = std::vector(); - delete annotations; -} + std::vector* const annotations = (yyvsp[-3].annotations); + // Declaration of a (named) constant array. See rule right above. + CHECK_EQ((yyvsp[-11].integer_value), 1) + << "Only [1..n] array are supported here."; + const int64 num_constants = (yyvsp[-9].integer_value); + CHECK_EQ(num_constants, 0) << "Empty arrays should have a size of 0"; + const std::string& identifier = (yyvsp[-4].string_value); + context->integer_array_map[identifier] = std::vector(); + delete annotations; + } #line 1481 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 22: + case 22: #line 195 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-4].annotations); - // Declaration of a (named) constant array. See rule right above. - CHECK_EQ((yyvsp[-12].integer_value), 1) << "Only [1..n] array are supported here."; - const int64 num_constants = (yyvsp[-10].integer_value); - const std::string& identifier = (yyvsp[-5].string_value); - const std::vector* const assignments = (yyvsp[-1].doubles); - CHECK(assignments != nullptr); - CHECK_EQ(num_constants, assignments->size()); - // TODO(lperron): CHECK all values within domain. - context->float_array_map[identifier] = *assignments; - delete assignments; - delete annotations; -} + std::vector* const annotations = (yyvsp[-4].annotations); + // Declaration of a (named) constant array. See rule right above. + CHECK_EQ((yyvsp[-12].integer_value), 1) + << "Only [1..n] array are supported here."; + const int64 num_constants = (yyvsp[-10].integer_value); + const std::string& identifier = (yyvsp[-5].string_value); + const std::vector* const assignments = (yyvsp[-1].doubles); + CHECK(assignments != nullptr); + CHECK_EQ(num_constants, assignments->size()); + // TODO(lperron): CHECK all values within domain. + context->float_array_map[identifier] = *assignments; + delete assignments; + delete annotations; + } #line 1500 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 23: + case 23: #line 210 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-3].annotations); - // Declaration of a (named) constant array. See rule right above. - CHECK_EQ((yyvsp[-11].integer_value), 1) << "Only [1..n] array are supported here."; - const int64 num_constants = (yyvsp[-9].integer_value); - CHECK_EQ(num_constants, 0) << "Empty arrays should have a size of 0"; - const std::string& identifier = (yyvsp[-4].string_value); - context->float_array_map[identifier] = std::vector(); - delete annotations; -} + std::vector* const annotations = (yyvsp[-3].annotations); + // Declaration of a (named) constant array. See rule right above. + CHECK_EQ((yyvsp[-11].integer_value), 1) + << "Only [1..n] array are supported here."; + const int64 num_constants = (yyvsp[-9].integer_value); + CHECK_EQ(num_constants, 0) << "Empty arrays should have a size of 0"; + const std::string& identifier = (yyvsp[-4].string_value); + context->float_array_map[identifier] = std::vector(); + delete annotations; + } #line 1515 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 24: + case 24: #line 221 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // Declaration of a (named) constant array: See rule above. - CHECK_EQ((yyvsp[-12].integer_value), 1) << "Only [1..n] array are supported here."; - const int64 num_constants = (yyvsp[-10].integer_value); - const Domain& domain = (yyvsp[-7].domain); - const std::string& identifier = (yyvsp[-5].string_value); - const std::vector* const assignments = (yyvsp[-1].domains); - const std::vector* const annotations = (yyvsp[-4].annotations); - CHECK(assignments != nullptr); - CHECK_EQ(num_constants, assignments->size()); - - if (!AllDomainsHaveOneValue(*assignments)) { - context->domain_array_map[identifier] = *assignments; - // TODO(lperron): check that all assignments are included in the domain. - } else { - std::vector values(num_constants); - for (int i = 0; i < num_constants; ++i) { - values[i] = (*assignments)[i].values.front(); - CHECK(domain.Contains(values[i])); + // Declaration of a (named) constant array: See rule above. + CHECK_EQ((yyvsp[-12].integer_value), 1) + << "Only [1..n] array are supported here."; + const int64 num_constants = (yyvsp[-10].integer_value); + const Domain& domain = (yyvsp[-7].domain); + const std::string& identifier = (yyvsp[-5].string_value); + const std::vector* const assignments = (yyvsp[-1].domains); + const std::vector* const annotations = + (yyvsp[-4].annotations); + CHECK(assignments != nullptr); + CHECK_EQ(num_constants, assignments->size()); + + if (!AllDomainsHaveOneValue(*assignments)) { + context->domain_array_map[identifier] = *assignments; + // TODO(lperron): check that all assignments are included in the domain. + } else { + std::vector values(num_constants); + for (int i = 0; i < num_constants; ++i) { + values[i] = (*assignments)[i].values.front(); + CHECK(domain.Contains(values[i])); + } + context->integer_array_map[identifier] = values; + } + delete assignments; + delete annotations; } - context->integer_array_map[identifier] = values; - } - delete assignments; - delete annotations; -} #line 1545 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 25: + case 25: #line 246 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // Declaration of a variable. If it's unassigned or assigned to a - // constant, we'll create a new var stored in the model. If it's - // assigned to another variable x then we simply adjust that - // existing variable x according to the current (re-)declaration. - const Domain& domain = (yyvsp[-4].domain); - const std::string& identifier = (yyvsp[-2].string_value); - std::vector* const annotations = (yyvsp[-1].annotations); - const VariableRefOrValue& assignment = (yyvsp[0].var_or_value); - const bool introduced = ContainsId(annotations, "var_is_introduced") || - strings::StartsWith(identifier, "X_INTRODUCED"); - IntegerVariable* var = nullptr; - if (!assignment.defined) { - var = model->AddVariable(identifier, domain, introduced); - } else if (assignment.variable == nullptr) { // just an integer constant. - CHECK(domain.Contains(assignment.value)); - var = model->AddVariable( - identifier, Domain::IntegerValue(assignment.value), introduced); - } else { // a variable. - var = assignment.variable; - var->Merge(identifier, domain, nullptr, introduced); - } + // Declaration of a variable. If it's unassigned or assigned to a + // constant, we'll create a new var stored in the model. If it's + // assigned to another variable x then we simply adjust that + // existing variable x according to the current (re-)declaration. + const Domain& domain = (yyvsp[-4].domain); + const std::string& identifier = (yyvsp[-2].string_value); + std::vector* const annotations = (yyvsp[-1].annotations); + const VariableRefOrValue& assignment = (yyvsp[0].var_or_value); + const bool introduced = ContainsId(annotations, "var_is_introduced") || + strings::StartsWith(identifier, "X_INTRODUCED"); + IntegerVariable* var = nullptr; + if (!assignment.defined) { + var = model->AddVariable(identifier, domain, introduced); + } else if (assignment.variable == nullptr) { // just an integer constant. + CHECK(domain.Contains(assignment.value)); + var = model->AddVariable( + identifier, Domain::IntegerValue(assignment.value), introduced); + } else { // a variable. + var = assignment.variable; + var->Merge(identifier, domain, nullptr, introduced); + } - // We also register the variable in the parser's context, and add some - // output to the model if needed. - context->variable_map[identifier] = var; - if (ContainsId(annotations, "output_var")) { - model->AddOutput( - SolutionOutputSpecs::SingleVariable(identifier, var, - domain.display_as_boolean)); - } - delete annotations; -} + // We also register the variable in the parser's context, and add some + // output to the model if needed. + context->variable_map[identifier] = var; + if (ContainsId(annotations, "output_var")) { + model->AddOutput(SolutionOutputSpecs::SingleVariable( + identifier, var, domain.display_as_boolean)); + } + delete annotations; + } #line 1583 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 26: + case 26: #line 280 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // Declaration of a "variable array": these is exactly like N simple - // variable declarations, where the identifier for declaration #i is - // IDENTIFIER[i] (1-based index). - CHECK_EQ((yyvsp[-10].integer_value), 1); - const int64 num_vars = (yyvsp[-8].integer_value); - const Domain& domain = (yyvsp[-4].domain); - const std::string& identifier = (yyvsp[-2].string_value); - std::vector* const annotations = (yyvsp[-1].annotations); - VariableRefOrValueArray* const assignments = (yyvsp[0].var_or_value_array); - CHECK(assignments == nullptr || assignments->variables.size() == num_vars); - CHECK(assignments == nullptr || assignments->values.size() == num_vars); - const bool introduced = ContainsId(annotations, "var_is_introduced") || - strings::StartsWith(identifier, "X_INTRODUCED"); - - std::vector vars(num_vars, nullptr); - - for (int i = 0; i < num_vars; ++i) { - const std::string var_name = StringPrintf("%s[%d]", identifier.c_str(), i + 1); - if (assignments == nullptr) { - vars[i] = model->AddVariable(var_name, domain, introduced); - } else if (assignments->variables[i] == nullptr) { - // Assigned to an integer constant. - const int64 value = assignments->values[i]; - CHECK(domain.Contains(value)); - vars[i] = - model->AddVariable(var_name, Domain::IntegerValue(value), introduced); - } else { - IntegerVariable* const var = assignments->variables[i]; - CHECK(var != nullptr); - vars[i] = var; - vars[i]->Merge(var_name, domain, nullptr, introduced); - } - } - delete assignments; - - // Register the variable array on the context. - context->variable_array_map[identifier] = vars; - - // We parse the annotations to build an output object if - // needed. It's a bit more convoluted than the simple variable - // output. - if (annotations != nullptr) { - for (int i = 0; i < annotations->size(); ++i) { - const Annotation& ann = (*annotations)[i]; - if (ann.IsFunctionCallWithIdentifier("output_array")) { - // We have found an output annotation. - CHECK_EQ(1, ann.annotations.size()); - CHECK_EQ(Annotation::ANNOTATION_LIST, ann.annotations.back().type); - const Annotation& list = ann.annotations.back(); - // Let's build the vector of bounds. - std::vector bounds; - for (int a = 0; a < list.annotations.size(); ++a) { - const Annotation& bound = list.annotations[a]; - CHECK_EQ(Annotation::INTERVAL, bound.type); - bounds.emplace_back( - SolutionOutputSpecs::Bounds(bound.interval_min, bound.interval_max)); + // Declaration of a "variable array": these is exactly like N simple + // variable declarations, where the identifier for declaration #i is + // IDENTIFIER[i] (1-based index). + CHECK_EQ((yyvsp[-10].integer_value), 1); + const int64 num_vars = (yyvsp[-8].integer_value); + const Domain& domain = (yyvsp[-4].domain); + const std::string& identifier = (yyvsp[-2].string_value); + std::vector* const annotations = (yyvsp[-1].annotations); + VariableRefOrValueArray* const assignments = + (yyvsp[0].var_or_value_array); + CHECK(assignments == nullptr || + assignments->variables.size() == num_vars); + CHECK(assignments == nullptr || assignments->values.size() == num_vars); + const bool introduced = ContainsId(annotations, "var_is_introduced") || + strings::StartsWith(identifier, "X_INTRODUCED"); + + std::vector vars(num_vars, nullptr); + + for (int i = 0; i < num_vars; ++i) { + const std::string var_name = + StringPrintf("%s[%d]", identifier.c_str(), i + 1); + if (assignments == nullptr) { + vars[i] = model->AddVariable(var_name, domain, introduced); + } else if (assignments->variables[i] == nullptr) { + // Assigned to an integer constant. + const int64 value = assignments->values[i]; + CHECK(domain.Contains(value)); + vars[i] = model->AddVariable(var_name, Domain::IntegerValue(value), + introduced); + } else { + IntegerVariable* const var = assignments->variables[i]; + CHECK(var != nullptr); + vars[i] = var; + vars[i]->Merge(var_name, domain, nullptr, introduced); } - // We add the output information. - model->AddOutput( - SolutionOutputSpecs::MultiDimensionalArray(identifier, bounds, vars, - domain.display_as_boolean)); + } + delete assignments; + + // Register the variable array on the context. + context->variable_array_map[identifier] = vars; + + // We parse the annotations to build an output object if + // needed. It's a bit more convoluted than the simple variable + // output. + if (annotations != nullptr) { + for (int i = 0; i < annotations->size(); ++i) { + const Annotation& ann = (*annotations)[i]; + if (ann.IsFunctionCallWithIdentifier("output_array")) { + // We have found an output annotation. + CHECK_EQ(1, ann.annotations.size()); + CHECK_EQ(Annotation::ANNOTATION_LIST, ann.annotations.back().type); + const Annotation& list = ann.annotations.back(); + // Let's build the vector of bounds. + std::vector bounds; + for (int a = 0; a < list.annotations.size(); ++a) { + const Annotation& bound = list.annotations[a]; + CHECK_EQ(Annotation::INTERVAL, bound.type); + bounds.emplace_back(SolutionOutputSpecs::Bounds( + bound.interval_min, bound.interval_max)); + } + // We add the output information. + model->AddOutput(SolutionOutputSpecs::MultiDimensionalArray( + identifier, bounds, vars, domain.display_as_boolean)); + } + } + delete annotations; } } - delete annotations; - } -} #line 1655 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 27: + case 27: #line 349 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value) = (yyvsp[0].var_or_value); } + { + (yyval.var_or_value) = (yyvsp[0].var_or_value); + } #line 1661 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 28: + case 28: #line 350 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value) = VariableRefOrValue::Undefined(); } + { + (yyval.var_or_value) = VariableRefOrValue::Undefined(); + } #line 1667 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 29: + case 29: #line 353 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value_array) = (yyvsp[-1].var_or_value_array); } + { + (yyval.var_or_value_array) = (yyvsp[-1].var_or_value_array); + } #line 1673 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 30: + case 30: #line 354 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value_array) = nullptr; } + { + (yyval.var_or_value_array) = nullptr; + } #line 1679 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 31: + case 31: #line 355 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value_array) = nullptr; } + { + (yyval.var_or_value_array) = nullptr; + } #line 1685 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 32: + case 32: #line 358 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.var_or_value_array) = (yyvsp[-2].var_or_value_array); - (yyval.var_or_value_array)->PushBack((yyvsp[0].var_or_value)); -} + (yyval.var_or_value_array) = (yyvsp[-2].var_or_value_array); + (yyval.var_or_value_array)->PushBack((yyvsp[0].var_or_value)); + } #line 1694 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 33: + case 33: #line 362 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.var_or_value_array) = new VariableRefOrValueArray(); - (yyval.var_or_value_array)->PushBack((yyvsp[0].var_or_value)); -} + (yyval.var_or_value_array) = new VariableRefOrValueArray(); + (yyval.var_or_value_array)->PushBack((yyvsp[0].var_or_value)); + } #line 1703 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 34: + case 34: #line 368 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.var_or_value) = VariableRefOrValue::Value((yyvsp[0].integer_value)); } + { + (yyval.var_or_value) = + VariableRefOrValue::Value((yyvsp[0].integer_value)); + } #line 1709 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 35: + case 35: #line 369 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // A reference to an existing integer constant or variable. - const std::string& id = (yyvsp[0].string_value); - if (gtl::ContainsKey(context->integer_map, id)) { - (yyval.var_or_value) = VariableRefOrValue::Value(gtl::FindOrDie(context->integer_map, id)); - } else if (gtl::ContainsKey(context->variable_map, id)) { - (yyval.var_or_value) = VariableRefOrValue::VariableRef(gtl::FindOrDie(context->variable_map, id)); - } else { - LOG(ERROR) << "Unknown symbol " << id; - (yyval.var_or_value) = VariableRefOrValue::Undefined(); - *ok = false; - } -} + // A reference to an existing integer constant or variable. + const std::string& id = (yyvsp[0].string_value); + if (gtl::ContainsKey(context->integer_map, id)) { + (yyval.var_or_value) = + VariableRefOrValue::Value(gtl::FindOrDie(context->integer_map, id)); + } else if (gtl::ContainsKey(context->variable_map, id)) { + (yyval.var_or_value) = VariableRefOrValue::VariableRef( + gtl::FindOrDie(context->variable_map, id)); + } else { + LOG(ERROR) << "Unknown symbol " << id; + (yyval.var_or_value) = VariableRefOrValue::Undefined(); + *ok = false; + } + } #line 1727 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 36: + case 36: #line 382 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - // A given element of an existing constant array or variable array. - const std::string& id = (yyvsp[-3].string_value); - const int64 value = (yyvsp[-1].integer_value); - if (gtl::ContainsKey(context->integer_array_map, id)) { - (yyval.var_or_value) = VariableRefOrValue::Value( - Lookup(gtl::FindOrDie(context->integer_array_map, id), value)); - } else if (gtl::ContainsKey(context->variable_array_map, id)) { - (yyval.var_or_value) = VariableRefOrValue::VariableRef( - Lookup(gtl::FindOrDie(context->variable_array_map, id), value)); - } else { - LOG(ERROR) << "Unknown symbol " << id; - (yyval.var_or_value) = VariableRefOrValue::Undefined(); - *ok = false; - } -} + // A given element of an existing constant array or variable array. + const std::string& id = (yyvsp[-3].string_value); + const int64 value = (yyvsp[-1].integer_value); + if (gtl::ContainsKey(context->integer_array_map, id)) { + (yyval.var_or_value) = VariableRefOrValue::Value( + Lookup(gtl::FindOrDie(context->integer_array_map, id), value)); + } else if (gtl::ContainsKey(context->variable_array_map, id)) { + (yyval.var_or_value) = VariableRefOrValue::VariableRef( + Lookup(gtl::FindOrDie(context->variable_array_map, id), value)); + } else { + LOG(ERROR) << "Unknown symbol " << id; + (yyval.var_or_value) = VariableRefOrValue::Undefined(); + *ok = false; + } + } #line 1748 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 37: + case 37: #line 400 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::Boolean(); } + { + (yyval.domain) = Domain::Boolean(); + } #line 1754 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 38: + case 38: #line 401 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::AllInt64(); } + { + (yyval.domain) = Domain::AllInt64(); + } #line 1760 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 39: + case 39: #line 402 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); } + { + (yyval.domain) = + Domain::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); + } #line 1766 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 40: + case 40: #line 403 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK((yyvsp[-1].integers) != nullptr); - (yyval.domain) = Domain::IntegerList(std::move(*(yyvsp[-1].integers))); - delete (yyvsp[-1].integers); -} + CHECK((yyvsp[-1].integers) != nullptr); + (yyval.domain) = Domain::IntegerList(std::move(*(yyvsp[-1].integers))); + delete (yyvsp[-1].integers); + } #line 1776 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 41: + case 41: #line 410 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::SetOfBoolean(); } + { + (yyval.domain) = Domain::SetOfBoolean(); + } #line 1782 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 42: + case 42: #line 411 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::SetOfAllInt64(); } + { + (yyval.domain) = Domain::SetOfAllInt64(); + } #line 1788 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 43: + case 43: #line 412 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::SetOfInterval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); } + { + (yyval.domain) = Domain::SetOfInterval((yyvsp[-2].integer_value), + (yyvsp[0].integer_value)); + } #line 1794 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 44: + case 44: #line 413 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK((yyvsp[-1].integers) != nullptr); - (yyval.domain) = Domain::SetOfIntegerList(std::move(*(yyvsp[-1].integers))); - delete (yyvsp[-1].integers); -} + CHECK((yyvsp[-1].integers) != nullptr); + (yyval.domain) = + Domain::SetOfIntegerList(std::move(*(yyvsp[-1].integers))); + delete (yyvsp[-1].integers); + } #line 1804 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 45: + case 45: #line 420 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::AllInt64(); } + { + (yyval.domain) = Domain::AllInt64(); + } #line 1810 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 46: + case 46: #line 421 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - const int64 lb = ConvertAsIntegerOrDie((yyvsp[-2].double_value)); - const int64 ub = ConvertAsIntegerOrDie((yyvsp[0].double_value)); - (yyval.domain) = Domain::Interval(lb, ub); -} + const int64 lb = ConvertAsIntegerOrDie((yyvsp[-2].double_value)); + const int64 ub = ConvertAsIntegerOrDie((yyvsp[0].double_value)); + (yyval.domain) = Domain::Interval(lb, ub); + } #line 1820 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 47: + case 47: #line 428 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = (yyvsp[0].domain); } + { + (yyval.domain) = (yyvsp[0].domain); + } #line 1826 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 48: + case 48: #line 429 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = (yyvsp[0].domain); } + { + (yyval.domain) = (yyvsp[0].domain); + } #line 1832 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 49: + case 49: #line 430 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = (yyvsp[0].domain); } + { + (yyval.domain) = (yyvsp[0].domain); + } #line 1838 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 50: + case 50: #line 433 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.integers) = (yyvsp[-2].integers); (yyval.integers)->emplace_back((yyvsp[0].integer_value)); } + { + (yyval.integers) = (yyvsp[-2].integers); + (yyval.integers)->emplace_back((yyvsp[0].integer_value)); + } #line 1844 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 51: + case 51: #line 434 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.integers) = new std::vector(); (yyval.integers)->emplace_back((yyvsp[0].integer_value)); } + { + (yyval.integers) = new std::vector(); + (yyval.integers)->emplace_back((yyvsp[0].integer_value)); + } #line 1850 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 52: + case 52: #line 437 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.integer_value) = (yyvsp[0].integer_value); } + { + (yyval.integer_value) = (yyvsp[0].integer_value); + } #line 1856 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 53: + case 53: #line 438 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.integer_value) = gtl::FindOrDie(context->integer_map, (yyvsp[0].string_value)); } + { + (yyval.integer_value) = + gtl::FindOrDie(context->integer_map, (yyvsp[0].string_value)); + } #line 1862 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 54: + case 54: #line 439 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.integer_value) = Lookup(gtl::FindOrDie(context->integer_array_map, (yyvsp[-3].string_value)), (yyvsp[-1].integer_value)); -} + (yyval.integer_value) = Lookup( + gtl::FindOrDie(context->integer_array_map, (yyvsp[-3].string_value)), + (yyvsp[-1].integer_value)); + } #line 1870 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 55: + case 55: #line 444 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.doubles) = (yyvsp[-2].doubles); (yyval.doubles)->emplace_back((yyvsp[0].double_value)); } + { + (yyval.doubles) = (yyvsp[-2].doubles); + (yyval.doubles)->emplace_back((yyvsp[0].double_value)); + } #line 1876 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 56: + case 56: #line 445 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.doubles) = new std::vector(); (yyval.doubles)->emplace_back((yyvsp[0].double_value)); } + { + (yyval.doubles) = new std::vector(); + (yyval.doubles)->emplace_back((yyvsp[0].double_value)); + } #line 1882 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 57: + case 57: #line 448 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.double_value) = (yyvsp[0].double_value); } + { + (yyval.double_value) = (yyvsp[0].double_value); + } #line 1888 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 58: + case 58: #line 449 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.double_value) = gtl::FindOrDie(context->float_map, (yyvsp[0].string_value)); } + { + (yyval.double_value) = + gtl::FindOrDie(context->float_map, (yyvsp[0].string_value)); + } #line 1894 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 59: + case 59: #line 450 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.double_value) = Lookup(gtl::FindOrDie(context->float_array_map, (yyvsp[-3].string_value)), (yyvsp[-1].integer_value)); -} + (yyval.double_value) = Lookup( + gtl::FindOrDie(context->float_array_map, (yyvsp[-3].string_value)), + (yyvsp[-1].integer_value)); + } #line 1902 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 60: + case 60: #line 455 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::IntegerValue((yyvsp[0].integer_value)); } + { + (yyval.domain) = Domain::IntegerValue((yyvsp[0].integer_value)); + } #line 1908 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 61: + case 61: #line 456 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); } + { + (yyval.domain) = + Domain::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); + } #line 1914 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 62: + case 62: #line 457 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK((yyvsp[-1].integers) != nullptr); - (yyval.domain) = Domain::IntegerList(std::move(*(yyvsp[-1].integers))); - delete (yyvsp[-1].integers); -} + CHECK((yyvsp[-1].integers) != nullptr); + (yyval.domain) = Domain::IntegerList(std::move(*(yyvsp[-1].integers))); + delete (yyvsp[-1].integers); + } #line 1924 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 63: + case 63: #line 462 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::EmptyDomain(); } + { + (yyval.domain) = Domain::EmptyDomain(); + } #line 1930 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 64: + case 64: #line 463 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK_EQ(std::round((yyvsp[0].double_value)), (yyvsp[0].double_value)); - (yyval.domain) = Domain::IntegerValue(static_cast((yyvsp[0].double_value))); -} + CHECK_EQ(std::round((yyvsp[0].double_value)), (yyvsp[0].double_value)); + (yyval.domain) = + Domain::IntegerValue(static_cast((yyvsp[0].double_value))); + } #line 1939 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 65: + case 65: #line 467 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domain) = Domain::IntegerValue(gtl::FindOrDie(context->integer_map, (yyvsp[0].string_value))); } + { + (yyval.domain) = Domain::IntegerValue( + gtl::FindOrDie(context->integer_map, (yyvsp[0].string_value))); + } #line 1945 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 66: + case 66: #line 468 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.domain) = Domain::IntegerValue( - Lookup(gtl::FindOrDie(context->integer_array_map, (yyvsp[-3].string_value)), (yyvsp[-1].integer_value))); -} + (yyval.domain) = Domain::IntegerValue(Lookup( + gtl::FindOrDie(context->integer_array_map, (yyvsp[-3].string_value)), + (yyvsp[-1].integer_value))); + } #line 1954 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 67: + case 67: #line 474 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.domains) = (yyvsp[-2].domains); - (yyval.domains)->emplace_back((yyvsp[0].domain)); -} + (yyval.domains) = (yyvsp[-2].domains); + (yyval.domains)->emplace_back((yyvsp[0].domain)); + } #line 1963 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 68: + case 68: #line 478 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.domains) = new std::vector(); (yyval.domains)->emplace_back((yyvsp[0].domain)); } + { + (yyval.domains) = new std::vector(); + (yyval.domains)->emplace_back((yyvsp[0].domain)); + } #line 1969 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 71: + case 71: #line 488 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - const std::string& identifier = (yyvsp[-4].string_value); - CHECK((yyvsp[-2].args) != nullptr) << "Missing argument in constraint"; - const std::vector& arguments = *(yyvsp[-2].args); - std::vector* const annotations = (yyvsp[0].annotations); - - // Does the constraint have a defines_var annotation? - IntegerVariable* defines_var = nullptr; - if (annotations != nullptr) { - for (int i = 0; i < annotations->size(); ++i) { - const Annotation& ann = (*annotations)[i]; - if (ann.IsFunctionCallWithIdentifier("defines_var")) { - CHECK_EQ(1, ann.annotations.size()); - CHECK_EQ(Annotation::INT_VAR_REF, ann.annotations.back().type); - defines_var = ann.annotations.back().variables[0]; - break; + const std::string& identifier = (yyvsp[-4].string_value); + CHECK((yyvsp[-2].args) != nullptr) << "Missing argument in constraint"; + const std::vector& arguments = *(yyvsp[-2].args); + std::vector* const annotations = (yyvsp[0].annotations); + + // Does the constraint have a defines_var annotation? + IntegerVariable* defines_var = nullptr; + if (annotations != nullptr) { + for (int i = 0; i < annotations->size(); ++i) { + const Annotation& ann = (*annotations)[i]; + if (ann.IsFunctionCallWithIdentifier("defines_var")) { + CHECK_EQ(1, ann.annotations.size()); + CHECK_EQ(Annotation::INT_VAR_REF, ann.annotations.back().type); + defines_var = ann.annotations.back().variables[0]; + break; + } + } } - } - } - model->AddConstraint(identifier, arguments, - ContainsId(annotations, "domain"), defines_var); - delete annotations; - delete (yyvsp[-2].args); -} + model->AddConstraint(identifier, arguments, + ContainsId(annotations, "domain"), defines_var); + delete annotations; + delete (yyvsp[-2].args); + } #line 1999 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 72: + case 72: #line 515 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.args) = (yyvsp[-2].args); (yyval.args)->emplace_back((yyvsp[0].arg)); } + { + (yyval.args) = (yyvsp[-2].args); + (yyval.args)->emplace_back((yyvsp[0].arg)); + } #line 2005 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 73: + case 73: #line 516 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.args) = new std::vector(); (yyval.args)->emplace_back((yyvsp[0].arg)); } + { + (yyval.args) = new std::vector(); + (yyval.args)->emplace_back((yyvsp[0].arg)); + } #line 2011 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 74: + case 74: #line 519 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.arg) = Argument::IntegerValue((yyvsp[0].integer_value)); } + { + (yyval.arg) = Argument::IntegerValue((yyvsp[0].integer_value)); + } #line 2017 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 75: + case 75: #line 520 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.arg) = Argument::IntegerValue(ConvertAsIntegerOrDie((yyvsp[0].double_value))); } + { + (yyval.arg) = Argument::IntegerValue( + ConvertAsIntegerOrDie((yyvsp[0].double_value))); + } #line 2023 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 76: + case 76: #line 521 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.arg) = Argument::VoidArgument(); } + { + (yyval.arg) = Argument::VoidArgument(); + } #line 2029 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 77: + case 77: #line 522 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.arg) = Argument::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); } + { + (yyval.arg) = Argument::Interval((yyvsp[-2].integer_value), + (yyvsp[0].integer_value)); + } #line 2035 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 78: + case 78: #line 523 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK((yyvsp[-1].integers) != nullptr); - (yyval.arg) = Argument::IntegerList(std::move(*(yyvsp[-1].integers))); - delete (yyvsp[-1].integers); -} + CHECK((yyvsp[-1].integers) != nullptr); + (yyval.arg) = Argument::IntegerList(std::move(*(yyvsp[-1].integers))); + delete (yyvsp[-1].integers); + } #line 2045 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 79: + case 79: #line 528 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - const std::string& id = (yyvsp[0].string_value); - if (gtl::ContainsKey(context->integer_map, id)) { - (yyval.arg) = Argument::IntegerValue(gtl::FindOrDie(context->integer_map, id)); - } else if (gtl::ContainsKey(context->integer_array_map, id)) { - (yyval.arg) = Argument::IntegerList(gtl::FindOrDie(context->integer_array_map, id)); - } else if (gtl::ContainsKey(context->float_map, id)) { - const double d = gtl::FindOrDie(context->float_map, id); - (yyval.arg) = Argument::IntegerValue(ConvertAsIntegerOrDie(d)); - } else if (gtl::ContainsKey(context->float_array_map, id)) { - const auto& double_values = gtl::FindOrDie(context->float_array_map, id); - std::vector integer_values; - for (const double d : double_values) { - const int64 i = ConvertAsIntegerOrDie(d); - integer_values.push_back(i); - } - (yyval.arg) = Argument::IntegerList(std::move(integer_values)); - } else if (gtl::ContainsKey(context->variable_map, id)) { - (yyval.arg) = Argument::IntVarRef(gtl::FindOrDie(context->variable_map, id)); - } else if (gtl::ContainsKey(context->variable_array_map, id)) { - (yyval.arg) = Argument::IntVarRefArray(gtl::FindOrDie(context->variable_array_map, id)); - } else if (gtl::ContainsKey(context->domain_map, id)) { - const Domain& d = gtl::FindOrDie(context->domain_map, id); - (yyval.arg) = Argument::FromDomain(d); - } else { - CHECK(gtl::ContainsKey(context->domain_array_map, id)) << "Unknown identifier: " - << id; - const std::vector& d = gtl::FindOrDie(context->domain_array_map, id); - (yyval.arg) = Argument::DomainList(d); - } -} + const std::string& id = (yyvsp[0].string_value); + if (gtl::ContainsKey(context->integer_map, id)) { + (yyval.arg) = + Argument::IntegerValue(gtl::FindOrDie(context->integer_map, id)); + } else if (gtl::ContainsKey(context->integer_array_map, id)) { + (yyval.arg) = Argument::IntegerList( + gtl::FindOrDie(context->integer_array_map, id)); + } else if (gtl::ContainsKey(context->float_map, id)) { + const double d = gtl::FindOrDie(context->float_map, id); + (yyval.arg) = Argument::IntegerValue(ConvertAsIntegerOrDie(d)); + } else if (gtl::ContainsKey(context->float_array_map, id)) { + const auto& double_values = + gtl::FindOrDie(context->float_array_map, id); + std::vector integer_values; + for (const double d : double_values) { + const int64 i = ConvertAsIntegerOrDie(d); + integer_values.push_back(i); + } + (yyval.arg) = Argument::IntegerList(std::move(integer_values)); + } else if (gtl::ContainsKey(context->variable_map, id)) { + (yyval.arg) = + Argument::IntVarRef(gtl::FindOrDie(context->variable_map, id)); + } else if (gtl::ContainsKey(context->variable_array_map, id)) { + (yyval.arg) = Argument::IntVarRefArray( + gtl::FindOrDie(context->variable_array_map, id)); + } else if (gtl::ContainsKey(context->domain_map, id)) { + const Domain& d = gtl::FindOrDie(context->domain_map, id); + (yyval.arg) = Argument::FromDomain(d); + } else { + CHECK(gtl::ContainsKey(context->domain_array_map, id)) + << "Unknown identifier: " << id; + const std::vector& d = + gtl::FindOrDie(context->domain_array_map, id); + (yyval.arg) = Argument::DomainList(d); + } + } #line 2081 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 80: + case 80: #line 559 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - const std::string& id = (yyvsp[-3].string_value); - const int64 index = (yyvsp[-1].integer_value); - if (gtl::ContainsKey(context->integer_array_map, id)) { - (yyval.arg) = Argument::IntegerValue( - Lookup(gtl::FindOrDie(context->integer_array_map, id), index)); - } else if (gtl::ContainsKey(context->variable_array_map, id)) { - (yyval.arg) = Argument::IntVarRef( - Lookup(gtl::FindOrDie(context->variable_array_map, id), index)); - } else { - CHECK(gtl::ContainsKey(context->domain_array_map, id)) - << "Unknown identifier: " << id; - const Domain& d = - Lookup(gtl::FindOrDie(context->domain_array_map, id), index); - (yyval.arg) = Argument::FromDomain(d); - } -} + const std::string& id = (yyvsp[-3].string_value); + const int64 index = (yyvsp[-1].integer_value); + if (gtl::ContainsKey(context->integer_array_map, id)) { + (yyval.arg) = Argument::IntegerValue( + Lookup(gtl::FindOrDie(context->integer_array_map, id), index)); + } else if (gtl::ContainsKey(context->variable_array_map, id)) { + (yyval.arg) = Argument::IntVarRef( + Lookup(gtl::FindOrDie(context->variable_array_map, id), index)); + } else { + CHECK(gtl::ContainsKey(context->domain_array_map, id)) + << "Unknown identifier: " << id; + const Domain& d = + Lookup(gtl::FindOrDie(context->domain_array_map, id), index); + (yyval.arg) = Argument::FromDomain(d); + } + } #line 2103 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 81: + case 81: #line 576 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - VariableRefOrValueArray* const arguments = (yyvsp[-1].var_or_value_array); - CHECK(arguments != nullptr); - bool has_variables = false; - for (int i = 0; i < arguments->Size(); ++i) { - if (arguments->variables[i] != nullptr) { - has_variables = true; - break; - } - } - if (has_variables) { - (yyval.arg) = Argument::IntVarRefArray(std::vector()); - (yyval.arg).variables.reserve(arguments->Size()); - for (int i = 0; i < arguments->Size(); ++i) { - if (arguments->variables[i] != nullptr) { - (yyval.arg).variables.emplace_back(arguments->variables[i]); + VariableRefOrValueArray* const arguments = (yyvsp[-1].var_or_value_array); + CHECK(arguments != nullptr); + bool has_variables = false; + for (int i = 0; i < arguments->Size(); ++i) { + if (arguments->variables[i] != nullptr) { + has_variables = true; + break; + } + } + if (has_variables) { + (yyval.arg) = Argument::IntVarRefArray(std::vector()); + (yyval.arg).variables.reserve(arguments->Size()); + for (int i = 0; i < arguments->Size(); ++i) { + if (arguments->variables[i] != nullptr) { + (yyval.arg).variables.emplace_back(arguments->variables[i]); + } else { + (yyval.arg).variables.emplace_back( + model->AddConstant(arguments->values[i])); + } + } } else { - (yyval.arg).variables.emplace_back(model->AddConstant(arguments->values[i])); + (yyval.arg) = Argument::IntegerList(arguments->values); } + delete arguments; } - } else { - (yyval.arg) = Argument::IntegerList(arguments->values); - } - delete arguments; -} #line 2133 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 82: + case 82: #line 601 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.arg) = Argument::VoidArgument(); -} + (yyval.arg) = Argument::VoidArgument(); + } #line 2141 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 83: + case 83: #line 610 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - (yyval.annotations) = (yyvsp[-2].annotations) != nullptr ? (yyvsp[-2].annotations) : new std::vector(); - (yyval.annotations)->emplace_back((yyvsp[0].annotation)); - } + (yyval.annotations) = (yyvsp[-2].annotations) != nullptr + ? (yyvsp[-2].annotations) + : new std::vector(); + (yyval.annotations)->emplace_back((yyvsp[0].annotation)); + } #line 2150 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 84: + case 84: #line 614 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotations) = nullptr; } + { + (yyval.annotations) = nullptr; + } #line 2156 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 85: + case 85: #line 617 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotations) = (yyvsp[-2].annotations); (yyval.annotations)->emplace_back((yyvsp[0].annotation)); } + { + (yyval.annotations) = (yyvsp[-2].annotations); + (yyval.annotations)->emplace_back((yyvsp[0].annotation)); + } #line 2162 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 86: + case 86: #line 618 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotations) = new std::vector(); (yyval.annotations)->emplace_back((yyvsp[0].annotation)); } + { + (yyval.annotations) = new std::vector(); + (yyval.annotations)->emplace_back((yyvsp[0].annotation)); + } #line 2168 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 87: + case 87: #line 621 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotation) = Annotation::Interval((yyvsp[-2].integer_value), (yyvsp[0].integer_value)); } + { + (yyval.annotation) = Annotation::Interval((yyvsp[-2].integer_value), + (yyvsp[0].integer_value)); + } #line 2174 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 88: + case 88: #line 622 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotation) = Annotation::IntegerValue((yyvsp[0].integer_value)); } + { + (yyval.annotation) = Annotation::IntegerValue((yyvsp[0].integer_value)); + } #line 2180 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 89: + case 89: #line 623 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ - { (yyval.annotation) = Annotation::String((yyvsp[0].string_value)); } + { + (yyval.annotation) = Annotation::String((yyvsp[0].string_value)); + } #line 2186 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 90: + case 90: #line 624 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - const std::string& id = (yyvsp[0].string_value); - if (gtl::ContainsKey(context->variable_map, id)) { - (yyval.annotation) = Annotation::Variable(gtl::FindOrDie(context->variable_map, id)); - } else if (gtl::ContainsKey(context->variable_array_map, id)) { - (yyval.annotation) = Annotation::VariableList(gtl::FindOrDie(context->variable_array_map, id)); - } else { - (yyval.annotation) = Annotation::Identifier(id); - } -} + const std::string& id = (yyvsp[0].string_value); + if (gtl::ContainsKey(context->variable_map, id)) { + (yyval.annotation) = + Annotation::Variable(gtl::FindOrDie(context->variable_map, id)); + } else if (gtl::ContainsKey(context->variable_array_map, id)) { + (yyval.annotation) = Annotation::VariableList( + gtl::FindOrDie(context->variable_array_map, id)); + } else { + (yyval.annotation) = Annotation::Identifier(id); + } + } #line 2201 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 91: + case 91: #line 634 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-1].annotations); - if (annotations != nullptr) { - (yyval.annotation) = Annotation::FunctionCallWithArguments((yyvsp[-3].string_value), std::move(*annotations)); - delete annotations; - } else { - (yyval.annotation) = Annotation::FunctionCall((yyvsp[-3].string_value)); - } -} + std::vector* const annotations = (yyvsp[-1].annotations); + if (annotations != nullptr) { + (yyval.annotation) = Annotation::FunctionCallWithArguments( + (yyvsp[-3].string_value), std::move(*annotations)); + delete annotations; + } else { + (yyval.annotation) = Annotation::FunctionCall((yyvsp[-3].string_value)); + } + } #line 2215 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 92: + case 92: #line 643 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK(gtl::ContainsKey(context->variable_array_map, (yyvsp[-3].string_value))) - << "Unknown identifier: " << (yyvsp[-3].string_value); - (yyval.annotation) = Annotation::Variable( - Lookup(gtl::FindOrDie(context->variable_array_map, (yyvsp[-3].string_value)), (yyvsp[-1].integer_value))); -} + CHECK(gtl::ContainsKey(context->variable_array_map, + (yyvsp[-3].string_value))) + << "Unknown identifier: " << (yyvsp[-3].string_value); + (yyval.annotation) = Annotation::Variable(Lookup( + gtl::FindOrDie(context->variable_array_map, (yyvsp[-3].string_value)), + (yyvsp[-1].integer_value))); + } #line 2226 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 93: + case 93: #line 649 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - std::vector* const annotations = (yyvsp[-1].annotations); - if (annotations != nullptr) { - (yyval.annotation) = Annotation::AnnotationList(std::move(*annotations)); - delete annotations; - } else { - (yyval.annotation) = Annotation::Empty(); - } -} + std::vector* const annotations = (yyvsp[-1].annotations); + if (annotations != nullptr) { + (yyval.annotation) = + Annotation::AnnotationList(std::move(*annotations)); + delete annotations; + } else { + (yyval.annotation) = Annotation::Empty(); + } + } #line 2240 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 94: + case 94: #line 664 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - if ((yyvsp[-1].annotations) != nullptr) { - model->Satisfy(std::move(*(yyvsp[-1].annotations))); - delete (yyvsp[-1].annotations); - } else { - model->Satisfy(std::vector()); - } -} + if ((yyvsp[-1].annotations) != nullptr) { + model->Satisfy(std::move(*(yyvsp[-1].annotations))); + delete (yyvsp[-1].annotations); + } else { + model->Satisfy(std::vector()); + } + } #line 2253 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 95: + case 95: #line 672 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK_EQ(Argument::INT_VAR_REF, (yyvsp[0].arg).type); - if ((yyvsp[-2].annotations) != nullptr) { - model->Minimize((yyvsp[0].arg).Var(), std::move(*(yyvsp[-2].annotations))); - delete (yyvsp[-2].annotations); - } else { - model->Minimize((yyvsp[0].arg).Var(), std::vector()); - } -} + CHECK_EQ(Argument::INT_VAR_REF, (yyvsp[0].arg).type); + if ((yyvsp[-2].annotations) != nullptr) { + model->Minimize((yyvsp[0].arg).Var(), + std::move(*(yyvsp[-2].annotations))); + delete (yyvsp[-2].annotations); + } else { + model->Minimize((yyvsp[0].arg).Var(), std::vector()); + } + } #line 2267 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - case 96: + case 96: #line 681 "./ortools/flatzinc/parser.yy" /* yacc.c:1646 */ { - CHECK_EQ(Argument::INT_VAR_REF, (yyvsp[0].arg).type); - if ((yyvsp[-2].annotations) != nullptr) { - model->Maximize((yyvsp[0].arg).Var(), std::move(*(yyvsp[-2].annotations))); - delete (yyvsp[-2].annotations); - } else { - model->Maximize((yyvsp[0].arg).Var(), std::vector()); - } -} + CHECK_EQ(Argument::INT_VAR_REF, (yyvsp[0].arg).type); + if ((yyvsp[-2].annotations) != nullptr) { + model->Maximize((yyvsp[0].arg).Var(), + std::move(*(yyvsp[-2].annotations))); + delete (yyvsp[-2].annotations); + } else { + model->Maximize((yyvsp[0].arg).Var(), std::vector()); + } + } #line 2281 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ break; - #line 2285 "./ortools/flatzinc/parser.tab.cc" /* yacc.c:1646 */ - default: break; - } + default: + break; + } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. @@ -2308,11 +2305,11 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc); - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); *++yyvsp = yyval; @@ -2330,81 +2327,64 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); goto yynewstate; - /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE(yychar); /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if ! YYERROR_VERBOSE - yyerror (context, model, ok, scanner, YY_("syntax error")); + if (!yyerrstatus) { + ++yynerrs; +#if !YYERROR_VERBOSE + yyerror(context, model, ok, scanner, YY_("syntax error")); #else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) +#define YYSYNTAX_ERROR yysyntax_error(&yymsg_alloc, &yymsg, yyssp, yytoken) + { + char const* yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) { + if (yymsg != yymsgbuf) YYSTACK_FREE(yymsg); + yymsg = (char*)YYSTACK_ALLOC(yymsg_alloc); + if (!yymsg) { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } else { + yysyntax_error_status = YYSYNTAX_ERROR; yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (context, model, ok, scanner, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + } } -# undef YYSYNTAX_ERROR -#endif + yyerror(context, model, ok, scanner, yymsgp); + if (yysyntax_error_status == 2) goto yyexhaustedlab; } +#undef YYSYNTAX_ERROR +#endif + } + if (yyerrstatus == 3) { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } - else - { - yydestruct ("Error: discarding", - yytoken, &yylval, context, model, ok, scanner); - yychar = YYEMPTY; - } + if (yychar <= YYEOF) { + /* Return failure if at end of input. */ + if (yychar == YYEOF) YYABORT; + } else { + yydestruct("Error: discarding", yytoken, &yylval, context, model, ok, + scanner); + yychar = YYEMPTY; } + } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; - /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ @@ -2413,62 +2393,52 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; + if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ - YYPOPSTACK (yylen); + YYPOPSTACK(yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); + YY_STACK_PRINT(yyss, yyssp); yystate = *yyssp; goto yyerrlab1; - /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) { + yyn = yypact[yystate]; + if (!yypact_value_is_default(yyn)) { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { + yyn = yytable[yyn]; + if (0 < yyn) break; + } + } + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) YYABORT; - yydestruct ("Error: popping", - yystos[yystate], yyvsp, context, model, ok, scanner); - YYPOPSTACK (1); - yystate = *yyssp; - YY_STACK_PRINT (yyss, yyssp); - } + yydestruct("Error: popping", yystos[yystate], yyvsp, context, model, ok, + scanner); + YYPOPSTACK(1); + yystate = *yyssp; + YY_STACK_PRINT(yyss, yyssp); + } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END - /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; - /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ @@ -2488,39 +2458,34 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default); | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (context, model, ok, scanner, YY_("memory exhausted")); + yyerror(context, model, ok, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: - if (yychar != YYEMPTY) - { - /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ - yytoken = YYTRANSLATE (yychar); - yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, context, model, ok, scanner); - } + if (yychar != YYEMPTY) { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE(yychar); + yydestruct("Cleanup: discarding lookahead", yytoken, &yylval, context, + model, ok, scanner); + } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ - YYPOPSTACK (yylen); - YY_STACK_PRINT (yyss, yyssp); - while (yyssp != yyss) - { - yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, context, model, ok, scanner); - YYPOPSTACK (1); - } + YYPOPSTACK(yylen); + YY_STACK_PRINT(yyss, yyssp); + while (yyssp != yyss) { + yydestruct("Cleanup: popping", yystos[*yyssp], yyvsp, context, model, ok, + scanner); + YYPOPSTACK(1); + } #ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); + if (yyss != yyssa) YYSTACK_FREE(yyss); #endif #if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); + if (yymsg != yymsgbuf) YYSTACK_FREE(yymsg); #endif return yyresult; } #line 691 "./ortools/flatzinc/parser.yy" /* yacc.c:1906 */ - diff --git a/ortools/flatzinc/parser.yy.cc b/ortools/flatzinc/parser.yy.cc index cf3dd4c73f6..ab18a84b619 100644 --- a/ortools/flatzinc/parser.yy.cc +++ b/ortools/flatzinc/parser.yy.cc @@ -15,7 +15,7 @@ #line 4 "./ortools/flatzinc/parser.yy.cc" -#define YY_INT_ALIGNED short int +#define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ @@ -30,10 +30,10 @@ /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ -#include -#include #include +#include #include +#include /* end standard C headers. */ @@ -44,10 +44,10 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. + * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 @@ -64,37 +64,37 @@ typedef uint32_t flex_uint32_t; typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; +typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN -#define INT8_MIN (-128) +#define INT8_MIN (-128) #endif #ifndef INT16_MIN -#define INT16_MIN (-32767-1) +#define INT16_MIN (-32767 - 1) #endif #ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) +#define INT32_MIN (-2147483647 - 1) #endif #ifndef INT8_MAX -#define INT8_MAX (127) +#define INT8_MAX (127) #endif #ifndef INT16_MAX -#define INT16_MAX (32767) +#define INT16_MAX (32767) #endif #ifndef INT32_MAX -#define INT32_MAX (2147483647) +#define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX -#define UINT8_MAX (255U) +#define UINT8_MAX (255U) #endif #ifndef UINT16_MAX -#define UINT16_MAX (65535U) +#define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) +#define UINT32_MAX (4294967295U) #endif #endif /* ! C99 */ @@ -118,12 +118,12 @@ typedef unsigned int flex_uint32_t; * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +#define YY_SC_TO_UI(c) ((unsigned int)(unsigned char)c) /* An opaque pointer. */ #ifndef YY_TYPEDEF_YY_SCANNER_T #define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; +typedef void *yyscan_t; #endif /* For convenience, these vars (plus the bison vars far below) @@ -154,7 +154,7 @@ typedef void* yyscan_t; #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE orfz_restart(yyin ,yyscanner ) +#define YY_NEW_FILE orfz_restart(yyin, yyscanner) #define YY_END_OF_BUFFER_CHAR 0 @@ -171,9 +171,10 @@ typedef void* yyscan_t; #endif /* __ia64__ */ #endif -/* The state buf must be large enough to hold one state per character in the main buffer. +/* The state buf must be large enough to hold one state per character in the + * main buffer. */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE @@ -189,107 +190,101 @@ typedef size_t yy_size_t; #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE orfz_lex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - +/* Note: We specifically omit the test for yy_rule_can_match_eol because it + * requires access to the local variable yy_act. Since yyless() is a macro, it + * would break existing scanners that call yyless() from OUTSIDE orfz_lex. One + * obvious solution it to make yy_act a global. I tried that, and saw a 5% + * performance hit in a non-yylineno scanner, because yy_act is normally + * declared as a register variable-- so it is not worth it. + */ +#define YY_LESS_LINENO(n) \ + do { \ + int yyl; \ + for (yyl = n; yyl < yyleng; ++yyl) \ + if (yytext[yyl] == '\n') --yylineno; \ + } while (0) +#define YY_LINENO_REWIND_TO(dst) \ + do { \ + const char *p; \ + for (p = yy_cp - 1; p >= (dst); --p) \ + if (*p == '\n') --yylineno; \ + } while (0) + /* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + *yy_cp = yyg->yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } while (0) + +#define unput(c) yyunput(c, yyg->yytext_ptr, yyscanner) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; +struct yy_buffer_state { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via orfz_restart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via orfz_restart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ #define YY_BUFFER_EOF_PENDING 2 - - }; +}; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* We provide macros for accessing buffer states in case in the @@ -298,64 +293,66 @@ struct yy_buffer_state * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) +#define YY_CURRENT_BUFFER \ + (yyg->yy_buffer_stack ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -void orfz_restart (FILE *input_file ,yyscan_t yyscanner ); -void orfz__switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -YY_BUFFER_STATE orfz__create_buffer (FILE *file,int size ,yyscan_t yyscanner ); -void orfz__delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void orfz__flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); -void orfz_push_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); -void orfz_pop_buffer_state (yyscan_t yyscanner ); +void orfz_restart(FILE *input_file, yyscan_t yyscanner); +void orfz__switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +YY_BUFFER_STATE orfz__create_buffer(FILE *file, int size, yyscan_t yyscanner); +void orfz__delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void orfz__flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner); +void orfz_push_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner); +void orfz_pop_buffer_state(yyscan_t yyscanner); -static void orfz_ensure_buffer_stack (yyscan_t yyscanner ); -static void orfz__load_buffer_state (yyscan_t yyscanner ); -static void orfz__init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); +static void orfz_ensure_buffer_stack(yyscan_t yyscanner); +static void orfz__load_buffer_state(yyscan_t yyscanner); +static void orfz__init_buffer(YY_BUFFER_STATE b, FILE *file, + yyscan_t yyscanner); -#define YY_FLUSH_BUFFER orfz__flush_buffer(YY_CURRENT_BUFFER ,yyscanner) +#define YY_FLUSH_BUFFER orfz__flush_buffer(YY_CURRENT_BUFFER, yyscanner) -YY_BUFFER_STATE orfz__scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); -YY_BUFFER_STATE orfz__scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); -YY_BUFFER_STATE orfz__scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); +YY_BUFFER_STATE orfz__scan_buffer(char *base, yy_size_t size, + yyscan_t yyscanner); +YY_BUFFER_STATE orfz__scan_string(yyconst char *yy_str, yyscan_t yyscanner); +YY_BUFFER_STATE orfz__scan_bytes(yyconst char *bytes, int len, + yyscan_t yyscanner); -void *orfz_alloc (yy_size_t ,yyscan_t yyscanner ); -void *orfz_realloc (void *,yy_size_t ,yyscan_t yyscanner ); -void orfz_free (void * ,yyscan_t yyscanner ); +void *orfz_alloc(yy_size_t, yyscan_t yyscanner); +void *orfz_realloc(void *, yy_size_t, yyscan_t yyscanner); +void orfz_free(void *, yyscan_t yyscanner); #define yy_new_buffer orfz__create_buffer -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - orfz_ensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - orfz__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - orfz_ensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - orfz__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } +#define yy_set_interactive(is_interactive) \ + { \ + if (!YY_CURRENT_BUFFER) { \ + orfz_ensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + orfz__create_buffer(yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if (!YY_CURRENT_BUFFER) { \ + orfz_ensure_buffer_stack(yyscanner); \ + YY_CURRENT_BUFFER_LVALUE = \ + orfz__create_buffer(yyin, YY_BUF_SIZE, yyscanner); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ -#define orfz_wrap(yyscanner) (/*CONSTCOND*/1) +#define orfz_wrap(yyscanner) (/*CONSTCOND*/ 1) #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -364,184 +361,130 @@ typedef int yy_state_type; #define yytext_ptr yytext_r -static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); -static int yy_get_next_buffer (yyscan_t yyscanner ); -static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner ); +static yy_state_type yy_get_previous_state(yyscan_t yyscanner); +static yy_state_type yy_try_NUL_trans(yy_state_type current_state, + yyscan_t yyscanner); +static int yy_get_next_buffer(yyscan_t yyscanner); +static void yynoreturn yy_fatal_error(yyconst char *msg, yyscan_t yyscanner); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; +#define YY_DO_BEFORE_ACTION \ + yyg->yytext_ptr = yy_bp; \ + yyleng = (int)(yy_cp - yy_bp); \ + yyg->yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 31 #define YY_END_OF_BUFFER 32 /* This struct is not used in this scanner, but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[117] = - { 0, - 0, 0, 32, 30, 28, 27, 30, 29, 30, 30, - 18, 18, 30, 24, 30, 24, 24, 24, 24, 24, - 24, 24, 24, 24, 24, 24, 0, 26, 29, 18, - 18, 14, 0, 0, 0, 0, 15, 24, 25, 0, - 24, 24, 24, 24, 24, 24, 24, 24, 8, 24, - 24, 24, 24, 24, 24, 21, 0, 23, 20, 19, - 25, 24, 24, 24, 24, 24, 5, 24, 24, 24, - 24, 11, 24, 24, 13, 0, 24, 2, 24, 24, - 24, 24, 24, 24, 24, 24, 16, 0, 22, 1, - 24, 17, 4, 24, 24, 24, 24, 12, 24, 24, - - 24, 24, 24, 24, 24, 24, 24, 10, 24, 6, - 7, 24, 24, 9, 3, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 4, 1, 1, 5, 1, 1, 1, - 1, 1, 6, 1, 7, 8, 1, 9, 10, 10, - 10, 10, 10, 10, 10, 11, 11, 12, 1, 1, - 1, 1, 1, 1, 13, 13, 13, 13, 14, 13, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 1, 1, 1, 1, 16, 1, 17, 18, 19, 20, - - 21, 22, 15, 15, 23, 15, 15, 24, 25, 26, - 27, 28, 15, 29, 30, 31, 32, 33, 15, 34, - 35, 36, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[37] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 1, 3, 3, - 3, 1, 4, 4, 5, 5, 4, 4, 4, 4, - 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5 - } ; - -static yyconst flex_uint16_t yy_base[123] = - { 0, - 0, 0, 174, 175, 175, 175, 169, 0, 28, 164, - 32, 17, 159, 0, 154, 140, 141, 140, 28, 140, - 31, 143, 135, 40, 134, 145, 157, 175, 0, 0, - 0, 175, 53, 62, 40, 0, 175, 0, 0, 144, - 130, 131, 131, 132, 128, 123, 119, 126, 0, 130, - 119, 118, 124, 115, 117, 65, 71, 74, 46, 0, - 0, 128, 120, 113, 112, 124, 0, 117, 116, 118, - 114, 0, 103, 114, 0, 81, 99, 0, 102, 111, - 100, 105, 104, 105, 97, 105, 0, 84, 87, 0, - 96, 0, 0, 101, 100, 103, 99, 0, 103, 83, - - 69, 83, 54, 55, 56, 49, 34, 0, 34, 0, - 0, 37, 16, 0, 0, 175, 98, 103, 106, 108, - 111, 113 - } ; - -static yyconst flex_int16_t yy_def[123] = - { 0, - 116, 1, 116, 116, 116, 116, 117, 118, 116, 116, - 116, 11, 116, 119, 120, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 117, 116, 118, 11, - 12, 116, 116, 116, 116, 121, 116, 119, 122, 120, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 116, 116, 116, 116, 121, - 122, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 116, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 116, 116, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 0, 116, 116, 116, 116, - 116, 116 - } ; - -static yyconst flex_uint16_t yy_nxt[212] = - { 0, - 4, 5, 6, 7, 8, 4, 9, 10, 11, 12, - 12, 13, 14, 14, 14, 15, 16, 17, 18, 14, - 14, 19, 20, 14, 21, 14, 22, 23, 14, 24, - 25, 14, 26, 14, 14, 14, 30, 31, 31, 33, - 31, 31, 31, 116, 44, 34, 115, 47, 59, 59, - 116, 45, 34, 48, 59, 59, 51, 114, 35, 113, - 52, 56, 56, 56, 112, 36, 53, 57, 57, 111, - 58, 58, 58, 56, 56, 56, 110, 109, 76, 58, - 58, 58, 58, 58, 58, 76, 88, 88, 108, 89, - 89, 89, 89, 89, 89, 89, 89, 89, 27, 107, - - 27, 27, 27, 29, 106, 29, 29, 29, 38, 38, - 38, 39, 39, 60, 60, 61, 61, 61, 105, 104, - 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, - 93, 92, 91, 90, 87, 86, 85, 84, 83, 82, - 81, 80, 79, 78, 77, 75, 74, 73, 72, 71, - 70, 69, 68, 67, 66, 65, 64, 63, 62, 40, - 28, 55, 54, 50, 49, 46, 43, 42, 41, 40, - 37, 32, 28, 116, 3, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116 - } ; - -static yyconst flex_int16_t yy_chk[212] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 9, 9, 9, 11, - 11, 11, 11, 12, 19, 11, 113, 21, 35, 35, - 12, 19, 11, 21, 59, 59, 24, 112, 11, 109, - 24, 33, 33, 33, 107, 11, 24, 34, 34, 106, - 34, 34, 34, 56, 56, 56, 105, 104, 56, 57, - 57, 57, 58, 58, 58, 56, 76, 76, 103, 76, - 76, 76, 88, 88, 88, 89, 89, 89, 117, 102, - - 117, 117, 117, 118, 101, 118, 118, 118, 119, 119, - 119, 120, 120, 121, 121, 122, 122, 122, 100, 99, - 97, 96, 95, 94, 91, 86, 85, 84, 83, 82, - 81, 80, 79, 77, 74, 73, 71, 70, 69, 68, - 66, 65, 64, 63, 62, 55, 54, 53, 52, 51, - 50, 48, 47, 46, 45, 44, 43, 42, 41, 40, - 27, 26, 25, 23, 22, 20, 18, 17, 16, 15, - 13, 10, 7, 3, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - - 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - 116 - } ; +struct yy_trans_info { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; +}; +static yyconst flex_int16_t yy_accept[117] = { + 0, 0, 0, 32, 30, 28, 27, 30, 29, 30, 30, 18, 18, 30, 24, 30, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 26, 29, 18, 18, 14, 0, + 0, 0, 0, 15, 24, 25, 0, 24, 24, 24, 24, 24, 24, 24, 24, 8, 24, + 24, 24, 24, 24, 24, 21, 0, 23, 20, 19, 25, 24, 24, 24, 24, 24, 5, + 24, 24, 24, 24, 11, 24, 24, 13, 0, 24, 2, 24, 24, 24, 24, 24, 24, + 24, 24, 16, 0, 22, 1, 24, 17, 4, 24, 24, 24, 24, 12, 24, 24, + + 24, 24, 24, 24, 24, 24, 24, 10, 24, 6, 7, 24, 24, 9, 3, 0}; + +static yyconst YY_CHAR yy_ec[256] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 4, 1, 1, 5, + 1, 1, 1, 1, 1, 6, 1, 7, 8, 1, 9, 10, 10, 10, 10, 10, 10, 10, 11, + 11, 12, 1, 1, 1, 1, 1, 1, 13, 13, 13, 13, 14, 13, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 1, 1, 1, 1, + 16, 1, 17, 18, 19, 20, + + 21, 22, 15, 15, 23, 15, 15, 24, 25, 26, 27, 28, 15, 29, 30, 31, 32, 33, 15, + 34, 35, 36, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + +static yyconst YY_CHAR yy_meta[37] = {0, 1, 1, 2, 1, 1, 1, 1, 1, 3, 3, 3, 1, + 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}; + +static yyconst flex_uint16_t yy_base[123] = { + 0, 0, 0, 174, 175, 175, 175, 169, 0, 28, 164, 32, 17, 159, 0, + 154, 140, 141, 140, 28, 140, 31, 143, 135, 40, 134, 145, 157, 175, 0, + 0, 0, 175, 53, 62, 40, 0, 175, 0, 0, 144, 130, 131, 131, 132, + 128, 123, 119, 126, 0, 130, 119, 118, 124, 115, 117, 65, 71, 74, 46, + 0, 0, 128, 120, 113, 112, 124, 0, 117, 116, 118, 114, 0, 103, 114, + 0, 81, 99, 0, 102, 111, 100, 105, 104, 105, 97, 105, 0, 84, 87, + 0, 96, 0, 0, 101, 100, 103, 99, 0, 103, 83, + + 69, 83, 54, 55, 56, 49, 34, 0, 34, 0, 0, 37, 16, 0, 0, + 175, 98, 103, 106, 108, 111, 113}; + +static yyconst flex_int16_t yy_def[123] = { + 0, 116, 1, 116, 116, 116, 116, 117, 118, 116, 116, 116, 11, 116, 119, + 120, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 117, 116, 118, + 11, 12, 116, 116, 116, 116, 121, 116, 119, 122, 120, 119, 119, 119, 119, + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 116, 116, 116, 116, + 121, 122, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + 119, 116, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 116, 116, + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + + 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, + 0, 116, 116, 116, 116, 116, 116}; + +static yyconst flex_uint16_t yy_nxt[212] = { + 0, 4, 5, 6, 7, 8, 4, 9, 10, 11, 12, 12, 13, 14, 14, + 14, 15, 16, 17, 18, 14, 14, 19, 20, 14, 21, 14, 22, 23, 14, + 24, 25, 14, 26, 14, 14, 14, 30, 31, 31, 33, 31, 31, 31, 116, + 44, 34, 115, 47, 59, 59, 116, 45, 34, 48, 59, 59, 51, 114, 35, + 113, 52, 56, 56, 56, 112, 36, 53, 57, 57, 111, 58, 58, 58, 56, + 56, 56, 110, 109, 76, 58, 58, 58, 58, 58, 58, 76, 88, 88, 108, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 27, 107, + + 27, 27, 27, 29, 106, 29, 29, 29, 38, 38, 38, 39, 39, 60, 60, + 61, 61, 61, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, + 93, 92, 91, 90, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, + 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 40, + 28, 55, 54, 50, 49, 46, 43, 42, 41, 40, 37, 32, 28, 116, 3, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116}; + +static yyconst flex_int16_t yy_chk[212] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 11, 11, 11, 11, 12, + 19, 11, 113, 21, 35, 35, 12, 19, 11, 21, 59, 59, 24, 112, 11, + 109, 24, 33, 33, 33, 107, 11, 24, 34, 34, 106, 34, 34, 34, 56, + 56, 56, 105, 104, 56, 57, 57, 57, 58, 58, 58, 56, 76, 76, 103, + 76, 76, 76, 88, 88, 88, 89, 89, 89, 117, 102, + + 117, 117, 117, 118, 101, 118, 118, 118, 119, 119, 119, 120, 120, 121, 121, + 122, 122, 122, 100, 99, 97, 96, 95, 94, 91, 86, 85, 84, 83, 82, + 81, 80, 79, 77, 74, 73, 71, 70, 69, 68, 66, 65, 64, 63, 62, + 55, 54, 53, 52, 51, 50, 48, 47, 46, 45, 44, 43, 42, 41, 40, + 27, 26, 25, 23, 22, 20, 18, 17, 16, 15, 13, 10, 7, 3, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + + 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116}; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[32] = - { 0, -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, }; +static yyconst flex_int32_t yy_rule_can_match_eol[32] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, +}; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -585,87 +528,86 @@ using operations_research::atoi64; #endif /* Holds the entire state of the reentrant scanner. */ -struct yyguts_t - { - - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; - - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; - - int yylineno_r; - int yy_flex_debug_r; - - char *yytext_r; - int yy_more_flag; - int yy_more_len; - - YYSTYPE * yylval_r; - - }; /* end struct yyguts_t */ - -static int yy_init_globals (yyscan_t yyscanner ); - - /* This must go here because YYSTYPE and YYLTYPE are included - * from bison output in section 1.*/ - # define yylval yyg->yylval_r - -int orfz_lex_init (yyscan_t* scanner); - -int orfz_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); +struct yyguts_t { + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. + */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE *yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char *yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE *yylval_r; + +}; /* end struct yyguts_t */ + +static int yy_init_globals(yyscan_t yyscanner); + +/* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ +#define yylval yyg->yylval_r + +int orfz_lex_init(yyscan_t *scanner); + +int orfz_lex_init_extra(YY_EXTRA_TYPE user_defined, yyscan_t *scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int orfz_lex_destroy (yyscan_t yyscanner ); +int orfz_lex_destroy(yyscan_t yyscanner); -int orfz_get_debug (yyscan_t yyscanner ); +int orfz_get_debug(yyscan_t yyscanner); -void orfz_set_debug (int debug_flag ,yyscan_t yyscanner ); +void orfz_set_debug(int debug_flag, yyscan_t yyscanner); -YY_EXTRA_TYPE orfz_get_extra (yyscan_t yyscanner ); +YY_EXTRA_TYPE orfz_get_extra(yyscan_t yyscanner); -void orfz_set_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); +void orfz_set_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner); -FILE *orfz_get_in (yyscan_t yyscanner ); +FILE *orfz_get_in(yyscan_t yyscanner); -void orfz_set_in (FILE * _in_str ,yyscan_t yyscanner ); +void orfz_set_in(FILE *_in_str, yyscan_t yyscanner); -FILE *orfz_get_out (yyscan_t yyscanner ); +FILE *orfz_get_out(yyscan_t yyscanner); -void orfz_set_out (FILE * _out_str ,yyscan_t yyscanner ); +void orfz_set_out(FILE *_out_str, yyscan_t yyscanner); - int orfz_get_leng (yyscan_t yyscanner ); +int orfz_get_leng(yyscan_t yyscanner); -char *orfz_get_text (yyscan_t yyscanner ); +char *orfz_get_text(yyscan_t yyscanner); -int orfz_get_lineno (yyscan_t yyscanner ); +int orfz_get_lineno(yyscan_t yyscanner); -void orfz_set_lineno (int _line_number ,yyscan_t yyscanner ); +void orfz_set_lineno(int _line_number, yyscan_t yyscanner); -int orfz_get_column (yyscan_t yyscanner ); +int orfz_get_column(yyscan_t yyscanner); -void orfz_set_column (int _column_no ,yyscan_t yyscanner ); +void orfz_set_column(int _column_no, yyscan_t yyscanner); -YYSTYPE * orfz_get_lval (yyscan_t yyscanner ); +YYSTYPE *orfz_get_lval(yyscan_t yyscanner); -void orfz_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); +void orfz_set_lval(YYSTYPE *yylval_param, yyscan_t yyscanner); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -673,32 +615,32 @@ void orfz_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int orfz_wrap (yyscan_t yyscanner ); +extern "C" int orfz_wrap(yyscan_t yyscanner); #else -extern int orfz_wrap (yyscan_t yyscanner ); +extern int orfz_wrap(yyscan_t yyscanner); #endif #endif #ifndef YY_NO_UNPUT - - static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner); - + +static void yyunput(int c, char *buf_ptr, yyscan_t yyscanner); + #endif #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); +static void yy_flex_strncpy(char *, yyconst char *, int, yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); +static int yy_flex_strlen(yyconst char *, yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput (yyscan_t yyscanner ); +static int yyinput(yyscan_t yyscanner); #else -static int input (yyscan_t yyscanner ); +static int input(yyscan_t yyscanner); #endif #endif @@ -718,42 +660,39 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#define ECHO \ + do { \ + if (fwrite(yytext, (size_t)yyleng, 1, yyout)) { \ + } \ + } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ +#define YY_INPUT(buf, result, max_size) \ + if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) { \ + int c = '*'; \ + size_t n; \ + for (n = 0; n < max_size && (c = getc(yyin)) != EOF && c != '\n'; ++n) \ + buf[n] = (char)c; \ + if (c == '\n') buf[n++] = (char)c; \ + if (c == EOF && ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = n; \ + } else { \ + errno = 0; \ + while ((result = (int)fread(buf, 1, max_size, yyin)) == 0 && \ + ferror(yyin)) { \ + if (errno != EINTR) { \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + break; \ + } \ + errno = 0; \ + clearerr(yyin); \ + } \ + } #endif @@ -772,7 +711,7 @@ static int input (yyscan_t yyscanner ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) +#define YY_FATAL_ERROR(msg) yy_fatal_error(msg, yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -783,11 +722,9 @@ static int input (yyscan_t yyscanner ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int orfz_lex \ - (YYSTYPE * yylval_param ,yyscan_t yyscanner); +extern int orfz_lex(YYSTYPE *yylval_param, yyscan_t yyscanner); -#define YY_DECL int orfz_lex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner) +#define YY_DECL int orfz_lex(YYSTYPE *yylval_param, yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -799,440 +736,450 @@ extern int orfz_lex \ /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; +#define YY_BREAK /*LINTED*/ break; #endif -#define YY_RULE_SETUP \ - YY_USER_ACTION +#define YY_RULE_SETUP YY_USER_ACTION /** The main scanner function which does all the work. */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +YY_DECL { + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - yylval = yylval_param; + yylval = yylval_param; - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; + if (!yyg->yy_init) { + yyg->yy_init = 1; #ifdef YY_USER_INIT - YY_USER_INIT; + YY_USER_INIT; #endif - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ + if (!yyg->yy_start) yyg->yy_start = 1; /* first start state */ - if ( ! yyin ) - yyin = stdin; + if (!yyin) yyin = stdin; - if ( ! yyout ) - yyout = stdout; + if (!yyout) yyout = stdout; - if ( ! YY_CURRENT_BUFFER ) { - orfz_ensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - orfz__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } + if (!YY_CURRENT_BUFFER) { + orfz_ensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = + orfz__create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - orfz__load_buffer_state(yyscanner ); - } + orfz__load_buffer_state(yyscanner); + } - { + { #line 27 "./ortools/flatzinc/parser.lex" #line 836 "./ortools/flatzinc/parser.yy.cc" - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yyg->yy_start; -yy_match: - do - { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 117 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 175 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - int yyl; - for ( yyl = 0; yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - } - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yyg->yy_hold_char; - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP + while (/*CONSTCOND*/ 1) /* loops until end-of-file is reached */ + { + yy_cp = yyg->yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yyg->yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yyg->yy_start; + yy_match: + do { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if (yy_accept[yy_current_state]) { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int)yy_def[yy_current_state]; + if (yy_current_state >= 117) yy_c = yy_meta[(unsigned int)yy_c]; + } + yy_current_state = + yy_nxt[yy_base[yy_current_state] + (flex_int16_t)yy_c]; + ++yy_cp; + } while (yy_base[yy_current_state] != 175); + + yy_find_action: + yy_act = yy_accept[yy_current_state]; + if (yy_act == 0) { /* have to back up */ + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + if (yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act]) { + int yyl; + for (yyl = 0; yyl < yyleng; ++yyl) + if (yytext[yyl] == '\n') do { + yylineno++; + yycolumn = 0; + } while (0); + } + + do_action: /* This label is used only to access EOF actions. */ + + switch (yy_act) { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; + goto yy_find_action; + + case 1: + YY_RULE_SETUP #line 28 "./ortools/flatzinc/parser.lex" -{ return ARRAY; } - YY_BREAK -case 2: -YY_RULE_SETUP + { + return ARRAY; + } + YY_BREAK + case 2: + YY_RULE_SETUP #line 29 "./ortools/flatzinc/parser.lex" -{ return BOOL; } - YY_BREAK -case 3: -YY_RULE_SETUP + { + return BOOL; + } + YY_BREAK + case 3: + YY_RULE_SETUP #line 30 "./ortools/flatzinc/parser.lex" -{ return CONSTRAINT;} - YY_BREAK -case 4: -YY_RULE_SETUP + { + return CONSTRAINT; + } + YY_BREAK + case 4: + YY_RULE_SETUP #line 31 "./ortools/flatzinc/parser.lex" -{ return FLOAT; } - YY_BREAK -case 5: -YY_RULE_SETUP + { + return FLOAT; + } + YY_BREAK + case 5: + YY_RULE_SETUP #line 32 "./ortools/flatzinc/parser.lex" -{ return INT; } - YY_BREAK -case 6: -YY_RULE_SETUP + { + return INT; + } + YY_BREAK + case 6: + YY_RULE_SETUP #line 33 "./ortools/flatzinc/parser.lex" -{ return MAXIMIZE; } - YY_BREAK -case 7: -YY_RULE_SETUP + { + return MAXIMIZE; + } + YY_BREAK + case 7: + YY_RULE_SETUP #line 34 "./ortools/flatzinc/parser.lex" -{ return MINIMIZE; } - YY_BREAK -case 8: -YY_RULE_SETUP + { + return MINIMIZE; + } + YY_BREAK + case 8: + YY_RULE_SETUP #line 35 "./ortools/flatzinc/parser.lex" -{ return OF; } - YY_BREAK -case 9: -YY_RULE_SETUP + { + return OF; + } + YY_BREAK + case 9: + YY_RULE_SETUP #line 36 "./ortools/flatzinc/parser.lex" -{ return PREDICATE; } - YY_BREAK -case 10: -YY_RULE_SETUP + { + return PREDICATE; + } + YY_BREAK + case 10: + YY_RULE_SETUP #line 37 "./ortools/flatzinc/parser.lex" -{ return SATISFY; } - YY_BREAK -case 11: -YY_RULE_SETUP + { + return SATISFY; + } + YY_BREAK + case 11: + YY_RULE_SETUP #line 38 "./ortools/flatzinc/parser.lex" -{ return SET; } - YY_BREAK -case 12: -YY_RULE_SETUP + { + return SET; + } + YY_BREAK + case 12: + YY_RULE_SETUP #line 39 "./ortools/flatzinc/parser.lex" -{ return SOLVE; } - YY_BREAK -case 13: -YY_RULE_SETUP + { + return SOLVE; + } + YY_BREAK + case 13: + YY_RULE_SETUP #line 40 "./ortools/flatzinc/parser.lex" -{ return VAR; } - YY_BREAK -case 14: -YY_RULE_SETUP + { + return VAR; + } + YY_BREAK + case 14: + YY_RULE_SETUP #line 41 "./ortools/flatzinc/parser.lex" -{ return DOTDOT; } - YY_BREAK -case 15: -YY_RULE_SETUP + { + return DOTDOT; + } + YY_BREAK + case 15: + YY_RULE_SETUP #line 42 "./ortools/flatzinc/parser.lex" -{ return COLONCOLON;} - YY_BREAK -case 16: -YY_RULE_SETUP + { + return COLONCOLON; + } + YY_BREAK + case 16: + YY_RULE_SETUP #line 44 "./ortools/flatzinc/parser.lex" -{ - yylval->integer_value = 1; - return IVALUE; -} - YY_BREAK -case 17: -YY_RULE_SETUP + { + yylval->integer_value = 1; + return IVALUE; + } + YY_BREAK + case 17: + YY_RULE_SETUP #line 48 "./ortools/flatzinc/parser.lex" -{ - yylval->integer_value = 0; - return IVALUE; -} - YY_BREAK -case 18: -YY_RULE_SETUP + { + yylval->integer_value = 0; + return IVALUE; + } + YY_BREAK + case 18: + YY_RULE_SETUP #line 52 "./ortools/flatzinc/parser.lex" -{ - yylval->integer_value = atoi64(yytext); - return IVALUE; -} - YY_BREAK -case 19: -YY_RULE_SETUP + { + yylval->integer_value = atoi64(yytext); + return IVALUE; + } + YY_BREAK + case 19: + YY_RULE_SETUP #line 56 "./ortools/flatzinc/parser.lex" -{ - yylval->integer_value = atoi64(yytext); - return IVALUE; -} - YY_BREAK -case 20: -YY_RULE_SETUP + { + yylval->integer_value = atoi64(yytext); + return IVALUE; + } + YY_BREAK + case 20: + YY_RULE_SETUP #line 60 "./ortools/flatzinc/parser.lex" -{ - yylval->integer_value = atoi64(yytext); - return IVALUE; -} - YY_BREAK -case 21: -YY_RULE_SETUP + { + yylval->integer_value = atoi64(yytext); + return IVALUE; + } + YY_BREAK + case 21: + YY_RULE_SETUP #line 64 "./ortools/flatzinc/parser.lex" -{ - yylval->double_value = strtod(yytext,nullptr); - return DVALUE; -} - YY_BREAK -case 22: -YY_RULE_SETUP + { + yylval->double_value = strtod(yytext, nullptr); + return DVALUE; + } + YY_BREAK + case 22: + YY_RULE_SETUP #line 68 "./ortools/flatzinc/parser.lex" -{ - yylval->double_value = strtod(yytext,nullptr); - return DVALUE; -} - YY_BREAK -case 23: -YY_RULE_SETUP + { + yylval->double_value = strtod(yytext, nullptr); + return DVALUE; + } + YY_BREAK + case 23: + YY_RULE_SETUP #line 72 "./ortools/flatzinc/parser.lex" -{ - yylval->double_value = strtod(yytext,nullptr); - return DVALUE; - -} - YY_BREAK -case 24: -YY_RULE_SETUP + { + yylval->double_value = strtod(yytext, nullptr); + return DVALUE; + } + YY_BREAK + case 24: + YY_RULE_SETUP #line 77 "./ortools/flatzinc/parser.lex" -{ - yylval->string_value = yytext; - return IDENTIFIER; -} - YY_BREAK -case 25: -YY_RULE_SETUP + { + yylval->string_value = yytext; + return IDENTIFIER; + } + YY_BREAK + case 25: + YY_RULE_SETUP #line 81 "./ortools/flatzinc/parser.lex" -{ - yylval->string_value = yytext; - return IDENTIFIER; -} - YY_BREAK -case 26: -YY_RULE_SETUP + { + yylval->string_value = yytext; + return IDENTIFIER; + } + YY_BREAK + case 26: + YY_RULE_SETUP #line 85 "./ortools/flatzinc/parser.lex" -{ yylval->string_value = yytext; return SVALUE; } - YY_BREAK -case 27: -/* rule 27 can match eol */ -YY_RULE_SETUP + { + yylval->string_value = yytext; + return SVALUE; + } + YY_BREAK + case 27: + /* rule 27 can match eol */ + YY_RULE_SETUP #line 86 "./ortools/flatzinc/parser.lex" -; - YY_BREAK -case 28: -YY_RULE_SETUP + ; + YY_BREAK + case 28: + YY_RULE_SETUP #line 87 "./ortools/flatzinc/parser.lex" -; - YY_BREAK -case 29: -YY_RULE_SETUP + ; + YY_BREAK + case 29: + YY_RULE_SETUP #line 88 "./ortools/flatzinc/parser.lex" -; - YY_BREAK -case 30: -YY_RULE_SETUP + ; + YY_BREAK + case 30: + YY_RULE_SETUP #line 89 "./ortools/flatzinc/parser.lex" -{ return yytext[0]; } - YY_BREAK -case 31: -YY_RULE_SETUP + { + return yytext[0]; + } + YY_BREAK + case 31: + YY_RULE_SETUP #line 90 "./ortools/flatzinc/parser.lex" -ECHO; - YY_BREAK + ECHO; + YY_BREAK #line 1092 "./ortools/flatzinc/parser.yy.cc" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * orfz_lex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yyg->yy_c_buf_p; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( orfz_wrap(yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ + case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int)(yy_cp - yyg->yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yyg->yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * orfz_lex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if (yyg->yy_c_buf_p <= + &YY_CURRENT_BUFFER_LVALUE + ->yy_ch_buf[yyg->yy_n_chars]) { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans(yy_current_state, yyscanner); + + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + + if (yy_next_state) { + /* Consume the NUL. */ + yy_cp = ++yyg->yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else { + yy_cp = yyg->yy_c_buf_p; + goto yy_find_action; + } + } + + else + switch (yy_get_next_buffer(yyscanner)) { + case EOB_ACT_END_OF_FILE: { + yyg->yy_did_buffer_switch_on_eof = 0; + + if (orfz_wrap(yyscanner)) { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else { + if (!yyg->yy_did_buffer_switch_on_eof) YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; + + yy_current_state = yy_get_previous_state(yyscanner); + + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR("fatal flex scanner internal error--no action found"); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ } /* end of orfz_lex */ /* yy_get_next_buffer - try to read in a new buffer @@ -1242,167 +1189,149 @@ case YY_STATE_EOF(INITIAL): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - int number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - orfz_realloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - orfz_restart(yyin ,yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) orfz_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; +static int yy_get_next_buffer(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; + int number_to_move, i; + int ret_val; + + if (yyg->yy_c_buf_p > + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1]) + YY_FATAL_ERROR("fatal flex scanner internal error--end of buffer missed"); + + if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == + 0) { /* Don't try to fill the buffer, so this is an EOF. */ + if (yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1) { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int)(yyg->yy_c_buf_p - yyg->yytext_ptr - 1); + + for (i = 0; i < number_to_move; ++i) *(dest++) = *(source++); + + if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; + + else { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while (num_to_read <= 0) { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = (int)(yyg->yy_c_buf_p - b->yy_ch_buf); + + if (b->yy_is_our_buffer) { + int new_size = b->yy_buf_size * 2; + + if (new_size <= 0) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + orfz_realloc((void *)b->yy_ch_buf, b->yy_buf_size + 2, yyscanner); + } else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; - return ret_val; + if (!b->yy_ch_buf) + YY_FATAL_ERROR("fatal error - scanner input buffer overflow"); + + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + } + + if (num_to_read > YY_READ_BUF_SIZE) num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT((&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + yyg->yy_n_chars, num_to_read); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + if (yyg->yy_n_chars == 0) { + if (number_to_move == YY_MORE_ADJ) { + ret_val = EOB_ACT_END_OF_FILE; + orfz_restart(yyin, yyscanner); + } + + else { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yyg->yy_n_chars + number_to_move) > + YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *)orfz_realloc( + (void *)YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, new_size, yyscanner); + if (!YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in yy_get_next_buffer()"); + } + + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = + YY_END_OF_BUFFER_CHAR; + + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) -{ - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 117 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; - } - - return yy_current_state; +static yy_state_type yy_get_previous_state(yyscan_t yyscanner) { + yy_state_type yy_current_state; + char *yy_cp; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + yy_current_state = yyg->yy_start; + + for (yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; + ++yy_cp) { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if (yy_accept[yy_current_state]) { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int)yy_def[yy_current_state]; + if (yy_current_state >= 117) yy_c = yy_meta[(unsigned int)yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t)yy_c]; + } + + return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character @@ -1410,328 +1339,303 @@ static int yy_get_next_buffer (yyscan_t yyscanner) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) -{ - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ - char *yy_cp = yyg->yy_c_buf_p; - - YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yyg->yy_last_accepting_state = yy_current_state; - yyg->yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 117 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; - yy_is_jam = (yy_current_state == 116); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; +static yy_state_type yy_try_NUL_trans(yy_state_type yy_current_state, + yyscan_t yyscanner) { + int yy_is_jam; + struct yyguts_t *yyg = (struct yyguts_t *) + yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; + + YY_CHAR yy_c = 1; + if (yy_accept[yy_current_state]) { + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; + } + while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) { + yy_current_state = (int)yy_def[yy_current_state]; + if (yy_current_state >= 117) yy_c = yy_meta[(unsigned int)yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t)yy_c]; + yy_is_jam = (yy_current_state == 116); + + (void)yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT - static void yyunput (int c, char * yy_bp , yyscan_t yyscanner) -{ - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +static void yyunput(int c, char *yy_bp, yyscan_t yyscanner) { + char *yy_cp; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - yy_cp = yyg->yy_c_buf_p; + yy_cp = yyg->yy_c_buf_p; - /* undo effects of setting up yytext */ - *yy_cp = yyg->yy_hold_char; + /* undo effects of setting up yytext */ + *yy_cp = yyg->yy_hold_char; - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - int number_to_move = yyg->yy_n_chars + 2; - char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + + 2) { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = yyg->yy_n_chars + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE + ->yy_ch_buf[YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; + while (source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf) *--dest = *--source; - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - yyg->yy_n_chars = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + yy_cp += (int)(dest - source); + yy_bp += (int)(dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = + (int)YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } + if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2) + YY_FATAL_ERROR("flex scanner push-back overflow"); + } - *--yy_cp = (char) c; + *--yy_cp = (char)c; - if ( c == '\n' ){ - --yylineno; - } + if (c == '\n') { + --yylineno; + } - yyg->yytext_ptr = yy_bp; - yyg->yy_hold_char = *yy_cp; - yyg->yy_c_buf_p = yy_cp; + yyg->yytext_ptr = yy_bp; + yyg->yy_hold_char = *yy_cp; + yyg->yy_c_buf_p = yy_cp; } #endif #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) +static int yyinput(yyscan_t yyscanner) #else - static int input (yyscan_t yyscanner) +static int input(yyscan_t yyscanner) #endif { - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - orfz_restart(yyin ,yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( orfz_wrap(yyscanner ) ) - return 0; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; + int c; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if (*yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR) { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if (yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]) + /* This was really a NUL. */ + *yyg->yy_c_buf_p = '\0'; + + else { /* need more input */ + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; + + switch (yy_get_next_buffer(yyscanner)) { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + orfz_restart(yyin, yyscanner); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: { + if (orfz_wrap(yyscanner)) return 0; + + if (!yyg->yy_did_buffer_switch_on_eof) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(yyscanner); + return yyinput(yyscanner); #else - return input(yyscanner); + return input(yyscanner); #endif - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; - - if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - - return c; + } + + case EOB_ACT_CONTINUE_SCAN: + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *)yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + + if (c == '\n') do { + yylineno++; + yycolumn = 0; + } while (0); + + return c; } -#endif /* ifndef YY_NO_INPUT */ +#endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void orfz_restart (FILE * input_file , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +void orfz_restart(FILE *input_file, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - if ( ! YY_CURRENT_BUFFER ){ - orfz_ensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - orfz__create_buffer(yyin,YY_BUF_SIZE ,yyscanner); - } + if (!YY_CURRENT_BUFFER) { + orfz_ensure_buffer_stack(yyscanner); + YY_CURRENT_BUFFER_LVALUE = + orfz__create_buffer(yyin, YY_BUF_SIZE, yyscanner); + } - orfz__init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); - orfz__load_buffer_state(yyscanner ); + orfz__init_buffer(YY_CURRENT_BUFFER, input_file, yyscanner); + orfz__load_buffer_state(yyscanner); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * @param yyscanner The scanner object. */ - void orfz__switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* TODO. We should be able to replace this entire function body - * with - * orfz_pop_buffer_state(); - * orfz_push_buffer_state(new_buffer); - */ - orfz_ensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - orfz__load_buffer_state(yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (orfz_wrap()) processing, but the only time this flag - * is looked at is after orfz_wrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; +void orfz__switch_to_buffer(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + /* TODO. We should be able to replace this entire function body + * with + * orfz_pop_buffer_state(); + * orfz_push_buffer_state(new_buffer); + */ + orfz_ensure_buffer_stack(yyscanner); + if (YY_CURRENT_BUFFER == new_buffer) return; + + if (YY_CURRENT_BUFFER) { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + orfz__load_buffer_state(yyscanner); + + /* We don't actually know whether we did this switch during + * EOF (orfz_wrap()) processing, but the only time this flag + * is looked at is after orfz_wrap() is called, so it's safe + * to go ahead and always set it. + */ + yyg->yy_did_buffer_switch_on_eof = 1; } -static void orfz__load_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; +static void orfz__load_buffer_state(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * @param size The character buffer size in bytes. When in doubt, use @c + * YY_BUF_SIZE. * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE orfz__create_buffer (FILE * file, int size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) orfz_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in orfz__create_buffer()" ); +YY_BUFFER_STATE orfz__create_buffer(FILE *file, int size, yyscan_t yyscanner) { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE)orfz_alloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) YY_FATAL_ERROR("out of dynamic memory in orfz__create_buffer()"); - b->yy_buf_size = (yy_size_t)size; + b->yy_buf_size = (yy_size_t)size; - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) orfz_alloc(b->yy_buf_size + 2 ,yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in orfz__create_buffer()" ); + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *)orfz_alloc(b->yy_buf_size + 2, yyscanner); + if (!b->yy_ch_buf) + YY_FATAL_ERROR("out of dynamic memory in orfz__create_buffer()"); - b->yy_is_our_buffer = 1; + b->yy_is_our_buffer = 1; - orfz__init_buffer(b,file ,yyscanner); + orfz__init_buffer(b, file, yyscanner); - return b; + return b; } /** Destroy the buffer. * @param b a buffer created with orfz__create_buffer() * @param yyscanner The scanner object. */ - void orfz__delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +void orfz__delete_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - if ( ! b ) - return; + if (!b) return; - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + if (b == YY_CURRENT_BUFFER) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE)0; - if ( b->yy_is_our_buffer ) - orfz_free((void *) b->yy_ch_buf ,yyscanner ); + if (b->yy_is_our_buffer) orfz_free((void *)b->yy_ch_buf, yyscanner); - orfz_free((void *) b ,yyscanner ); + orfz_free((void *)b, yyscanner); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a orfz_restart() or at EOF. */ - static void orfz__init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) +static void orfz__init_buffer(YY_BUFFER_STATE b, FILE *file, yyscan_t yyscanner) { - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + int oerrno = errno; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - orfz__flush_buffer(b ,yyscanner); + orfz__flush_buffer(b, yyscanner); - b->yy_input_file = file; - b->yy_fill_buffer = 1; + b->yy_input_file = file; + b->yy_fill_buffer = 1; - /* If b is the current buffer, then orfz__init_buffer was _probably_ - * called from orfz_restart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } + /* If b is the current buffer, then orfz__init_buffer was _probably_ + * called from orfz_restart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER) { + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; + b->yy_is_interactive = file ? (isatty(fileno(file)) > 0) : 0; + + errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * @param yyscanner The scanner object. */ - void orfz__flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; +void orfz__flush_buffer(YY_BUFFER_STATE b, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + if (!b) return; - b->yy_n_chars = 0; + b->yy_n_chars = 0; - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - b->yy_buf_pos = &b->yy_ch_buf[0]; + b->yy_buf_pos = &b->yy_ch_buf[0]; - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; - if ( b == YY_CURRENT_BUFFER ) - orfz__load_buffer_state(yyscanner ); + if (b == YY_CURRENT_BUFFER) orfz__load_buffer_state(yyscanner); } /** Pushes the new state onto the stack. The new state becomes @@ -1740,328 +1644,297 @@ static void orfz__load_buffer_state (yyscan_t yyscanner) * @param new_buffer The new state. * @param yyscanner The scanner object. */ -void orfz_push_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - orfz_ensure_buffer_stack(yyscanner); - - /* This block is copied from orfz__switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from orfz__switch_to_buffer. */ - orfz__load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; +void orfz_push_buffer_state(YY_BUFFER_STATE new_buffer, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + if (new_buffer == NULL) return; + + orfz_ensure_buffer_stack(yyscanner); + + /* This block is copied from orfz__switch_to_buffer. */ + if (YY_CURRENT_BUFFER) { + /* Flush out information for old buffer. */ + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) yyg->yy_buffer_stack_top++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from orfz__switch_to_buffer. */ + orfz__load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * @param yyscanner The scanner object. */ -void orfz_pop_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - orfz__delete_buffer(YY_CURRENT_BUFFER ,yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - orfz__load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } +void orfz_pop_buffer_state(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + if (!YY_CURRENT_BUFFER) return; + + orfz__delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + if (yyg->yy_buffer_stack_top > 0) --yyg->yy_buffer_stack_top; + + if (YY_CURRENT_BUFFER) { + orfz__load_buffer_state(yyscanner); + yyg->yy_did_buffer_switch_on_eof = 1; + } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void orfz_ensure_buffer_stack (yyscan_t yyscanner) -{ - int num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (!yyg->yy_buffer_stack) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)orfz_alloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in orfz_ensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)orfz_realloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in orfz_ensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } +static void orfz_ensure_buffer_stack(yyscan_t yyscanner) { + int num_to_alloc; + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + if (!yyg->yy_buffer_stack) { + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + yyg->yy_buffer_stack = (struct yy_buffer_state **)orfz_alloc( + num_to_alloc * sizeof(struct yy_buffer_state *), yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in orfz_ensure_buffer_stack()"); + + memset(yyg->yy_buffer_stack, 0, + num_to_alloc * sizeof(struct yy_buffer_state *)); + + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; + return; + } + + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1) { + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state **)orfz_realloc( + yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state *), + yyscanner); + if (!yyg->yy_buffer_stack) + YY_FATAL_ERROR("out of dynamic memory in orfz_ensure_buffer_stack()"); + + /* zero only the new slots.*/ + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, + grow_size * sizeof(struct yy_buffer_state *)); + yyg->yy_buffer_stack_max = num_to_alloc; + } } -/** Setup the input buffer state to scan directly from a user-specified character buffer. +/** Setup the input buffer state to scan directly from a user-specified + * character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE orfz__scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) orfz_alloc(sizeof( struct yy_buffer_state ) ,yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in orfz__scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - orfz__switch_to_buffer(b ,yyscanner ); - - return b; +YY_BUFFER_STATE orfz__scan_buffer(char *base, yy_size_t size, + yyscan_t yyscanner) { + YY_BUFFER_STATE b; + + if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || + base[size - 1] != YY_END_OF_BUFFER_CHAR) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE)orfz_alloc(sizeof(struct yy_buffer_state), yyscanner); + if (!b) YY_FATAL_ERROR("out of dynamic memory in orfz__scan_buffer()"); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + orfz__switch_to_buffer(b, yyscanner); + + return b; } -/** Setup the input buffer state to scan a string. The next call to orfz_lex() will - * scan from a @e copy of @a str. +/** Setup the input buffer state to scan a string. The next call to orfz_lex() + * will scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * orfz__scan_bytes() instead. */ -YY_BUFFER_STATE orfz__scan_string (yyconst char * yystr , yyscan_t yyscanner) -{ - - return orfz__scan_bytes(yystr,(int) strlen(yystr) ,yyscanner); +YY_BUFFER_STATE orfz__scan_string(yyconst char *yystr, yyscan_t yyscanner) { + return orfz__scan_bytes(yystr, (int)strlen(yystr), yyscanner); } -/** Setup the input buffer state to scan the given bytes. The next call to orfz_lex() will - * scan from a @e copy of @a bytes. +/** Setup the input buffer state to scan the given bytes. The next call to + * orfz_lex() will scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE orfz__scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) orfz_alloc(n ,yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in orfz__scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = orfz__scan_buffer(buf,n ,yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in orfz__scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; +YY_BUFFER_STATE orfz__scan_bytes(yyconst char *yybytes, int _yybytes_len, + yyscan_t yyscanner) { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t)(_yybytes_len + 2); + buf = (char *)orfz_alloc(n, yyscanner); + if (!buf) YY_FATAL_ERROR("out of dynamic memory in orfz__scan_bytes()"); + + for (i = 0; i < _yybytes_len; ++i) buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len + 1] = YY_END_OF_BUFFER_CHAR; + + b = orfz__scan_buffer(buf, n, yyscanner); + if (!b) YY_FATAL_ERROR("bad buffer in orfz__scan_bytes()"); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); +static void yynoreturn yy_fatal_error(yyconst char *msg, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + (void)yyg; + (void)fprintf(stderr, "%s\n", msg); + exit(YY_EXIT_FAILURE); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) +#define yyless(n) \ + do { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg); \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ + yyleng = yyless_macro_arg; \ + } while (0) /* Accessor methods (get/set functions) to struct members. */ /** Get the user-defined data for this scanner. * @param yyscanner The scanner object. */ -YY_EXTRA_TYPE orfz_get_extra (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; +YY_EXTRA_TYPE orfz_get_extra(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yyextra; } /** Get the current line number. * @param yyscanner The scanner object. */ -int orfz_get_lineno (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +int orfz_get_lineno(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + if (!YY_CURRENT_BUFFER) return 0; - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; + return yylineno; } /** Get the current column number. * @param yyscanner The scanner object. */ -int orfz_get_column (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +int orfz_get_column(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + if (!YY_CURRENT_BUFFER) return 0; - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; + return yycolumn; } /** Get the input stream. * @param yyscanner The scanner object. */ -FILE *orfz_get_in (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; +FILE *orfz_get_in(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yyin; } /** Get the output stream. * @param yyscanner The scanner object. */ -FILE *orfz_get_out (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; +FILE *orfz_get_out(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yyout; } /** Get the length of the current token. * @param yyscanner The scanner object. */ -int orfz_get_leng (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; +int orfz_get_leng(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yyleng; } /** Get the current token. * @param yyscanner The scanner object. */ -char *orfz_get_text (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; +char *orfz_get_text(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yytext; } /** Set the user-defined data. This data is never touched by the scanner. * @param user_defined The data to be associated with this scanner. * @param yyscanner The scanner object. */ -void orfz_set_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; +void orfz_set_extra(YY_EXTRA_TYPE user_defined, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yyextra = user_defined; } /** Set the current line number. * @param _line_number line number * @param yyscanner The scanner object. */ -void orfz_set_lineno (int _line_number , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +void orfz_set_lineno(int _line_number, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "orfz_set_lineno called with no buffer" ); - - yylineno = _line_number; + /* lineno is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("orfz_set_lineno called with no buffer"); + + yylineno = _line_number; } /** Set the current column. * @param _column_no column number * @param yyscanner The scanner object. */ -void orfz_set_column (int _column_no , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +void orfz_set_column(int _column_no, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "orfz_set_column called with no buffer" ); - - yycolumn = _column_no; + /* column is only valid if an input buffer exists. */ + if (!YY_CURRENT_BUFFER) + YY_FATAL_ERROR("orfz_set_column called with no buffer"); + + yycolumn = _column_no; } /** Set the input stream. This does not discard the current @@ -2070,169 +1943,164 @@ void orfz_set_column (int _column_no , yyscan_t yyscanner) * @param yyscanner The scanner object. * @see orfz__switch_to_buffer */ -void orfz_set_in (FILE * _in_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; +void orfz_set_in(FILE *_in_str, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yyin = _in_str; } -void orfz_set_out (FILE * _out_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; +void orfz_set_out(FILE *_out_str, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yyout = _out_str; } -int orfz_get_debug (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; +int orfz_get_debug(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yy_flex_debug; } -void orfz_set_debug (int _bdebug , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; +void orfz_set_debug(int _bdebug, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yy_flex_debug = _bdebug; } /* Accessor methods for yylval and yylloc */ -YYSTYPE * orfz_get_lval (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yylval; +YYSTYPE *orfz_get_lval(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + return yylval; } -void orfz_set_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yylval = yylval_param; +void orfz_set_lval(YYSTYPE *yylval_param, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + yylval = yylval_param; } /* User-visible API */ /* orfz_lex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. + * the ONLY reentrant function that doesn't take the scanner as the last + * argument. That's why we explicitly handle the declaration, instead of using + * our macros. */ -int orfz_lex_init(yyscan_t* ptr_yy_globals) +int orfz_lex_init(yyscan_t *ptr_yy_globals) { - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) orfz_alloc ( sizeof( struct yyguts_t ), NULL ); + *ptr_yy_globals = (yyscan_t)orfz_alloc(sizeof(struct yyguts_t), NULL); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for + * releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } -/* orfz_lex_init_extra has the same functionality as orfz_lex_init, but follows the - * convention of taking the scanner as the last argument. Note however, that +/* orfz_lex_init_extra has the same functionality as orfz_lex_init, but follows + * the convention of taking the scanner as the last argument. Note however, that * this is a *pointer* to a scanner, as it will be allocated by this call (and * is the reason, too, why this function also must handle its own declaration). - * The user defined value in the first argument will be available to orfz_alloc in - * the yyextra field. + * The user defined value in the first argument will be available to orfz_alloc + * in the yyextra field. */ -int orfz_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) +int orfz_lex_init_extra(YY_EXTRA_TYPE yy_user_defined, yyscan_t *ptr_yy_globals) { - struct yyguts_t dummy_yyguts; + struct yyguts_t dummy_yyguts; - orfz_set_extra (yy_user_defined, &dummy_yyguts); + orfz_set_extra(yy_user_defined, &dummy_yyguts); - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } + if (ptr_yy_globals == NULL) { + errno = EINVAL; + return 1; + } - *ptr_yy_globals = (yyscan_t) orfz_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + *ptr_yy_globals = + (yyscan_t)orfz_alloc(sizeof(struct yyguts_t), &dummy_yyguts); - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } + if (*ptr_yy_globals == NULL) { + errno = ENOMEM; + return 1; + } - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals, 0x00, sizeof(struct yyguts_t)); - orfz_set_extra (yy_user_defined, *ptr_yy_globals); + orfz_set_extra(yy_user_defined, *ptr_yy_globals); - return yy_init_globals ( *ptr_yy_globals ); + return yy_init_globals(*ptr_yy_globals); } -static int yy_init_globals (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from orfz_lex_destroy(), so don't allocate here. - */ +static int yy_init_globals(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from orfz_lex_destroy(), so don't allocate here. + */ - yyg->yy_buffer_stack = NULL; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = NULL; - yyg->yy_init = 0; - yyg->yy_start = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; + yyin = stdin; + yyout = stdout; #else - yyin = NULL; - yyout = NULL; + yyin = NULL; + yyout = NULL; #endif - /* For future reference: Set errno on error, since we are called by - * orfz_lex_init() - */ - return 0; + /* For future reference: Set errno on error, since we are called by + * orfz_lex_init() + */ + return 0; } /* orfz_lex_destroy is for both reentrant and non-reentrant scanners. */ -int orfz_lex_destroy (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - orfz__delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - orfz_pop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - orfz_free(yyg->yy_buffer_stack ,yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - orfz_free(yyg->yy_start_stack ,yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * orfz_lex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - orfz_free ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; +int orfz_lex_destroy(yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + + /* Pop the buffer stack, destroying each element. */ + while (YY_CURRENT_BUFFER) { + orfz__delete_buffer(YY_CURRENT_BUFFER, yyscanner); + YY_CURRENT_BUFFER_LVALUE = NULL; + orfz_pop_buffer_state(yyscanner); + } + + /* Destroy the stack itself. */ + orfz_free(yyg->yy_buffer_stack, yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + orfz_free(yyg->yy_start_stack, yyscanner); + yyg->yy_start_stack = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next + * time orfz_lex() is called, initialization will occur. */ + yy_init_globals(yyscanner); + + /* Destroy the main struct (reentrant only). */ + orfz_free(yyscanner, yyscanner); + yyscanner = NULL; + return 0; } /* @@ -2240,60 +2108,52 @@ int orfz_lex_destroy (yyscan_t yyscanner) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; +static void yy_flex_strncpy(char *s1, yyconst char *s2, int n, + yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + (void)yyg; - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; + int i; + for (i = 0; i < n; ++i) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; +static int yy_flex_strlen(yyconst char *s, yyscan_t yyscanner) { + int n; + for (n = 0; s[n]; ++n) + ; - return n; + return n; } #endif -void *orfz_alloc (yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return malloc(size); +void *orfz_alloc(yy_size_t size, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + (void)yyg; + return malloc(size); } -void *orfz_realloc (void * ptr, yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); +void *orfz_realloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + (void)yyg; + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); } -void orfz_free (void * ptr , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see orfz_realloc() for (char *) cast */ +void orfz_free(void *ptr, yyscan_t yyscanner) { + struct yyguts_t *yyg = (struct yyguts_t *)yyscanner; + (void)yyg; + free((char *)ptr); /* see orfz_realloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 90 "./ortools/flatzinc/parser.lex" - - - diff --git a/ortools/flatzinc/parser_main.cc b/ortools/flatzinc/parser_main.cc index e730fa2894f..f0cf209970e 100644 --- a/ortools/flatzinc/parser_main.cc +++ b/ortools/flatzinc/parser_main.cc @@ -17,7 +17,6 @@ #include -#include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/timer.h" #include "ortools/flatzinc/logging.h" diff --git a/ortools/flatzinc/parser_util.h b/ortools/flatzinc/parser_util.h index f9f9c0e70f5..4640a58508e 100644 --- a/ortools/flatzinc/parser_util.h +++ b/ortools/flatzinc/parser_util.h @@ -34,7 +34,8 @@ struct ParserContext { std::unordered_map float_map; std::unordered_map> float_array_map; std::unordered_map variable_map; - std::unordered_map> variable_array_map; + std::unordered_map> + variable_array_map; std::unordered_map domain_map; std::unordered_map> domain_array_map; }; diff --git a/ortools/flatzinc/presolve.cc b/ortools/flatzinc/presolve.cc index ffb33146431..1e7a2458d22 100644 --- a/ortools/flatzinc/presolve.cc +++ b/ortools/flatzinc/presolve.cc @@ -17,14 +17,12 @@ #include #include -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" -#include "ortools/base/stringpiece_utils.h" -#include "ortools/base/stringprintf.h" +#include "ortools/base/map_util.h" #include "ortools/base/string_view.h" #include "ortools/base/stringpiece_utils.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/strutil.h" -#include "ortools/base/map_util.h" #include "ortools/flatzinc/logging.h" #include "ortools/graph/cliques.h" #include "ortools/util/saturated_arithmetic.h" @@ -173,7 +171,8 @@ void AppendIfNotInSet(T* value, std::unordered_set* s, void Presolver::ApplyRule( Constraint* ct, const std::string& rule_name, - const std::function& rule) { + const std::function& + rule) { const std::string before = HASVLOG ? ct->DebugString() : ""; std::string log; @@ -263,7 +262,8 @@ void Presolver::RemoveConstraintFromMapping(Constraint* ct) { // Input: bool2int(b, x) // Action: Replace all instances of x by b. // Output: inactive constraint -Presolver::RuleStatus Presolver::PresolveBool2Int(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveBool2Int(Constraint* ct, + std::string* log) { DCHECK_EQ(ct->type, "bool2int"); if (ct->arguments[0].HasOneValue() || ct->arguments[1].HasOneValue()) { // Rule 1. @@ -307,7 +307,8 @@ Presolver::RuleStatus Presolver::PresolveBool2Int(Constraint* ct, std::string* l // Input : int_eq(c1, c2) // Output: inactive constraint if c1 == c2, and do nothing if c1 != c2. // TODO(user): reorder rules? -Presolver::RuleStatus Presolver::PresolveIntEq(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntEq(Constraint* ct, + std::string* log) { // Rule 1 if (ct->arguments[0].IsVariable() && ct->arguments[1].HasOneValue() && ct->arguments[1].Value() == 0 && @@ -362,7 +363,8 @@ Presolver::RuleStatus Presolver::PresolveIntEq(Constraint* ct, std::string* log) // Action: remove c from the domain of x. // Output: inactive constraint if the removal was successful // (domain is not too large to remove a value). -Presolver::RuleStatus Presolver::PresolveIntNe(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntNe(Constraint* ct, + std::string* log) { // Rule 1. if (ct->arguments[0].IsVariable() && ct->arguments[1].IsVariable()) { IntegerVariable* const left = ct->arguments[0].Var(); @@ -576,7 +578,8 @@ Presolver::RuleStatus Presolver::Unreify(Constraint* ct, std::string* log) { // Action: Intersect the domain of x with the set of values. // Output: inactive constraint. // note: set_in(x1, {x2, ...}) is plain illegal so we don't bother with it. -Presolver::RuleStatus Presolver::PresolveSetIn(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveSetIn(Constraint* ct, + std::string* log) { if (ct->arguments[0].IsVariable()) { // IntersectDomainWith() will DCHECK that the second argument is a set // of constant values. @@ -590,7 +593,8 @@ Presolver::RuleStatus Presolver::PresolveSetIn(Constraint* ct, std::string* log) // Propagates the values of set_not_in // Input : set_not_in(x, [c1..c2]) or set_not_in(x, {c1, .., cn}) // Action: Remove the values from the domain of x. -Presolver::RuleStatus Presolver::PresolveSetNotIn(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveSetNotIn(Constraint* ct, + std::string* log) { if (ct->arguments[0].IsVariable()) { const Argument& arg = ct->arguments[1]; IntegerVariable* const var = ct->arguments[0].Var(); @@ -692,7 +696,8 @@ Presolver::RuleStatus Presolver::PresolveSetInReif(Constraint* ct, // Input : int_times(c1, c2, x) // Action: reduce domain of x to {c1 * c2} // Output: inactive constraint. -Presolver::RuleStatus Presolver::PresolveIntTimes(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntTimes(Constraint* ct, + std::string* log) { if (ct->arguments[0].HasOneValue() && ct->arguments[1].HasOneValue() && ct->arguments[2].IsVariable() && !ct->presolve_propagation_done) { log->append("propagate constants"); @@ -733,7 +738,8 @@ Presolver::RuleStatus Presolver::PresolveIntTimes(Constraint* ct, std::string* l // Input : int_div(c1, c2, x) (c2 != 0) // Action: reduce domain of x to {c1 / c2} // Output: inactive constraint. -Presolver::RuleStatus Presolver::PresolveIntDiv(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntDiv(Constraint* ct, + std::string* log) { if (ct->arguments[0].HasOneValue() && ct->arguments[1].HasOneValue() && ct->arguments[2].IsVariable() && !ct->presolve_propagation_done && ct->arguments[1].Value() != 0) { @@ -971,7 +977,8 @@ Presolver::RuleStatus Presolver::PresolveBoolEqNeReif(Constraint* ct, // int_lin_ge. // Input : int_lin_gt(arg1, arg2, c) // Output: int_lin_ge(arg1, arg2, c + 1) -Presolver::RuleStatus Presolver::PresolveIntLinGt(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntLinGt(Constraint* ct, + std::string* log) { CHECK_EQ(Argument::INT_VALUE, ct->arguments[2].type); if (ct->arguments[2].Value() != kint64max) { ct->arguments[2].values[0]++; @@ -987,7 +994,8 @@ Presolver::RuleStatus Presolver::PresolveIntLinGt(Constraint* ct, std::string* l // Transform int_lin_lt into int_lin_le. // Input : int_lin_lt(arg1, arg2, c) // Output: int_lin_le(arg1, arg2, c - 1) -Presolver::RuleStatus Presolver::PresolveIntLinLt(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntLinLt(Constraint* ct, + std::string* log) { CHECK_EQ(Argument::INT_VALUE, ct->arguments[2].type); if (ct->arguments[2].Value() != kint64min) { ct->arguments[2].values[0]--; @@ -1332,7 +1340,8 @@ Presolver::RuleStatus Presolver::PresolveArrayIntElement(Constraint* ct, // c0 - ck * xk.Value()) // // TODO(user): The code is broken in case of integer-overflow. -Presolver::RuleStatus Presolver::PresolveLinear(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveLinear(Constraint* ct, + std::string* log) { // Rule 2a and 2b. if (ct->arguments[0].values.empty() || ct->arguments[1].IsArrayOfValues()) { log->append("rewrite constant linear equation"); @@ -1477,7 +1486,8 @@ Presolver::RuleStatus Presolver::PresolveLinear(Constraint* ct, std::string* log // Regroup linear term with the same variable. // Input : int_lin_xxx([c1, .., cn], [x1, .., xn], c0) with xi = xj // Output: int_lin_xxx([c1, .., ci + cj, .., cn], [x1, .., xi, .., xn], c0) -Presolver::RuleStatus Presolver::RegroupLinear(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::RegroupLinear(Constraint* ct, + std::string* log) { if (ct->arguments[1].variables.empty()) { // Only constants, or size == 0. return NOT_CHANGED; @@ -1552,7 +1562,7 @@ Presolver::RuleStatus Presolver::PropagatePositiveLinear(Constraint* ct, if (bound < var->domain.Max()) { absl::StrAppendFormat(log, ", intersect %s with [0..%" GG_LL_FORMAT "d]", - var->DebugString().c_str(), bound); + var->DebugString().c_str(), bound); IntersectVarWithInterval(var, 0, bound); } } @@ -1580,7 +1590,8 @@ Presolver::RuleStatus Presolver::PropagatePositiveLinear(Constraint* ct, // Computes the bounds on the rhs. // Rule1: remove always true/false constraint or fix the reif Boolean. // Rule2: transform ne/eq to gt/ge/lt/le if rhs is at one bound of its domain. -Presolver::RuleStatus Presolver::SimplifyLinear(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::SimplifyLinear(Constraint* ct, + std::string* log) { const int64 rhs = ct->arguments[2].Value(); if (ct->arguments[1].variables.empty()) return NOT_CHANGED; @@ -2227,8 +2238,9 @@ Presolver::RuleStatus Presolver::PropagateReifiedComparisons(Constraint* ct, reverse = true; } if (var != nullptr) { - if (Has01Values(var) && (id == "int_eq_reif" || id == "int_ne_reif" || - id == "bool_eq_reif" || id == "bool_ne_reif") && + if (Has01Values(var) && + (id == "int_eq_reif" || id == "int_ne_reif" || id == "bool_eq_reif" || + id == "bool_ne_reif") && (value == 0 || value == 1)) { // Rule 2. bool parity = (id == "int_eq_reif" || id == "bool_eq_reif"); @@ -2354,7 +2366,8 @@ Presolver::RuleStatus Presolver::PropagateReifiedComparisons(Constraint* ct, } // Stores the existence of int_eq_reif(x, y, b) -Presolver::RuleStatus Presolver::StoreIntEqReif(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::StoreIntEqReif(Constraint* ct, + std::string* log) { if (ct->arguments[0].IsVariable() && ct->arguments[1].IsVariable() && ct->arguments[2].IsVariable()) { IntegerVariable* const first = ct->arguments[0].Var(); @@ -2458,7 +2471,8 @@ Presolver::RuleStatus Presolver::RemoveAbsFromIntEqNeReif(Constraint* ct, // Rule 3: // Input : bool_xor(b1, b2, t) // Action: bool_not(b1, b2) if t = true, bool_eq(b1, b2) if t = false. -Presolver::RuleStatus Presolver::PresolveBoolXor(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveBoolXor(Constraint* ct, + std::string* log) { if (ct->arguments[0].HasOneValue()) { // Rule 1. const int64 value = ct->arguments[0].Value(); @@ -2509,7 +2523,8 @@ Presolver::RuleStatus Presolver::PresolveBoolXor(Constraint* ct, std::string* lo // Rule 5: // Input : bool_not(c1, c2) (2 boolean constants) // Output: inactive constraint or false constraint. -Presolver::RuleStatus Presolver::PresolveBoolNot(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveBoolNot(Constraint* ct, + std::string* log) { if (ct->arguments[0].variables.empty() && ct->arguments[1].variables.empty()) { return (ct->arguments[0].Value() != ct->arguments[1].Value()) @@ -2743,7 +2758,8 @@ Presolver::RuleStatus Presolver::SimplifyIntLinEqReif(Constraint* ct, // // Input : int_mod(x1, x2, x3) => x3 // Output: int_mod(x1, x2, x3) if x3 has only one value. -Presolver::RuleStatus Presolver::PresolveIntMod(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveIntMod(Constraint* ct, + std::string* log) { if (ct->target_variable != nullptr && ct->arguments[2].Var() == ct->target_variable && ct->arguments[2].HasOneValue()) { @@ -2757,7 +2773,8 @@ Presolver::RuleStatus Presolver::PresolveIntMod(Constraint* ct, std::string* log // Remove invalid tuples, remove unreached values from domain variables. // -Presolver::RuleStatus Presolver::PresolveTableInt(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveTableInt(Constraint* ct, + std::string* log) { if (ct->arguments[0].variables.empty()) { return NOT_CHANGED; } @@ -2807,7 +2824,8 @@ Presolver::RuleStatus Presolver::PresolveTableInt(Constraint* ct, std::string* l return NOT_CHANGED; } -Presolver::RuleStatus Presolver::PresolveRegular(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveRegular(Constraint* ct, + std::string* log) { const std::vector vars = ct->arguments[0].variables; if (vars.empty()) { // TODO(user): presolve when all variables are instantiated. @@ -2930,7 +2948,8 @@ Presolver::RuleStatus Presolver::PresolveRegular(Constraint* ct, std::string* lo // // Input : diffn([x1, .. xn], [1, .., 1], [1, .., 1], [1, .., 1]) // Output: all_different_int([x1, .. xn]) -Presolver::RuleStatus Presolver::PresolveDiffN(Constraint* ct, std::string* log) { +Presolver::RuleStatus Presolver::PresolveDiffN(Constraint* ct, + std::string* log) { const int size = ct->arguments[0].variables.size(); if (size > 0 && ct->arguments[1].IsArrayOfValues() && ct->arguments[2].IsArrayOfValues() && @@ -2957,23 +2976,23 @@ Presolver::RuleStatus Presolver::PresolveDiffN(Constraint* ct, std::string* log) return NOT_CHANGED; } -#define CALL_TYPE(ct, t, method) \ - if (ct->active && ct->type == t) { \ +#define CALL_TYPE(ct, t, method) \ + if (ct->active && ct->type == t) { \ ApplyRule(ct, #method, [this](Constraint* ct, std::string* log) { \ - return method(ct, log); \ - }); \ + return method(ct, log); \ + }); \ } -#define CALL_PREFIX(ct, t, method) \ - if (ct->active && strings::StartsWith(ct->type, t)) { \ +#define CALL_PREFIX(ct, t, method) \ + if (ct->active && strings::StartsWith(ct->type, t)) { \ ApplyRule(ct, #method, [this](Constraint* ct, std::string* log) { \ - return method(ct, log); \ - }); \ + return method(ct, log); \ + }); \ } -#define CALL_SUFFIX(ct, t, method) \ - if (ct->active && strings::EndsWith(ct->type, t)) { \ +#define CALL_SUFFIX(ct, t, method) \ + if (ct->active && strings::EndsWith(ct->type, t)) { \ ApplyRule(ct, #method, [this](Constraint* ct, std::string* log) { \ - return method(ct, log); \ - }); \ + return method(ct, log); \ + }); \ } // Main presolve rule caller. @@ -3356,9 +3375,10 @@ bool Presolver::Run(Model* model) { for (Constraint* const ct : model->constraints()) { if (ct->active && ct->type == "bool2int") { std::string log; - ApplyRule(ct, "PresolveBool2Int", [this](Constraint* ct, std::string* log) { - return PresolveBool2Int(ct, log); - }); + ApplyRule(ct, "PresolveBool2Int", + [this](Constraint* ct, std::string* log) { + return PresolveBool2Int(ct, log); + }); } } if (!var_representative_map_.empty()) { diff --git a/ortools/flatzinc/presolve.h b/ortools/flatzinc/presolve.h index 9c331099bbb..4b632d64645 100644 --- a/ortools/flatzinc/presolve.h +++ b/ortools/flatzinc/presolve.h @@ -19,10 +19,10 @@ #include #include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringpiece_utils.h" -#include "ortools/base/hash.h" #include "ortools/flatzinc/model.h" namespace operations_research { diff --git a/ortools/flatzinc/reporting.cc b/ortools/flatzinc/reporting.cc index 5467f2903c8..660eab5d0f8 100644 --- a/ortools/flatzinc/reporting.cc +++ b/ortools/flatzinc/reporting.cc @@ -18,9 +18,8 @@ #include #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/mutex.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/flatzinc/logging.h" @@ -54,8 +53,8 @@ void MonoThreadReporting::OnSatSolution(int thread_id, IncrementSolutions(); } -void MonoThreadReporting::OnOptimizeSolution(int thread_id, int64 value, - const std::string& solution_string) { +void MonoThreadReporting::OnOptimizeSolution( + int thread_id, int64 value, const std::string& solution_string) { best_objective_ = value; if (ShouldPrintAllSolutions() || MaxNumSolutions() > 1) { Print(thread_id, solution_string); @@ -65,7 +64,8 @@ void MonoThreadReporting::OnOptimizeSolution(int thread_id, int64 value, IncrementSolutions(); } -void MonoThreadReporting::Log(int thread_id, const std::string& final_output) const { +void MonoThreadReporting::Log(int thread_id, + const std::string& final_output) const { FZLOG << final_output << FZENDL; } @@ -104,8 +104,8 @@ SilentMonoThreadReporting::SilentMonoThreadReporting(bool print_all, SilentMonoThreadReporting::~SilentMonoThreadReporting() {} -void SilentMonoThreadReporting::Init(int thread_id, const std::string& init_string) { -} +void SilentMonoThreadReporting::Init(int thread_id, + const std::string& init_string) {} void SilentMonoThreadReporting::Log(int thread_id, const std::string& final_output) const {} @@ -226,8 +226,8 @@ void MultiThreadReporting::OnSatSolution(int thread_id, IncrementSolutions(); } -void MultiThreadReporting::OnOptimizeSolution(int thread_id, int64 value, - const std::string& solution_string) { +void MultiThreadReporting::OnOptimizeSolution( + int thread_id, int64 value, const std::string& solution_string) { absl::MutexLock lock(&mutex_); if (!should_finish_) { switch (type_) { @@ -275,12 +275,14 @@ void MultiThreadReporting::OnOptimizeSolution(int thread_id, int64 value, } } -void MultiThreadReporting::Log(int thread_id, const std::string& message) const { +void MultiThreadReporting::Log(int thread_id, + const std::string& message) const { absl::MutexLock lock(&mutex_); FZLOG << message << FZENDL; } -void MultiThreadReporting::Print(int thread_id, const std::string& message) const { +void MultiThreadReporting::Print(int thread_id, + const std::string& message) const { std::cout << message << std::endl; } bool MultiThreadReporting::ShouldFinish() const { @@ -329,7 +331,8 @@ bool MultiThreadReporting::Interrupted() const { return interrupted_; } -void MultiThreadReporting::LogNoLock(int thread_id, const std::string& message) { +void MultiThreadReporting::LogNoLock(int thread_id, + const std::string& message) { FZLOG << "%% thread " << thread_id << ": " << message << FZENDL; } diff --git a/ortools/flatzinc/reporting.h b/ortools/flatzinc/reporting.h index 4bb1def0d2e..6cb1114c00f 100644 --- a/ortools/flatzinc/reporting.h +++ b/ortools/flatzinc/reporting.h @@ -16,8 +16,8 @@ #include #include "ortools/base/integral_types.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/mutex.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" namespace operations_research { @@ -59,7 +59,8 @@ class SearchReportingInterface { // Worker 'thread_id' notifies a new solution in a satisfaction // problem. 'solution_string' is the solution to display if needed. - virtual void OnSatSolution(int thread_id, const std::string& solution_string) = 0; + virtual void OnSatSolution(int thread_id, + const std::string& solution_string) = 0; // Worker 'thread_id' notifies a new solution in an optimization // problem. 'solution_string' is the solution to display if needed. @@ -100,7 +101,7 @@ class SearchReportingInterface { // Indicates if we should print all solutions. bool ShouldPrintAllSolutions() const { return print_all_solutions_; } -// ----- Dedicated methods to create MT/Sequential specific objects ----- + // ----- Dedicated methods to create MT/Sequential specific objects ----- #if !defined(SWIG) // Creates the objective used by the search. @@ -129,7 +130,8 @@ class MonoThreadReporting : public SearchReportingInterface { void Init(int thread_id, const std::string& init_string) override; void OnSearchStart(int thread_id, Type type) override; - void OnSatSolution(int thread_id, const std::string& solution_string) override; + void OnSatSolution(int thread_id, + const std::string& solution_string) override; void OnOptimizeSolution(int thread_id, int64 value, const std::string& solution_string) override; void Log(int thread_id, const std::string& message) const override; @@ -167,7 +169,8 @@ class MultiThreadReporting : public SearchReportingInterface { ~MultiThreadReporting() override; void Init(int thread_id, const std::string& init_string) override; void OnSearchStart(int thread_id, Type type) override; - void OnSatSolution(int thread_id, const std::string& solution_string) override; + void OnSatSolution(int thread_id, + const std::string& solution_string) override; void OnOptimizeSolution(int thread_id, int64 value, const std::string& solution_string) override; void Log(int thread_id, const std::string& message) const override; diff --git a/ortools/flatzinc/sat_constraint.cc b/ortools/flatzinc/sat_constraint.cc index d494b700867..144ce61f09e 100644 --- a/ortools/flatzinc/sat_constraint.cc +++ b/ortools/flatzinc/sat_constraint.cc @@ -19,13 +19,13 @@ #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" +#include "ortools/base/hash.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/integral_types.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/flatzinc/logging.h" diff --git a/ortools/flatzinc/solver.cc b/ortools/flatzinc/solver.cc index 4854c2b62f3..d2efcebbad0 100644 --- a/ortools/flatzinc/solver.cc +++ b/ortools/flatzinc/solver.cc @@ -16,13 +16,12 @@ #include #include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" -#include "ortools/base/stringprintf.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/flatzinc/checker.h" #include "ortools/flatzinc/constraints.h" @@ -97,7 +96,8 @@ std::string Solver::SolutionString(const SolutionOutputSpecs& output) const { return StringPrintf("%s = %s;", output.name.c_str(), value == 1 ? "true" : "false"); } else { - return absl::StrFormat("%s = %" GG_LL_FORMAT "d;", output.name.c_str(), value); + return absl::StrFormat("%s = %" GG_LL_FORMAT "d;", output.name.c_str(), + value); } } else { const int bound_size = output.bounds.size(); @@ -264,7 +264,7 @@ bool Solver::Extract() { // variable) // And we clean all of them (mark as non target). std::vector required_vars(ctio->required.begin(), - ctio->required.end()); + ctio->required.end()); for (IntegerVariable* const fz_var : required_vars) { FZDLOG << " - clean " << fz_var->DebugString() << FZENDL; if (fz_var->defining_constraint != nullptr) { @@ -738,10 +738,9 @@ void Solver::Solve(FlatzincParameters p, SearchReportingInterface* report) { objective_monitor_ = report->CreateObjective( solver_, model_.maximize(), objective_var_, 1, p.thread_id); SearchMonitor* const log = - p.logging - ? solver_->RevAlloc( - new Log(solver_, objective_monitor_, p.log_period)) - : nullptr; + p.logging ? solver_->RevAlloc( + new Log(solver_, objective_monitor_, p.log_period)) + : nullptr; SearchLimit* const ctrl_c = solver_->RevAlloc(new Interrupt(solver_)); monitors.push_back(log); monitors.push_back(objective_monitor_); @@ -921,9 +920,9 @@ void Solver::Solve(FlatzincParameters p, SearchReportingInterface* report) { "%%%% csv: %s, %s, %s, %d, %" GG_LL_FORMAT "d ms, %" GG_LL_FORMAT "d ms, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT "d, %d, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT "d, %s, %s", - model_.name().c_str(), status_string.c_str(), obj_string.c_str(), num_solutions, solve_time, - build_time, solver_->branches(), solver_->failures(), - solver_->constraints(), + model_.name().c_str(), status_string.c_str(), obj_string.c_str(), + num_solutions, solve_time, build_time, solver_->branches(), + solver_->failures(), solver_->constraints(), solver_->demon_runs(operations_research::Solver::NORMAL_PRIORITY), solver_->demon_runs(operations_research::Solver::DELAYED_PRIORITY), MemoryUsage().c_str(), search_name_.c_str())); diff --git a/ortools/flatzinc/solver_util.cc b/ortools/flatzinc/solver_util.cc index 4c8b8efea7a..91a3668934c 100644 --- a/ortools/flatzinc/solver_util.cc +++ b/ortools/flatzinc/solver_util.cc @@ -13,8 +13,8 @@ #include "ortools/flatzinc/solver_util.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" +#include "ortools/base/stringprintf.h" #include "ortools/flatzinc/logging.h" namespace operations_research { diff --git a/ortools/glop/basis_representation.cc b/ortools/glop/basis_representation.cc index d81f74855c0..083a3117988 100644 --- a/ortools/glop/basis_representation.cc +++ b/ortools/glop/basis_representation.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/basis_representation.h" #include "ortools/base/stl_util.h" @@ -449,8 +448,8 @@ void BasisFactorization::RightSolveForProblemColumn(ColIndex col, d->SortNonZerosIfNeeded(); } -Fractional BasisFactorization::RightSolveSquaredNorm(const SparseColumn& a) - const { +Fractional BasisFactorization::RightSolveSquaredNorm( + const SparseColumn& a) const { SCOPED_TIME_STAT(&stats_); DCHECK(IsRefactorized()); BumpDeterministicTimeForSolve(a.num_entries().value()); diff --git a/ortools/glop/basis_representation.h b/ortools/glop/basis_representation.h index bbeaf840c1e..e57298cee08 100644 --- a/ortools/glop/basis_representation.h +++ b/ortools/glop/basis_representation.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_GLOP_BASIS_REPRESENTATION_H_ #define OR_TOOLS_GLOP_BASIS_REPRESENTATION_H_ @@ -280,8 +279,7 @@ class BasisFactorization { // Qi Huangfu, J. A. Julian Hall, "Novel update techniques for the revised // simplex method", 28 january 2013, Technical Report ERGO-13-0001 Status MiddleProductFormUpdate(ColIndex entering_col, - RowIndex leaving_variable_row) - MUST_USE_RESULT; + RowIndex leaving_variable_row) MUST_USE_RESULT; // Increases the deterministic time for a solve operation with a vector having // this number of non-zero entries (it can be an approximation). diff --git a/ortools/glop/entering_variable.cc b/ortools/glop/entering_variable.cc index bad1b1b1f72..84359dc905c 100644 --- a/ortools/glop/entering_variable.cc +++ b/ortools/glop/entering_variable.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/entering_variable.h" #include diff --git a/ortools/glop/entering_variable.h b/ortools/glop/entering_variable.h index 87c6dad2e0f..3872981b727 100644 --- a/ortools/glop/entering_variable.h +++ b/ortools/glop/entering_variable.h @@ -61,8 +61,7 @@ class EnteringVariable { // IsValidPrimalEnteringCandidate() for more details) or kInvalidCol if no // such column exists. This latter case means that the primal algorithm has // terminated: the optimal has been reached. - Status PrimalChooseEnteringColumn(ColIndex* entering_col) - MUST_USE_RESULT; + Status PrimalChooseEnteringColumn(ColIndex* entering_col) MUST_USE_RESULT; // Dual optimization phase (i.e. phase II) ratio test. // Returns the index of the entering column given that we want to move along diff --git a/ortools/glop/initial_basis.cc b/ortools/glop/initial_basis.cc index ef2344ff6e2..cb0eb5e9827 100644 --- a/ortools/glop/initial_basis.cc +++ b/ortools/glop/initial_basis.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/initial_basis.h" #include @@ -147,7 +146,7 @@ bool InitialBasis::CompleteTriangularBasis(ColIndex num_cols, max_scaled_abs_cost_ = (max_scaled_abs_cost_ == 0.0) ? 1.0 : kBixbyWeight * max_scaled_abs_cost_; std::priority_queue, - InitialBasis::TriangularColumnComparator> + InitialBasis::TriangularColumnComparator> queue(residual_singleton_column.begin(), residual_singleton_column.end(), triangular_column_comparator_); @@ -240,8 +239,7 @@ int InitialBasis::GetColumnCategory(ColIndex col) const { case VariableType::FIXED_VARIABLE: return 5; default: - LOG(DFATAL) << "Column " << col - << " has no meaningful type."; + LOG(DFATAL) << "Column " << col << " has no meaningful type."; return 6; } } diff --git a/ortools/glop/lp_solver.cc b/ortools/glop/lp_solver.cc index 554f9ae45a6..d8bc35b91bf 100644 --- a/ortools/glop/lp_solver.cc +++ b/ortools/glop/lp_solver.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/lp_solver.h" #include @@ -310,7 +309,6 @@ ProblemStatus LPSolver::LoadAndVerifySolution(const LinearProgram& lp, ComputeReducedCosts(lp); ComputeConstraintActivities(lp); - // These will be set to true if the associated "infeasibility" is too large. // // The tolerance used is the parameter solution_feasibility_tolerance. To be @@ -463,7 +461,6 @@ int LPSolver::GetNumberOfSimplexIterations() const { return num_revised_simplex_iterations_; } - double LPSolver::DeterministicTime() const { return revised_simplex_ == nullptr ? 0.0 : revised_simplex_->DeterministicTime(); @@ -555,7 +552,6 @@ void LPSolver::RunRevisedSimplexIfNeeded(ProblemSolution* solution, } } - namespace { void LogVariableStatusError(ColIndex col, Fractional value, @@ -756,8 +752,8 @@ void LPSolver::ComputeConstraintActivities(const LinearProgram& lp) { DCHECK_EQ(num_cols, primal_values_.size()); constraint_activities_.assign(num_rows, 0.0); for (ColIndex col(0); col < num_cols; ++col) { - lp.GetSparseColumn(col) - .AddMultipleToDenseVector(primal_values_[col], &constraint_activities_); + lp.GetSparseColumn(col).AddMultipleToDenseVector(primal_values_[col], + &constraint_activities_); } } diff --git a/ortools/glop/lp_solver.h b/ortools/glop/lp_solver.h index 1089dee0611..829f8a0af75 100644 --- a/ortools/glop/lp_solver.h +++ b/ortools/glop/lp_solver.h @@ -138,7 +138,6 @@ class LPSolver { // Returns the number of simplex iterations used by the last Solve(). int GetNumberOfSimplexIterations() const; - // Returns the "deterministic time" since the creation of the solver. Note // That this time is only increased when some operations take place in this // class. @@ -166,7 +165,6 @@ class LPSolver { void RunRevisedSimplexIfNeeded(ProblemSolution* solution, TimeLimit* time_limit); - // Checks that the returned solution values and statuses are consistent. // Returns true if this is the case. See the code for the exact check // performed. @@ -248,7 +246,6 @@ class LPSolver { // The number of revised simplex iterations used by the last Solve(). int num_revised_simplex_iterations_; - // The current ProblemSolution. // TODO(user): use a ProblemSolution directly? DenseRow primal_values_; diff --git a/ortools/glop/lu_factorization.cc b/ortools/glop/lu_factorization.cc index 67d4f642824..399615e5024 100644 --- a/ortools/glop/lu_factorization.cc +++ b/ortools/glop/lu_factorization.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/lu_factorization.h" #include "ortools/lp_data/lp_utils.h" @@ -441,8 +440,9 @@ double LuFactorization::GetFillInPercentage(const MatrixView& matrix) const { } EntryIndex LuFactorization::NumberOfEntries() const { - return is_identity_factorization_ ? EntryIndex(0) : lower_.num_entries() + - upper_.num_entries(); + return is_identity_factorization_ + ? EntryIndex(0) + : lower_.num_entries() + upper_.num_entries(); } Fractional LuFactorization::ComputeDeterminant() const { diff --git a/ortools/glop/markowitz.cc b/ortools/glop/markowitz.cc index 08b1bb2b507..2b91357a5c1 100644 --- a/ortools/glop/markowitz.cc +++ b/ortools/glop/markowitz.cc @@ -216,8 +216,8 @@ void Markowitz::ExtractSingletonColumns(const MatrixView& basis_matrix, for (ColIndex col(0); col < num_cols; ++col) { const SparseColumn& column = basis_matrix.column(col); if (column.num_entries().value() == 1) { - singleton_entries.push_back(MatrixEntry( - column.GetFirstRow(), col, column.GetFirstCoefficient())); + singleton_entries.push_back( + MatrixEntry(column.GetFirstRow(), col, column.GetFirstCoefficient())); } } @@ -661,8 +661,8 @@ void MatrixNonZeroPattern::RemoveDeletedColumnsFromRow(RowIndex row) { ref.resize(new_index); } -ColIndex MatrixNonZeroPattern::GetFirstNonDeletedColumnFromRow(RowIndex row) - const { +ColIndex MatrixNonZeroPattern::GetFirstNonDeletedColumnFromRow( + RowIndex row) const { for (const ColIndex col : RowNonZero(row)) { if (!IsColumnDeleted(col)) return col; } diff --git a/ortools/glop/markowitz.h b/ortools/glop/markowitz.h index 1baed5e3731..c3d32ff5476 100644 --- a/ortools/glop/markowitz.h +++ b/ortools/glop/markowitz.h @@ -75,8 +75,8 @@ #include -#include "ortools/base/logging.h" #include "ortools/base/inlined_vector.h" +#include "ortools/base/logging.h" #include "ortools/glop/parameters.pb.h" #include "ortools/glop/status.h" #include "ortools/lp_data/lp_types.h" diff --git a/ortools/glop/preprocessor.cc b/ortools/glop/preprocessor.cc index 875ebe7ca25..194c613e18c 100644 --- a/ortools/glop/preprocessor.cc +++ b/ortools/glop/preprocessor.cc @@ -11,10 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/preprocessor.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/stringprintf.h" #include "ortools/glop/revised_simplex.h" #include "ortools/glop/status.h" @@ -231,7 +229,6 @@ void ColumnDeletionHelper::RestoreDeletedColumns( new_variable_statuses.swap(solution->variable_statuses); } - // -------------------------------------------------------- // RowDeletionHelper // -------------------------------------------------------- @@ -1554,7 +1551,6 @@ bool DoubletonFreeColumnPreprocessor::Run(LinearProgram* lp) { std::swap(r.row[DELETED], r.row[MODIFIED]); } - // Save the deleted row for postsolve. Note that we remove it from the // transpose at the same time. This last operation is not strictly needed, // but it is faster to do it this way (both here and later when we will take @@ -1616,7 +1612,6 @@ bool DoubletonFreeColumnPreprocessor::Run(LinearProgram* lp) { return false; } - void DoubletonFreeColumnPreprocessor::RecoverSolution( ProblemSolution* solution) const { SCOPED_INSTRUCTION_COUNT(time_limit_); @@ -2159,7 +2154,6 @@ void SingletonPreprocessor::DeleteSingletonRow(MatrixEntry e, ? implied_upper_bound : old_upper_bound; - if (new_upper_bound < new_lower_bound) { if (!IsSmallerWithinFeasibilityTolerance(new_lower_bound, new_upper_bound)) { @@ -2270,7 +2264,6 @@ void SingletonPreprocessor::UpdateConstraintBoundsWithVariableBounds( lp->constraint_upper_bounds()[e.row] + upper_delta); } - void SingletonPreprocessor::DeleteZeroCostSingletonColumn( const SparseMatrix& transpose, MatrixEntry e, LinearProgram* lp) { const ColIndex transpose_col = RowToColIndex(e.row); @@ -2922,7 +2915,6 @@ bool DoubletonEqualityRowPreprocessor::Run(LinearProgram* lp) { continue; } - // Look at the bounds of both variables and exit early if we can delegate // to another pre-processor; otherwise adjust the bounds of the remaining // variable as necessary. @@ -2945,7 +2937,6 @@ bool DoubletonEqualityRowPreprocessor::Run(LinearProgram* lp) { break; } - Fractional lb = r.lb[MODIFIED]; Fractional ub = r.ub[MODIFIED]; Fractional carried_over_lb = @@ -2962,8 +2953,9 @@ bool DoubletonEqualityRowPreprocessor::Run(LinearProgram* lp) { } else { lb = carried_over_lb; r.bound_backtracking_at_lower_bound = RestoreInfo::ColChoiceAndStatus( - DELETED, carry_over_factor > 0 ? VariableStatus::AT_LOWER_BOUND - : VariableStatus::AT_UPPER_BOUND, + DELETED, + carry_over_factor > 0 ? VariableStatus::AT_LOWER_BOUND + : VariableStatus::AT_UPPER_BOUND, carry_over_factor > 0 ? r.lb[DELETED] : r.ub[DELETED]); } if (carried_over_ub >= ub) { @@ -2973,8 +2965,9 @@ bool DoubletonEqualityRowPreprocessor::Run(LinearProgram* lp) { } else { ub = carried_over_ub; r.bound_backtracking_at_upper_bound = RestoreInfo::ColChoiceAndStatus( - DELETED, carry_over_factor > 0 ? VariableStatus::AT_UPPER_BOUND - : VariableStatus::AT_LOWER_BOUND, + DELETED, + carry_over_factor > 0 ? VariableStatus::AT_UPPER_BOUND + : VariableStatus::AT_LOWER_BOUND, carry_over_factor > 0 ? r.ub[DELETED] : r.lb[DELETED]); } // 3) If the new bounds are fixed (the domain is a singleton) or @@ -3489,7 +3482,6 @@ bool ScalingPreprocessor::Run(LinearProgram* lp) { cost_scaling_factor_ = lp->ScaleObjective(); bound_scaling_factor_ = lp->ScaleBounds(); - return true; } @@ -3604,14 +3596,14 @@ void AddSlackVariablesPreprocessor::RecoverSolution( // -------------------------------------------------------- bool SolowHalimPreprocessor::Run(LinearProgram* lp) { RETURN_VALUE_IF_NULL(lp, false); - if (!parameters_.use_solowhalim()){ + if (!parameters_.use_solowhalim()) { return false; } // mip context not implemented // TODO : in order to manage mip context we must take care // of truncated offsets - if (in_mip_context_){ + if (in_mip_context_) { return false; } @@ -3633,20 +3625,20 @@ bool SolowHalimPreprocessor::Run(LinearProgram* lp) { column_transform_.resize(num_cols.value(), NOT_MODIFIED); for (ColIndex col(0); col < num_cols; ++col) { const Fractional coeff = lp->objective_coefficients()[col]; - if (coeff != 0.0){ + if (coeff != 0.0) { bool coeff_opposite_direction = - ( (coeff < 0.0 && !lp_is_maximization_problem) || - (coeff > 0.0 && lp_is_maximization_problem)); + ((coeff < 0.0 && !lp_is_maximization_problem) || + (coeff > 0.0 && lp_is_maximization_problem)); const Fractional ub = lp->variable_upper_bounds()[col]; const Fractional lb = lp->variable_lower_bounds()[col]; - if (IsFinite(ub) && IsFinite(lb)){ + if (IsFinite(ub) && IsFinite(lb)) { ColumnTransformType column_transform = NOT_MODIFIED; double shift_value = 0.0; if (coeff_opposite_direction) { SparseColumn* mutable_sparse_column = lp->GetMutableSparseColumn(col); - for (const SparseColumn::Entry e : (*mutable_sparse_column) ) { + for (const SparseColumn::Entry e : (*mutable_sparse_column)) { row_offsets[e.row()].Add(e.coefficient() * ub); } mutable_sparse_column->MultiplyByConstant(-1); @@ -3664,7 +3656,7 @@ bool SolowHalimPreprocessor::Run(LinearProgram* lp) { num_shifted_cols++; } - if (column_transform != NOT_MODIFIED){ + if (column_transform != NOT_MODIFIED) { column_transform_[col] = column_transform; objective_offset.Add(coeff * shift_value); lp->SetVariableBounds(col, 0, ub - lb); @@ -3691,14 +3683,13 @@ void SolowHalimPreprocessor::RecoverSolution(ProblemSolution* solution) const { RETURN_IF_NULL(solution); const ColIndex num_cols = solution->variable_statuses.size(); for (ColIndex col(0); col < num_cols; ++col) { - VLOG(2) << "col = " << col << "\t" << column_transform_[col]; - VLOG(2) << "\tinitial range : \t [" << variable_initial_lbs_[col] - << " ; " << variable_initial_ubs_[col] << "]"; - VLOG(2) << "\tstatus : " << solution->variable_statuses[col] + VLOG(2) << "\tinitial range : \t [" << variable_initial_lbs_[col] << " ; " + << variable_initial_ubs_[col] << "]"; + VLOG(2) << "\tstatus : " << solution->variable_statuses[col] << "\t raw value : " << solution->primal_values[col]; - switch (column_transform_[col]){ + switch (column_transform_[col]) { case NOT_MODIFIED: break; case SHIFTED: @@ -3711,7 +3702,7 @@ void SolowHalimPreprocessor::RecoverSolution(ProblemSolution* solution) const { break; case VariableStatus::BASIC: solution->primal_values[col] = - variable_initial_lbs_[col] + solution->primal_values[col]; + variable_initial_lbs_[col] + solution->primal_values[col]; break; case VariableStatus::FIXED_VALUE: FALLTHROUGH_INTENDED; @@ -3731,7 +3722,7 @@ void SolowHalimPreprocessor::RecoverSolution(ProblemSolution* solution) const { break; case VariableStatus::BASIC: solution->primal_values[col] = - variable_initial_ubs_[col] - solution->primal_values[col]; + variable_initial_ubs_[col] - solution->primal_values[col]; break; case VariableStatus::FIXED_VALUE: FALLTHROUGH_INTENDED; @@ -3741,7 +3732,6 @@ void SolowHalimPreprocessor::RecoverSolution(ProblemSolution* solution) const { break; } VLOG(2) << " recover value : " << solution->primal_values[col]; - } } diff --git a/ortools/glop/preprocessor.h b/ortools/glop/preprocessor.h index 66d8c79fcd2..87367e3069f 100644 --- a/ortools/glop/preprocessor.h +++ b/ortools/glop/preprocessor.h @@ -416,7 +416,6 @@ class SingletonPreprocessor : public Preprocessor { void UpdateConstraintBoundsWithVariableBounds(MatrixEntry e, LinearProgram* lp); - // A singleton column with a cost of zero can always be removed by changing // the corresponding constraint bounds to take into acount the bound of this // singleton column. @@ -620,7 +619,6 @@ class DoubletonFreeColumnPreprocessor : public Preprocessor { SparseColumn deleted_row_as_column; }; - std::vector restore_stack_; RowDeletionHelper row_deletion_helper_; DISALLOW_COPY_AND_ASSIGN(DoubletonFreeColumnPreprocessor); diff --git a/ortools/glop/revised_simplex.cc b/ortools/glop/revised_simplex.cc index 13283b1241b..51695bd92ee 100644 --- a/ortools/glop/revised_simplex.cc +++ b/ortools/glop/revised_simplex.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/glop/revised_simplex.h" #include @@ -24,9 +23,8 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" #include "ortools/glop/initial_basis.h" #include "ortools/glop/parameters.pb.h" @@ -2884,12 +2882,14 @@ void RevisedSimplex::DisplayErrors() const { namespace { -std::string StringifyMonomialWithFlags(const Fractional a, const std::string& x) { +std::string StringifyMonomialWithFlags(const Fractional a, + const std::string& x) { return StringifyMonomial(a, x, FLAGS_simplex_display_numbers_as_fractions); } -// Returns a std::string representing the rational approximation of x or a decimal -// approximation of x according to FLAGS_simplex_display_numbers_as_fractions. +// Returns a std::string representing the rational approximation of x or a +// decimal approximation of x according to +// FLAGS_simplex_display_numbers_as_fractions. std::string StringifyWithFlags(const Fractional x) { return Stringify(x, FLAGS_simplex_display_numbers_as_fractions); } @@ -2950,9 +2950,8 @@ void RevisedSimplex::DisplayVariableBounds() { VLOG(3) << variable_name_[col] << " = " << StringifyWithFlags(lower_bound_[col]) << ";"; break; - default: // This should never happen. - LOG(DFATAL) << "Column " << col - << " has no meaningful status."; + default: // This should never happen. + LOG(DFATAL) << "Column " << col << " has no meaningful status."; break; } } diff --git a/ortools/glop/revised_simplex.h b/ortools/glop/revised_simplex.h index b85e8376821..1b7450976e8 100644 --- a/ortools/glop/revised_simplex.h +++ b/ortools/glop/revised_simplex.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Solves a Linear Programing problem using the Revised Simplex algorithm // as described by G.B. Dantzig. // The general form is: @@ -242,8 +241,8 @@ class RevisedSimplex { // contructor though. void PropagateParameters(); - // Returns a std::string containing the same information as with GetSolverStats, - // but in a much more human-readable format. For example: + // Returns a std::string containing the same information as with + // GetSolverStats, but in a much more human-readable format. For example: // Problem status : Optimal // Solving time : 1.843 // Number of iterations : 12345 @@ -260,7 +259,8 @@ class RevisedSimplex { // corresponding to column col. std::string SimpleVariableInfo(ColIndex col) const; - // Displays a short std::string with the current iteration and objective value. + // Displays a short std::string with the current iteration and objective + // value. void DisplayIterationInfo() const; // Displays the error bounds of the current solution. @@ -469,9 +469,9 @@ class RevisedSimplex { // along this dual edge. // - target_bound: the bound at which the leaving variable should go when // leaving the basis. - Status DualChooseLeavingVariableRow( - RowIndex* leaving_row, Fractional* cost_variation, - Fractional* target_bound) MUST_USE_RESULT; + Status DualChooseLeavingVariableRow(RowIndex* leaving_row, + Fractional* cost_variation, + Fractional* target_bound) MUST_USE_RESULT; // Updates the prices used by DualChooseLeavingVariableRow() after a simplex // iteration by using direction_. The prices are stored in diff --git a/ortools/glop/status.h b/ortools/glop/status.h index a5680e48775..9a314ee50be 100644 --- a/ortools/glop/status.h +++ b/ortools/glop/status.h @@ -77,18 +77,18 @@ std::string GetErrorCodeString(Status::ErrorCode error_code); // Macro to simplify the creation of an error. #define GLOP_RETURN_AND_LOG_ERROR(error_code, message) \ do { \ - const std::string error_message = message; \ + const std::string error_message = message; \ LOG(ERROR) << GetErrorCodeString(error_code) << ": " << error_message; \ return Status(error_code, error_message); \ } while (false) // Macro to check that a pointer argument is not null. -#define GLOP_RETURN_ERROR_IF_NULL(arg) \ - if (arg == nullptr) { \ +#define GLOP_RETURN_ERROR_IF_NULL(arg) \ + if (arg == nullptr) { \ const std::string variable_name = #arg; \ const std::string error_message = variable_name + " must not be null."; \ - LOG(DFATAL) << error_message; \ - return Status(Status::ERROR_NULL, error_message); \ + LOG(DFATAL) << error_message; \ + return Status(Status::ERROR_NULL, error_message); \ } } // namespace glop diff --git a/ortools/graph/astar.cc b/ortools/graph/astar.cc index 83393d96851..29508dba279 100644 --- a/ortools/graph/astar.cc +++ b/ortools/graph/astar.cc @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - +#include #include #include -#include #include +#include "ortools/base/adjustable_priority_queue.h" #include "ortools/base/callback.h" #include "ortools/base/integral_types.h" -#include "ortools/base/adjustable_priority_queue.h" namespace operations_research { namespace { @@ -27,7 +26,8 @@ namespace { // Priority queue element class Element { public: - Element() : heap_index_(-1), distance_(0), node_(-1), distance_with_heuristic_(0) {} + Element() + : heap_index_(-1), distance_(0), node_(-1), distance_with_heuristic_(0) {} // The distance_with_heuristic is used for the comparison // in the priority queue @@ -37,8 +37,9 @@ class Element { void SetHeapIndex(int h) { heap_index_ = h; } int GetHeapIndex() const { return heap_index_; } void set_distance(int64 distance) { distance_ = distance; } - void set_distance_with_heuristic(int64 distance_with_heuristic) - { distance_with_heuristic_ = distance_with_heuristic; } + void set_distance_with_heuristic(int64 distance_with_heuristic) { + distance_with_heuristic_ = distance_with_heuristic; + } int64 distance_with_heuristic() { return distance_with_heuristic_; } int64 distance() const { return distance_; } @@ -57,10 +58,8 @@ class AStarSP { public: static const int64 kInfinity = kint64max / 2; - AStarSP(int node_count, int start_node, - std::function graph, - std::function heuristic, - int64 disconnected_distance) + AStarSP(int node_count, int start_node, std::function graph, + std::function heuristic, int64 disconnected_distance) : node_count_(node_count), start_node_(start_node), graph_(std::move(graph)), diff --git a/ortools/graph/bellman_ford.cc b/ortools/graph/bellman_ford.cc index c551270eb9b..2aaab0f230d 100644 --- a/ortools/graph/bellman_ford.cc +++ b/ortools/graph/bellman_ford.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include #include #include diff --git a/ortools/graph/christofides.h b/ortools/graph/christofides.h index 6353fe0d08c..fef2798b153 100644 --- a/ortools/graph/christofides.h +++ b/ortools/graph/christofides.h @@ -24,8 +24,8 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/graph/graph.h" #include "ortools/graph/eulerian_path.h" +#include "ortools/graph/graph.h" #include "ortools/graph/minimum_spanning_tree.h" #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" @@ -40,9 +40,9 @@ template ComputeMinimumWeightMatchingWithMIP( } } } - #if defined(USE_SCIP) +#if defined(USE_SCIP) MPSolver mp_solver("MatchingWithSCIP", MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); - #elif defined(USE_CBC) - MPSolver mp_solver("MatchingWithCBC", - MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); - #endif +#elif defined(USE_CBC) + MPSolver mp_solver("MatchingWithCBC", + MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); +#endif std::string error; mp_solver.LoadModelFromProto(model, &error); MPSolver::ResultStatus status = mp_solver.Solve(); @@ -228,7 +228,7 @@ void ChristofidesPathSolver reduced_graph(reduced_size); std::vector closure_arcs; switch (matching_) { - #if defined(USE_CBC) || defined(USE_SCIP) +#if defined(USE_CBC) || defined(USE_SCIP) case MatchingAlgorithm::MINIMUM_WEIGHT_MATCHING: { closure_arcs = ComputeMinimumWeightMatchingWithMIP( reduced_graph, [this, &reduced_graph, @@ -238,7 +238,7 @@ void ChristofidesPathSolver -#include #include +#include #include #include @@ -248,7 +247,9 @@ void CoverArcsByCliques(std::function graph, int node_count, return cache.GraphCallback(i, j); }; std::function&)> cached_callback = - [&cache](const std::vector& res) { return cache.SolutionCallback(res); }; + [&cache](const std::vector& res) { + return cache.SolutionCallback(res); + }; for (int c = 0; c < node_count; ++c) { initial_candidates[c] = c; diff --git a/ortools/graph/cliques.h b/ortools/graph/cliques.h index d838b052f45..8c9d953d79b 100644 --- a/ortools/graph/cliques.h +++ b/ortools/graph/cliques.h @@ -25,14 +25,14 @@ #define OR_TOOLS_GRAPH_CLIQUES_H_ #include -#include #include +#include #include -#include "ortools/base/logging.h" -#include "ortools/base/join.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/util/time_limit.h" namespace operations_research { @@ -82,7 +82,8 @@ enum class BronKerboschAlgorithmStatus { // // Typical usage: // auto graph = [](int node1, int node2) { return true; }; -// auto on_clique = [](const std::vector& clique) { LOG(INFO) << "Clique!"; }; +// auto on_clique = [](const std::vector& clique) { LOG(INFO) << "Clique!"; +// }; // // BronKerboschAlgorithm bron_kerbosch(graph, num_nodes, on_clique); // bron_kerbosch.Run(); @@ -387,8 +388,9 @@ void BronKerboschAlgorithm::InitializeState(State* state) { } template -typename BronKerboschAlgorithm::CandidateIndex BronKerboschAlgorithm< - NodeIndex>::SelectCandidateIndexForRecursion(State* state) { +typename BronKerboschAlgorithm::CandidateIndex +BronKerboschAlgorithm::SelectCandidateIndexForRecursion( + State* state) { DCHECK(state != nullptr); CandidateIndex disconnected_node_index = std::max(state->first_candidate_index, state->candidate_for_recursion); diff --git a/ortools/graph/connectivity.h b/ortools/graph/connectivity.h index 95eafb8f80d..6423e1f25bd 100644 --- a/ortools/graph/connectivity.h +++ b/ortools/graph/connectivity.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Graph connectivity algorithm for undirected graphs. // Memory consumption: O(n) where m is the number of arcs and n the number // of nodes. diff --git a/ortools/graph/dijkstra.cc b/ortools/graph/dijkstra.cc index e3303e352d9..975d2f8f4e0 100644 --- a/ortools/graph/dijkstra.cc +++ b/ortools/graph/dijkstra.cc @@ -11,14 +11,13 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include -#include #include +#include #include -#include "ortools/base/integral_types.h" #include "ortools/base/adjustable_priority_queue.h" +#include "ortools/base/integral_types.h" namespace operations_research { namespace { diff --git a/ortools/graph/ebert_graph.h b/ortools/graph/ebert_graph.h index d1c8553318a..f63c7d659ee 100644 --- a/ortools/graph/ebert_graph.h +++ b/ortools/graph/ebert_graph.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_GRAPH_EBERT_GRAPH_H_ #define OR_TOOLS_GRAPH_EBERT_GRAPH_H_ @@ -176,10 +175,10 @@ #include #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/util/permutation.h" #include "ortools/util/zvector.h" @@ -537,7 +536,8 @@ class ForwardStaticGraph : public StarGraphBase > { typedef StarGraphBase > Base; + ForwardStaticGraph > + Base; friend class StarGraphBase >; @@ -1188,7 +1188,8 @@ class EbertGraph : public EbertGraphBase > { typedef EbertGraphBase > Base; + EbertGraph > + Base; friend class EbertGraphBase >; friend class StarGraphBase > { typedef EbertGraphBase > Base; + ForwardEbertGraph > + Base; friend class EbertGraphBase >; friend class StarGraphBase std::vector BuildEulerianPathFromNode(const Graph& graph, - NodeIndex root) { + NodeIndex root) { typedef typename Graph::ArcIndex ArcIndex; std::vector unvisited_edges(graph.num_arcs(), true); std::vector tour; @@ -114,7 +114,7 @@ std::vector BuildEulerianPathFromNode(const Graph& graph, // As of 10/2015, assumes the graph is connected. template std::vector BuildEulerianTourFromNode(const Graph& graph, - NodeIndex root) { + NodeIndex root) { std::vector tour; if (IsEulerianGraph(graph)) { tour = BuildEulerianPathFromNode(graph, root); diff --git a/ortools/graph/graph.h b/ortools/graph/graph.h index 0ac36f92d7b..666250f1f4b 100644 --- a/ortools/graph/graph.h +++ b/ortools/graph/graph.h @@ -169,7 +169,6 @@ #include "ortools/base/port.h" #include "ortools/graph/iterators.h" - namespace util { // Forward declaration. @@ -299,11 +298,11 @@ class BaseGraph { template class ListGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: using Base::IsArcValid; @@ -399,11 +398,11 @@ class ListGraph : public BaseGraph { template class StaticGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: using Base::IsArcValid; @@ -464,11 +463,11 @@ template class ReverseArcListGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: using Base::IsArcValid; @@ -548,11 +547,11 @@ template class ReverseArcStaticGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: using Base::IsArcValid; @@ -632,11 +631,11 @@ template class ReverseArcMixedGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: using Base::IsArcValid; @@ -1627,8 +1626,9 @@ ArcIndexType ReverseArcStaticGraph::InDegree( } template -BeginEndWrapper ReverseArcStaticGraph< - NodeIndexType, ArcIndexType>::operator[](NodeIndexType node) const { +BeginEndWrapper + ReverseArcStaticGraph::operator[]( + NodeIndexType node) const { return BeginEndWrapper( head_.data() + start_[node], head_.data() + DirectArcLimit(node)); } @@ -1863,8 +1863,9 @@ ArcIndexType ReverseArcMixedGraph::InDegree( } template -BeginEndWrapper ReverseArcMixedGraph< - NodeIndexType, ArcIndexType>::operator[](NodeIndexType node) const { +BeginEndWrapper + ReverseArcMixedGraph::operator[]( + NodeIndexType node) const { return BeginEndWrapper( head_.data() + start_[node], head_.data() + DirectArcLimit(node)); } @@ -2064,11 +2065,11 @@ class ReverseArcMixedGraph< template class CompleteGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: // Builds a complete graph with num_nodes nodes. @@ -2109,8 +2110,9 @@ ArcIndexType CompleteGraph::OutDegree( } template -IntegerRange CompleteGraph< - NodeIndexType, ArcIndexType>::OutgoingArcs(NodeIndexType node) const { +IntegerRange +CompleteGraph::OutgoingArcs( + NodeIndexType node) const { DCHECK_LT(node, num_nodes_); return IntegerRange( static_cast(num_nodes_) * node, @@ -2140,11 +2142,11 @@ template class CompleteBipartiteGraph : public BaseGraph { typedef BaseGraph Base; - using Base::num_arcs_; - using Base::num_nodes_; using Base::arc_capacity_; - using Base::node_capacity_; using Base::const_capacities_; + using Base::node_capacity_; + using Base::num_arcs_; + using Base::num_nodes_; public: // Builds a complete bipartite graph from a set of left nodes to a set of @@ -2210,8 +2212,9 @@ ArcIndexType CompleteBipartiteGraph::OutDegree( } template -IntegerRange CompleteBipartiteGraph< - NodeIndexType, ArcIndexType>::OutgoingArcs(NodeIndexType node) const { +IntegerRange +CompleteBipartiteGraph::OutgoingArcs( + NodeIndexType node) const { if (node < left_nodes_) { return IntegerRange(right_nodes_ * node, right_nodes_ * (node + 1)); @@ -2232,8 +2235,9 @@ CompleteBipartiteGraph::OutgoingArcsStartingFrom( } template -IntegerRange CompleteBipartiteGraph< - NodeIndexType, ArcIndexType>::operator[](NodeIndexType node) const { +IntegerRange + CompleteBipartiteGraph::operator[]( + NodeIndexType node) const { if (node < left_nodes_) { return IntegerRange(left_nodes_, left_nodes_ + right_nodes_); } else { diff --git a/ortools/graph/hamiltonian_path.h b/ortools/graph/hamiltonian_path.h index abbdb5bc244..31e90ee4df5 100644 --- a/ortools/graph/hamiltonian_path.h +++ b/ortools/graph/hamiltonian_path.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_GRAPH_HAMILTONIAN_PATH_H_ #define OR_TOOLS_GRAPH_HAMILTONIAN_PATH_H_ @@ -798,9 +797,9 @@ bool HamiltonianPathSolver::IsRobust() { } // We determine if the range of the cost matrix is going to // make the algorithm not robust because of precision issues. - robust_ = min_cost >= 0 && - min_cost > num_nodes_ * max_cost * - std::numeric_limits::epsilon(); + robust_ = + min_cost >= 0 && min_cost > num_nodes_ * max_cost * + std::numeric_limits::epsilon(); robustness_checked_ = true; return robust_; } diff --git a/ortools/graph/io.h b/ortools/graph/io.h index 6bb6f00b818..3594c3fa61a 100644 --- a/ortools/graph/io.h +++ b/ortools/graph/io.h @@ -26,12 +26,10 @@ #include "ortools/base/join.h" #include "ortools/base/numbers.h" #include "ortools/base/split.h" -#include "ortools/base/join.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" -#include "ortools/graph/graph.h" #include "ortools/base/status.h" #include "ortools/base/statusor.h" +#include "ortools/base/stringprintf.h" +#include "ortools/graph/graph.h" namespace util { diff --git a/ortools/graph/linear_assignment.cc b/ortools/graph/linear_assignment.cc index 72caf63601e..1e95bfd5207 100644 --- a/ortools/graph/linear_assignment.cc +++ b/ortools/graph/linear_assignment.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/graph/linear_assignment.h" #include "ortools/base/commandlineflags.h" diff --git a/ortools/graph/linear_assignment.h b/ortools/graph/linear_assignment.h index 23ea65619a3..78a52f05ed3 100644 --- a/ortools/graph/linear_assignment.h +++ b/ortools/graph/linear_assignment.h @@ -209,7 +209,6 @@ #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #include "ortools/graph/ebert_graph.h" #include "ortools/util/permutation.h" #include "ortools/util/zvector.h" @@ -261,7 +260,7 @@ class LinearSumAssignment { // Passes ownership of the cycle handler to the caller. // operations_research::PermutationCycleHandler* - ArcAnnotationCycleHandler(); + ArcAnnotationCycleHandler(); // Optimizes the layout of the graph for the access pattern our // implementation will use. @@ -1122,8 +1121,8 @@ bool LinearSumAssignment::UpdateEpsilon() { // For production code that checks whether a left-side node is active. template -inline bool LinearSumAssignment::IsActive(NodeIndex left_node) - const { +inline bool LinearSumAssignment::IsActive( + NodeIndex left_node) const { DCHECK_LT(left_node, num_left_nodes_); return matched_arc_[left_node] == GraphType::kNilArc; } @@ -1132,8 +1131,8 @@ inline bool LinearSumAssignment::IsActive(NodeIndex left_node) // so that method can assert that its argument is a left-side node, // while for debugging we need to be able to test any node. template -inline bool LinearSumAssignment::IsActiveForDebugging(NodeIndex node) - const { +inline bool LinearSumAssignment::IsActiveForDebugging( + NodeIndex node) const { if (node < num_left_nodes_) { return IsActive(node); } else { @@ -1266,8 +1265,8 @@ bool LinearSumAssignment::Refine() { template inline typename LinearSumAssignment::ImplicitPriceSummary LinearSumAssignment::BestArcAndGap(NodeIndex left_node) const { - DCHECK(IsActive(left_node)) << "Node " << left_node - << " must be active (unmatched)!"; + DCHECK(IsActive(left_node)) + << "Node " << left_node << " must be active (unmatched)!"; DCHECK_GT(epsilon_, 0); typename GraphType::OutgoingArcIterator arc_it(*graph_, left_node); ArcIndex best_arc = arc_it.Index(); diff --git a/ortools/graph/max_flow.cc b/ortools/graph/max_flow.cc index c7ac496536b..73e570f15c0 100644 --- a/ortools/graph/max_flow.cc +++ b/ortools/graph/max_flow.cc @@ -11,12 +11,10 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/graph/max_flow.h" #include -#include "ortools/base/stringprintf.h" #include "ortools/base/stringprintf.h" #include "ortools/graph/graph.h" #include "ortools/graph/graphs.h" @@ -317,7 +315,7 @@ bool GenericMaxFlow::CheckRelabelPrecondition(NodeIndex node) const { template std::string GenericMaxFlow::DebugString(const std::string& context, - ArcIndex arc) const { + ArcIndex arc) const { const NodeIndex tail = Tail(arc); const NodeIndex head = Head(arc); return absl::StrFormat( diff --git a/ortools/graph/max_flow.h b/ortools/graph/max_flow.h index 8ec8bf2d642..25fc3a7e2e6 100644 --- a/ortools/graph/max_flow.h +++ b/ortools/graph/max_flow.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // An implementation of a push-relabel algorithm for the max flow problem. // // In the following, we consider a graph G = (V,E,s,t) where V denotes the set @@ -132,9 +131,9 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/graph/graph.h" #include "ortools/graph/ebert_graph.h" #include "ortools/graph/flow_problem.pb.h" +#include "ortools/graph/graph.h" #include "ortools/util/stats.h" #include "ortools/util/zvector.h" diff --git a/ortools/graph/min_cost_flow.cc b/ortools/graph/min_cost_flow.cc index c75e818babf..9a871ca2cda 100644 --- a/ortools/graph/min_cost_flow.cc +++ b/ortools/graph/min_cost_flow.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/graph/min_cost_flow.h" #include @@ -19,10 +18,9 @@ #include #include "ortools/base/commandlineflags.h" -#include "ortools/base/stringprintf.h" +#include "ortools/base/mathutil.h" #include "ortools/base/stringprintf.h" #include "ortools/graph/graph.h" -#include "ortools/base/mathutil.h" #include "ortools/graph/graphs.h" #include "ortools/graph/max_flow.h" @@ -245,9 +243,8 @@ bool GenericMinCostFlow::CheckCostRange() } template -bool GenericMinCostFlow< - Graph, ArcFlowType, - ArcScaledCostType>::CheckRelabelPrecondition(NodeIndex node) const { +bool GenericMinCostFlow:: + CheckRelabelPrecondition(NodeIndex node) const { // Note that the classical Relabel precondition assumes IsActive(node), i.e., // the node_excess_[node] > 0. However, to implement the Push Look-Ahead // heuristic, we can relax this condition as explained in the section 4.3 of @@ -264,7 +261,8 @@ bool GenericMinCostFlow< } template -std::string GenericMinCostFlow::DebugString( +std::string +GenericMinCostFlow::DebugString( const std::string& context, ArcIndex arc) const { const NodeIndex tail = Tail(arc); const NodeIndex head = Head(arc); @@ -288,10 +286,9 @@ std::string GenericMinCostFlow::DebugStri } template -bool -GenericMinCostFlow::CheckFeasibility( - std::vector* const infeasible_supply_node, - std::vector* const infeasible_demand_node) { +bool GenericMinCostFlow:: + CheckFeasibility(std::vector* const infeasible_supply_node, + std::vector* const infeasible_demand_node) { SCOPED_TIME_STAT(&stats_); // Create a new graph, which is a copy of graph_, with the following // modifications: @@ -401,8 +398,9 @@ FlowQuantity GenericMinCostFlow::Flow( // We use the equations given in the comment of residual_arc_capacity_. template -FlowQuantity GenericMinCostFlow< - Graph, ArcFlowType, ArcScaledCostType>::Capacity(ArcIndex arc) const { +FlowQuantity +GenericMinCostFlow::Capacity( + ArcIndex arc) const { if (IsArcDirect(arc)) { return residual_arc_capacity_[arc] + residual_arc_capacity_[Opposite(arc)]; } else { @@ -426,16 +424,16 @@ FlowQuantity GenericMinCostFlow::Supply( } template -FlowQuantity GenericMinCostFlow< - Graph, ArcFlowType, ArcScaledCostType>::InitialSupply(NodeIndex node) - const { +FlowQuantity +GenericMinCostFlow::InitialSupply( + NodeIndex node) const { return initial_node_excess_[node]; } template -FlowQuantity GenericMinCostFlow< - Graph, ArcFlowType, ArcScaledCostType>::FeasibleSupply(NodeIndex node) - const { +FlowQuantity +GenericMinCostFlow::FeasibleSupply( + NodeIndex node) const { return feasible_node_excess_[node]; } @@ -446,9 +444,8 @@ bool GenericMinCostFlow::IsAdmissible( } template -bool -GenericMinCostFlow::FastIsAdmissible( - ArcIndex arc, CostValue tail_potential) const { +bool GenericMinCostFlow:: + FastIsAdmissible(ArcIndex arc, CostValue tail_potential) const { DCHECK_EQ(node_potential_[Tail(arc)], tail_potential); return residual_arc_capacity_[arc] > 0 && FastReducedCost(arc, tail_potential) < 0; @@ -461,8 +458,9 @@ bool GenericMinCostFlow::IsActive( } template -CostValue GenericMinCostFlow< - Graph, ArcFlowType, ArcScaledCostType>::ReducedCost(ArcIndex arc) const { +CostValue +GenericMinCostFlow::ReducedCost( + ArcIndex arc) const { return FastReducedCost(arc, node_potential_[Tail(arc)]); } @@ -956,8 +954,9 @@ void GenericMinCostFlow::Relabel( } template -typename Graph::ArcIndex GenericMinCostFlow< - Graph, ArcFlowType, ArcScaledCostType>::Opposite(ArcIndex arc) const { +typename Graph::ArcIndex +GenericMinCostFlow::Opposite( + ArcIndex arc) const { return Graphs::OppositeArc(*graph_, arc); } diff --git a/ortools/graph/min_cost_flow.h b/ortools/graph/min_cost_flow.h index 41d3d98b76f..6ba48c09cdb 100644 --- a/ortools/graph/min_cost_flow.h +++ b/ortools/graph/min_cost_flow.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // An implementation of a cost-scaling push-relabel algorithm for // the min-cost flow problem. // @@ -177,8 +176,8 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/graph/graph.h" #include "ortools/graph/ebert_graph.h" +#include "ortools/graph/graph.h" #include "ortools/util/stats.h" #include "ortools/util/zvector.h" @@ -278,10 +277,7 @@ class SimpleMinCostFlow : public MinCostFlowBase { private: typedef ::util::ReverseArcStaticGraph Graph; - enum SupplyAdjustment { - ADJUST, - DONT_ADJUST - }; + enum SupplyAdjustment { ADJUST, DONT_ADJUST }; // Applies the permutation in arc_permutation_ to the given arc index. ArcIndex PermutedArc(ArcIndex arc); diff --git a/ortools/graph/minimum_spanning_tree.h b/ortools/graph/minimum_spanning_tree.h index f4477baf015..1320a32dc53 100644 --- a/ortools/graph/minimum_spanning_tree.h +++ b/ortools/graph/minimum_spanning_tree.h @@ -17,11 +17,11 @@ #include #include +#include "ortools/base/adjustable_priority_queue-inl.h" +#include "ortools/base/adjustable_priority_queue.h" #include "ortools/base/integral_types.h" #include "ortools/graph/connectivity.h" #include "ortools/util/vector_or_function.h" -#include "ortools/base/adjustable_priority_queue-inl.h" -#include "ortools/base/adjustable_priority_queue.h" namespace operations_research { diff --git a/ortools/graph/shortestpaths.cc b/ortools/graph/shortestpaths.cc index 22aabfc1d01..447a384ed6e 100644 --- a/ortools/graph/shortestpaths.cc +++ b/ortools/graph/shortestpaths.cc @@ -11,14 +11,13 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/graph/shortestpaths.h" #include #include #include -#include #include +#include #include #include "ortools/base/commandlineflags.h" diff --git a/ortools/graph/shortestpaths.h b/ortools/graph/shortestpaths.h index f2f1b88d608..619d4b8af96 100644 --- a/ortools/graph/shortestpaths.h +++ b/ortools/graph/shortestpaths.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // This file contains various shortest paths utilities. // // Keywords: directed graph, cheapest path, shortest path, Dijkstra, spp. diff --git a/ortools/graph/strongly_connected_components.h b/ortools/graph/strongly_connected_components.h index 7b076a4c328..9cc211f4b5a 100644 --- a/ortools/graph/strongly_connected_components.h +++ b/ortools/graph/strongly_connected_components.h @@ -23,9 +23,9 @@ // // SIMPLE EXAMPLE: // -// Fill a std::vector> graph; representing your graph adjacency lists. -// That is, graph[i] contains the nodes adjacent to node #i. The nodes must be -// integers in [0, num_nodes). Then just do: +// Fill a std::vector> graph; representing your graph adjacency +// lists. That is, graph[i] contains the nodes adjacent to node #i. The nodes +// must be integers in [0, num_nodes). Then just do: // // std::vector> components; // FindStronglyConnectedComponents( @@ -68,25 +68,26 @@ // - It is really fast! and work in O(nodes + edges). // - Its memory usage is also bounded by O(nodes + edges) but in practice it // uses less than the input graph. -template +template void FindStronglyConnectedComponents(const NodeIndex num_nodes, - const Graph& graph, - SccOutput* components); + const Graph& graph, SccOutput* components); // A simple custom output class that just counts the number of SCC. Not // allocating many vectors can save both space and speed if your graph is large. // -// Note: If this matters, you probably don't want to use std::vector> as -// an input either. See StaticGraph in ortools/graph/graph.h -// for an efficient graph data structure compatible with this algorithm. -template +// Note: If this matters, you probably don't want to use +// std::vector> as an input either. See StaticGraph in +// ortools/graph/graph.h for an efficient graph data structure compatible with +// this algorithm. +template struct SccCounterOutput { int number_of_components = 0; void emplace_back(NodeIndex const* b, NodeIndex const* e) { ++number_of_components; } // This is just here so this class can transparently replace a code that - // use std::vector> as an SccOutput, and get its size with size(). + // use std::vector> as an SccOutput, and get its size with + // size(). int size() const { return number_of_components; } }; @@ -100,7 +101,7 @@ struct SccCounterOutput { // - For a client needing many Scc computations one after another, it could be // better to wrap this in a class so we don't need to allocate the stacks at // each computation. -template +template void FindStronglyConnectedComponents(const NodeIndex num_nodes, const Graph& graph, SccOutput* components) { diff --git a/ortools/graph/util.h b/ortools/graph/util.h index 8624e6bfcbb..d9472612097 100644 --- a/ortools/graph/util.h +++ b/ortools/graph/util.h @@ -17,18 +17,18 @@ #define UTIL_GRAPH_UTIL_H_ #include -#include -#include #include #include #include #include +#include +#include #include +#include "ortools/base/hash.h" +#include "ortools/base/map_util.h" #include "ortools/graph/connected_components.h" #include "ortools/graph/graph.h" -#include "ortools/base/map_util.h" -#include "ortools/base/hash.h" namespace util { @@ -331,7 +331,8 @@ template std::vector ComputeOnePossibleReverseArcMapping( const Graph& graph, bool die_if_not_symmetric) { std::vector reverse_arc(graph.num_arcs(), -1); - std::unordered_multimap, /*arc index*/ int> + std::unordered_multimap, + /*arc index*/ int> arc_map; for (int arc = 0; arc < graph.num_arcs(); ++arc) { const int tail = graph.Tail(arc); diff --git a/ortools/linear_solver/bop_interface.cc b/ortools/linear_solver/bop_interface.cc index c13870bf42c..576d84998c4 100644 --- a/ortools/linear_solver/bop_interface.cc +++ b/ortools/linear_solver/bop_interface.cc @@ -11,18 +11,18 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include -#include +#include "google/protobuf/text_format.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/file.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" -#include "google/protobuf/text_format.h" #include "ortools/base/port.h" -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/bop/bop_parameters.pb.h" #include "ortools/bop/integral_solver.h" #include "ortools/linear_solver/linear_solver.h" @@ -103,7 +103,8 @@ class BopInterface : public MPSolverInterface { void SetPresolveMode(int value) override; void SetScalingMode(int value) override; void SetLpAlgorithm(int value) override; - bool SetSolverSpecificParametersAsString(const std::string& parameters) override; + bool SetSolverSpecificParametersAsString( + const std::string& parameters) override; private: void NonIncrementalChange(); @@ -379,7 +380,8 @@ void BopInterface::SetPresolveMode(int value) { bool BopInterface::SetSolverSpecificParametersAsString( const std::string& parameters) { - const bool ok = google::protobuf::TextFormat::MergeFromString(parameters, ¶meters_); + const bool ok = + google::protobuf::TextFormat::MergeFromString(parameters, ¶meters_); bop_solver_.SetParameters(parameters_); return ok; } @@ -394,6 +396,5 @@ MPSolverInterface* BuildBopInterface(MPSolver* const solver) { return new BopInterface(solver); } - } // namespace operations_research #endif // #if defined(USE_BOP) diff --git a/ortools/linear_solver/cbc_interface.cc b/ortools/linear_solver/cbc_interface.cc index d851a6b6e34..2ec9760fd03 100644 --- a/ortools/linear_solver/cbc_interface.cc +++ b/ortools/linear_solver/cbc_interface.cc @@ -13,20 +13,20 @@ // -#include #include #include #include +#include #include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/port.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/port.h" -#include "ortools/base/hash.h" #include "ortools/linear_solver/linear_solver.h" #if defined(USE_CBC) @@ -322,8 +322,12 @@ MPSolver::ResultStatus CBCInterface::Solve(const MPSolverParameters& param) { osi_.loadFromCoinModel(build); break; } - case MODEL_SYNCHRONIZED: { break; } - case SOLUTION_SYNCHRONIZED: { break; } + case MODEL_SYNCHRONIZED: { + break; + } + case SOLUTION_SYNCHRONIZED: { + break; + } } // Changing optimization direction through OSI so that the model file @@ -527,6 +531,5 @@ MPSolverInterface* BuildCBCInterface(MPSolver* const solver) { return new CBCInterface(solver); } - } // namespace operations_research #endif // #if defined(USE_CBC) diff --git a/ortools/linear_solver/clp_interface.cc b/ortools/linear_solver/clp_interface.cc index 593710b1328..578bc0a61ca 100644 --- a/ortools/linear_solver/clp_interface.cc +++ b/ortools/linear_solver/clp_interface.cc @@ -14,19 +14,19 @@ // #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/port.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/timer.h" #include "ortools/base/strutil.h" -#include "ortools/base/port.h" -#include "ortools/base/hash.h" +#include "ortools/base/timer.h" #include "ortools/linear_solver/linear_solver.h" #if defined(USE_CLP) || defined(USE_CBC) @@ -275,8 +275,8 @@ void CLPInterface::CreateDummyVariableForEmptyConstraints() { clp_->setColumnBounds(kDummyVariableIndex, 0.0, 0.0); clp_->setObjectiveCoefficient(kDummyVariableIndex, 0.0); // Workaround for peculiar signature of setColumnName. Note that we do need - // std::string here, and not 'std::string', which aren't the same as of 2013-12 - // (this will change later). + // std::string here, and not 'std::string', which aren't the same as of + // 2013-12 (this will change later). std::string dummy = "dummy"; // We do need to create this temporary variable. clp_->setColumnName(kDummyVariableIndex, dummy); } @@ -635,6 +635,5 @@ MPSolverInterface* BuildCLPInterface(MPSolver* const solver) { return new CLPInterface(solver); } - } // namespace operations_research #endif // #if defined(USE_CBC) || defined(USE_CLP) diff --git a/ortools/linear_solver/cplex_interface.cc b/ortools/linear_solver/cplex_interface.cc index 869c9999812..acefbfae323 100644 --- a/ortools/linear_solver/cplex_interface.cc +++ b/ortools/linear_solver/cplex_interface.cc @@ -25,1364 +25,1273 @@ #if defined(USE_CPLEX) extern "C" { -# include "ilcplex/cplexx.h" - // This is an undocumented function, setting the objective offset - // is not supported everywhere (for example it may not be exported if a - // model is written to a file), but it works in the cases we need here. - CPXLIBAPI int CPXPUBLIC CPXEsetobjoffset(CPXCENVptr, CPXLPptr, double); +#include "ilcplex/cplexx.h" +// This is an undocumented function, setting the objective offset +// is not supported everywhere (for example it may not be exported if a +// model is written to a file), but it works in the cases we need here. +CPXLIBAPI int CPXPUBLIC CPXEsetobjoffset(CPXCENVptr, CPXLPptr, double); } // In case we need to return a double but don't have a value for that // we just return a NaN. #if !defined(CPX_NAN) -# define CPX_NAN std::numeric_limits::quiet_NaN() +#define CPX_NAN std::numeric_limits::quiet_NaN() #endif // The argument to this macro is the invocation of a CPXX function that // returns a status. If the function returns non-zero the macro aborts // the program with an appropriate error message. -#define CHECK_STATUS(s) do { \ - int const status_ = s; \ - CHECK_EQ(0, status_); \ - } while (0) +#define CHECK_STATUS(s) \ + do { \ + int const status_ = s; \ + CHECK_EQ(0, status_); \ + } while (0) namespace operations_research { - using std::unique_ptr; - - // For a model that is extracted to an instance of this class there is a - // 1:1 corresponence between MPVariable instances and CPLEX columns: the - // index of an extracted variable is the column index in the CPLEX model. - // Similiar for instances of MPConstraint: the index of the constraint in - // the model is the row index in the CPLEX model. - class CplexInterface : public MPSolverInterface { - public: - // NOTE: 'mip' specifies the type of the problem (either continuous or - // mixed integer. This type is fixed for the lifetime of the - // instance. There are no dynamic changes to the model type. - explicit CplexInterface(MPSolver* const solver, bool mip); - ~CplexInterface(); - - // Sets the optimization direction (min/max). - virtual void SetOptimizationDirection(bool maximize); - - // ----- Solve ----- - // Solve the problem using the parameter values specified. - virtual MPSolver::ResultStatus Solve(MPSolverParameters const¶m); - - // ----- Model modifications and extraction ----- - // Resets extracted model - virtual void Reset(); - - virtual void SetVariableBounds(int var_index, double lb, double ub); - virtual void SetVariableInteger(int var_index, bool integer); - virtual void SetConstraintBounds(int row_index, double lb, double ub); - - virtual void AddRowConstraint(MPConstraint* const ct); - virtual void AddVariable(MPVariable* const var); - virtual void SetCoefficient(MPConstraint* const constraint, - MPVariable const* const variable, - double new_value, double old_value); - - // Clear a constraint from all its terms. - virtual void ClearConstraint(MPConstraint* const constraint); - // Change a coefficient in the linear objective - virtual void SetObjectiveCoefficient(MPVariable const* const variable, - double coefficient); - // Change the constant term in the linear objective. - virtual void SetObjectiveOffset(double value); - // Clear the objective from all its terms. - virtual void ClearObjective(); - - // ------ Query statistics on the solution and the solve ------ - // Number of simplex iterations - virtual int64 iterations() const; - // Number of branch-and-bound nodes. Only available for discrete problems. - virtual int64 nodes() const; - // Best objective bound. Only available for discrete problems. - virtual double best_objective_bound() const; - - // Returns the basis status of a row. - virtual MPSolver::BasisStatus row_status(int constraint_index) const; - // Returns the basis status of a column. - virtual MPSolver::BasisStatus column_status(int variable_index) const; - - // ----- Misc ----- - - // Query problem type. - // Remember that problem type is a static property that is set - // in the constructor and never changed. - virtual bool IsContinuous() const { return IsLP(); } - virtual bool IsLP() const { return !mMip; } - virtual bool IsMIP() const { return mMip; } - - virtual void ExtractNewVariables(); - virtual void ExtractNewConstraints(); - virtual void ExtractObjective(); - - virtual std::string SolverVersion() const; - - virtual void* underlying_solver() { - return reinterpret_cast(mLp); - } +using std::unique_ptr; + +// For a model that is extracted to an instance of this class there is a +// 1:1 corresponence between MPVariable instances and CPLEX columns: the +// index of an extracted variable is the column index in the CPLEX model. +// Similiar for instances of MPConstraint: the index of the constraint in +// the model is the row index in the CPLEX model. +class CplexInterface : public MPSolverInterface { + public: + // NOTE: 'mip' specifies the type of the problem (either continuous or + // mixed integer. This type is fixed for the lifetime of the + // instance. There are no dynamic changes to the model type. + explicit CplexInterface(MPSolver *const solver, bool mip); + ~CplexInterface(); + + // Sets the optimization direction (min/max). + virtual void SetOptimizationDirection(bool maximize); + + // ----- Solve ----- + // Solve the problem using the parameter values specified. + virtual MPSolver::ResultStatus Solve(MPSolverParameters const ¶m); + + // ----- Model modifications and extraction ----- + // Resets extracted model + virtual void Reset(); + + virtual void SetVariableBounds(int var_index, double lb, double ub); + virtual void SetVariableInteger(int var_index, bool integer); + virtual void SetConstraintBounds(int row_index, double lb, double ub); + + virtual void AddRowConstraint(MPConstraint *const ct); + virtual void AddVariable(MPVariable *const var); + virtual void SetCoefficient(MPConstraint *const constraint, + MPVariable const *const variable, + double new_value, double old_value); + + // Clear a constraint from all its terms. + virtual void ClearConstraint(MPConstraint *const constraint); + // Change a coefficient in the linear objective + virtual void SetObjectiveCoefficient(MPVariable const *const variable, + double coefficient); + // Change the constant term in the linear objective. + virtual void SetObjectiveOffset(double value); + // Clear the objective from all its terms. + virtual void ClearObjective(); + + // ------ Query statistics on the solution and the solve ------ + // Number of simplex iterations + virtual int64 iterations() const; + // Number of branch-and-bound nodes. Only available for discrete problems. + virtual int64 nodes() const; + // Best objective bound. Only available for discrete problems. + virtual double best_objective_bound() const; + + // Returns the basis status of a row. + virtual MPSolver::BasisStatus row_status(int constraint_index) const; + // Returns the basis status of a column. + virtual MPSolver::BasisStatus column_status(int variable_index) const; + + // ----- Misc ----- + + // Query problem type. + // Remember that problem type is a static property that is set + // in the constructor and never changed. + virtual bool IsContinuous() const { return IsLP(); } + virtual bool IsLP() const { return !mMip; } + virtual bool IsMIP() const { return mMip; } + + virtual void ExtractNewVariables(); + virtual void ExtractNewConstraints(); + virtual void ExtractObjective(); + + virtual std::string SolverVersion() const; + + virtual void *underlying_solver() { return reinterpret_cast(mLp); } + + virtual double ComputeExactConditionNumber() const { + if (!IsContinuous()) { + LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" + << " CPLEX_MIXED_INTEGER_PROGRAMMING"; + return CPX_NAN; + } + + if (CheckSolutionIsSynchronized()) { + double kappa = CPX_NAN; + CHECK_STATUS(CPXXgetdblquality(mEnv, mLp, &kappa, CPX_EXACT_KAPPA)); + return kappa; + } + LOG(DFATAL) << "Cannot get exact condition number without solution"; + return CPX_NAN; + } + + protected: + // Set all parameters in the underlying solver. + virtual void SetParameters(MPSolverParameters const ¶m); + // Set each parameter in the underlying solver. + virtual void SetRelativeMipGap(double value); + virtual void SetPrimalTolerance(double value); + virtual void SetDualTolerance(double value); + virtual void SetPresolveMode(int value); + virtual void SetScalingMode(int value); + virtual void SetLpAlgorithm(int value); + + virtual bool ReadParameterFile(std::string const &filename); + virtual std::string ValidFileExtensionForParameterFile() const; + + private: + // Mark modeling object "out of sync". This implicitly invalidates + // solution information as well. It is the counterpart of + // MPSolverInterface::InvalidateSolutionSynchronization + void InvalidateModelSynchronization() { + mCstat = 0; + mRstat = 0; + sync_status_ = MUST_RELOAD; + } + + // Transform CPLEX basis status to MPSolver basis status. + static MPSolver::BasisStatus xformBasisStatus(int cplex_basis_status); + + private: + CPXLPptr mLp; + CPXENVptr mEnv; + bool const mMip; + // Incremental extraction. + // Without incremental extraction we have to re-extract the model every + // time we perform a solve. Due to the way the Reset() function is + // implemented, this will lose MIP start or basis information from a + // previous solve. On the other hand, if there is a significant changes + // to the model then just re-extracting everything is usually faster than + // keeping the low-level modeling object in sync with the high-level + // variables/constraints. + // Note that incremental extraction is particularly expensive in function + // ExtractNewVariables() since there we must scan _all_ old constraints + // and update them with respect to the new variables. + bool const supportIncrementalExtraction; + + // Use slow and immediate updates or try to do bulk updates. + // For many updates to the model we have the option to either perform + // the update immediately with a potentially slow operation or to + // just mark the low-level modeling object out of sync and re-extract + // the model later. + enum SlowUpdates { + SlowSetCoefficient = 0x0001, + SlowClearConstraint = 0x0002, + SlowSetObjectiveCoefficient = 0x0004, + SlowClearObjective = 0x0008, + SlowSetConstraintBounds = 0x0010, + SlowSetVariableInteger = 0x0020, + SlowSetVariableBounds = 0x0040, + SlowUpdatesAll = 0xffff + } const slowUpdates; + // CPLEX has no method to query the basis status of a single variable. + // Hence we query the status only once and cache the array. This is + // much faster in case the basis status of more than one row/column + // is required. + unique_ptr mutable mCstat; + unique_ptr mutable mRstat; + + // Setup the right-hand side of a constraint from its lower and upper bound. + static void MakeRhs(double lb, double ub, double &rhs, char &sense, + double &range); +}; + +// Creates a LP/MIP instance. +CplexInterface::CplexInterface(MPSolver *const solver, bool mip) + : MPSolverInterface(solver), + mEnv(0), + mLp(0), + mMip(mip), + slowUpdates(static_cast(SlowSetObjectiveCoefficient | + SlowClearObjective)), + supportIncrementalExtraction(false), + mCstat(), + mRstat() { + int status; + + mEnv = CPXXopenCPLEX(&status); + CHECK_STATUS(status); + DCHECK(mEnv != nullptr); // should not be NULL if status=0 + + char const *name = solver_->name_.c_str(); + mLp = CPXXcreateprob(mEnv, &status, name); + CHECK_STATUS(status); + DCHECK(mLp != nullptr); // should not be NULL if status=0 + + CHECK_STATUS(CPXXchgobjsen(mEnv, mLp, maximize_ ? CPX_MAX : CPX_MIN)); + if (mMip) CHECK_STATUS(CPXXchgprobtype(mEnv, mLp, CPXPROB_MILP)); +} - virtual double ComputeExactConditionNumber() const { - if (!IsContinuous()) { - LOG(DFATAL) << "ComputeExactConditionNumber not implemented for" - << " CPLEX_MIXED_INTEGER_PROGRAMMING"; - return CPX_NAN; - } - - if ( CheckSolutionIsSynchronized() ) { - double kappa = CPX_NAN; - CHECK_STATUS(CPXXgetdblquality(mEnv, mLp, &kappa, CPX_EXACT_KAPPA)); - return kappa; - } - LOG(DFATAL) << "Cannot get exact condition number without solution"; - return CPX_NAN; - } +CplexInterface::~CplexInterface() { + CHECK_STATUS(CPXXfreeprob(mEnv, &mLp)); + CHECK_STATUS(CPXXcloseCPLEX(&mEnv)); +} - protected: - // Set all parameters in the underlying solver. - virtual void SetParameters(MPSolverParameters const ¶m); - // Set each parameter in the underlying solver. - virtual void SetRelativeMipGap(double value); - virtual void SetPrimalTolerance(double value); - virtual void SetDualTolerance(double value); - virtual void SetPresolveMode(int value); - virtual void SetScalingMode(int value); - virtual void SetLpAlgorithm(int value); - - virtual bool ReadParameterFile(std::string const &filename); - virtual std::string ValidFileExtensionForParameterFile() const; - - private: - // Mark modeling object "out of sync". This implicitly invalidates - // solution information as well. It is the counterpart of - // MPSolverInterface::InvalidateSolutionSynchronization - void InvalidateModelSynchronization() { - mCstat = 0; - mRstat = 0; - sync_status_ = MUST_RELOAD; - } +std::string CplexInterface::SolverVersion() const { + // We prefer CPXXversionnumber() over CPXXversion() since the + // former will never pose any encoding issues. + int version = 0; + CHECK_STATUS(CPXXversionnumber(mEnv, &version)); + + int const major = version / 1000000; + version -= major * 1000000; + int const release = version / 10000; + version -= release * 10000; + int const mod = version / 100; + version -= mod * 100; + int const fix = version; + + return StringPrintf("CPLEX library version %d.%02d.%02d.%02d", major, release, + mod, fix); +} - // Transform CPLEX basis status to MPSolver basis status. - static MPSolver::BasisStatus xformBasisStatus(int cplex_basis_status); - - private: - CPXLPptr mLp; - CPXENVptr mEnv; - bool const mMip; - // Incremental extraction. - // Without incremental extraction we have to re-extract the model every - // time we perform a solve. Due to the way the Reset() function is - // implemented, this will lose MIP start or basis information from a - // previous solve. On the other hand, if there is a significant changes - // to the model then just re-extracting everything is usually faster than - // keeping the low-level modeling object in sync with the high-level - // variables/constraints. - // Note that incremental extraction is particularly expensive in function - // ExtractNewVariables() since there we must scan _all_ old constraints - // and update them with respect to the new variables. - bool const supportIncrementalExtraction; - - // Use slow and immediate updates or try to do bulk updates. - // For many updates to the model we have the option to either perform - // the update immediately with a potentially slow operation or to - // just mark the low-level modeling object out of sync and re-extract - // the model later. - enum SlowUpdates { - SlowSetCoefficient = 0x0001, - SlowClearConstraint = 0x0002, - SlowSetObjectiveCoefficient = 0x0004, - SlowClearObjective = 0x0008, - SlowSetConstraintBounds = 0x0010, - SlowSetVariableInteger = 0x0020, - SlowSetVariableBounds = 0x0040, - SlowUpdatesAll = 0xffff - } const slowUpdates; - // CPLEX has no method to query the basis status of a single variable. - // Hence we query the status only once and cache the array. This is - // much faster in case the basis status of more than one row/column - // is required. - unique_ptr mutable mCstat; - unique_ptr mutable mRstat; - - // Setup the right-hand side of a constraint from its lower and upper bound. - static void MakeRhs(double lb, double ub, - double &rhs, char &sense, double &range); - }; - - // Creates a LP/MIP instance. - CplexInterface::CplexInterface(MPSolver* const solver, bool mip) - : MPSolverInterface(solver) - , mEnv(0) - , mLp(0) - , mMip(mip) - , slowUpdates(static_cast(SlowSetObjectiveCoefficient - | SlowClearObjective)) - , supportIncrementalExtraction(false) - , mCstat() - , mRstat() - { - int status; - - mEnv = CPXXopenCPLEX(&status); - CHECK_STATUS(status); - DCHECK(mEnv != nullptr); // should not be NULL if status=0 - - char const *name = solver_->name_.c_str(); - mLp = CPXXcreateprob(mEnv, &status, name); - CHECK_STATUS(status); - DCHECK(mLp != nullptr); // should not be NULL if status=0 - - CHECK_STATUS(CPXXchgobjsen(mEnv, mLp, maximize_ ? CPX_MAX : CPX_MIN)); - if ( mMip ) - CHECK_STATUS(CPXXchgprobtype(mEnv, mLp, CPXPROB_MILP)); - } - - CplexInterface::~CplexInterface() - { - CHECK_STATUS(CPXXfreeprob(mEnv, &mLp)); - CHECK_STATUS(CPXXcloseCPLEX(&mEnv)); - } - - std::string CplexInterface::SolverVersion() const { - // We prefer CPXXversionnumber() over CPXXversion() since the - // former will never pose any encoding issues. - int version = 0; - CHECK_STATUS(CPXXversionnumber(mEnv, &version)); - - int const major = version / 1000000; version -= major * 1000000; - int const release = version / 10000; version -= release * 10000; - int const mod = version / 100; version -= mod * 100; - int const fix = version; - - return StringPrintf("CPLEX library version %d.%02d.%02d.%02d", - major, release, mod, fix); - } - - // ------ Model modifications and extraction ----- - - void CplexInterface::Reset() - { - // Instead of explicitly clearing all modeling objects we - // just delete the problem object and allocate a new one. - CHECK_STATUS(CPXXfreeprob(mEnv, &mLp)); - - int status; - const char* const name = solver_->name_.c_str(); - mLp = CPXXcreateprob(mEnv, &status, name); - CHECK_STATUS(status); - DCHECK(mLp != nullptr); // should not be NULL if status=0 - - CHECK_STATUS(CPXXchgobjsen(mEnv, mLp, maximize_ ? CPX_MAX : CPX_MIN)); - if ( mMip ) - CHECK_STATUS(CPXXchgprobtype(mEnv, mLp, CPXPROB_MILP)); - - ResetExtractionInformation(); - mCstat = 0; - mRstat = 0; - } - - void CplexInterface::SetOptimizationDirection(bool maximize) - { - InvalidateSolutionSynchronization(); - CPXXchgobjsen(mEnv, mLp, maximize ? CPX_MAX : CPX_MIN); - } - - void CplexInterface::SetVariableBounds(int var_index, double lb, double ub) { - InvalidateSolutionSynchronization(); - - // Changing the bounds of a variable is fast. However, doing this for - // many variables may still be slow. So we don't perform the update by - // default. However, if we support incremental extraction - // (supportIncrementalExtraction is true) then we MUST perform the - // update here or we will lose it. - - if ( !supportIncrementalExtraction && - !(slowUpdates & SlowSetVariableBounds) ) - { - InvalidateModelSynchronization(); - } - else { - if ( variable_is_extracted(var_index) ) { - // Variable has already been extracted, so we must modify the - // modeling object. - DCHECK_LT(var_index, last_variable_index_); - char const lu[2] = { 'L', 'U' }; - double const bd[2] = { lb, ub }; - CPXDIM const idx[2] = { var_index, var_index }; - CHECK_STATUS(CPXXchgbds(mEnv, mLp, 2, idx, lu, bd)); - } - else { - // Variable is not yet extracted. It is sufficient to just mark - // the modeling object "out of sync" - InvalidateModelSynchronization(); - } - } - } - - // Modifies integrality of an extracted variable. - void CplexInterface::SetVariableInteger(int var_index, bool integer) - { - InvalidateSolutionSynchronization(); - - // NOTE: The type of the model (continuous or mixed integer) is - // defined once and for all in the constructor. There are no - // dynamic changes to the model type. - - // Changing the type of a variable should be fast. Still, doing all - // updates in one big chunk right before solve() is usually faster. - // However, if we support incremental extraction - // (supportIncrementalExtraction is true) then we MUST change the - // type of extracted variables here. - - if ( !supportIncrementalExtraction && - !(slowUpdates && SlowSetVariableInteger) ) - { - InvalidateModelSynchronization(); - } - else { - if ( mMip ) { - if ( variable_is_extracted(var_index) ) { - // Variable is extracted. Change the type immediately. - // TODO: Should we check the current type and don't do anything - // in case the type does not change? - DCHECK_LE(var_index, CPXXgetnumcols(mEnv, mLp)); - char const type = integer ? CPX_INTEGER : CPX_CONTINUOUS; - CHECK_STATUS (CPXXchgctype(mEnv, mLp, 1, &var_index, &type)); - } - else - InvalidateModelSynchronization(); - } - else { - LOG(DFATAL) - << "Attempt to change variable to integer in non-MIP problem!"; - } - } - } - - // Setup the right-hand side of a constraint. - void CplexInterface::MakeRhs(double lb, double ub, double &rhs, char &sense, double &range) - { - if ( lb == ub ) { - // Both bounds are equal -> this is an equality constraint - rhs = lb; - range = 0.0; - sense = 'E'; - } - else if ( lb > -CPX_INFBOUND && ub < CPX_INFBOUND ) { - // Both bounds are finite -> this is a ranged constraint - // The value of a ranged constraint is allowed to be in - // [ rhs[i], rhs[i]+rngval[i] ] - // see also the reference documentation for CPXXnewrows() - if ( ub < lb ) { - // The bounds for the constraint are contradictory. CPLEX models - // a range constraint l <= ax <= u as - // ax = l + v - // where v is an auxiliary variable the range of which is controlled - // by l and u: if l < u then v in [0, u-l] - // else v in [u-l, 0] - // (the range is specified as the rngval[] argument to CPXXnewrows). - // Thus CPLEX cannot represent range constraints with contradictory - // bounds and we must error out here. - CHECK_STATUS(CPXERR_BAD_ARGUMENT); - } - rhs = lb; - range = ub - lb; - sense = 'R'; - } - else if ( ub < CPX_INFBOUND || - (fabs(ub) == CPX_INFBOUND && fabs(lb) > CPX_INFBOUND) ) - { - // Finite upper, infinite lower bound -> this is a <= constraint - rhs = ub; - range = 0.0; - sense = 'L'; - } - else if ( lb > -CPX_INFBOUND || - (fabs(lb) == CPX_INFBOUND && fabs(ub) > CPX_INFBOUND) ) - { - // Finite lower, infinite upper bound -> this is a >= constraint - rhs = lb; - range = 0.0; - sense = 'G'; - } - else { - // Lower and upper bound are both infinite. - // This is used for example in .mps files to specify alternate - // objective functions. - // Note that the case lb==ub was already handled above, so we just - // pick the bound with larger magnitude and create a constraint for it. - // Note that we replace the infinite bound by CPX_INFBOUND since - // bounds with larger magnitude may cause other CPLEX functions to - // fail (for example the export to LP files). - DCHECK_GT(fabs(lb), CPX_INFBOUND); - DCHECK_GT(fabs(ub), CPX_INFBOUND); - if ( fabs(lb) > fabs(ub) ) { - rhs = (lb < 0) ? -CPX_INFBOUND : CPX_INFBOUND; - sense = 'G'; - } - else { - rhs = (ub < 0) ? -CPX_INFBOUND : CPX_INFBOUND; - sense = 'L'; - } - range = 0.0; - } - } - - void CplexInterface::SetConstraintBounds(int index, double lb, double ub) - { - InvalidateSolutionSynchronization(); - - // Changing rhs, sense, or range of a constraint is not too slow. - // Still, doing all the updates in one large operation is faster. - // Note however that if we do not want to re-extract the full model - // for each solve (supportIncrementalExtraction is true) then we MUST - // update the constraint here, otherwise we lose this update information. - - if ( !supportIncrementalExtraction && - !(slowUpdates & SlowSetConstraintBounds) ) - { - InvalidateModelSynchronization(); - } - else { - if ( constraint_is_extracted(index) ) { - // Constraint is already extracted, so we must update its bounds - // and its type. - DCHECK(mLp != NULL); - char sense; - double range, rhs; - MakeRhs(lb, ub, rhs, sense, range); - CHECK_STATUS(CPXXchgrhs(mEnv, mLp, 1, &index, &lb)); - CHECK_STATUS(CPXXchgsense(mEnv, mLp, 1, &index, &sense)); - CHECK_STATUS(CPXXchgrngval(mEnv, mLp, 1, &index, &range)); - } - else { - // Constraint is not yet extracted. It is sufficient to mark the - // modeling object as "out of sync" - InvalidateModelSynchronization(); - } - } - } - - void CplexInterface::AddRowConstraint(MPConstraint* const ct) - { - // This is currently only invoked when a new constraint is created, - // see MPSolver::MakeRowConstraint(). - // At this point we only have the lower and upper bounds of the - // constraint. We could immediately call CPXXaddrows() here but it is - // usually much faster to handle the fully populated constraint in - // ExtractNewConstraints() right before the solve. +// ------ Model modifications and extraction ----- + +void CplexInterface::Reset() { + // Instead of explicitly clearing all modeling objects we + // just delete the problem object and allocate a new one. + CHECK_STATUS(CPXXfreeprob(mEnv, &mLp)); + + int status; + const char *const name = solver_->name_.c_str(); + mLp = CPXXcreateprob(mEnv, &status, name); + CHECK_STATUS(status); + DCHECK(mLp != nullptr); // should not be NULL if status=0 + + CHECK_STATUS(CPXXchgobjsen(mEnv, mLp, maximize_ ? CPX_MAX : CPX_MIN)); + if (mMip) CHECK_STATUS(CPXXchgprobtype(mEnv, mLp, CPXPROB_MILP)); + + ResetExtractionInformation(); + mCstat = 0; + mRstat = 0; +} + +void CplexInterface::SetOptimizationDirection(bool maximize) { + InvalidateSolutionSynchronization(); + CPXXchgobjsen(mEnv, mLp, maximize ? CPX_MAX : CPX_MIN); +} + +void CplexInterface::SetVariableBounds(int var_index, double lb, double ub) { + InvalidateSolutionSynchronization(); + + // Changing the bounds of a variable is fast. However, doing this for + // many variables may still be slow. So we don't perform the update by + // default. However, if we support incremental extraction + // (supportIncrementalExtraction is true) then we MUST perform the + // update here or we will lose it. + + if (!supportIncrementalExtraction && !(slowUpdates & SlowSetVariableBounds)) { + InvalidateModelSynchronization(); + } else { + if (variable_is_extracted(var_index)) { + // Variable has already been extracted, so we must modify the + // modeling object. + DCHECK_LT(var_index, last_variable_index_); + char const lu[2] = {'L', 'U'}; + double const bd[2] = {lb, ub}; + CPXDIM const idx[2] = {var_index, var_index}; + CHECK_STATUS(CPXXchgbds(mEnv, mLp, 2, idx, lu, bd)); + } else { + // Variable is not yet extracted. It is sufficient to just mark + // the modeling object "out of sync" InvalidateModelSynchronization(); - } - - void CplexInterface::AddVariable(MPVariable* const ct) - { - // This is currently only invoked when a new variable is created, - // see MPSolver::MakeVar(). - // At this point the variable does not appear in any constraints or - // the objective function. We could invoke CPXXaddcols() to immediately - // create the variable here but it is usually much faster to handle the - // fully setup variable in ExtractNewVariables() right before the solve. + } + } +} + +// Modifies integrality of an extracted variable. +void CplexInterface::SetVariableInteger(int var_index, bool integer) { + InvalidateSolutionSynchronization(); + + // NOTE: The type of the model (continuous or mixed integer) is + // defined once and for all in the constructor. There are no + // dynamic changes to the model type. + + // Changing the type of a variable should be fast. Still, doing all + // updates in one big chunk right before solve() is usually faster. + // However, if we support incremental extraction + // (supportIncrementalExtraction is true) then we MUST change the + // type of extracted variables here. + + if (!supportIncrementalExtraction && + !(slowUpdates && SlowSetVariableInteger)) { + InvalidateModelSynchronization(); + } else { + if (mMip) { + if (variable_is_extracted(var_index)) { + // Variable is extracted. Change the type immediately. + // TODO: Should we check the current type and don't do anything + // in case the type does not change? + DCHECK_LE(var_index, CPXXgetnumcols(mEnv, mLp)); + char const type = integer ? CPX_INTEGER : CPX_CONTINUOUS; + CHECK_STATUS(CPXXchgctype(mEnv, mLp, 1, &var_index, &type)); + } else + InvalidateModelSynchronization(); + } else { + LOG(DFATAL) + << "Attempt to change variable to integer in non-MIP problem!"; + } + } +} + +// Setup the right-hand side of a constraint. +void CplexInterface::MakeRhs(double lb, double ub, double &rhs, char &sense, + double &range) { + if (lb == ub) { + // Both bounds are equal -> this is an equality constraint + rhs = lb; + range = 0.0; + sense = 'E'; + } else if (lb > -CPX_INFBOUND && ub < CPX_INFBOUND) { + // Both bounds are finite -> this is a ranged constraint + // The value of a ranged constraint is allowed to be in + // [ rhs[i], rhs[i]+rngval[i] ] + // see also the reference documentation for CPXXnewrows() + if (ub < lb) { + // The bounds for the constraint are contradictory. CPLEX models + // a range constraint l <= ax <= u as + // ax = l + v + // where v is an auxiliary variable the range of which is controlled + // by l and u: if l < u then v in [0, u-l] + // else v in [u-l, 0] + // (the range is specified as the rngval[] argument to CPXXnewrows). + // Thus CPLEX cannot represent range constraints with contradictory + // bounds and we must error out here. + CHECK_STATUS(CPXERR_BAD_ARGUMENT); + } + rhs = lb; + range = ub - lb; + sense = 'R'; + } else if (ub < CPX_INFBOUND || + (fabs(ub) == CPX_INFBOUND && fabs(lb) > CPX_INFBOUND)) { + // Finite upper, infinite lower bound -> this is a <= constraint + rhs = ub; + range = 0.0; + sense = 'L'; + } else if (lb > -CPX_INFBOUND || + (fabs(lb) == CPX_INFBOUND && fabs(ub) > CPX_INFBOUND)) { + // Finite lower, infinite upper bound -> this is a >= constraint + rhs = lb; + range = 0.0; + sense = 'G'; + } else { + // Lower and upper bound are both infinite. + // This is used for example in .mps files to specify alternate + // objective functions. + // Note that the case lb==ub was already handled above, so we just + // pick the bound with larger magnitude and create a constraint for it. + // Note that we replace the infinite bound by CPX_INFBOUND since + // bounds with larger magnitude may cause other CPLEX functions to + // fail (for example the export to LP files). + DCHECK_GT(fabs(lb), CPX_INFBOUND); + DCHECK_GT(fabs(ub), CPX_INFBOUND); + if (fabs(lb) > fabs(ub)) { + rhs = (lb < 0) ? -CPX_INFBOUND : CPX_INFBOUND; + sense = 'G'; + } else { + rhs = (ub < 0) ? -CPX_INFBOUND : CPX_INFBOUND; + sense = 'L'; + } + range = 0.0; + } +} + +void CplexInterface::SetConstraintBounds(int index, double lb, double ub) { + InvalidateSolutionSynchronization(); + + // Changing rhs, sense, or range of a constraint is not too slow. + // Still, doing all the updates in one large operation is faster. + // Note however that if we do not want to re-extract the full model + // for each solve (supportIncrementalExtraction is true) then we MUST + // update the constraint here, otherwise we lose this update information. + + if (!supportIncrementalExtraction && + !(slowUpdates & SlowSetConstraintBounds)) { + InvalidateModelSynchronization(); + } else { + if (constraint_is_extracted(index)) { + // Constraint is already extracted, so we must update its bounds + // and its type. + DCHECK(mLp != NULL); + char sense; + double range, rhs; + MakeRhs(lb, ub, rhs, sense, range); + CHECK_STATUS(CPXXchgrhs(mEnv, mLp, 1, &index, &lb)); + CHECK_STATUS(CPXXchgsense(mEnv, mLp, 1, &index, &sense)); + CHECK_STATUS(CPXXchgrngval(mEnv, mLp, 1, &index, &range)); + } else { + // Constraint is not yet extracted. It is sufficient to mark the + // modeling object as "out of sync" InvalidateModelSynchronization(); - } - - void CplexInterface::SetCoefficient(MPConstraint* const constraint, - MPVariable const* const variable, - double new_value, double) - { - InvalidateSolutionSynchronization(); - - // Changing a single coefficient in the matrix is potentially pretty - // slow since that coefficient has to be found in the sparse matrix - // representation. So by default we don't perform this update immediately - // but instead mark the low-level modeling object "out of sync". - // If we want to support incremental extraction then we MUST perform - // the modification immediately or we will lose it. - - if ( !supportIncrementalExtraction && - !(slowUpdates & SlowSetCoefficient) ) - { - InvalidateModelSynchronization(); - } - else { - int const row = constraint->index(); - int const col = variable->index(); - if ( constraint_is_extracted(row) && variable_is_extracted(col) ) { - // If row and column are both extracted then we can directly - // update the modeling object - DCHECK_LE(row, last_constraint_index_); - DCHECK_LE(col, last_variable_index_); - CHECK_STATUS(CPXXchgcoef(mEnv, mLp, row, col, new_value)); - } - else { - // If either row or column is not yet extracted then we can - // defer the update to ExtractModel() - InvalidateModelSynchronization(); - } - } - } - - void CplexInterface::ClearConstraint(MPConstraint* const constraint) - { - CPXDIM const row = constraint->index(); - if ( !constraint_is_extracted(row) ) - // There is nothing to do if the constraint was not even extracted. - return; - - // Clearing a constraint means setting all coefficients in the corresponding - // row to 0 (we cannot just delete the row since that would renumber all - // the constraints/rows after it). - // Modifying coefficients in the matrix is potentially pretty expensive - // since they must be found in the sparse matrix representation. That is - // why by default we do not modify the coefficients here but only mark - // the low-level modeling object "out of sync". - - if ( !(slowUpdates & SlowClearConstraint) ) { - InvalidateModelSynchronization(); - } - else { - InvalidateSolutionSynchronization(); - - CPXDIM const len = constraint->coefficients_.size(); - unique_ptr rowind(new CPXDIM[len]); - unique_ptr colind(new CPXDIM[len]); - unique_ptr val(new double[len]); - CPXDIM j = 0; - CoeffMap const &coeffs = constraint->coefficients_; - for (CoeffMap::const_iterator it(coeffs.begin()); - it != coeffs.end(); ++it) - { - CPXDIM const col = it->first->index(); - if ( variable_is_extracted(col) ) { - rowind[j] = row; - colind[j] = col; - val[j] = 0.0; - ++j; - } - } - if ( j ) - CHECK_STATUS(CPXXchgcoeflist(mEnv, mLp, j, rowind.get(), - colind.get(), val.get())); - } - } - - void CplexInterface::SetObjectiveCoefficient(MPVariable const* const variable, - double coefficient) - { - CPXDIM const col = variable->index(); - if ( !variable_is_extracted(col) ) - // Nothing to do if variable was not even extracted - return; - - InvalidateSolutionSynchronization(); - - // The objective function is stored as a dense vector, so updating a - // single coefficient is O(1). So by default we update the low-level - // modeling object here. - // If we support incremental extraction then we have no choice but to - // perform the update immediately. - - if ( supportIncrementalExtraction || - (slowUpdates & SlowSetObjectiveCoefficient) ) - { - CHECK_STATUS(CPXXchgobj(mEnv, mLp, 1, &col, &coefficient)); - } - else - InvalidateModelSynchronization(); - } - - void CplexInterface::SetObjectiveOffset(double value) - { - // Changing the objective offset is O(1), so we always do it immediately. - InvalidateSolutionSynchronization(); - CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, value)); - } - - void CplexInterface::ClearObjective() - { - InvalidateSolutionSynchronization(); - - // Since the objective function is stored as a dense vector updating - // it is O(n), so we usually perform the update immediately. - // If we want to support incremental extraction then we have no choice - // but to perform the update immediately. - - if ( supportIncrementalExtraction || - (slowUpdates & SlowClearObjective) ) - { - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - unique_ptr ind(new CPXDIM[cols]); - unique_ptr zero(new double[cols]); - CPXDIM j = 0; - CoeffMap const &coeffs = solver_->objective_->coefficients_; - for (CoeffMap::const_iterator it(coeffs.begin()); - it != coeffs.end(); ++it) - { - CPXDIM const idx = it->first->index(); - // We only need to reset variables that have been extracted. - if ( variable_is_extracted(idx) ) { - DCHECK_LT(idx, cols); - ind[j] = idx; - zero[j] = 0.0; - ++j; - } - } - if ( j > 0 ) - CHECK_STATUS(CPXXchgobj(mEnv, mLp, j, ind.get(), zero.get())); - CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, 0.0)); - } - else - InvalidateModelSynchronization(); - } - - // ------ Query statistics on the solution and the solve ------ - - int64 CplexInterface::iterations() const - { - int iter; - if (!CheckSolutionIsSynchronized()) - return kUnknownNumberOfIterations; - if (mMip) - return static_cast(CPXXgetmipitcnt(mEnv, mLp)); - else - return static_cast(CPXXgetitcnt(mEnv, mLp)); - } - - int64 CplexInterface::nodes() const - { - if ( mMip ) { - if (!CheckSolutionIsSynchronized()) - return kUnknownNumberOfNodes; - return static_cast(CPXXgetnodecnt(mEnv, mLp)); - } - else { - LOG(DFATAL) << "Number of nodes only available for discrete problems"; - return kUnknownNumberOfNodes; - } - } - - // Returns the best objective bound. Only available for discrete problems. - double CplexInterface::best_objective_bound() const - { - if ( mMip ) { - if ( !CheckSolutionIsSynchronized() || !CheckBestObjectiveBoundExists()) - // trivial_worst_objective_bound() returns sense*infinity, - // that is meaningful even for infeasible problems - return trivial_worst_objective_bound(); - if (solver_->variables_.size() == 0 && solver_->constraints_.size() == 0) { - // For an empty model the best objective bound is just the offset. - return solver_->Objective().offset(); - } - else { - double value = CPX_NAN; - CHECK_STATUS(CPXXgetbestobjval(mEnv, mLp, &value)); - return value; - } - } - else { - LOG(DFATAL) << "Best objective bound only available for discrete problems"; - return trivial_worst_objective_bound(); - } - } - - // Transform a CPLEX basis status to an MPSolver basis status. - MPSolver::BasisStatus - CplexInterface::xformBasisStatus(int cplex_basis_status) - { - switch (cplex_basis_status) { - case CPX_AT_LOWER: - return MPSolver::AT_LOWER_BOUND; - case CPX_BASIC: - return MPSolver::BASIC; - case CPX_AT_UPPER: - return MPSolver::AT_UPPER_BOUND; - case CPX_FREE_SUPER: - return MPSolver::FREE; - default: - LOG(DFATAL) << "Unknown CPLEX basis status"; - return MPSolver::FREE; - } - } - - // Returns the basis status of a row. - MPSolver::BasisStatus CplexInterface::row_status(int constraint_index) const - { - if ( mMip ) { - LOG(FATAL) << "Basis status only available for continuous problems"; - return MPSolver::FREE; - } + } + } +} - if ( CheckSolutionIsSynchronized() ) { - if ( !mRstat ) { - CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); - unique_ptr data(new int[rows]); - mRstat.swap(data); - CHECK_STATUS(CPXXgetbase(mEnv, mLp, 0, mRstat.get())); - } - } - else - mRstat = 0; - - if ( mRstat ) - return xformBasisStatus(mRstat[constraint_index]); - else { - LOG(FATAL) << "Row basis status not available"; - return MPSolver::FREE; - } - } - - // Returns the basis status of a column. - MPSolver::BasisStatus CplexInterface::column_status(int variable_index) const - { - if ( mMip ) { - LOG(FATAL) << "Basis status only available for continuous problems"; - return MPSolver::FREE; - } +void CplexInterface::AddRowConstraint(MPConstraint *const ct) { + // This is currently only invoked when a new constraint is created, + // see MPSolver::MakeRowConstraint(). + // At this point we only have the lower and upper bounds of the + // constraint. We could immediately call CPXXaddrows() here but it is + // usually much faster to handle the fully populated constraint in + // ExtractNewConstraints() right before the solve. + InvalidateModelSynchronization(); +} - if ( CheckSolutionIsSynchronized() ) { - if ( !mCstat ) { - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - unique_ptr data(new int[cols]); - mCstat.swap(data); - CHECK_STATUS(CPXXgetbase(mEnv, mLp, mCstat.get(), 0)); - } - } - else - mCstat = 0; - - if ( mCstat ) - return xformBasisStatus(mCstat[variable_index]); - else { - LOG(FATAL) << "Column basis status not available"; - return MPSolver::FREE; - } - } - - // Extract all variables that have not yet been extracted. - void CplexInterface::ExtractNewVariables() - { - // NOTE: The code assumes that a linear expression can never contain - // non-zero duplicates. - - InvalidateSolutionSynchronization(); - - if ( !supportIncrementalExtraction ) { - // Without incremental extraction ExtractModel() is always called - // to extract the full model. - CHECK(last_variable_index_ == 0 || - last_variable_index_ == solver_->variables_.size()); - CHECK(last_constraint_index_ == 0 || - last_constraint_index_ == solver_->constraints_.size()); - } +void CplexInterface::AddVariable(MPVariable *const ct) { + // This is currently only invoked when a new variable is created, + // see MPSolver::MakeVar(). + // At this point the variable does not appear in any constraints or + // the objective function. We could invoke CPXXaddcols() to immediately + // create the variable here but it is usually much faster to handle the + // fully setup variable in ExtractNewVariables() right before the solve. + InvalidateModelSynchronization(); +} - int const last_extracted = last_variable_index_; - int const var_count = solver_->variables_.size(); - CPXDIM newcols = var_count - last_extracted; - if ( newcols > 0 ) { - // There are non-extracted variables. Extract them now. - - unique_ptr obj(new double[newcols]); - unique_ptr lb(new double[newcols]); - unique_ptr ub(new double[newcols]); - unique_ptr ctype(new char[newcols]); - unique_ptr colname(new const char*[newcols]); - - bool have_names = false; - for (int j = 0, varidx = last_extracted; j < newcols; ++j, ++varidx) { - MPVariable const* const var = solver_->variables_[varidx]; - lb[j] = var->lb(); - ub[j] = var->ub(); - ctype[j] = var->integer() ? CPX_INTEGER : CPX_CONTINUOUS; - colname[j] = var->name().empty() ? 0 : var->name().c_str(); - have_names = have_names || var->name().empty(); - obj[j] = solver_->objective_->GetCoefficient(var); - } - - // Arrays for modifying the problem are setup. Update the index - // of variables that will get extracted now. Updating indices - // _before_ the actual extraction makes things much simpler in - // case we support incremental extraction. - // In case of error we just reset the indeces. - std::vector const &variables = solver_->variables(); - for (int j = last_extracted; j < var_count; ++j) { - CHECK(!variable_is_extracted(variables[j]->index())); - set_variable_as_extracted(variables[j]->index(), true); - } - - try { - bool use_newcols = true; - - if ( supportIncrementalExtraction ) { - // If we support incremental extraction then we must - // update existing constraints with the new variables. - // To do that we use CPXXaddcols() to actually create the - // variables. This is supposed to be faster than combining - // CPXXnewcols() and CPXXchgcoeflist(). - - // For each column count the size of the intersection with - // existing constraints. - unique_ptr collen(new CPXDIM[newcols]); - for (CPXDIM j = 0; j < newcols; ++j) - collen[j] = 0; - CPXNNZ nonzeros = 0; - // TODO: Use a bitarray to flag the constraints that actually - // intersect new variables? - for (int i = 0; i < last_constraint_index_; ++i) { - MPConstraint const *const ct = solver_->constraints_[i]; - CHECK(constraint_is_extracted(ct->index())); - CoeffMap const &coeffs = ct->coefficients_; - for (CoeffMap::const_iterator it(coeffs.begin()); - it != coeffs.end(); ++it) - { - int const idx = it->first->index(); - if ( variable_is_extracted(idx) && - idx > last_variable_index_ ) { - collen[idx - last_variable_index_]++; - ++nonzeros; - } - } - } - - if ( nonzeros > 0 ) { - // At least one of the new variables did intersect with an - // old constraint. We have to create the new columns via - // CPXXaddcols(). - use_newcols = false; - unique_ptr begin(new CPXNNZ[newcols + 2]); - unique_ptr cmatind(new CPXDIM[nonzeros]); - unique_ptr cmatval(new double[nonzeros]); - - // Here is how cmatbeg[] is setup: - // - it is initialized as - // [ 0, 0, collen[0], collen[0]+collen[1], ... ] - // so that cmatbeg[j+1] tells us where in cmatind[] and - // cmatval[] we need to put the next nonzero for column - // j - // - after nonzeros have been setup the array looks like - // [ 0, collen[0], collen[0]+collen[1], ... ] - // so that it is the correct input argument for CPXXaddcols - CPXNNZ *cmatbeg = begin.get(); - cmatbeg[0] = 0; - cmatbeg[1] = 0; - ++cmatbeg; - for (CPXDIM j = 0; j < newcols; ++j) - cmatbeg[j + 1] = cmatbeg[j] + collen[j]; - - for (int i = 0; i < last_constraint_index_; ++i) { - MPConstraint const *const ct = solver_->constraints_[i]; - CPXDIM const row = ct->index(); - CoeffMap const &coeffs = ct->coefficients_; - for (CoeffMap::const_iterator it(coeffs.begin()); - it != coeffs.end(); ++it) - { - int const idx = it->first->index(); - if ( variable_is_extracted(idx) && - idx > last_variable_index_ ) { - CPXNNZ const nz = cmatbeg[idx]++; - cmatind[nz] = idx; - cmatval[nz] = it->second; - } - } - } - --cmatbeg; - CHECK_STATUS(CPXXaddcols(mEnv, mLp, newcols, nonzeros, - obj.get(), cmatbeg, - cmatind.get(), cmatval.get(), - lb.get(), ub.get(), - have_names ? colname.get() : 0)); - } - } - if ( use_newcols ) { - // Either incremental extraction is not supported or none of - // the new variables did intersect an existing constraint. - // We can just use CPXXnewcols() to create the new variables. - CHECK_STATUS(CPXXnewcols(mEnv, mLp, newcols, obj.get(), - lb.get(), ub.get(), - mMip ? ctype.get() : 0, - have_names ? colname.get() : 0)); - } - else { - // Incremental extraction: we must update the ctype of the - // newly created variables (CPXXaddcols() does not allow - // specifying the ctype) - if ( mMip ) { - // Query the actual number of columns in case we did not - // manage to extract all columns. - int const cols = CPXXgetnumcols(mEnv, mLp); - unique_ptr ind(new CPXDIM[newcols]); - for (int j = last_extracted; j < cols; ++j) - ind[j - last_extracted] = j; - CHECK_STATUS(CPXXchgctype(mEnv, mLp, cols - last_extracted, - ind.get(), ctype.get())); - } - } - } - catch (...) { - // Undo all changes in case of error. - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - if ( cols > last_extracted ) - (void)CPXXdelcols(mEnv, mLp, last_extracted, cols - 1); - std::vector const &variables = solver_->variables(); - int const size = variables.size(); - for (int j = last_extracted; j < size; ++j) - set_variable_as_extracted(j, false); - throw; - } - } - } - - // Extract constraints that have not yet been extracted. - void CplexInterface::ExtractNewConstraints() - { - // NOTE: The code assumes that a linear expression can never contain - // non-zero duplicates. - - if ( !supportIncrementalExtraction ) { - // Without incremental extraction ExtractModel() is always called - // to extract the full model. - CHECK(last_variable_index_ == 0 || - last_variable_index_ == solver_->variables_.size()); - CHECK(last_constraint_index_ == 0 || - last_constraint_index_ == solver_->constraints_.size()); - } +void CplexInterface::SetCoefficient(MPConstraint *const constraint, + MPVariable const *const variable, + double new_value, double) { + InvalidateSolutionSynchronization(); + + // Changing a single coefficient in the matrix is potentially pretty + // slow since that coefficient has to be found in the sparse matrix + // representation. So by default we don't perform this update immediately + // but instead mark the low-level modeling object "out of sync". + // If we want to support incremental extraction then we MUST perform + // the modification immediately or we will lose it. + + if (!supportIncrementalExtraction && !(slowUpdates & SlowSetCoefficient)) { + InvalidateModelSynchronization(); + } else { + int const row = constraint->index(); + int const col = variable->index(); + if (constraint_is_extracted(row) && variable_is_extracted(col)) { + // If row and column are both extracted then we can directly + // update the modeling object + DCHECK_LE(row, last_constraint_index_); + DCHECK_LE(col, last_variable_index_); + CHECK_STATUS(CPXXchgcoef(mEnv, mLp, row, col, new_value)); + } else { + // If either row or column is not yet extracted then we can + // defer the update to ExtractModel() + InvalidateModelSynchronization(); + } + } +} - CPXDIM const offset = last_constraint_index_; - CPXDIM const total = solver_->constraints_.size(); - - if ( total > offset ) { - // There are constraints that are not yet extracted. - - InvalidateSolutionSynchronization(); - - CPXDIM newCons = total - offset; - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - DCHECK_EQ(last_variable_index_, cols); - CPXDIM const chunk = 10; // max number of rows to add in one shot - - // Update indices of new constraints _before_ actually extracting - // them. In case of error we will just reset the indices. - for (CPXDIM c = offset; c < total; ++c) - set_constraint_as_extracted(c, true); - - try { - unique_ptr rmatind(new CPXDIM[cols]); - unique_ptr rmatval(new double[cols]); - unique_ptr rmatbeg(new CPXNNZ[chunk]); - unique_ptr sense(new char[chunk]); - unique_ptr rhs(new double[chunk]); - unique_ptr name(new char const*[chunk]); - unique_ptr rngval(new double[chunk]); - unique_ptr rngind(new CPXDIM[chunk]); - bool haveRanges = false; - - // Loop over the new constraints, collecting rows for up to - // CHUNK constraints into the arrays so that adding constraints - // is faster. - for (CPXDIM c = 0; c < newCons; /* nothing */) { - // Collect up to CHUNK constraints into the arrays. - CPXDIM nextRow = 0; - CPXNNZ nextNz = 0; - for (/* nothing */; c < newCons && nextRow < chunk; ++c, ++nextRow) { - MPConstraint const *const ct = solver_->constraints_[offset + c]; - - // Stop if there is not enough room in the arrays - // to add the current constraint. - if ( nextNz + ct->coefficients_.size() > cols ) { - DCHECK_GT(nextRow, 0); - break; - } - - // Setup right-hand side of constraint. - MakeRhs(ct->lb(), ct->ub(), rhs[nextRow], sense[nextRow], rngval[nextRow]); - haveRanges = haveRanges || (rngval[nextRow] != 0.0); - rngind[nextRow] = offset + c; - - // Setup left-hand side of constraint. - rmatbeg[nextRow] = nextNz; - CoeffMap const &coeffs = ct->coefficients_; - for (CoeffMap::const_iterator it(coeffs.begin()); - it != coeffs.end(); ++it) - { - CPXDIM const idx = it->first->index(); - if ( variable_is_extracted(idx) ) { - DCHECK_LT(nextNz, cols); - DCHECK_LT(idx, cols); - rmatind[nextNz] = idx; - rmatval[nextNz] = it->second; - ++nextNz; - } - } - - // Finally the name of the constraint. - name[nextRow] = ct->name().empty() ? 0 : ct->name().c_str(); - } - if ( nextRow > 0 ) { - CHECK_STATUS(CPXXaddrows(mEnv, mLp, 0, nextRow, nextNz, - rhs.get(), sense.get(), - rmatbeg.get(), rmatind.get(), - rmatval.get(), 0, - name.get())); - if ( haveRanges ) { - CHECK_STATUS(CPXXchgrngval(mEnv, mLp, nextRow, - rngind.get(), rngval.get())); - } - } - } - } - catch (...) { - // Undo all changes in case of error. - CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); - if ( rows > offset ) - (void)CPXXdelrows(mEnv, mLp, offset, rows - 1); - std::vector const &constraints = solver_->constraints(); - int const size = constraints.size(); - for (int i = offset; i < size; ++i) - set_constraint_as_extracted(i, false); - throw; - } +void CplexInterface::ClearConstraint(MPConstraint *const constraint) { + CPXDIM const row = constraint->index(); + if (!constraint_is_extracted(row)) + // There is nothing to do if the constraint was not even extracted. + return; + + // Clearing a constraint means setting all coefficients in the corresponding + // row to 0 (we cannot just delete the row since that would renumber all + // the constraints/rows after it). + // Modifying coefficients in the matrix is potentially pretty expensive + // since they must be found in the sparse matrix representation. That is + // why by default we do not modify the coefficients here but only mark + // the low-level modeling object "out of sync". + + if (!(slowUpdates & SlowClearConstraint)) { + InvalidateModelSynchronization(); + } else { + InvalidateSolutionSynchronization(); + + CPXDIM const len = constraint->coefficients_.size(); + unique_ptr rowind(new CPXDIM[len]); + unique_ptr colind(new CPXDIM[len]); + unique_ptr val(new double[len]); + CPXDIM j = 0; + CoeffMap const &coeffs = constraint->coefficients_; + for (CoeffMap::const_iterator it(coeffs.begin()); it != coeffs.end(); + ++it) { + CPXDIM const col = it->first->index(); + if (variable_is_extracted(col)) { + rowind[j] = row; + colind[j] = col; + val[j] = 0.0; + ++j; } - } + } + if (j) + CHECK_STATUS( + CPXXchgcoeflist(mEnv, mLp, j, rowind.get(), colind.get(), val.get())); + } +} - // Extract the objective function. - void CplexInterface::ExtractObjective() - { - // NOTE: The code assumes that the objective expression does not contain - // any non-zero duplicates. +void CplexInterface::SetObjectiveCoefficient(MPVariable const *const variable, + double coefficient) { + CPXDIM const col = variable->index(); + if (!variable_is_extracted(col)) + // Nothing to do if variable was not even extracted + return; + + InvalidateSolutionSynchronization(); + + // The objective function is stored as a dense vector, so updating a + // single coefficient is O(1). So by default we update the low-level + // modeling object here. + // If we support incremental extraction then we have no choice but to + // perform the update immediately. + + if (supportIncrementalExtraction || + (slowUpdates & SlowSetObjectiveCoefficient)) { + CHECK_STATUS(CPXXchgobj(mEnv, mLp, 1, &col, &coefficient)); + } else + InvalidateModelSynchronization(); +} - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - DCHECK_EQ(last_variable_index_, cols); +void CplexInterface::SetObjectiveOffset(double value) { + // Changing the objective offset is O(1), so we always do it immediately. + InvalidateSolutionSynchronization(); + CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, value)); +} - unique_ptr ind(new CPXDIM[cols]); - unique_ptr val(new double[cols]); - for (CPXDIM j = 0; j < cols; ++j) { - ind[j] = j; - val[j] = 0.0; +void CplexInterface::ClearObjective() { + InvalidateSolutionSynchronization(); + + // Since the objective function is stored as a dense vector updating + // it is O(n), so we usually perform the update immediately. + // If we want to support incremental extraction then we have no choice + // but to perform the update immediately. + + if (supportIncrementalExtraction || (slowUpdates & SlowClearObjective)) { + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + unique_ptr ind(new CPXDIM[cols]); + unique_ptr zero(new double[cols]); + CPXDIM j = 0; + CoeffMap const &coeffs = solver_->objective_->coefficients_; + for (CoeffMap::const_iterator it(coeffs.begin()); it != coeffs.end(); + ++it) { + CPXDIM const idx = it->first->index(); + // We only need to reset variables that have been extracted. + if (variable_is_extracted(idx)) { + DCHECK_LT(idx, cols); + ind[j] = idx; + zero[j] = 0.0; + ++j; } + } + if (j > 0) CHECK_STATUS(CPXXchgobj(mEnv, mLp, j, ind.get(), zero.get())); + CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, 0.0)); + } else + InvalidateModelSynchronization(); +} - CoeffMap const &coeffs = solver_->objective_->coefficients_; - for (CoeffMap::const_iterator it = coeffs.begin(); it != coeffs.end(); ++it) - { - CPXDIM const idx = it->first->index(); - if ( variable_is_extracted(idx) ) { - DCHECK_LT(idx, cols); - val[idx] = it->second; - } - } +// ------ Query statistics on the solution and the solve ------ - CHECK_STATUS(CPXXchgobj(mEnv, mLp, cols, ind.get(), val.get())); - CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, solver_->Objective().offset())); - } +int64 CplexInterface::iterations() const { + int iter; + if (!CheckSolutionIsSynchronized()) return kUnknownNumberOfIterations; + if (mMip) + return static_cast(CPXXgetmipitcnt(mEnv, mLp)); + else + return static_cast(CPXXgetitcnt(mEnv, mLp)); +} - // ------ Parameters ----- +int64 CplexInterface::nodes() const { + if (mMip) { + if (!CheckSolutionIsSynchronized()) return kUnknownNumberOfNodes; + return static_cast(CPXXgetnodecnt(mEnv, mLp)); + } else { + LOG(DFATAL) << "Number of nodes only available for discrete problems"; + return kUnknownNumberOfNodes; + } +} - void CplexInterface::SetParameters(const MPSolverParameters& param) - { - SetCommonParameters(param); - if (mMip) - SetMIPParameters(param); - } +// Returns the best objective bound. Only available for discrete problems. +double CplexInterface::best_objective_bound() const { + if (mMip) { + if (!CheckSolutionIsSynchronized() || !CheckBestObjectiveBoundExists()) + // trivial_worst_objective_bound() returns sense*infinity, + // that is meaningful even for infeasible problems + return trivial_worst_objective_bound(); + if (solver_->variables_.size() == 0 && solver_->constraints_.size() == 0) { + // For an empty model the best objective bound is just the offset. + return solver_->Objective().offset(); + } else { + double value = CPX_NAN; + CHECK_STATUS(CPXXgetbestobjval(mEnv, mLp, &value)); + return value; + } + } else { + LOG(DFATAL) << "Best objective bound only available for discrete problems"; + return trivial_worst_objective_bound(); + } +} - void CplexInterface::SetRelativeMipGap(double value) - { - if (mMip) { - CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPGAP, value)); - } - else { - LOG(WARNING) << "The relative MIP gap is only available " - << "for discrete problems."; - } - } - - void CplexInterface::SetPrimalTolerance(double value) - { - CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPRHS, value)); - } - - void CplexInterface::SetDualTolerance(double value) - { - CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPOPT, value)); - } - - void CplexInterface::SetPresolveMode(int value) - { - MPSolverParameters::PresolveValues const presolve - = static_cast(value); - - switch (presolve) { - case MPSolverParameters::PRESOLVE_OFF: - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_PREIND, CPX_OFF)); - return; - case MPSolverParameters::PRESOLVE_ON: - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_PREIND, CPX_ON)); - return; - } - SetIntegerParamToUnsupportedValue(MPSolverParameters::PRESOLVE, value); - } - - // Sets the scaling mode. - void CplexInterface::SetScalingMode(int value) - { - MPSolverParameters::ScalingValues const scaling - = static_cast(value); - - switch (scaling) { - case MPSolverParameters::SCALING_OFF: - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SCAIND, -1)); - break; - case MPSolverParameters::SCALING_ON: - // TODO: 0 is equilibrium scaling (the default), CPLEX also supports - // 1 aggressive scaling - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SCAIND, 0)); - break; - } - } +// Transform a CPLEX basis status to an MPSolver basis status. +MPSolver::BasisStatus CplexInterface::xformBasisStatus(int cplex_basis_status) { + switch (cplex_basis_status) { + case CPX_AT_LOWER: + return MPSolver::AT_LOWER_BOUND; + case CPX_BASIC: + return MPSolver::BASIC; + case CPX_AT_UPPER: + return MPSolver::AT_UPPER_BOUND; + case CPX_FREE_SUPER: + return MPSolver::FREE; + default: + LOG(DFATAL) << "Unknown CPLEX basis status"; + return MPSolver::FREE; + } +} - // Sets the LP algorithm : primal, dual or barrier. Note that CPLEX offers other LP algorithm (e.g. network) and automatic selection - void CplexInterface::SetLpAlgorithm(int value) - { - MPSolverParameters::LpAlgorithmValues const algorithm - = static_cast(value); +// Returns the basis status of a row. +MPSolver::BasisStatus CplexInterface::row_status(int constraint_index) const { + if (mMip) { + LOG(FATAL) << "Basis status only available for continuous problems"; + return MPSolver::FREE; + } + + if (CheckSolutionIsSynchronized()) { + if (!mRstat) { + CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); + unique_ptr data(new int[rows]); + mRstat.swap(data); + CHECK_STATUS(CPXXgetbase(mEnv, mLp, 0, mRstat.get())); + } + } else + mRstat = 0; + + if (mRstat) + return xformBasisStatus(mRstat[constraint_index]); + else { + LOG(FATAL) << "Row basis status not available"; + return MPSolver::FREE; + } +} - int alg = CPX_ALG_NONE; +// Returns the basis status of a column. +MPSolver::BasisStatus CplexInterface::column_status(int variable_index) const { + if (mMip) { + LOG(FATAL) << "Basis status only available for continuous problems"; + return MPSolver::FREE; + } - switch (algorithm) { - case MPSolverParameters::DUAL: alg = CPX_ALG_DUAL; break; - case MPSolverParameters::PRIMAL: alg = CPX_ALG_PRIMAL; break; - case MPSolverParameters::BARRIER: alg = CPX_ALG_BARRIER; break; - } + if (CheckSolutionIsSynchronized()) { + if (!mCstat) { + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + unique_ptr data(new int[cols]); + mCstat.swap(data); + CHECK_STATUS(CPXXgetbase(mEnv, mLp, mCstat.get(), 0)); + } + } else + mCstat = 0; + + if (mCstat) + return xformBasisStatus(mCstat[variable_index]); + else { + LOG(FATAL) << "Column basis status not available"; + return MPSolver::FREE; + } +} - if ( alg == CPX_ALG_NONE ) - SetIntegerParamToUnsupportedValue(MPSolverParameters::LP_ALGORITHM, value); - else { - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_LPMETHOD, alg)); - if ( mMip ) { - // For MIP we have to change two more parameters to specify the - // algorithm that is used to solve LP relaxations. - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_STARTALG, alg)); - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SUBALG, alg)); - } +// Extract all variables that have not yet been extracted. +void CplexInterface::ExtractNewVariables() { + // NOTE: The code assumes that a linear expression can never contain + // non-zero duplicates. + + InvalidateSolutionSynchronization(); + + if (!supportIncrementalExtraction) { + // Without incremental extraction ExtractModel() is always called + // to extract the full model. + CHECK(last_variable_index_ == 0 || + last_variable_index_ == solver_->variables_.size()); + CHECK(last_constraint_index_ == 0 || + last_constraint_index_ == solver_->constraints_.size()); + } + + int const last_extracted = last_variable_index_; + int const var_count = solver_->variables_.size(); + CPXDIM newcols = var_count - last_extracted; + if (newcols > 0) { + // There are non-extracted variables. Extract them now. + + unique_ptr obj(new double[newcols]); + unique_ptr lb(new double[newcols]); + unique_ptr ub(new double[newcols]); + unique_ptr ctype(new char[newcols]); + unique_ptr colname(new const char *[newcols]); + + bool have_names = false; + for (int j = 0, varidx = last_extracted; j < newcols; ++j, ++varidx) { + MPVariable const *const var = solver_->variables_[varidx]; + lb[j] = var->lb(); + ub[j] = var->ub(); + ctype[j] = var->integer() ? CPX_INTEGER : CPX_CONTINUOUS; + colname[j] = var->name().empty() ? 0 : var->name().c_str(); + have_names = have_names || var->name().empty(); + obj[j] = solver_->objective_->GetCoefficient(var); + } + + // Arrays for modifying the problem are setup. Update the index + // of variables that will get extracted now. Updating indices + // _before_ the actual extraction makes things much simpler in + // case we support incremental extraction. + // In case of error we just reset the indeces. + std::vector const &variables = solver_->variables(); + for (int j = last_extracted; j < var_count; ++j) { + CHECK(!variable_is_extracted(variables[j]->index())); + set_variable_as_extracted(variables[j]->index(), true); + } + + try { + bool use_newcols = true; + + if (supportIncrementalExtraction) { + // If we support incremental extraction then we must + // update existing constraints with the new variables. + // To do that we use CPXXaddcols() to actually create the + // variables. This is supposed to be faster than combining + // CPXXnewcols() and CPXXchgcoeflist(). + + // For each column count the size of the intersection with + // existing constraints. + unique_ptr collen(new CPXDIM[newcols]); + for (CPXDIM j = 0; j < newcols; ++j) collen[j] = 0; + CPXNNZ nonzeros = 0; + // TODO: Use a bitarray to flag the constraints that actually + // intersect new variables? + for (int i = 0; i < last_constraint_index_; ++i) { + MPConstraint const *const ct = solver_->constraints_[i]; + CHECK(constraint_is_extracted(ct->index())); + CoeffMap const &coeffs = ct->coefficients_; + for (CoeffMap::const_iterator it(coeffs.begin()); it != coeffs.end(); + ++it) { + int const idx = it->first->index(); + if (variable_is_extracted(idx) && idx > last_variable_index_) { + collen[idx - last_variable_index_]++; + ++nonzeros; + } + } + } + + if (nonzeros > 0) { + // At least one of the new variables did intersect with an + // old constraint. We have to create the new columns via + // CPXXaddcols(). + use_newcols = false; + unique_ptr begin(new CPXNNZ[newcols + 2]); + unique_ptr cmatind(new CPXDIM[nonzeros]); + unique_ptr cmatval(new double[nonzeros]); + + // Here is how cmatbeg[] is setup: + // - it is initialized as + // [ 0, 0, collen[0], collen[0]+collen[1], ... ] + // so that cmatbeg[j+1] tells us where in cmatind[] and + // cmatval[] we need to put the next nonzero for column + // j + // - after nonzeros have been setup the array looks like + // [ 0, collen[0], collen[0]+collen[1], ... ] + // so that it is the correct input argument for CPXXaddcols + CPXNNZ *cmatbeg = begin.get(); + cmatbeg[0] = 0; + cmatbeg[1] = 0; + ++cmatbeg; + for (CPXDIM j = 0; j < newcols; ++j) + cmatbeg[j + 1] = cmatbeg[j] + collen[j]; + + for (int i = 0; i < last_constraint_index_; ++i) { + MPConstraint const *const ct = solver_->constraints_[i]; + CPXDIM const row = ct->index(); + CoeffMap const &coeffs = ct->coefficients_; + for (CoeffMap::const_iterator it(coeffs.begin()); + it != coeffs.end(); ++it) { + int const idx = it->first->index(); + if (variable_is_extracted(idx) && idx > last_variable_index_) { + CPXNNZ const nz = cmatbeg[idx]++; + cmatind[nz] = idx; + cmatval[nz] = it->second; + } + } + } + --cmatbeg; + CHECK_STATUS(CPXXaddcols(mEnv, mLp, newcols, nonzeros, obj.get(), + cmatbeg, cmatind.get(), cmatval.get(), + lb.get(), ub.get(), + have_names ? colname.get() : 0)); + } } - } - - bool CplexInterface::ReadParameterFile(std::string const &filename) - { - // Return true on success and false on error. - return CPXXreadcopyparam(mEnv, filename.c_str()) == 0; - } - - std::string CplexInterface::ValidFileExtensionForParameterFile() const - { - return ".prm"; - } - - MPSolver::ResultStatus CplexInterface::Solve(MPSolverParameters const ¶m) - { - int status; - - // Delete chached information - mCstat = 0; - mRstat = 0; - - WallTimer timer; - timer.Start(); - - // Set incrementality - MPSolverParameters::IncrementalityValues const inc - = static_cast(param.GetIntegerParam(MPSolverParameters::INCREMENTALITY)); - switch (inc) { - case MPSolverParameters::INCREMENTALITY_OFF: - Reset(); /* This should not be required but re-extracting everything - * may be faster, so we do it. */ - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_ADVIND, 0)); - break; - case MPSolverParameters::INCREMENTALITY_ON: - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_ADVIND, 2)); - break; + if (use_newcols) { + // Either incremental extraction is not supported or none of + // the new variables did intersect an existing constraint. + // We can just use CPXXnewcols() to create the new variables. + CHECK_STATUS(CPXXnewcols(mEnv, mLp, newcols, obj.get(), lb.get(), + ub.get(), mMip ? ctype.get() : 0, + have_names ? colname.get() : 0)); + } else { + // Incremental extraction: we must update the ctype of the + // newly created variables (CPXXaddcols() does not allow + // specifying the ctype) + if (mMip) { + // Query the actual number of columns in case we did not + // manage to extract all columns. + int const cols = CPXXgetnumcols(mEnv, mLp); + unique_ptr ind(new CPXDIM[newcols]); + for (int j = last_extracted; j < cols; ++j) + ind[j - last_extracted] = j; + CHECK_STATUS(CPXXchgctype(mEnv, mLp, cols - last_extracted, ind.get(), + ctype.get())); + } } + } catch (...) { + // Undo all changes in case of error. + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + if (cols > last_extracted) + (void)CPXXdelcols(mEnv, mLp, last_extracted, cols - 1); + std::vector const &variables = solver_->variables(); + int const size = variables.size(); + for (int j = last_extracted; j < size; ++j) + set_variable_as_extracted(j, false); + throw; + } + } +} - // Extract the model to be solved. - // If we don't support incremental extraction and the low-level modeling - // is out of sync then we have to re-extract everything. Note that this - // will lose MIP starts or advanced basis information from a previous - // solve. - if ( !supportIncrementalExtraction && - sync_status_ == MUST_RELOAD ) - Reset(); - ExtractModel(); - VLOG(1) << StringPrintf("Model build in %.3f seconds.", timer.Get()); - - // Set log level. - CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SCRIND, quiet() ? CPX_OFF : CPX_ON)); - - // Set parameters. - // NOTE: We must invoke SetSolverSpecificParametersAsString() _first_. - // Its current implementation invokes ReadParameterFile() which in - // turn invokes CPXXreadcopyparam(). The latter will _overwrite_ - // all current parameter settings in the environment. - solver_->SetSolverSpecificParametersAsString(solver_->solver_specific_parameter_string_); - SetParameters(param); - if (solver_->time_limit()) { - VLOG(1) << "Setting time limit = " << solver_->time_limit() << " ms."; - CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_TILIM, solver_->time_limit() *1e-3)); +// Extract constraints that have not yet been extracted. +void CplexInterface::ExtractNewConstraints() { + // NOTE: The code assumes that a linear expression can never contain + // non-zero duplicates. + + if (!supportIncrementalExtraction) { + // Without incremental extraction ExtractModel() is always called + // to extract the full model. + CHECK(last_variable_index_ == 0 || + last_variable_index_ == solver_->variables_.size()); + CHECK(last_constraint_index_ == 0 || + last_constraint_index_ == solver_->constraints_.size()); + } + + CPXDIM const offset = last_constraint_index_; + CPXDIM const total = solver_->constraints_.size(); + + if (total > offset) { + // There are constraints that are not yet extracted. + + InvalidateSolutionSynchronization(); + + CPXDIM newCons = total - offset; + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + DCHECK_EQ(last_variable_index_, cols); + CPXDIM const chunk = 10; // max number of rows to add in one shot + + // Update indices of new constraints _before_ actually extracting + // them. In case of error we will just reset the indices. + for (CPXDIM c = offset; c < total; ++c) + set_constraint_as_extracted(c, true); + + try { + unique_ptr rmatind(new CPXDIM[cols]); + unique_ptr rmatval(new double[cols]); + unique_ptr rmatbeg(new CPXNNZ[chunk]); + unique_ptr sense(new char[chunk]); + unique_ptr rhs(new double[chunk]); + unique_ptr name(new char const *[chunk]); + unique_ptr rngval(new double[chunk]); + unique_ptr rngind(new CPXDIM[chunk]); + bool haveRanges = false; + + // Loop over the new constraints, collecting rows for up to + // CHUNK constraints into the arrays so that adding constraints + // is faster. + for (CPXDIM c = 0; c < newCons; /* nothing */) { + // Collect up to CHUNK constraints into the arrays. + CPXDIM nextRow = 0; + CPXNNZ nextNz = 0; + for (/* nothing */; c < newCons && nextRow < chunk; ++c, ++nextRow) { + MPConstraint const *const ct = solver_->constraints_[offset + c]; + + // Stop if there is not enough room in the arrays + // to add the current constraint. + if (nextNz + ct->coefficients_.size() > cols) { + DCHECK_GT(nextRow, 0); + break; + } + + // Setup right-hand side of constraint. + MakeRhs(ct->lb(), ct->ub(), rhs[nextRow], sense[nextRow], + rngval[nextRow]); + haveRanges = haveRanges || (rngval[nextRow] != 0.0); + rngind[nextRow] = offset + c; + + // Setup left-hand side of constraint. + rmatbeg[nextRow] = nextNz; + CoeffMap const &coeffs = ct->coefficients_; + for (CoeffMap::const_iterator it(coeffs.begin()); it != coeffs.end(); + ++it) { + CPXDIM const idx = it->first->index(); + if (variable_is_extracted(idx)) { + DCHECK_LT(nextNz, cols); + DCHECK_LT(idx, cols); + rmatind[nextNz] = idx; + rmatval[nextNz] = it->second; + ++nextNz; + } + } + + // Finally the name of the constraint. + name[nextRow] = ct->name().empty() ? 0 : ct->name().c_str(); + } + if (nextRow > 0) { + CHECK_STATUS(CPXXaddrows(mEnv, mLp, 0, nextRow, nextNz, rhs.get(), + sense.get(), rmatbeg.get(), rmatind.get(), + rmatval.get(), 0, name.get())); + if (haveRanges) { + CHECK_STATUS( + CPXXchgrngval(mEnv, mLp, nextRow, rngind.get(), rngval.get())); + } + } } + } catch (...) { + // Undo all changes in case of error. + CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); + if (rows > offset) (void)CPXXdelrows(mEnv, mLp, offset, rows - 1); + std::vector const &constraints = solver_->constraints(); + int const size = constraints.size(); + for (int i = offset; i < size; ++i) set_constraint_as_extracted(i, false); + throw; + } + } +} - // Solve. - // Do not CHECK_STATUS here since some errors (for example CPXERR_NO_MEMORY) - // still allow us to query useful information. - timer.Restart(); - if (mMip) { - status = CPXXmipopt(mEnv, mLp); - } - else { - status = CPXXlpopt(mEnv, mLp); - } +// Extract the objective function. +void CplexInterface::ExtractObjective() { + // NOTE: The code assumes that the objective expression does not contain + // any non-zero duplicates. + + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + DCHECK_EQ(last_variable_index_, cols); + + unique_ptr ind(new CPXDIM[cols]); + unique_ptr val(new double[cols]); + for (CPXDIM j = 0; j < cols; ++j) { + ind[j] = j; + val[j] = 0.0; + } + + CoeffMap const &coeffs = solver_->objective_->coefficients_; + for (CoeffMap::const_iterator it = coeffs.begin(); it != coeffs.end(); ++it) { + CPXDIM const idx = it->first->index(); + if (variable_is_extracted(idx)) { + DCHECK_LT(idx, cols); + val[idx] = it->second; + } + } + + CHECK_STATUS(CPXXchgobj(mEnv, mLp, cols, ind.get(), val.get())); + CHECK_STATUS(CPXEsetobjoffset(mEnv, mLp, solver_->Objective().offset())); +} - // Disable screen output right after solve - (void)CPXXsetintparam(mEnv, CPX_PARAM_SCRIND, CPX_OFF); +// ------ Parameters ----- - if ( status ) { - VLOG(1) << StringPrintf("Failed to optimize MIP. Error %d", status); - // NOTE: We do not return immediately since there may be information - // to grab (for example an incumbent) - } - else { - VLOG(1) << StringPrintf("Solved in %.3f seconds.", timer.Get()); - } +void CplexInterface::SetParameters(const MPSolverParameters ¶m) { + SetCommonParameters(param); + if (mMip) SetMIPParameters(param); +} - int const cpxstat = CPXXgetstat(mEnv, mLp); - VLOG(1) << StringPrintf("CPLEX solution status %d.", cpxstat); +void CplexInterface::SetRelativeMipGap(double value) { + if (mMip) { + CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPGAP, value)); + } else { + LOG(WARNING) << "The relative MIP gap is only available " + << "for discrete problems."; + } +} - // Figure out what solution we have. - int solnmethod, solntype, pfeas, dfeas; - CHECK_STATUS(CPXXsolninfo(mEnv, mLp, &solnmethod, &solntype, &pfeas, &dfeas)); - bool const feasible = pfeas != 0; +void CplexInterface::SetPrimalTolerance(double value) { + CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPRHS, value)); +} - // Get problem dimensions for solution queries below. - CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); - CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); - DCHECK_EQ(rows, solver_->constraints_.size()); - DCHECK_EQ(cols, solver_->variables_.size()); - - // Capture objective function value. - objective_value_ = CPX_NAN; - if ( pfeas ) - CHECK_STATUS(CPXXgetobjval(mEnv, mLp, &objective_value_)); - VLOG(1) << "objective = " << objective_value_; - - // Capture primal and dual solutions - if ( mMip ) { - // If there is a primal feasible solution then capture it. - if ( pfeas ) { - if ( cols > 0 ) { - unique_ptr x(new double[cols]); - CHECK_STATUS(CPXXgetx(mEnv, mLp, x.get(), 0, cols - 1)); - for (int i = 0; i < solver_->variables_.size(); ++i) { - MPVariable* const var = solver_->variables_[i]; - var->set_solution_value(x[i]); - VLOG(3) << var->name() << ": value =" << x[i]; - } - } - } - else { - for (int i = 0; i < solver_->variables_.size(); ++i) - solver_->variables_[i]->set_solution_value(CPX_NAN); - } - - // MIP does not have duals - for (int i = 0; i < solver_->variables_.size(); ++i) - solver_->variables_[i]->set_reduced_cost(CPX_NAN); - for (int i = 0; i < solver_->constraints_.size(); ++i) - solver_->constraints_[i]->set_dual_value(CPX_NAN); +void CplexInterface::SetDualTolerance(double value) { + CHECK_STATUS(CPXXsetdblparam(mEnv, CPX_PARAM_EPOPT, value)); +} + +void CplexInterface::SetPresolveMode(int value) { + MPSolverParameters::PresolveValues const presolve = + static_cast(value); + + switch (presolve) { + case MPSolverParameters::PRESOLVE_OFF: + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_PREIND, CPX_OFF)); + return; + case MPSolverParameters::PRESOLVE_ON: + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_PREIND, CPX_ON)); + return; + } + SetIntegerParamToUnsupportedValue(MPSolverParameters::PRESOLVE, value); +} + +// Sets the scaling mode. +void CplexInterface::SetScalingMode(int value) { + MPSolverParameters::ScalingValues const scaling = + static_cast(value); + + switch (scaling) { + case MPSolverParameters::SCALING_OFF: + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SCAIND, -1)); + break; + case MPSolverParameters::SCALING_ON: + // TODO: 0 is equilibrium scaling (the default), CPLEX also supports + // 1 aggressive scaling + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SCAIND, 0)); + break; + } +} + +// Sets the LP algorithm : primal, dual or barrier. Note that CPLEX offers other +// LP algorithm (e.g. network) and automatic selection +void CplexInterface::SetLpAlgorithm(int value) { + MPSolverParameters::LpAlgorithmValues const algorithm = + static_cast(value); + + int alg = CPX_ALG_NONE; + + switch (algorithm) { + case MPSolverParameters::DUAL: + alg = CPX_ALG_DUAL; + break; + case MPSolverParameters::PRIMAL: + alg = CPX_ALG_PRIMAL; + break; + case MPSolverParameters::BARRIER: + alg = CPX_ALG_BARRIER; + break; + } + + if (alg == CPX_ALG_NONE) + SetIntegerParamToUnsupportedValue(MPSolverParameters::LP_ALGORITHM, value); + else { + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_LPMETHOD, alg)); + if (mMip) { + // For MIP we have to change two more parameters to specify the + // algorithm that is used to solve LP relaxations. + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_STARTALG, alg)); + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_SUBALG, alg)); + } + } +} + +bool CplexInterface::ReadParameterFile(std::string const &filename) { + // Return true on success and false on error. + return CPXXreadcopyparam(mEnv, filename.c_str()) == 0; +} + +std::string CplexInterface::ValidFileExtensionForParameterFile() const { + return ".prm"; +} + +MPSolver::ResultStatus CplexInterface::Solve(MPSolverParameters const ¶m) { + int status; + + // Delete chached information + mCstat = 0; + mRstat = 0; + + WallTimer timer; + timer.Start(); + + // Set incrementality + MPSolverParameters::IncrementalityValues const inc = + static_cast( + param.GetIntegerParam(MPSolverParameters::INCREMENTALITY)); + switch (inc) { + case MPSolverParameters::INCREMENTALITY_OFF: + Reset(); /* This should not be required but re-extracting everything + * may be faster, so we do it. */ + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_ADVIND, 0)); + break; + case MPSolverParameters::INCREMENTALITY_ON: + CHECK_STATUS(CPXXsetintparam(mEnv, CPX_PARAM_ADVIND, 2)); + break; + } + + // Extract the model to be solved. + // If we don't support incremental extraction and the low-level modeling + // is out of sync then we have to re-extract everything. Note that this + // will lose MIP starts or advanced basis information from a previous + // solve. + if (!supportIncrementalExtraction && sync_status_ == MUST_RELOAD) Reset(); + ExtractModel(); + VLOG(1) << StringPrintf("Model build in %.3f seconds.", timer.Get()); + + // Set log level. + CHECK_STATUS( + CPXXsetintparam(mEnv, CPX_PARAM_SCRIND, quiet() ? CPX_OFF : CPX_ON)); + + // Set parameters. + // NOTE: We must invoke SetSolverSpecificParametersAsString() _first_. + // Its current implementation invokes ReadParameterFile() which in + // turn invokes CPXXreadcopyparam(). The latter will _overwrite_ + // all current parameter settings in the environment. + solver_->SetSolverSpecificParametersAsString( + solver_->solver_specific_parameter_string_); + SetParameters(param); + if (solver_->time_limit()) { + VLOG(1) << "Setting time limit = " << solver_->time_limit() << " ms."; + CHECK_STATUS( + CPXXsetdblparam(mEnv, CPX_PARAM_TILIM, solver_->time_limit() * 1e-3)); + } + + // Solve. + // Do not CHECK_STATUS here since some errors (for example CPXERR_NO_MEMORY) + // still allow us to query useful information. + timer.Restart(); + if (mMip) { + status = CPXXmipopt(mEnv, mLp); + } else { + status = CPXXlpopt(mEnv, mLp); + } + + // Disable screen output right after solve + (void)CPXXsetintparam(mEnv, CPX_PARAM_SCRIND, CPX_OFF); + + if (status) { + VLOG(1) << StringPrintf("Failed to optimize MIP. Error %d", status); + // NOTE: We do not return immediately since there may be information + // to grab (for example an incumbent) + } else { + VLOG(1) << StringPrintf("Solved in %.3f seconds.", timer.Get()); + } + + int const cpxstat = CPXXgetstat(mEnv, mLp); + VLOG(1) << StringPrintf("CPLEX solution status %d.", cpxstat); + + // Figure out what solution we have. + int solnmethod, solntype, pfeas, dfeas; + CHECK_STATUS(CPXXsolninfo(mEnv, mLp, &solnmethod, &solntype, &pfeas, &dfeas)); + bool const feasible = pfeas != 0; + + // Get problem dimensions for solution queries below. + CPXDIM const rows = CPXXgetnumrows(mEnv, mLp); + CPXDIM const cols = CPXXgetnumcols(mEnv, mLp); + DCHECK_EQ(rows, solver_->constraints_.size()); + DCHECK_EQ(cols, solver_->variables_.size()); + + // Capture objective function value. + objective_value_ = CPX_NAN; + if (pfeas) CHECK_STATUS(CPXXgetobjval(mEnv, mLp, &objective_value_)); + VLOG(1) << "objective = " << objective_value_; + + // Capture primal and dual solutions + if (mMip) { + // If there is a primal feasible solution then capture it. + if (pfeas) { + if (cols > 0) { + unique_ptr x(new double[cols]); + CHECK_STATUS(CPXXgetx(mEnv, mLp, x.get(), 0, cols - 1)); + for (int i = 0; i < solver_->variables_.size(); ++i) { + MPVariable *const var = solver_->variables_[i]; + var->set_solution_value(x[i]); + VLOG(3) << var->name() << ": value =" << x[i]; + } } - else { - // Continuous problem. - if ( cols > 0 ) { - unique_ptr x(new double[cols]); - unique_ptr dj(new double[cols]); - if ( pfeas ) - CHECK_STATUS(CPXXgetx(mEnv, mLp, x.get(), 0, cols - 1)); - if ( dfeas ) - CHECK_STATUS(CPXXgetdj(mEnv, mLp, dj.get(), 0, cols - 1)); - for (int i = 0; i < solver_->variables_.size(); ++i) { - MPVariable* const var = solver_->variables_[i]; - var->set_solution_value(x[i]); - bool value = false, dual = false; - - if ( pfeas ) { - var->set_solution_value(x[i]); - value = true; - } - else - var->set_solution_value(CPX_NAN); - if ( dfeas ) { - var->set_reduced_cost(dj[i]); - dual = true; - } - else - var->set_reduced_cost(CPX_NAN); - VLOG(3) << var->name() << ":" - << (value ? StringPrintf(" value = %f", x[i]) : "") - << (dual ? StringPrintf(" reduced cost = %f", dj[i]) : ""); - } - } - - if ( rows > 0 ) { - unique_ptr pi(new double[rows]); - if ( dfeas ) - CHECK_STATUS(CPXXgetpi(mEnv, mLp, pi.get(), 0, rows - 1)); - for (int i = 0; i < solver_->constraints_.size(); ++i) { - MPConstraint* const ct = solver_->constraints_[i]; - bool dual = false; - if ( dfeas ) { - ct->set_dual_value(pi[i]); - dual = true; - } - else - ct->set_dual_value(CPX_NAN); - VLOG(4) << "row " << ct->index() << ":" - << (dual ? StringPrintf(" dual = %f", pi[i]) : ""); - } - } + } else { + for (int i = 0; i < solver_->variables_.size(); ++i) + solver_->variables_[i]->set_solution_value(CPX_NAN); + } + + // MIP does not have duals + for (int i = 0; i < solver_->variables_.size(); ++i) + solver_->variables_[i]->set_reduced_cost(CPX_NAN); + for (int i = 0; i < solver_->constraints_.size(); ++i) + solver_->constraints_[i]->set_dual_value(CPX_NAN); + } else { + // Continuous problem. + if (cols > 0) { + unique_ptr x(new double[cols]); + unique_ptr dj(new double[cols]); + if (pfeas) CHECK_STATUS(CPXXgetx(mEnv, mLp, x.get(), 0, cols - 1)); + if (dfeas) CHECK_STATUS(CPXXgetdj(mEnv, mLp, dj.get(), 0, cols - 1)); + for (int i = 0; i < solver_->variables_.size(); ++i) { + MPVariable *const var = solver_->variables_[i]; + var->set_solution_value(x[i]); + bool value = false, dual = false; + + if (pfeas) { + var->set_solution_value(x[i]); + value = true; + } else + var->set_solution_value(CPX_NAN); + if (dfeas) { + var->set_reduced_cost(dj[i]); + dual = true; + } else + var->set_reduced_cost(CPX_NAN); + VLOG(3) << var->name() << ":" + << (value ? StringPrintf(" value = %f", x[i]) : "") + << (dual ? StringPrintf(" reduced cost = %f", dj[i]) : ""); } - - // Map CPLEX status to more generic solution status in MPSolver - switch (cpxstat) { - case CPX_STAT_OPTIMAL: - case CPXMIP_OPTIMAL: - result_status_ = MPSolver::OPTIMAL; - break; - case CPXMIP_OPTIMAL_TOL: - // To be consistent with the other solvers. - result_status_ = MPSolver::OPTIMAL; - break; - case CPX_STAT_INFEASIBLE: - case CPXMIP_INFEASIBLE: - result_status_ = MPSolver::INFEASIBLE; - break; - case CPX_STAT_UNBOUNDED: - case CPXMIP_UNBOUNDED: - result_status_ = MPSolver::UNBOUNDED; - break; - case CPX_STAT_INForUNBD: - case CPXMIP_INForUNBD: - result_status_ = MPSolver::INFEASIBLE; - break; - default: - result_status_ = feasible ? MPSolver::FEASIBLE : MPSolver::ABNORMAL; - break; + } + + if (rows > 0) { + unique_ptr pi(new double[rows]); + if (dfeas) CHECK_STATUS(CPXXgetpi(mEnv, mLp, pi.get(), 0, rows - 1)); + for (int i = 0; i < solver_->constraints_.size(); ++i) { + MPConstraint *const ct = solver_->constraints_[i]; + bool dual = false; + if (dfeas) { + ct->set_dual_value(pi[i]); + dual = true; + } else + ct->set_dual_value(CPX_NAN); + VLOG(4) << "row " << ct->index() << ":" + << (dual ? StringPrintf(" dual = %f", pi[i]) : ""); } + } + } + + // Map CPLEX status to more generic solution status in MPSolver + switch (cpxstat) { + case CPX_STAT_OPTIMAL: + case CPXMIP_OPTIMAL: + result_status_ = MPSolver::OPTIMAL; + break; + case CPXMIP_OPTIMAL_TOL: + // To be consistent with the other solvers. + result_status_ = MPSolver::OPTIMAL; + break; + case CPX_STAT_INFEASIBLE: + case CPXMIP_INFEASIBLE: + result_status_ = MPSolver::INFEASIBLE; + break; + case CPX_STAT_UNBOUNDED: + case CPXMIP_UNBOUNDED: + result_status_ = MPSolver::UNBOUNDED; + break; + case CPX_STAT_INForUNBD: + case CPXMIP_INForUNBD: + result_status_ = MPSolver::INFEASIBLE; + break; + default: + result_status_ = feasible ? MPSolver::FEASIBLE : MPSolver::ABNORMAL; + break; + } + + sync_status_ = SOLUTION_SYNCHRONIZED; + return result_status_; +} - sync_status_ = SOLUTION_SYNCHRONIZED; - return result_status_; - } - - MPSolverInterface *BuildCplexInterface(bool mip, MPSolver *const solver) - { - return new CplexInterface(solver, mip); - } +MPSolverInterface *BuildCplexInterface(bool mip, MPSolver *const solver) { + return new CplexInterface(solver, mip); +} } // namespace operations_research #endif // #if defined(USE_CPLEX) diff --git a/ortools/linear_solver/glop_interface.cc b/ortools/linear_solver/glop_interface.cc index f80628ad487..aca07599759 100644 --- a/ortools/linear_solver/glop_interface.cc +++ b/ortools/linear_solver/glop_interface.cc @@ -11,17 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. - -#include +#include #include +#include #include -#include - #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/port.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/hash.h" #include "ortools/glop/lp_solver.h" @@ -33,12 +31,9 @@ #include "ortools/port/proto_utils.h" #include "ortools/util/time_limit.h" - namespace operations_research { -namespace { - -} // Anonymous namespace +namespace {} // Anonymous namespace class GLOPInterface : public MPSolverInterface { public: @@ -96,7 +91,8 @@ class GLOPInterface : public MPSolverInterface { void SetPresolveMode(int value) override; void SetScalingMode(int value) override; void SetLpAlgorithm(int value) override; - bool SetSolverSpecificParametersAsString(const std::string& parameters) override; + bool SetSolverSpecificParametersAsString( + const std::string& parameters) override; private: void NonIncrementalChange(); @@ -345,7 +341,6 @@ void GLOPInterface::SetParameters(const MPSolverParameters& param) { parameters_.Clear(); SetCommonParameters(param); SetScalingMode(param.GetIntegerParam(MPSolverParameters::SCALING)); - } void GLOPInterface::SetRelativeMipGap(double value) { @@ -443,5 +438,4 @@ MPSolverInterface* BuildGLOPInterface(MPSolver* const solver) { return new GLOPInterface(solver); } - } // namespace operations_research diff --git a/ortools/linear_solver/glpk_interface.cc b/ortools/linear_solver/glpk_interface.cc index 6d0abf2b6d7..2562399bfa7 100644 --- a/ortools/linear_solver/glpk_interface.cc +++ b/ortools/linear_solver/glpk_interface.cc @@ -17,20 +17,20 @@ #include #include -#include #include #include #include +#include #include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/port.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/port.h" -#include "ortools/base/hash.h" #include "ortools/linear_solver/linear_solver.h" extern "C" { @@ -993,6 +993,5 @@ MPSolverInterface* BuildGLPKInterface(bool mip, MPSolver* const solver) { return new GLPKInterface(solver, mip); } - } // namespace operations_research #endif // #if defined(USE_GLPK) diff --git a/ortools/linear_solver/gurobi_interface.cc b/ortools/linear_solver/gurobi_interface.cc index 54bdc34ace7..65c931aca9b 100644 --- a/ortools/linear_solver/gurobi_interface.cc +++ b/ortools/linear_solver/gurobi_interface.cc @@ -15,27 +15,26 @@ #include #include -#include #include #include #include +#include #include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/map_util.h" +#include "ortools/base/port.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/port.h" -#include "ortools/base/map_util.h" #include "ortools/linear_solver/linear_solver.h" extern "C" { #include "gurobi_c.h" } - DEFINE_int32(num_gurobi_threads, 4, "Number of threads available for Gurobi."); namespace operations_research { @@ -157,8 +156,8 @@ class GurobiInterface : public MPSolverInterface { bool ReadParameterFile(const std::string& filename) override; std::string ValidFileExtensionForParameterFile() const override; - MPSolver::BasisStatus TransformGRBVarBasisStatus(int gurobi_basis_status) - const; + MPSolver::BasisStatus TransformGRBVarBasisStatus( + int gurobi_basis_status) const; MPSolver::BasisStatus TransformGRBConstraintBasisStatus( int gurobi_basis_status, int constraint_index) const; @@ -176,10 +175,10 @@ class GurobiInterface : public MPSolverInterface { // Creates a LP/MIP instance with the specified name and minimization objective. GurobiInterface::GurobiInterface(MPSolver* const solver, bool mip) : MPSolverInterface(solver), model_(nullptr), env_(nullptr), mip_(mip) { - if (GRBloadenv(&env_, nullptr) != 0 || env_ == nullptr) { - LOG(FATAL) << "Error: could not create environment: " - << GRBgeterrormsg(env_); - } + if (GRBloadenv(&env_, nullptr) != 0 || env_ == nullptr) { + LOG(FATAL) << "Error: could not create environment: " + << GRBgeterrormsg(env_); + } CheckedGurobiCall(GRBnewmodel(env_, &model_, solver_->name_.c_str(), 0, // numvars @@ -444,8 +443,7 @@ void GurobiInterface::ExtractNewVariables() { std::unique_ptr lb(new double[num_new_variables]); std::unique_ptr ub(new double[num_new_variables]); std::unique_ptr ctype(new char[num_new_variables]); - std::unique_ptr colname( - new const char* [num_new_variables]); + std::unique_ptr colname(new const char*[num_new_variables]); for (int j = 0; j < num_new_variables; ++j) { MPVariable* const var = solver_->variables_[last_variable_index_ + j]; @@ -783,6 +781,5 @@ MPSolverInterface* BuildGurobiInterface(bool mip, MPSolver* const solver) { return new GurobiInterface(solver, mip); } - } // namespace operations_research #endif // #if defined(USE_GUROBI) diff --git a/ortools/linear_solver/linear_expr.h b/ortools/linear_solver/linear_expr.h index fb47f8a3bd5..1fc9cbd02f0 100644 --- a/ortools/linear_solver/linear_expr.h +++ b/ortools/linear_solver/linear_expr.h @@ -149,7 +149,8 @@ LinearExpr operator*(double lhs, LinearExpr rhs); // The sum is represented as a LinearExpr with offset 0. // // Must be added to model with -// MPSolver::AddRowConstraint(const LinearRange& range[, const std::string& name]); +// MPSolver::AddRowConstraint(const LinearRange& range[, const std::string& +// name]); class LinearRange { public: LinearRange() : lower_bound_(0), upper_bound_(0) {} diff --git a/ortools/linear_solver/linear_solver.cc b/ortools/linear_solver/linear_solver.cc index fbf9000a6df..9cc3faf9426 100644 --- a/ortools/linear_solver/linear_solver.cc +++ b/ortools/linear_solver/linear_solver.cc @@ -19,7 +19,6 @@ #include #endif - #include #include #include @@ -32,18 +31,17 @@ #include "ortools/port/file.h" - +#include "ortools/base/accurate_sum.h" +#include "ortools/base/canonical_errors.h" +#include "ortools/base/hash.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" -#include "ortools/base/accurate_sum.h" -#include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/base/stringprintf.h" +#include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/linear_solver/model_exporter.h" #include "ortools/linear_solver/model_validator.h" #include "ortools/util/fp_utils.h" -#include "ortools/base/canonical_errors.h" DEFINE_bool(verify_solution, false, "Systematically verify the solution when calling Solve()" @@ -61,7 +59,6 @@ DEFINE_bool(mpsolver_bypass_model_validation, false, " Invalid models will typically trigger various error responses" " from the underlying solvers; sometimes crashes."); - // To compile the open-source code, the anonymous namespace should be // inside the operations_research namespace (This is due to the // open-sourced version of StringPrintf which is defined inside the @@ -300,13 +297,16 @@ void MPVariable::SetInteger(bool integer) { bool MPSolver::IsMIP() const { return interface_->IsMIP(); } -std::string MPSolver::SolverVersion() const { return interface_->SolverVersion(); } +std::string MPSolver::SolverVersion() const { + return interface_->SolverVersion(); +} void* MPSolver::underlying_solver() { return interface_->underlying_solver(); } // ---- Solver-specific parameters ---- -bool MPSolver::SetSolverSpecificParametersAsString(const std::string& parameters) { +bool MPSolver::SetSolverSpecificParametersAsString( + const std::string& parameters) { solver_specific_parameter_string_ = parameters; return interface_->SetSolverSpecificParametersAsString(parameters); } @@ -345,7 +345,6 @@ extern MPSolverInterface* BuildCplexInterface(bool mip, MPSolver* const solver); extern MPSolverInterface* BuildGLOPInterface(MPSolver* const solver); #endif - namespace { MPSolverInterface* BuildSolverInterface(MPSolver* const solver) { DCHECK(solver != nullptr); @@ -413,7 +412,8 @@ MPSolver::OptimizationProblemType DetourProblemType( } } // namespace -MPSolver::MPSolver(const std::string& name, OptimizationProblemType problem_type) +MPSolver::MPSolver(const std::string& name, + OptimizationProblemType problem_type) : name_(name), problem_type_(problem_type), #if !defined(_MSC_VER) @@ -434,29 +434,29 @@ MPSolver::~MPSolver() { Clear(); } // static bool MPSolver::SupportsProblemType(OptimizationProblemType problem_type) { #ifdef USE_CLP - if (problem_type == CLP_LINEAR_PROGRAMMING) return true; - #endif - #ifdef USE_GLPK - if (problem_type == GLPK_LINEAR_PROGRAMMING) return true; - if (problem_type == GLPK_MIXED_INTEGER_PROGRAMMING) return true; - #endif - #ifdef USE_BOP - if (problem_type == BOP_INTEGER_PROGRAMMING) return true; - #endif - #ifdef USE_GLOP - if (problem_type == GLOP_LINEAR_PROGRAMMING) return true; - #endif - #ifdef USE_GUROBI - if (problem_type == GUROBI_LINEAR_PROGRAMMING) return true; - if (problem_type == GUROBI_MIXED_INTEGER_PROGRAMMING) return true; - #endif - #ifdef USE_SCIP - if (problem_type == SCIP_MIXED_INTEGER_PROGRAMMING) return true; - #endif - #ifdef USE_CBC - if (problem_type == CBC_MIXED_INTEGER_PROGRAMMING) return true; - #endif - return false; + if (problem_type == CLP_LINEAR_PROGRAMMING) return true; +#endif +#ifdef USE_GLPK + if (problem_type == GLPK_LINEAR_PROGRAMMING) return true; + if (problem_type == GLPK_MIXED_INTEGER_PROGRAMMING) return true; +#endif +#ifdef USE_BOP + if (problem_type == BOP_INTEGER_PROGRAMMING) return true; +#endif +#ifdef USE_GLOP + if (problem_type == GLOP_LINEAR_PROGRAMMING) return true; +#endif +#ifdef USE_GUROBI + if (problem_type == GUROBI_LINEAR_PROGRAMMING) return true; + if (problem_type == GUROBI_MIXED_INTEGER_PROGRAMMING) return true; +#endif +#ifdef USE_SCIP + if (problem_type == SCIP_MIXED_INTEGER_PROGRAMMING) return true; +#endif +#ifdef USE_CBC + if (problem_type == CBC_MIXED_INTEGER_PROGRAMMING) return true; +#endif + return false; } // static @@ -523,8 +523,8 @@ void MPSolver::SetIndexConstraints(bool enabled) { constraint_name_to_index_.reset(new_map); } -MPConstraint* MPSolver::LookupConstraintOrNull(const std::string& constraint_name) - const { +MPConstraint* MPSolver::LookupConstraintOrNull( + const std::string& constraint_name) const { if (!constraint_name_to_index_) { return nullptr; } @@ -555,7 +555,8 @@ MPSolverResponseStatus MPSolver::LoadModelFromProtoWithUniqueNamesOrDie( } MPSolverResponseStatus MPSolver::LoadModelFromProtoInternal( - const MPModelProto& input_model, bool clear_names, std::string* error_message) { + const MPModelProto& input_model, bool clear_names, + std::string* error_message) { CHECK(error_message != nullptr); const std::string error = FindErrorInMPModelProto(input_model); if (!error.empty()) { @@ -567,8 +568,9 @@ MPSolverResponseStatus MPSolver::LoadModelFromProtoInternal( << "Ignoring the model error(s) because of" << " --mpsolver_bypass_model_validation."; } else { - return error.find("Infeasible") == std::string::npos ? MPSOLVER_MODEL_INVALID - : MPSOLVER_INFEASIBLE; + return error.find("Infeasible") == std::string::npos + ? MPSOLVER_MODEL_INVALID + : MPSOLVER_INFEASIBLE; } } @@ -674,10 +676,10 @@ void MPSolver::SolveWithProto(const MPModelRequest& model_request, std::string error_message; response->set_status(solver.LoadModelFromProto(model, &error_message)); if (response->status() != MPSOLVER_MODEL_IS_VALID) { - LOG(WARNING) - << "Loading model from protocol buffer failed, load status = " - << ProtoEnumToString(response->status()) << " (" - << response->status() << "); Error: " << error_message; + LOG(WARNING) << "Loading model from protocol buffer failed, load status = " + << ProtoEnumToString( + response->status()) + << " (" << response->status() << "); Error: " << error_message; return; } @@ -858,11 +860,13 @@ MPVariable* MPSolver::MakeVar(double lb, double ub, bool integer, return v; } -MPVariable* MPSolver::MakeNumVar(double lb, double ub, const std::string& name) { +MPVariable* MPSolver::MakeNumVar(double lb, double ub, + const std::string& name) { return MakeVar(lb, ub, false, name); } -MPVariable* MPSolver::MakeIntVar(double lb, double ub, const std::string& name) { +MPVariable* MPSolver::MakeIntVar(double lb, double ub, + const std::string& name) { return MakeVar(lb, ub, true, name); } @@ -886,12 +890,14 @@ void MPSolver::MakeVarArray(int nb, double lb, double ub, bool integer, } } -void MPSolver::MakeNumVarArray(int nb, double lb, double ub, const std::string& name, +void MPSolver::MakeNumVarArray(int nb, double lb, double ub, + const std::string& name, std::vector* vars) { MakeVarArray(nb, lb, ub, false, name, vars); } -void MPSolver::MakeIntVarArray(int nb, double lb, double ub, const std::string& name, +void MPSolver::MakeIntVarArray(int nb, double lb, double ub, + const std::string& name, std::vector* vars) { MakeVarArray(nb, lb, ub, true, name, vars); } @@ -915,8 +921,7 @@ MPConstraint* MPSolver::MakeRowConstraint(double lb, double ub, const std::string fixed_name = name.empty() ? StringPrintf("auto_c_%09d", constraint_index) : name; if (constraint_name_to_index_) { - gtl::InsertOrDie(&*constraint_name_to_index_, fixed_name, - constraint_index); + gtl::InsertOrDie(&*constraint_name_to_index_, fixed_name, constraint_index); } MPConstraint* const constraint = new MPConstraint(constraint_index, lb, ub, fixed_name, interface_.get()); @@ -996,15 +1001,14 @@ MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters& param) { return interface_->result_status_; } - MPSolver::ResultStatus status = interface_->Solve(param); if (FLAGS_verify_solution) { if (status != MPSolver::OPTIMAL && status != MPSolver::FEASIBLE) { VLOG(1) << "--verify_solution enabled, but the solver did not find a" << " solution: skipping the verification."; } else if (!VerifySolution( - param.GetDoubleParam(MPSolverParameters::PRIMAL_TOLERANCE), - FLAGS_log_verification_errors)) { + param.GetDoubleParam(MPSolverParameters::PRIMAL_TOLERANCE), + FLAGS_log_verification_errors)) { status = MPSolver::ABNORMAL; interface_->result_status_ = status; } @@ -1013,7 +1017,9 @@ MPSolver::ResultStatus MPSolver::Solve(const MPSolverParameters& param) { return status; } -void MPSolver::Write(const std::string& file_name) { interface_->Write(file_name); } +void MPSolver::Write(const std::string& file_name) { + interface_->Write(file_name); +} namespace { std::string PrettyPrintVar(const MPVariable& var) { @@ -1112,8 +1118,8 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (value < var.lb() - tolerance) { ++num_errors; max_observed_error = std::max(max_observed_error, var.lb() - value); - LOG_IF(ERROR, log_errors) << "Value " << value << " too low for " - << PrettyPrintVar(var); + LOG_IF(ERROR, log_errors) + << "Value " << value << " too low for " << PrettyPrintVar(var); } } // Check upper bound. @@ -1121,8 +1127,8 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (value > var.ub() + tolerance) { ++num_errors; max_observed_error = std::max(max_observed_error, value - var.ub()); - LOG_IF(ERROR, log_errors) << "Value " << value << " too high for " - << PrettyPrintVar(var); + LOG_IF(ERROR, log_errors) + << "Value " << value << " too high for " << PrettyPrintVar(var); } } // Check integrality. @@ -1131,8 +1137,8 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { ++num_errors; max_observed_error = std::max(max_observed_error, fabs(value - round(value))); - LOG_IF(ERROR, log_errors) << "Non-integer value " << value << " for " - << PrettyPrintVar(var); + LOG_IF(ERROR, log_errors) + << "Non-integer value " << value << " for " << PrettyPrintVar(var); } } } @@ -1157,8 +1163,8 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { if (std::isnan(activity) || std::isnan(inaccurate_activity)) { ++num_errors; max_observed_error = infinity(); - LOG_IF(ERROR, log_errors) << "NaN value for " - << PrettyPrintConstraint(constraint); + LOG_IF(ERROR, log_errors) + << "NaN value for " << PrettyPrintConstraint(constraint); continue; } // Check bounds. @@ -1204,15 +1210,14 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { } const double actual_objective_value = objective_sum.Value(); if (!AreWithinAbsoluteOrRelativeTolerances( - objective.Value(), actual_objective_value, tolerance, tolerance)) { + objective.Value(), actual_objective_value, tolerance, tolerance)) { ++num_errors; max_observed_error = std::max( max_observed_error, fabs(actual_objective_value - objective.Value())); - LOG_IF(ERROR, log_errors) << "Objective value " << objective.Value() - << " isn't accurate" - << ", it should be " << actual_objective_value - << " (delta=" << actual_objective_value - - objective.Value() << ")."; + LOG_IF(ERROR, log_errors) + << "Objective value " << objective.Value() << " isn't accurate" + << ", it should be " << actual_objective_value + << " (delta=" << actual_objective_value - objective.Value() << ")."; } else if (!AreWithinAbsoluteOrRelativeTolerances(objective.Value(), inaccurate_objective_value, tolerance, tolerance)) { @@ -1222,9 +1227,9 @@ bool MPSolver::VerifySolution(double tolerance, bool log_errors) const { << " sum of its terms."; } if (num_errors > 0) { - LOG_IF(ERROR, log_errors) << "There were " << num_errors - << " errors above the tolerance (" << tolerance - << "), the largest was " << max_observed_error; + LOG_IF(ERROR, log_errors) + << "There were " << num_errors << " errors above the tolerance (" + << tolerance << "), the largest was " << max_observed_error; return false; } return true; @@ -1253,7 +1258,8 @@ bool MPSolver::OwnsVariable(const MPVariable* var) const { return false; } -bool MPSolver::ExportModelAsLpFormat(bool obfuscate, std::string* model_str) const { +bool MPSolver::ExportModelAsLpFormat(bool obfuscate, + std::string* model_str) const { MPModelProto proto; ExportModelToProto(&proto); MPModelProtoExporter exporter(proto); @@ -1412,8 +1418,8 @@ void MPSolverInterface::SetMIPParameters(const MPSolverParameters& param) { #if defined(USE_GLOP) if (solver_->ProblemType() != MPSolver::GLOP_LINEAR_PROGRAMMING) { #endif - SetRelativeMipGap(param.GetDoubleParam( - MPSolverParameters::RELATIVE_MIP_GAP)); + SetRelativeMipGap( + param.GetDoubleParam(MPSolverParameters::RELATIVE_MIP_GAP)); #if defined(USE_GLOP) } #endif @@ -1452,20 +1458,20 @@ bool MPSolverInterface::SetSolverSpecificParametersAsString( if (parameters.empty()) return true; std::string extension = ValidFileExtensionForParameterFile(); - #if defined(__linux) - int32 tid = static_cast(pthread_self()); - #else // defined(__linux__) - int32 tid = 123; - #endif // defined(__linux__) - #if !defined(_MSC_VER) - int32 pid = static_cast(getpid()); - #else // _MSC_VER - int32 pid = 456; - #endif // _MSC_VER - int64 now = absl::GetCurrentTimeNanos(); - std::string filename = StringPrintf("/tmp/parameters-tempfile-%x-%d-%llx%s", - tid, pid, now, extension.c_str()); - bool no_error_so_far = true; +#if defined(__linux) + int32 tid = static_cast(pthread_self()); +#else // defined(__linux__) + int32 tid = 123; +#endif // defined(__linux__) +#if !defined(_MSC_VER) + int32 pid = static_cast(getpid()); +#else // _MSC_VER + int32 pid = 456; +#endif // _MSC_VER + int64 now = absl::GetCurrentTimeNanos(); + std::string filename = StringPrintf("/tmp/parameters-tempfile-%x-%d-%llx%s", + tid, pid, now, extension.c_str()); + bool no_error_so_far = true; if (no_error_so_far) { no_error_so_far = FileSetContents(filename, parameters).ok(); } @@ -1643,12 +1649,18 @@ void MPSolverParameters::Reset() { ResetIntegerParam(INCREMENTALITY); } -double MPSolverParameters::GetDoubleParam(MPSolverParameters::DoubleParam param) - const { +double MPSolverParameters::GetDoubleParam( + MPSolverParameters::DoubleParam param) const { switch (param) { - case RELATIVE_MIP_GAP: { return relative_mip_gap_value_; } - case PRIMAL_TOLERANCE: { return primal_tolerance_value_; } - case DUAL_TOLERANCE: { return dual_tolerance_value_; } + case RELATIVE_MIP_GAP: { + return relative_mip_gap_value_; + } + case PRIMAL_TOLERANCE: { + return primal_tolerance_value_; + } + case DUAL_TOLERANCE: { + return dual_tolerance_value_; + } default: { LOG(ERROR) << "Trying to get an unknown parameter: " << param << "."; return kUnknownDoubleParamValue; @@ -1656,16 +1668,22 @@ double MPSolverParameters::GetDoubleParam(MPSolverParameters::DoubleParam param) } } -int MPSolverParameters::GetIntegerParam(MPSolverParameters::IntegerParam param) - const { +int MPSolverParameters::GetIntegerParam( + MPSolverParameters::IntegerParam param) const { switch (param) { - case PRESOLVE: { return presolve_value_; } + case PRESOLVE: { + return presolve_value_; + } case LP_ALGORITHM: { if (lp_algorithm_is_default_) return kDefaultIntegerParamValue; return lp_algorithm_value_; } - case INCREMENTALITY: { return incrementality_value_; } - case SCALING: { return scaling_value_; } + case INCREMENTALITY: { + return incrementality_value_; + } + case SCALING: { + return scaling_value_; + } default: { LOG(ERROR) << "Trying to get an unknown parameter: " << param << "."; return kUnknownIntegerParamValue; @@ -1673,5 +1691,4 @@ int MPSolverParameters::GetIntegerParam(MPSolverParameters::IntegerParam param) } } - } // namespace operations_research diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index 1fd7d2be1ba..71e6cd92ff6 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -137,24 +137,23 @@ #define OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_ #include -#include -#include #include #include #include #include +#include +#include #include #include #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/status.h" #include "ortools/base/timer.h" #include "ortools/glop/parameters.pb.h" #include "ortools/linear_solver/linear_expr.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/port/proto_utils.h" -#include "ortools/base/status.h" - namespace operations_research { @@ -173,42 +172,42 @@ class MPSolver { // This must remain consistent with MPModelRequest::OptimizationProblemType // (take particular care of the open-source version). enum OptimizationProblemType { - // Linear programming problems. - #ifdef USE_CLP +// Linear programming problems. +#ifdef USE_CLP CLP_LINEAR_PROGRAMMING = 0, // Recommended default value. - #endif - #ifdef USE_GLPK +#endif +#ifdef USE_GLPK GLPK_LINEAR_PROGRAMMING = 1, - #endif - #ifdef USE_GLOP +#endif +#ifdef USE_GLOP GLOP_LINEAR_PROGRAMMING = 2, - #endif - #ifdef USE_GUROBI +#endif +#ifdef USE_GUROBI GUROBI_LINEAR_PROGRAMMING = 6, - #endif - #ifdef USE_CPLEX +#endif +#ifdef USE_CPLEX CPLEX_LINEAR_PROGRAMMING = 10, - #endif +#endif - // Integer programming problems. - #ifdef USE_SCIP +// Integer programming problems. +#ifdef USE_SCIP SCIP_MIXED_INTEGER_PROGRAMMING = 3, // Recommended default value. - #endif - #ifdef USE_GLPK +#endif +#ifdef USE_GLPK GLPK_MIXED_INTEGER_PROGRAMMING = 4, - #endif - #ifdef USE_CBC +#endif +#ifdef USE_CBC CBC_MIXED_INTEGER_PROGRAMMING = 5, - #endif - #if defined(USE_GUROBI) +#endif +#if defined(USE_GUROBI) GUROBI_MIXED_INTEGER_PROGRAMMING = 7, - #endif - #if defined(USE_CPLEX) +#endif +#if defined(USE_CPLEX) CPLEX_MIXED_INTEGER_PROGRAMMING = 11, - #endif - #if defined(USE_BOP) +#endif +#if defined(USE_BOP) BOP_INTEGER_PROGRAMMING = 12, - #endif +#endif }; MPSolver(const std::string& name, OptimizationProblemType problem_type); @@ -252,7 +251,8 @@ class MPSolver { // The MPSolver owns the variable (i.e. the returned pointer is borrowed). // Variable names must be unique (it may crash otherwise). Empty variable // names are allowed, an automated variable name will then be assigned. - MPVariable* MakeVar(double lb, double ub, bool integer, const std::string& name); + MPVariable* MakeVar(double lb, double ub, bool integer, + const std::string& name); // Creates a continuous variable. MPVariable* MakeNumVar(double lb, double ub, const std::string& name); // Creates an integer variable. @@ -266,7 +266,8 @@ class MPSolver { // @param name the prefix of the variable names. Variables are named // name0, name1, ... void MakeVarArray(int nb, double lb, double ub, bool integer, - const std::string& name_prefix, std::vector* vars); + const std::string& name_prefix, + std::vector* vars); // Creates an array of continuous variables. void MakeNumVarArray(int nb, double lb, double ub, const std::string& name, std::vector* vars); @@ -289,7 +290,8 @@ class MPSolver { void SetIndexConstraints(bool enabled); // Look up a constraint by name, and return nullptr if it does not exist or if // constraints are not indexed. - MPConstraint* LookupConstraintOrNull(const std::string& constraint_name) const; + MPConstraint* LookupConstraintOrNull( + const std::string& constraint_name) const; // Creates a linear constraint with given bounds. Bounds can be // finite or +/- MPSolver::infinity(). The MPSolver class assumes @@ -299,7 +301,8 @@ class MPSolver { // Creates a constraint with -infinity and +infinity bounds. MPConstraint* MakeRowConstraint(); // Creates a named constraint with given bounds. - MPConstraint* MakeRowConstraint(double lb, double ub, const std::string& name); + MPConstraint* MakeRowConstraint(double lb, double ub, + const std::string& name); // Creates a named constraint with -infinity and +infinity bounds. MPConstraint* MakeRowConstraint(const std::string& name); @@ -307,7 +310,8 @@ class MPSolver { // range.lower_bound() <= range.linear_expr() <= range.upper_bound() MPConstraint* MakeRowConstraint(const LinearRange& range); // As above, but also names the constraint. - MPConstraint* MakeRowConstraint(const LinearRange& range, const std::string& name); + MPConstraint* MakeRowConstraint(const LinearRange& range, + const std::string& name); // ----- Objective ----- // Note that the objective is owned by the solver, and is initialized to @@ -616,7 +620,8 @@ class MPSolver { // The vector of constraints in the problem. std::vector constraints_; // A map from a constraint's name to its index in constraints_. - std::unique_ptr > constraint_name_to_index_; + std::unique_ptr > + constraint_name_to_index_; // Whether constraints have been extracted to the underlying interface. std::vector constraint_is_extracted_; @@ -637,9 +642,9 @@ class MPSolver { // Permanent storage for SetSolverSpecificParametersAsString(). std::string solver_specific_parameter_string_; - MPSolverResponseStatus LoadModelFromProtoInternal( - const MPModelProto& input_model, bool clear_names, std::string* error_message); + const MPModelProto& input_model, bool clear_names, + std::string* error_message); DISALLOW_COPY_AND_ASSIGN(MPSolver); }; @@ -823,8 +828,8 @@ class MPVariable { // Constructor. A variable points to a single MPSolverInterface that // is specified in the constructor. A variable cannot belong to // several models. - MPVariable(int index, double lb, double ub, bool integer, const std::string& name, - MPSolverInterface* const interface) + MPVariable(int index, double lb, double ub, bool integer, + const std::string& name, MPSolverInterface* const interface) : index_(index), lb_(lb), ub_(ub), @@ -1092,7 +1097,6 @@ class MPSolverParameters { int GetIntegerParam(MPSolverParameters::IntegerParam param) const; // @} - private: // @{ // Parameter value for each parameter. @@ -1112,7 +1116,6 @@ class MPSolverParameters { // does not define a default value need such an indicator. bool lp_algorithm_is_default_; - DISALLOW_COPY_AND_ASSIGN(MPSolverParameters); }; @@ -1375,7 +1378,8 @@ class MPSolverInterface { // temporary file and calls ReadParameterFile to import the parameter file // into the solver. Solvers that support passing the parameters directly can // override this method to skip the temporary file logic. - virtual bool SetSolverSpecificParametersAsString(const std::string& parameters); + virtual bool SetSolverSpecificParametersAsString( + const std::string& parameters); // Reads a solver-specific file of parameters and set them. // Returns true if there was no errors. @@ -1391,7 +1395,6 @@ class MPSolverInterface { virtual void SetLpAlgorithm(int value) = 0; }; - } // namespace operations_research #endif // OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_ diff --git a/ortools/linear_solver/model_exporter.cc b/ortools/linear_solver/model_exporter.cc index 9773f54823b..714bfd72777 100644 --- a/ortools/linear_solver/model_exporter.cc +++ b/ortools/linear_solver/model_exporter.cc @@ -19,12 +19,11 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" +#include "ortools/base/map_util.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/strutil.h" -#include "ortools/base/join.h" -#include "ortools/base/map_util.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/util/fp_utils.h" @@ -75,10 +74,12 @@ std::string NameManager::MakeUniqueName(const std::string& name) { return result; } -std::string MakeExportableName(const std::string& name, bool* found_forbidden_char) { +std::string MakeExportableName(const std::string& name, + bool* found_forbidden_char) { // Prepend with "_" all the names starting with a forbidden character. const std::string kForbiddenFirstChars = "$.0123456789"; - *found_forbidden_char = kForbiddenFirstChars.find(name[0]) != std::string::npos; + *found_forbidden_char = + kForbiddenFirstChars.find(name[0]) != std::string::npos; std::string exportable_name = *found_forbidden_char ? absl::StrCat("_", name) : name; @@ -170,13 +171,13 @@ void MPModelProtoExporter::AppendComments(const std::string& separator, namespace { class LineBreaker { public: - explicit LineBreaker(int max_line_size) : - max_line_size_(max_line_size), line_size_(0), output_() {} + explicit LineBreaker(int max_line_size) + : max_line_size_(max_line_size), line_size_(0), output_() {} // Lines are broken in such a way that: // - Strings that are given to Append() are never split. // - Lines are split so that their length doesn't exceed the max length; - // unless a single std::string given to Append() exceeds that length (in which - // case it will be put alone on a single unsplit line). + // unless a single std::string given to Append() exceeds that length (in + // which case it will be put alone on a single unsplit line). void Append(const std::string& s); // Returns true if std::string s will fit on the current line without adding @@ -317,7 +318,8 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, absl::StrAppend(&rhs_name, "_rhs"); } absl::StrAppend(output, " ", rhs_name, ": ", line_breaker.GetOutput()); - const std::string relation = absl::StrCat(" <= ", DoubleToString(ub), "\n"); + const std::string relation = + absl::StrCat(" <= ", DoubleToString(ub), "\n"); // Here we have to make sure we do not add the relation to the contents // of line_breaker, which may be used in the subsequent clause. if (!line_breaker.WillFit(relation)) absl::StrAppend(output, "\n "); @@ -329,7 +331,8 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, absl::StrAppend(&lhs_name, "_lhs"); } absl::StrAppend(output, " ", lhs_name, ": ", line_breaker.GetOutput()); - const std::string relation = absl::StrCat(" >= ", DoubleToString(lb), "\n"); + const std::string relation = + absl::StrCat(" >= ", DoubleToString(lb), "\n"); if (!line_breaker.WillFit(relation)) absl::StrAppend(output, "\n "); absl::StrAppend(output, relation); } @@ -351,7 +354,8 @@ bool MPModelProtoExporter::ExportModelAsLpFormat(bool obfuscated, exported_variable_names_[var_index].c_str(), ub); } else { absl::StrAppend(output, " "); - if (lb == -std::numeric_limits::infinity() && ub == std::numeric_limits::infinity()) { + if (lb == -std::numeric_limits::infinity() && + ub == std::numeric_limits::infinity()) { absl::StrAppend(output, exported_variable_names_[var_index], " free"); } else { if (lb != -std::numeric_limits::infinity()) { @@ -426,10 +430,9 @@ void MPModelProtoExporter::AppendMpsLineHeaderWithNewLine( absl::StrAppend(output, "\n"); } -void MPModelProtoExporter::AppendMpsTermWithContext(const std::string& head_name, - const std::string& name, - double value, - std::string* output) { +void MPModelProtoExporter::AppendMpsTermWithContext( + const std::string& head_name, const std::string& name, double value, + std::string* output) { if (current_mps_column_ == 0) { AppendMpsLineHeader("", head_name, output); } @@ -465,8 +468,7 @@ void MPModelProtoExporter::AppendMpsColumns( current_mps_column_ = 0; if (var_proto.objective_coefficient() != 0.0) { AppendMpsTermWithContext(var_name, "COST", - var_proto.objective_coefficient(), - output); + var_proto.objective_coefficient(), output); } for (const std::pair cst_index_and_coeff : transpose[var_index]) { @@ -549,10 +551,11 @@ bool MPModelProtoExporter::ExportModelAsMpsFormat(bool fixed_format, AppendMpsColumns(/*integrality=*/true, transpose, &columns_section); if (!columns_section.empty()) { const char* const kIntMarkerFormat = " %-10s%-36s%-10s\n"; - columns_section = StringPrintf(kIntMarkerFormat, "INTSTART", - "'MARKER'", "'INTORG'") + columns_section; - StringAppendF(&columns_section, kIntMarkerFormat, - "INTEND", "'MARKER'", "'INTEND'"); + columns_section = + StringPrintf(kIntMarkerFormat, "INTSTART", "'MARKER'", "'INTORG'") + + columns_section; + StringAppendF(&columns_section, kIntMarkerFormat, "INTEND", "'MARKER'", + "'INTEND'"); } AppendMpsColumns(/*integrality=*/false, transpose, &columns_section); if (!columns_section.empty()) { diff --git a/ortools/linear_solver/model_exporter.h b/ortools/linear_solver/model_exporter.h index fb55164e2a8..795930a8feb 100644 --- a/ortools/linear_solver/model_exporter.h +++ b/ortools/linear_solver/model_exporter.h @@ -14,12 +14,12 @@ #ifndef OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_ #define OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_ -#include #include +#include #include -#include "ortools/base/macros.h" #include "ortools/base/hash.h" +#include "ortools/base/macros.h" namespace operations_research { @@ -34,9 +34,9 @@ class MPModelProtoExporter { // The argument must live as long as this class is active. explicit MPModelProtoExporter(const MPModelProto& proto); - // Outputs the current model (variables, constraints, objective) as a std::string - // encoded in the so-called "CPLEX LP file format" as generated by SCIP. - // The LP file format is easily readable by a human. + // Outputs the current model (variables, constraints, objective) as a + // std::string encoded in the so-called "CPLEX LP file format" as generated by + // SCIP. The LP file format is easily readable by a human. // // Returns false if some error has occurred during execution. // The validity of names is automatically checked. If a variable name or a @@ -55,9 +55,9 @@ class MPModelProtoExporter { // http://www.gurobi.com/documentation/5.1/reference-manual/node871 bool ExportModelAsLpFormat(bool obfuscated, std::string* model_str); - // Outputs the current model (variables, constraints, objective) as a std::string - // encoded in MPS file format, using the "fixed" MPS format if possible, - // and the "free" MPS format otherwise. + // Outputs the current model (variables, constraints, objective) as a + // std::string encoded in MPS file format, using the "fixed" MPS format if + // possible, and the "free" MPS format otherwise. // // Returns false if some error has occurred during execution. // @@ -131,11 +131,13 @@ class MPModelProtoExporter { // Clears "output" and writes a term to it, in "Lp" format. Returns false on // error (for example, var_index is out of range). - bool WriteLpTerm(int var_index, double coefficient, std::string* output) const; + bool WriteLpTerm(int var_index, double coefficient, + std::string* output) const; // Appends a pair name, value to "output", formatted to comply with the MPS // standard. - void AppendMpsPair(const std::string& name, double value, std::string* output) const; + void AppendMpsPair(const std::string& name, double value, + std::string* output) const; // Appends the head of a line, consisting of an id and a name to output. void AppendMpsLineHeader(const std::string& id, const std::string& name, @@ -143,15 +145,17 @@ class MPModelProtoExporter { // Same as AppendMpsLineHeader. Appends an extra new-line at the end the // std::string pointed to by output. - void AppendMpsLineHeaderWithNewLine(const std::string& id, const std::string& name, + void AppendMpsLineHeaderWithNewLine(const std::string& id, + const std::string& name, std::string* output) const; // Appends an MPS term in various contexts. The term consists of a head name, // a name, and a value. If the line is not empty, then only the pair // (name, value) is appended. The number of columns, limited to 2 by the MPS // format is also taken care of. - void AppendMpsTermWithContext(const std::string& head_name, const std::string& name, - double value, std::string* output); + void AppendMpsTermWithContext(const std::string& head_name, + const std::string& name, double value, + std::string* output); // Appends a new-line if two columns are already present on the MPS line. // Used by and in complement to AppendMpsTermWithContext. diff --git a/ortools/linear_solver/model_validator.cc b/ortools/linear_solver/model_validator.cc index 40cbe950fca..a4f45aeaddf 100644 --- a/ortools/linear_solver/model_validator.cc +++ b/ortools/linear_solver/model_validator.cc @@ -15,8 +15,8 @@ #include #include -#include "ortools/base/join.h" #include "ortools/base/accurate_sum.h" +#include "ortools/base/join.h" #include "ortools/port/proto_utils.h" #include "ortools/util/fp_utils.h" @@ -55,7 +55,7 @@ std::string FindErrorInMPVariable(const MPVariableProto& variable) { // "var_mask" is a std::vector whose size is the number of variables in // the model, and it will be all set to false before and after the call. std::string FindErrorInMPConstraint(const MPConstraintProto& constraint, - std::vector* var_mask) { + std::vector* var_mask) { if (std::isnan(constraint.lower_bound()) || std::isnan(constraint.upper_bound()) || constraint.lower_bound() == kInfinity || @@ -108,8 +108,8 @@ std::string FindErrorInMPConstraint(const MPConstraintProto& constraint, return std::string(); } -std::string FindErrorInSolutionHint(const PartialVariableAssignment& solution_hint, - int num_vars) { +std::string FindErrorInSolutionHint( + const PartialVariableAssignment& solution_hint, int num_vars) { if (solution_hint.var_index_size() != solution_hint.var_value_size()) { return absl::StrCat("var_index_size() != var_value_size() [", solution_hint.var_index_size(), " VS ", @@ -202,7 +202,7 @@ std::string FindErrorInMPModelProto(const MPModelProto& model) { // TODO(user): Add a general FindFeasibilityErrorInSolution() and factor out the // common code. std::string FindFeasibilityErrorInSolutionHint(const MPModelProto& model, - double tolerance) { + double tolerance) { const int num_vars = model.variable_size(); // First, we validate the solution hint. diff --git a/ortools/linear_solver/model_validator.h b/ortools/linear_solver/model_validator.h index 6912986c4ea..a5db9755726 100644 --- a/ortools/linear_solver/model_validator.h +++ b/ortools/linear_solver/model_validator.h @@ -18,17 +18,17 @@ #include "ortools/linear_solver/linear_solver.pb.h" namespace operations_research { -// Returns an empty std::string iff the model is valid and not trivially infeasible. -// Otherwise, returns a description of the first error or trivial infeasibility -// encountered. +// Returns an empty std::string iff the model is valid and not trivially +// infeasible. Otherwise, returns a description of the first error or trivial +// infeasibility encountered. // // NOTE(user): the code of this method (and the client code too!) is // considerably simplified by this std::string-based, simple API. If clients // require it, we could add a formal error status enum. std::string FindErrorInMPModelProto(const MPModelProto& model); -// Returns an empty std::string if the solution hint given in the model is a feasible -// solution. Otherwise, returns a description of the first reason for +// Returns an empty std::string if the solution hint given in the model is a +// feasible solution. Otherwise, returns a description of the first reason for // infeasibility. // // This function can be useful for debugging/checking that the given solution @@ -36,7 +36,7 @@ std::string FindErrorInMPModelProto(const MPModelProto& model); // checked up to the given tolerance using the // ::operations_research::IsLowerWithinTolerance() function. std::string FindFeasibilityErrorInSolutionHint(const MPModelProto& model, - double tolerance); + double tolerance); } // namespace operations_research diff --git a/ortools/linear_solver/scip_interface.cc b/ortools/linear_solver/scip_interface.cc index 6811eb0287a..f21a1d45ff9 100644 --- a/ortools/linear_solver/scip_interface.cc +++ b/ortools/linear_solver/scip_interface.cc @@ -15,21 +15,21 @@ #include #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/port.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/port.h" +#include "ortools/linear_solver/linear_solver.h" #include "scip/scip.h" #include "scip/scipdefplugins.h" -#include "ortools/base/hash.h" -#include "ortools/linear_solver/linear_solver.h" // Our own version of SCIP_CALL to do error management. // TODO(user): The error management could be improved, especially @@ -363,7 +363,7 @@ void SCIPInterface::ExtractNewConstraints() { max_row_length = ct->coefficients_.size(); } } - std::unique_ptr vars(new SCIP_VAR*[max_row_length]); + std::unique_ptr vars(new SCIP_VAR*[max_row_length]); std::unique_ptr coefs(new double[max_row_length]); // Add each new constraint. for (int i = last_constraint_index_; i < total_num_rows; ++i) { @@ -671,7 +671,6 @@ MPSolverInterface* BuildSCIPInterface(MPSolver* const solver) { return new SCIPInterface(solver); } - } // namespace operations_research #endif // #if defined(USE_SCIP) diff --git a/ortools/lp_data/lp_data.cc b/ortools/lp_data/lp_data.cc index b654b0cd14d..efe16fec91a 100644 --- a/ortools/lp_data/lp_data.cc +++ b/ortools/lp_data/lp_data.cc @@ -11,19 +11,16 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/lp_data.h" #include #include -#include #include +#include #include -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/join.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" #include "ortools/lp_data/lp_print_utils.h" #include "ortools/lp_data/lp_utils.h" @@ -216,7 +213,8 @@ ColIndex LinearProgram::FindOrCreateVariable(const std::string& variable_id) { } } -RowIndex LinearProgram::FindOrCreateConstraint(const std::string& constraint_id) { +RowIndex LinearProgram::FindOrCreateConstraint( + const std::string& constraint_id) { const std::unordered_map::iterator it = constraint_table_.find(constraint_id); if (it != constraint_table_.end()) { @@ -597,7 +595,6 @@ std::string LinearProgram::DumpSolution(const DenseRow& variable_values) const { return output; } - std::string LinearProgram::GetProblemStats() const { return ProblemStatFormatter( "%d,%d,%lld,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d," @@ -1033,7 +1030,8 @@ void LinearProgram::DeleteColumns(const DenseBooleanRow& columns_to_delete) { variable_names_.resize(new_index, ""); // Remove the id of the deleted columns and adjust the index of the other. - std::unordered_map::iterator it = variable_table_.begin(); + std::unordered_map::iterator it = + variable_table_.begin(); while (it != variable_table_.end()) { const ColIndex col = it->second; if (col >= columns_to_delete.size() || !columns_to_delete[col]) { diff --git a/ortools/lp_data/lp_data.h b/ortools/lp_data/lp_data.h index 4b87b1ba97d..44c605e9ef3 100644 --- a/ortools/lp_data/lp_data.h +++ b/ortools/lp_data/lp_data.h @@ -25,17 +25,17 @@ #define OR_TOOLS_LP_DATA_LP_DATA_H_ #include // for max -#include -#include #include #include // for std::string +#include +#include #include // for vector -#include "ortools/base/logging.h" // for CHECK* -#include "ortools/base/macros.h" // for DISALLOW_COPY_AND_ASSIGN, NULL +#include "ortools/base/hash.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" +#include "ortools/base/logging.h" // for CHECK* +#include "ortools/base/macros.h" // for DISALLOW_COPY_AND_ASSIGN, NULL #include "ortools/glop/parameters.pb.h" #include "ortools/lp_data/lp_types.h" #include "ortools/lp_data/sparse.h" @@ -82,7 +82,8 @@ class LinearProgram { // to create non-slack variables. ColIndex CreateNewSlackVariable(bool is_integer_slack_variable, Fractional lower_bound, - Fractional upper_bound, const std::string& name); + Fractional upper_bound, + const std::string& name); // Creates a new constraint and returns its index. // By default, the constraint bounds will be [0, 0]. @@ -297,9 +298,8 @@ class LinearProgram { // format var1 = X, var2 = Y, var3 = Z, ... std::string DumpSolution(const DenseRow& variable_values) const; - - // Returns a comma-separated std::string of integers containing (in that order) - // num_constraints_, num_variables_in_file_, num_entries_, + // Returns a comma-separated std::string of integers containing (in that + // order) num_constraints_, num_variables_in_file_, num_entries_, // num_objective_non_zeros_, num_rhs_non_zeros_, num_less_than_constraints_, // num_greater_than_constraints_, num_equal_constraints_, // num_range_constraints_, num_non_negative_variables_, num_boxed_variables_, @@ -307,8 +307,8 @@ class LinearProgram { // Very useful for reporting in the way used in journal articles. std::string GetProblemStats() const; - // Returns a std::string containing the same information as with GetProblemStats(), - // but in a much more human-readable form, for example: + // Returns a std::string containing the same information as with + // GetProblemStats(), but in a much more human-readable form, for example: // Number of rows : 27 // Number of variables in file : 32 // Number of entries (non-zeros) : 83 @@ -335,8 +335,8 @@ class LinearProgram { // moved to SparseMatrix. std::string GetNonZeroStats() const; - // Returns a std::string containing the same information as with GetNonZeroStats(), - // but in a much more human-readable form, for example: + // Returns a std::string containing the same information as with + // GetNonZeroStats(), but in a much more human-readable form, for example: // Fill rate : 9.61% // Entries in row (Max / average / std, dev.) : 9 / 3.07 / 1.94 // Entries in column (Max / average / std, dev.): 4 / 2.59 / 0.96 diff --git a/ortools/lp_data/lp_decomposer.cc b/ortools/lp_data/lp_decomposer.cc index ddaf7191441..bac0103399a 100644 --- a/ortools/lp_data/lp_decomposer.cc +++ b/ortools/lp_data/lp_decomposer.cc @@ -15,8 +15,8 @@ #include -#include "ortools/base/mutex.h" #include "ortools/algorithms/dynamic_partition.h" +#include "ortools/base/mutex.h" #include "ortools/lp_data/lp_data.h" #include "ortools/lp_data/lp_utils.h" @@ -27,9 +27,7 @@ namespace glop { // LPDecomposer //------------------------------------------------------------------------------ LPDecomposer::LPDecomposer() - : original_problem_(nullptr), - clusters_(), - mutex_() {} + : original_problem_(nullptr), clusters_(), mutex_() {} void LPDecomposer::Decompose(const LinearProgram* linear_problem) { absl::MutexLock mutex_lock(&mutex_); diff --git a/ortools/lp_data/lp_print_utils.cc b/ortools/lp_data/lp_print_utils.cc index 8f65d6899f3..fdbaa6b8e72 100644 --- a/ortools/lp_data/lp_print_utils.cc +++ b/ortools/lp_data/lp_print_utils.cc @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/lp_print_utils.h" #include #include #include #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/lp_data/lp_types.h" #include "ortools/util/rational_approximation.h" @@ -43,15 +42,16 @@ std::string StringifyRational(const double x, const double precision) { } std::string Stringify(const Fractional x, bool fraction) { - return fraction - ? StringifyRational(ToDouble(x), std::numeric_limits::epsilon()) - : Stringify(x); + return fraction ? StringifyRational(ToDouble(x), + std::numeric_limits::epsilon()) + : Stringify(x); } // Returns a std::string that pretty-prints a monomial ax with coefficient // a and variable name x -std::string StringifyMonomial(const Fractional a, const std::string& x, bool fraction) { - if (a == 0.0) return ""; +std::string StringifyMonomial(const Fractional a, const std::string& x, + bool fraction) { + if (a == 0.0) return ""; return a > 0.0 ? absl::StrCat( " + ", diff --git a/ortools/lp_data/lp_print_utils.h b/ortools/lp_data/lp_print_utils.h index 5e6b84c8201..74959eb58f8 100644 --- a/ortools/lp_data/lp_print_utils.h +++ b/ortools/lp_data/lp_print_utils.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Utilities to display linear expression in a human-readable way. #ifndef OR_TOOLS_LP_DATA_LP_PRINT_UTILS_H_ @@ -30,7 +29,9 @@ namespace glop { // with a precision corresponding to the type of the argument. inline std::string Stringify(const float a) { return StringPrintf("%.7g", a); } -inline std::string Stringify(const double a) { return StringPrintf("%.16g", a); } +inline std::string Stringify(const double a) { + return StringPrintf("%.16g", a); +} inline std::string Stringify(const long double a) { return StringPrintf("%.19Lg", a); @@ -51,7 +52,8 @@ std::string Stringify(const Fractional x, bool fraction); // taking care of the sign of x, whether a is 0, 1, -1, integer. Note that the // absolute difference between the output fraction and "x" will never exceed // std::numeric_limits::epsilon(). -std::string StringifyMonomial(const Fractional a, const std::string& x, bool fraction); +std::string StringifyMonomial(const Fractional a, const std::string& x, + bool fraction); } // namespace glop } // namespace operations_research diff --git a/ortools/lp_data/lp_types.cc b/ortools/lp_data/lp_types.cc index 069252b9fad..bbbfa195f38 100644 --- a/ortools/lp_data/lp_types.cc +++ b/ortools/lp_data/lp_types.cc @@ -126,7 +126,5 @@ ConstraintStatus VariableToConstraintStatus(VariableStatus status) { return ConstraintStatus::FREE; } - - } // namespace glop } // namespace operations_research diff --git a/ortools/lp_data/lp_types.h b/ortools/lp_data/lp_types.h index 711a3cc6b9c..985ec3bce00 100644 --- a/ortools/lp_data/lp_types.h +++ b/ortools/lp_data/lp_types.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Common types and constants used by the Linear Programming solver. #ifndef OR_TOOLS_LP_DATA_LP_TYPES_H_ @@ -250,7 +249,7 @@ ConstraintStatus VariableToConstraintStatus(VariableStatus status); template class StrictITIVector : public ITIVector { public: - typedef IntType IndexType; // g++ 4.8.1 needs this. + typedef IntType IndexType; // g++ 4.8.1 needs this. typedef ITIVector ParentType; // This allows for brace initialization, which is really useful in tests. // It is not 'explicit' by design, so one can do vector = {...}; diff --git a/ortools/lp_data/lp_utils.cc b/ortools/lp_data/lp_utils.cc index 543327630d0..7d7415705fc 100644 --- a/ortools/lp_data/lp_utils.cc +++ b/ortools/lp_data/lp_utils.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/lp_utils.h" namespace operations_research { diff --git a/ortools/lp_data/lp_utils.h b/ortools/lp_data/lp_utils.h index 4df7a8b0d62..cd39c9e131d 100644 --- a/ortools/lp_data/lp_utils.h +++ b/ortools/lp_data/lp_utils.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Basic utility functions on Fractional or row/column of Fractional. #ifndef OR_TOOLS_LP_DATA_LP_UTILS_H_ diff --git a/ortools/lp_data/matrix_scaler.cc b/ortools/lp_data/matrix_scaler.cc index 2a646e1245f..763ee507fd5 100644 --- a/ortools/lp_data/matrix_scaler.cc +++ b/ortools/lp_data/matrix_scaler.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/matrix_scaler.h" #include diff --git a/ortools/lp_data/matrix_scaler.h b/ortools/lp_data/matrix_scaler.h index 3aad9fd1d08..94c5111ea57 100644 --- a/ortools/lp_data/matrix_scaler.h +++ b/ortools/lp_data/matrix_scaler.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // The SparseMatrixScaler class provides tools to scale a SparseMatrix, i.e. // reduce the range of its coefficients and make for each column and each row // the maximum magnitude of its coefficients equal to 1. @@ -63,9 +62,9 @@ #include +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/glop/parameters.pb.h" #include "ortools/glop/revised_simplex.h" #include "ortools/glop/status.h" diff --git a/ortools/lp_data/mps_reader.cc b/ortools/lp_data/mps_reader.cc index cf98c2e925c..24337e71bfe 100644 --- a/ortools/lp_data/mps_reader.cc +++ b/ortools/lp_data/mps_reader.cc @@ -11,31 +11,29 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/mps_reader.h" #include #include +#include #include #include -#include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" -#include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/file.h" -#include "ortools/base/numbers.h" // for safe_strtod +#include "ortools/base/filelineiter.h" +#include "ortools/base/logging.h" +#include "ortools/base/map_util.h" // for FindOrNull, gtl::FindWithDefault +#include "ortools/base/numbers.h" // for safe_strtod #include "ortools/base/split.h" +#include "ortools/base/status.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/strutil.h" -#include "ortools/base/map_util.h" // for FindOrNull, gtl::FindWithDefault #include "ortools/lp_data/lp_print_utils.h" -#include "ortools/base/filelineiter.h" -#include "ortools/base/status.h" DEFINE_bool(mps_free_form, false, "Read MPS files in free form."); -DEFINE_bool(mps_stop_after_first_error, true, - "Stop after the first error."); +DEFINE_bool(mps_stop_after_first_error, true, "Stop after the first error."); namespace operations_research { namespace glop { @@ -109,7 +107,8 @@ void MPSReader::DisplaySummary() { void MPSReader::SplitLineIntoFields() { if (free_form_) { - fields_ = absl::StrSplit(line_, absl::delimiter::AnyOf(" \t"), absl::SkipEmpty()); + fields_ = + absl::StrSplit(line_, absl::delimiter::AnyOf(" \t"), absl::SkipEmpty()); CHECK_GE(kNumFields, fields_.size()); } else { int length = line_.length(); @@ -176,7 +175,6 @@ bool MPSReader::LoadFileAndTryFreeFormOnFail(const std::string& file_name, return true; } - std::string MPSReader::GetProblemName() const { return problem_name_; } bool MPSReader::IsCommentOrBlank() const { @@ -194,8 +192,7 @@ bool MPSReader::IsCommentOrBlank() const { void MPSReader::ProcessLine(const std::string& line) { ++line_num_; - if (!parse_success_ && FLAGS_mps_stop_after_first_error) - return; + if (!parse_success_ && FLAGS_mps_stop_after_first_error) return; line_ = line; if (IsCommentOrBlank()) { return; // Skip blank lines and comments. @@ -298,8 +295,8 @@ double MPSReader::GetDoubleFromString(const std::string& param) { if (!strings::safe_strtod(param, &result)) { if (log_errors_) { LOG(ERROR) << "At line " << line_num_ - << ": Failed to convert std::string to double. String = " << param - << ". (Line contents = '" << line_ << "')." + << ": Failed to convert std::string to double. String = " + << param << ". (Line contents = '" << line_ << "')." << " free_form_ = " << free_form_; } parse_success_ = false; @@ -310,8 +307,8 @@ double MPSReader::GetDoubleFromString(const std::string& param) { void MPSReader::ProcessRowsSection() { std::string row_type_name = fields_[0]; std::string row_name = fields_[1]; - MPSRowType row_type = - gtl::FindWithDefault(row_name_to_id_map_, row_type_name, UNKNOWN_ROW_TYPE); + MPSRowType row_type = gtl::FindWithDefault(row_name_to_id_map_, row_type_name, + UNKNOWN_ROW_TYPE); if (row_type == UNKNOWN_ROW_TYPE) { if (log_errors_) { LOG(ERROR) << "At line " << line_num_ << ": Unknown row type " @@ -471,7 +468,8 @@ void MPSReader::StoreRightHandSide(const std::string& row_name, } } -void MPSReader::StoreRange(const std::string& row_name, const std::string& range_value) { +void MPSReader::StoreRange(const std::string& row_name, + const std::string& range_value) { if (row_name.empty()) { return; } diff --git a/ortools/lp_data/mps_reader.h b/ortools/lp_data/mps_reader.h index 10be634d43a..873f7b9c80b 100644 --- a/ortools/lp_data/mps_reader.h +++ b/ortools/lp_data/mps_reader.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // A reader for files in the MPS format. // see http://lpsolve.sourceforge.net/5.5/mps-format.htm // and http://www.ici.ro/camo/language/ml11.htm. @@ -26,17 +25,17 @@ #define OR_TOOLS_LP_DATA_MPS_READER_H_ #include // for max +#include // for std::string #include -#include // for std::string #include // for vector #include "ortools/base/commandlineflags.h" -#include "ortools/base/macros.h" // for DISALLOW_COPY_AND_ASSIGN, NULL -#include "ortools/base/stringprintf.h" +#include "ortools/base/hash.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/macros.h" // for DISALLOW_COPY_AND_ASSIGN, NULL #include "ortools/base/map_util.h" // for FindOrNull, FindWithDefault -#include "ortools/base/hash.h" +#include "ortools/base/stringprintf.h" #include "ortools/lp_data/lp_data.h" #include "ortools/lp_data/lp_types.h" @@ -162,7 +161,8 @@ class MPSReader { } BoundTypeId; // Stores a bound value of a given type, for a given column name. - void StoreBound(const std::string& bound_type_mnemonic, const std::string& column_name, + void StoreBound(const std::string& bound_type_mnemonic, + const std::string& column_name, const std::string& bound_value); // Stores a coefficient value for a column number and a row name. @@ -170,7 +170,8 @@ class MPSReader { const std::string& row_value); // Stores a right-hand-side value for a row name. - void StoreRightHandSide(const std::string& row_name, const std::string& row_value); + void StoreRightHandSide(const std::string& row_name, + const std::string& row_value); // Stores a range constraint of value row_value for a row name. void StoreRange(const std::string& row_name, const std::string& row_value); diff --git a/ortools/lp_data/permutation.h b/ortools/lp_data/permutation.h index a07e747cd49..cf9d2951119 100644 --- a/ortools/lp_data/permutation.h +++ b/ortools/lp_data/permutation.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_LP_DATA_PERMUTATION_H_ #define OR_TOOLS_LP_DATA_PERMUTATION_H_ diff --git a/ortools/lp_data/sparse.cc b/ortools/lp_data/sparse.cc index bff3abb6b6f..9d200b12dd5 100644 --- a/ortools/lp_data/sparse.cc +++ b/ortools/lp_data/sparse.cc @@ -11,12 +11,11 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/lp_data/sparse.h" #include -#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" +#include "ortools/base/stringprintf.h" namespace operations_research { namespace glop { diff --git a/ortools/lp_data/sparse_column.cc b/ortools/lp_data/sparse_column.cc index 91fe606b2e3..2b3a1917857 100644 --- a/ortools/lp_data/sparse_column.cc +++ b/ortools/lp_data/sparse_column.cc @@ -54,8 +54,8 @@ void RandomAccessSparseColumn::PopulateFromSparseColumn( } } -void RandomAccessSparseColumn::PopulateSparseColumn(SparseColumn* sparse_column) - const { +void RandomAccessSparseColumn::PopulateSparseColumn( + SparseColumn* sparse_column) const { RETURN_IF_NULL(sparse_column); sparse_column->Clear(); diff --git a/ortools/lp_data/sparse_vector.h b/ortools/lp_data/sparse_vector.h index 30296fb353e..2021f3da5b0 100644 --- a/ortools/lp_data/sparse_vector.h +++ b/ortools/lp_data/sparse_vector.h @@ -600,8 +600,7 @@ void SparseVector::CleanUp() { for (int i = 0; i < num_entries_; ++i) { const std::pair entry = entries[i]; if (entry.second == 0.0) continue; - if (i + 1 == num_entries_ || - entry.first != entries[i + 1].first) { + if (i + 1 == num_entries_ || entry.first != entries[i + 1].first) { MutableIndex(new_size) = entry.first; MutableCoefficient(new_size) = entry.second; ++new_size; diff --git a/ortools/port/file.h b/ortools/port/file.h index 352bfe9a12d..6f2cd49f579 100644 --- a/ortools/port/file.h +++ b/ortools/port/file.h @@ -14,8 +14,8 @@ #ifndef OR_TOOLS_PORT_FILE_H_ #define OR_TOOLS_PORT_FILE_H_ -#include "ortools/base/string_view.h" #include "ortools/base/status.h" +#include "ortools/base/string_view.h" namespace operations_research { @@ -23,12 +23,14 @@ namespace operations_research { ::util::Status FileSetContents(absl::string_view file_name, absl::string_view content); -::util::Status FileGetContents(absl::string_view file_name, std::string* output); +::util::Status FileGetContents(absl::string_view file_name, + std::string* output); ::util::Status DeleteFile(absl::string_view file_name); // Returns true if successful. Outputs temp file to filename. -bool PortableTemporaryFile(const char* directory_prefix, std::string* filename_out); +bool PortableTemporaryFile(const char* directory_prefix, + std::string* filename_out); } // namespace operations_research diff --git a/ortools/port/file_nonport.cc b/ortools/port/file_nonport.cc index c148e6a672e..4733ae00526 100644 --- a/ortools/port/file_nonport.cc +++ b/ortools/port/file_nonport.cc @@ -22,12 +22,14 @@ ::util::Status FileSetContents(absl::string_view file_name, return file::SetContents(file_name, content, file::Defaults()); } -::util::Status FileGetContents(absl::string_view file_name, std::string* output) { +::util::Status FileGetContents(absl::string_view file_name, + std::string* output) { return file::GetContents(file_name, output, file::Defaults()); } -bool PortableTemporaryFile(const char* directory_prefix, std::string* filename_out) { - return false; +bool PortableTemporaryFile(const char* directory_prefix, + std::string* filename_out) { + return false; } ::util::Status DeleteFile(absl::string_view file_name) { diff --git a/ortools/port/proto_utils.h b/ortools/port/proto_utils.h index 669dbf32049..bfb2508e9f2 100644 --- a/ortools/port/proto_utils.h +++ b/ortools/port/proto_utils.h @@ -21,8 +21,8 @@ #include "google/protobuf/text_format.h" #endif -#include "ortools/base/port.h" #include "ortools/base/join.h" +#include "ortools/base/port.h" namespace operations_research { #if defined(__PORTABLE_PLATFORM__) @@ -66,8 +66,8 @@ std::string ProtoEnumToString(ProtoEnumType enum_value) { auto enum_value_descriptor = enum_descriptor->FindValueByNumber(enum_value); if (enum_value_descriptor == nullptr) { return absl::StrCat( - "Invalid enum value of: ", enum_value, - " for enum type: ", google::protobuf::GetEnumDescriptor()->name()); + "Invalid enum value of: ", enum_value, " for enum type: ", + google::protobuf::GetEnumDescriptor()->name()); } return enum_value_descriptor->name(); } @@ -75,7 +75,8 @@ std::string ProtoEnumToString(ProtoEnumType enum_value) { template bool ProtobufTextFormatMergeFromString(const std::string& proto_text_string, ProtoType* proto) { - return google::protobuf::TextFormat::MergeFromString(proto_text_string, proto); + return google::protobuf::TextFormat::MergeFromString(proto_text_string, + proto); } #endif // !__PORTABLE_PLATFORM__ diff --git a/ortools/port/sysinfo_nonport.cc b/ortools/port/sysinfo_nonport.cc index cbcae559885..90eb5cea06c 100644 --- a/ortools/port/sysinfo_nonport.cc +++ b/ortools/port/sysinfo_nonport.cc @@ -20,5 +20,5 @@ namespace sysinfo { int64 MemoryUsageProcess() { return ::MemoryUsage(0); } -} // sysinfo -} // operations_research +} // namespace sysinfo +} // namespace operations_research diff --git a/ortools/sat/all_different.cc b/ortools/sat/all_different.cc index bc53f765554..eaef6b2175d 100644 --- a/ortools/sat/all_different.cc +++ b/ortools/sat/all_different.cc @@ -14,14 +14,14 @@ #include "ortools/sat/all_different.h" #include -#include #include #include +#include -#include "ortools/base/logging.h" -#include "ortools/graph/strongly_connected_components.h" #include "ortools/base/int_type.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" +#include "ortools/graph/strongly_connected_components.h" #include "ortools/sat/sat_solver.h" #include "ortools/util/sort.h" diff --git a/ortools/sat/boolean_problem.cc b/ortools/sat/boolean_problem.cc index b3da385f200..18bc9ea93a4 100644 --- a/ortools/sat/boolean_problem.cc +++ b/ortools/sat/boolean_problem.cc @@ -15,24 +15,23 @@ #include #include -#include #include #include +#include #include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #if !defined(__PORTABLE_PLATFORM__) #include "ortools/graph/io.h" #endif // __PORTABLE_PLATFORM__ -#include "ortools/graph/util.h" +#include "ortools/algorithms/find_graph_symmetries.h" +#include "ortools/base/hash.h" #include "ortools/base/int_type.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" -#include "ortools/algorithms/find_graph_symmetries.h" +#include "ortools/graph/util.h" #include "ortools/port/proto_utils.h" #include "ortools/sat/sat_parameters.pb.h" @@ -64,7 +63,7 @@ namespace { // A non-empty std::string indicates an error. template std::string ValidateLinearTerms(const LinearTerms& terms, - std::vector* variable_seen) { + std::vector* variable_seen) { // variable_seen already has all items false and is reset before return. std::string err_str; int num_errs = 0; @@ -104,7 +103,8 @@ std::string ValidateLinearTerms(const LinearTerms& terms, err_str = StringPrintf("%d validation errors:\n", num_errs) + err_str; } else { err_str = StringPrintf("%d validation errors; here are the first %d:\n", - num_errs, max_num_errs) + err_str; + num_errs, max_num_errs) + + err_str; } } return err_str; @@ -136,7 +136,8 @@ util::Status ValidateBooleanProblem(const LinearBooleanProblem& problem) { StringPrintf("Invalid constraint %i: ", i) + error); } } - const std::string error = ValidateLinearTerms(problem.objective(), &variable_seen); + const std::string error = + ValidateLinearTerms(problem.objective(), &variable_seen); if (!error.empty()) { return util::Status(util::error::INVALID_ARGUMENT, StringPrintf("Invalid objective: ") + error); @@ -383,7 +384,8 @@ bool IsAssignmentValid(const LinearBooleanProblem& problem, // Note(user): This function makes a few assumptions about the format of the // given LinearBooleanProblem. All constraint coefficients must be 1 (and of the // form >= 1) and all objective weights must be strictly positive. -std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem) { +std::string LinearBooleanProblemToCnfString( + const LinearBooleanProblem& problem) { std::string output; const bool is_wcnf = (problem.objective().coefficients_size() > 0); const LinearObjective& objective = problem.objective(); @@ -460,7 +462,8 @@ std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem) // Since it is falsifying this clause that cost "weigtht", we need to take // its negation. const Literal literal(-p.first); - output += absl::StrFormat("%lld %s 0\n", p.second, literal.DebugString().c_str()); + output += absl::StrFormat("%lld %s 0\n", p.second, + literal.DebugString().c_str()); } } diff --git a/ortools/sat/boolean_problem.h b/ortools/sat/boolean_problem.h index 48bd5b6a490..1bdea8d9dd5 100644 --- a/ortools/sat/boolean_problem.h +++ b/ortools/sat/boolean_problem.h @@ -18,15 +18,15 @@ #include #include -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/algorithms/sparse_permutation.h" +#include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/status.h" #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/pb_constraint.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_solver.h" #include "ortools/sat/simplification.h" -#include "ortools/base/status.h" namespace operations_research { namespace sat { @@ -95,7 +95,8 @@ bool IsAssignmentValid(const LinearBooleanProblem& problem, // Converts a LinearBooleanProblem to the cnf file format. // Note that this only works for pure SAT problems (only clauses), max-sat or // weighted max-sat problems. Returns an empty std::string on error. -std::string LinearBooleanProblemToCnfString(const LinearBooleanProblem& problem); +std::string LinearBooleanProblemToCnfString( + const LinearBooleanProblem& problem); // Store a variable assignment into the given BooleanAssignement proto. // Note that only the assigned variables are stored, so the assignment may be diff --git a/ortools/sat/circuit.h b/ortools/sat/circuit.h index a6ef35ac4a8..2a53c50c0e8 100644 --- a/ortools/sat/circuit.h +++ b/ortools/sat/circuit.h @@ -18,11 +18,11 @@ #include #include +#include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include -#include "ortools/base/int_type.h" #include "ortools/sat/integer.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/clause.cc b/ortools/sat/clause.cc index 9618cce5340..ae34ffc02ef 100644 --- a/ortools/sat/clause.cc +++ b/ortools/sat/clause.cc @@ -168,7 +168,7 @@ bool LiteralWatchers::Propagate(Trail* trail) { } absl::Span LiteralWatchers::Reason(const Trail& trail, - int trail_index) const { + int trail_index) const { return reasons_[trail_index]->PropagationReason(); } @@ -393,8 +393,8 @@ bool BinaryImplicationGraph::Propagate(Trail* trail) { return true; } -absl::Span BinaryImplicationGraph::Reason( - const Trail& trail, int trail_index) const { +absl::Span BinaryImplicationGraph::Reason(const Trail& trail, + int trail_index) const { return {&reasons_[trail_index], 1}; } diff --git a/ortools/sat/clause.h b/ortools/sat/clause.h index cfd4bccfc62..ebde54f40dc 100644 --- a/ortools/sat/clause.h +++ b/ortools/sat/clause.h @@ -18,19 +18,19 @@ #define OR_TOOLS_SAT_CLAUSE_H_ #include +#include #include #include -#include #include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/macros.h" +#include "ortools/base/hash.h" #include "ortools/base/inlined_vector.h" -#include "ortools/base/span.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" +#include "ortools/base/integral_types.h" +#include "ortools/base/macros.h" +#include "ortools/base/span.h" #include "ortools/sat/drat_proof_handler.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_parameters.pb.h" @@ -42,8 +42,8 @@ namespace operations_research { namespace sat { // This is how the SatSolver stores a clause. A clause is just a disjunction of -// literals. In many places, we just use std::vector to encode one. But in -// the critical propagation code, we use this class to remove one memory +// literals. In many places, we just use std::vector to encode one. But +// in the critical propagation code, we use this class to remove one memory // indirection. class SatClause { public: @@ -158,8 +158,7 @@ class LiteralWatchers : public SatPropagator { // SatPropagator API. bool Propagate(Trail* trail) final; - absl::Span Reason(const Trail& trail, - int trail_index) const final; + absl::Span Reason(const Trail& trail, int trail_index) const final; // Returns the reason of the variable at given trail_index. This only works // for variable propagated by this class and is almost the same as Reason() @@ -387,8 +386,7 @@ class BinaryImplicationGraph : public SatPropagator { } bool Propagate(Trail* trail) final; - absl::Span Reason(const Trail& trail, - int trail_index) const final; + absl::Span Reason(const Trail& trail, int trail_index) const final; // Resizes the data structure. void Resize(int num_variables); diff --git a/ortools/sat/cp_constraints.h b/ortools/sat/cp_constraints.h index c409b885eb6..e83122c9694 100644 --- a/ortools/sat/cp_constraints.h +++ b/ortools/sat/cp_constraints.h @@ -18,10 +18,10 @@ #include #include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" #include "ortools/sat/integer.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/cp_model_checker.cc b/ortools/sat/cp_model_checker.cc index 81c0aa43060..0e1fd46014e 100644 --- a/ortools/sat/cp_model_checker.cc +++ b/ortools/sat/cp_model_checker.cc @@ -14,16 +14,15 @@ #include "ortools/sat/cp_model_checker.h" #include -#include #include #include #include #include -#include "ortools/base/logging.h" +#include "ortools/base/hash.h" #include "ortools/base/join.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" #include "ortools/port/proto_utils.h" #include "ortools/sat/cp_model_utils.h" #include "ortools/util/saturated_arithmetic.h" @@ -40,7 +39,7 @@ namespace { // If the std::string returned by "statement" is not empty, returns it. #define RETURN_IF_NOT_EMPTY(statement) \ do { \ - const std::string error_message = statement; \ + const std::string error_message = statement; \ if (!error_message.empty()) return error_message; \ } while (false) @@ -96,7 +95,7 @@ std::string ValidateIntegerVariable(const CpModelProto& model, int v) { } std::string ValidateArgumentReferencesInConstraint(const CpModelProto& model, - int c) { + int c) { const ConstraintProto& ct = model.constraints(c); IndexReferences references; AddReferencesUsedByConstraint(ct, &references); @@ -142,7 +141,7 @@ std::string ValidateArgumentReferencesInConstraint(const CpModelProto& model, } std::string ValidateLinearConstraint(const CpModelProto& model, - const ConstraintProto& ct) { + const ConstraintProto& ct) { const LinearConstraintProto& arg = ct.linear(); int64 sum_min = 0; int64 sum_max = 0; @@ -171,7 +170,7 @@ std::string ValidateLinearConstraint(const CpModelProto& model, } std::string ValidateReservoirConstraint(const CpModelProto& model, - const ConstraintProto& ct) { + const ConstraintProto& ct) { for (const int t : ct.reservoir().times()) { const IntegerVariableProto& time = model.variables(t); for (const int64 bound : time.domain()) { @@ -204,7 +203,7 @@ std::string ValidateCircuitCoveringConstraint(const ConstraintProto& ct) { } std::string ValidateObjective(const CpModelProto& model, - const CpObjectiveProto& obj) { + const CpObjectiveProto& obj) { // TODO(user): share the code with ValidateLinearConstraint(). if (obj.vars_size() == 1 && obj.coeffs(0) == 1) return ""; int64 sum_min = 0; diff --git a/ortools/sat/cp_model_checker.h b/ortools/sat/cp_model_checker.h index 74ebf73c843..02a194f49a5 100644 --- a/ortools/sat/cp_model_checker.h +++ b/ortools/sat/cp_model_checker.h @@ -24,8 +24,9 @@ namespace operations_research { namespace sat { // Verifies that the given model satisfies all the properties described in the -// proto comments. Returns an empty std::string if it is the case, otherwise fails at -// the first error and returns a human-readable description of the issue. +// proto comments. Returns an empty std::string if it is the case, otherwise +// fails at the first error and returns a human-readable description of the +// issue. // // TODO(user): Add any needed overflow validation. std::string ValidateCpModel(const CpModelProto& model); diff --git a/ortools/sat/cp_model_expand.cc b/ortools/sat/cp_model_expand.cc index 3ae53ab19b8..205c4686a86 100644 --- a/ortools/sat/cp_model_expand.cc +++ b/ortools/sat/cp_model_expand.cc @@ -16,8 +16,8 @@ #include #include -#include "ortools/base/map_util.h" #include "ortools/base/hash.h" +#include "ortools/base/map_util.h" #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/cp_model_utils.h" #include "ortools/util/saturated_arithmetic.h" diff --git a/ortools/sat/cp_model_presolve.cc b/ortools/sat/cp_model_presolve.cc index 33414f258f3..5d0c24aaad2 100644 --- a/ortools/sat/cp_model_presolve.cc +++ b/ortools/sat/cp_model_presolve.cc @@ -16,24 +16,24 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include +#include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" -#include "ortools/base/port.h" #include "ortools/base/join.h" -#include +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" +#include "ortools/base/port.h" #include "ortools/base/stl_util.h" -#include "ortools/base/hash.h" #include "ortools/sat/cp_model_checker.h" #include "ortools/sat/cp_model_objective.h" #include "ortools/sat/cp_model_utils.h" @@ -299,13 +299,13 @@ struct PresolveContext { // ============================================================================= MUST_USE_RESULT bool RemoveConstraint(ConstraintProto* ct, - PresolveContext* context) { + PresolveContext* context) { ct->Clear(); return true; } MUST_USE_RESULT bool MarkConstraintAsFalse(ConstraintProto* ct, - PresolveContext* context) { + PresolveContext* context) { if (HasEnforcementLiteral(*ct)) { context->SetLiteralToFalse(ct->enforcement_literal(0)); } else { @@ -2127,7 +2127,7 @@ void PresolveCpModel(CpModelProto* presolved_model, CpModelProto* mapping_model, VLOG(1) << "- " << context.var_equiv_relations.NumRelations() << " variable equivalence relations where detected."; std::map sorted_rules(context.stats_by_rule_name.begin(), - context.stats_by_rule_name.end()); + context.stats_by_rule_name.end()); for (const auto& entry : sorted_rules) { if (entry.second == 1) { VLOG(1) << "- rule '" << entry.first << "' was applied 1 time."; diff --git a/ortools/sat/cp_model_solver.cc b/ortools/sat/cp_model_solver.cc index 7a5ed9d03b5..9ae4b1e8eeb 100644 --- a/ortools/sat/cp_model_solver.cc +++ b/ortools/sat/cp_model_solver.cc @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -31,11 +30,10 @@ #if !defined(__PORTABLE_PLATFORM__) #include "google/protobuf/text_format.h" #endif // __PORTABLE_PLATFORM__ -#include "ortools/base/join.h" -#include "ortools/base/join.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/iterator_adaptors.h" +#include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" #include "ortools/graph/connectivity.h" @@ -1402,7 +1400,8 @@ void LoadInverseConstraint(const ConstraintProto& ct, ModelWithMapping* m) { } } -// Makes the std::string fit in one line by cutting it in the middle if necessary. +// Makes the std::string fit in one line by cutting it in the middle if +// necessary. std::string Summarize(const std::string& input) { if (input.size() < 105) return input; const int half = 50; @@ -1456,8 +1455,8 @@ std::string CpModelStats(const CpModelProto& model_proto) { absl::StrAppend(&result, "#Variables: ", model_proto.variables_size(), "\n"); if (num_vars_per_domains.size() < 20) { for (const auto& entry : num_vars_per_domains) { - const std::string temp = absl::StrCat(" - ", entry.second, " in ", - IntervalsAsString(entry.first), "\n"); + const std::string temp = absl::StrCat( + " - ", entry.second, " in ", IntervalsAsString(entry.first), "\n"); absl::StrAppend(&result, Summarize(temp)); } } else { @@ -2210,10 +2209,12 @@ std::function NewFeasibleSolutionObserver( #if !defined(__PORTABLE_PLATFORM__) // TODO(user): Support it on android. -std::function NewSatParameters(const std::string& params) { +std::function NewSatParameters( + const std::string& params) { sat::SatParameters parameters; if (!params.empty()) { - CHECK(google::protobuf::TextFormat::ParseFromString(params, ¶meters)) << params; + CHECK(google::protobuf::TextFormat::ParseFromString(params, ¶meters)) + << params; } return NewSatParameters(parameters); } @@ -2490,26 +2491,25 @@ CpSolverResponse SolveCpModelInternal( const CpObjectiveProto& obj = model_proto.objective(); VLOG(1) << obj.vars_size() << " terms in the proto objective."; VLOG(1) << "Initial num_bool: " << model->Get()->NumVariables(); - const auto solution_observer = - [&model_proto, &response, &num_solutions, &obj, &m, - &external_solution_observer, objective_var, - &fill_response_statistics](const Model& sat_model) { - num_solutions++; - FillSolutionInResponse(model_proto, m, &response); - fill_response_statistics(); - int64 objective_value = 0; - for (int i = 0; i < model_proto.objective().vars_size(); ++i) { - objective_value += model_proto.objective().coeffs(i) * - sat_model.Get(LowerBound( - m.Integer(model_proto.objective().vars(i)))); - } - response.set_objective_value( - ScaleObjectiveValue(obj, objective_value)); - external_solution_observer(response); - VLOG(1) << "Solution #" << num_solutions - << " obj:" << response.objective_value() - << " num_bool:" << sat_model.Get()->NumVariables(); - }; + const auto solution_observer = [&model_proto, &response, &num_solutions, + &obj, &m, &external_solution_observer, + objective_var, &fill_response_statistics]( + const Model& sat_model) { + num_solutions++; + FillSolutionInResponse(model_proto, m, &response); + fill_response_statistics(); + int64 objective_value = 0; + for (int i = 0; i < model_proto.objective().vars_size(); ++i) { + objective_value += model_proto.objective().coeffs(i) * + sat_model.Get(LowerBound( + m.Integer(model_proto.objective().vars(i)))); + } + response.set_objective_value(ScaleObjectiveValue(obj, objective_value)); + external_solution_observer(response); + VLOG(1) << "Solution #" << num_solutions + << " obj:" << response.objective_value() + << " num_bool:" << sat_model.Get()->NumVariables(); + }; if (parameters.optimize_with_core()) { std::vector linear_vars; @@ -2833,7 +2833,7 @@ CpSolverResponse SolveCpModel(const CpModelProto& model_proto, Model* model) { SatParameters params = *model->GetOrCreate(); SatParameters flag_params; CHECK(google::protobuf::TextFormat::ParseFromString(FLAGS_cp_model_params, - &flag_params)); + &flag_params)); params.MergeFrom(flag_params); model->Add(NewSatParameters(params)); LOG(INFO) << "Parameters: " << params.ShortDebugString(); diff --git a/ortools/sat/cp_model_solver.h b/ortools/sat/cp_model_solver.h index 2ec71db8aba..d66d34cc950 100644 --- a/ortools/sat/cp_model_solver.h +++ b/ortools/sat/cp_model_solver.h @@ -57,7 +57,8 @@ std::function NewFeasibleSolutionObserver( // model->Add(NewSatParameters(parameters_as_string_or_proto)) // before calling SolveCpModel(). #if !defined(__PORTABLE_PLATFORM__) -std::function NewSatParameters(const std::string& params); +std::function NewSatParameters( + const std::string& params); #endif // !__PORTABLE_PLATFORM__ std::function NewSatParameters( const SatParameters& parameters); diff --git a/ortools/sat/cp_model_utils.cc b/ortools/sat/cp_model_utils.cc index 3bbaa5f4ffa..98f6dbfe46e 100644 --- a/ortools/sat/cp_model_utils.cc +++ b/ortools/sat/cp_model_utils.cc @@ -320,7 +320,8 @@ void ApplyToAllIntervalIndices(const std::function& f, #undef APPLY_TO_SINGULAR_FIELD #undef APPLY_TO_REPEATED_FIELD -std::string ConstraintCaseName(ConstraintProto::ConstraintCase constraint_case) { +std::string ConstraintCaseName( + ConstraintProto::ConstraintCase constraint_case) { switch (constraint_case) { case ConstraintProto::ConstraintCase::kBoolOr: return "kBoolOr"; diff --git a/ortools/sat/cp_model_utils.h b/ortools/sat/cp_model_utils.h index 5ae2a5e2bee..7e35a68c2ea 100644 --- a/ortools/sat/cp_model_utils.h +++ b/ortools/sat/cp_model_utils.h @@ -19,9 +19,9 @@ #include #include +#include #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include #include "ortools/sat/cp_model.pb.h" #include "ortools/util/sorted_interval_list.h" diff --git a/ortools/sat/cumulative.cc b/ortools/sat/cumulative.cc index 5825912acbc..1778e1e5046 100644 --- a/ortools/sat/cumulative.cc +++ b/ortools/sat/cumulative.cc @@ -16,8 +16,8 @@ #include #include -#include "ortools/base/logging.h" #include "ortools/base/int_type.h" +#include "ortools/base/logging.h" #include "ortools/sat/disjunctive.h" #include "ortools/sat/overload_checker.h" #include "ortools/sat/pb_constraint.h" diff --git a/ortools/sat/disjunctive.cc b/ortools/sat/disjunctive.cc index ce6f682d855..70f88b08960 100644 --- a/ortools/sat/disjunctive.cc +++ b/ortools/sat/disjunctive.cc @@ -15,8 +15,8 @@ #include -#include "ortools/base/logging.h" #include "ortools/base/iterator_adaptors.h" +#include "ortools/base/logging.h" #include "ortools/sat/all_different.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/sat/sat_solver.h" diff --git a/ortools/sat/disjunctive.h b/ortools/sat/disjunctive.h index 73ae7fdba9c..1ea60757668 100644 --- a/ortools/sat/disjunctive.h +++ b/ortools/sat/disjunctive.h @@ -18,8 +18,8 @@ #include #include -#include "ortools/base/macros.h" #include "ortools/base/int_type.h" +#include "ortools/base/macros.h" #include "ortools/sat/integer.h" #include "ortools/sat/intervals.h" #include "ortools/sat/model.h" diff --git a/ortools/sat/drat_checker.cc b/ortools/sat/drat_checker.cc index 862f9bbfa91..0b746152854 100644 --- a/ortools/sat/drat_checker.cc +++ b/ortools/sat/drat_checker.cc @@ -18,8 +18,8 @@ #include "ortools/base/hash.h" #include "ortools/base/numbers.h" #include "ortools/base/split.h" -#include "ortools/base/time_support.h" #include "ortools/base/stl_util.h" +#include "ortools/base/time_support.h" #include "ortools/util/time_limit.h" namespace operations_research { @@ -98,8 +98,8 @@ ClauseIndex DratChecker::AddClause(absl::Span clause) { for (int i = first_literal_index + 1; i < literals_.size(); ++i) { CHECK(literals_[i] != literals_[i - 1].Negated()); } - clauses_.push_back(Clause(first_literal_index, - literals_.size() - first_literal_index)); + clauses_.push_back( + Clause(first_literal_index, literals_.size() - first_literal_index)); if (!clause.empty()) { num_variables_ = std::max(num_variables_, literals_.back().Variable().value() + 1); @@ -234,8 +234,8 @@ std::vector> DratChecker::GetClausesNeededForProof( } absl::Span DratChecker::Literals(const Clause& clause) const { - return absl::Span( - literals_.data() + clause.first_literal_index, clause.num_literals); + return absl::Span(literals_.data() + clause.first_literal_index, + clause.num_literals); } void DratChecker::Init() { @@ -460,8 +460,7 @@ bool ContainsLiteral(absl::Span clause, Literal literal) { return std::find(clause.begin(), clause.end(), literal) != clause.end(); } -bool Resolve(absl::Span clause, - absl::Span other_clause, +bool Resolve(absl::Span clause, absl::Span other_clause, Literal complementary_literal, VariablesAssignment* assignment, std::vector* resolvent) { DCHECK(ContainsLiteral(clause, complementary_literal)); @@ -516,7 +515,8 @@ bool AddProblemClauses(const std::string& file_path, } if (words[0] == "p") { if (num_clauses > 0 || words.size() != 4 || words[1] != "cnf" || - !strings::safe_strto32(words[2], &num_variables) || num_variables <= 0 || + !strings::safe_strto32(words[2], &num_variables) || + num_variables <= 0 || !strings::safe_strto32(words[3], &num_clauses) || num_clauses <= 0) { LOG(ERROR) << "Invalid content '" << line << "' at line " << line_number << " of " << file_path; diff --git a/ortools/sat/drat_checker.h b/ortools/sat/drat_checker.h index b4fe02f6a91..26a0724471d 100644 --- a/ortools/sat/drat_checker.h +++ b/ortools/sat/drat_checker.h @@ -17,10 +17,10 @@ #include #include -#include "ortools/base/span.h" #include #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/span.h" #include "ortools/sat/sat_base.h" namespace operations_research { @@ -189,8 +189,7 @@ class DratChecker { // deleted clauses whose index is strictly less than 'num_clauses'. If so, // marks the clauses actually used in this process as needed to check to DRAT // proof. - bool HasRupProperty(ClauseIndex num_clauses, - absl::Span clause); + bool HasRupProperty(ClauseIndex num_clauses, absl::Span clause); // Assigns 'literal' to true in 'assignment_' (and pushes it to 'assigned_'), // records its source clause 'source_clause_index' in 'assignment_source_', @@ -306,8 +305,7 @@ bool ContainsLiteral(absl::Span clause, Literal literal); // 'other_clause' must contain its negation. 'assignment' must have at least as // many variables as each clause, and they must all be unassigned. They are // still unassigned upon return. -bool Resolve(absl::Span clause, - absl::Span other_clause, +bool Resolve(absl::Span clause, absl::Span other_clause, Literal complementary_literal, VariablesAssignment* assignment, std::vector* resolvent); diff --git a/ortools/sat/drat_proof_handler.cc b/ortools/sat/drat_proof_handler.cc index 8324bf07976..b91213efbd5 100644 --- a/ortools/sat/drat_proof_handler.cc +++ b/ortools/sat/drat_proof_handler.cc @@ -15,9 +15,9 @@ #include +#include "ortools/base/int_type.h" #include "ortools/base/logging.h" #include "ortools/base/memory.h" -#include "ortools/base/int_type.h" namespace operations_research { namespace sat { diff --git a/ortools/sat/drat_proof_handler.h b/ortools/sat/drat_proof_handler.h index d7268c934c1..6b632ca9f2b 100644 --- a/ortools/sat/drat_proof_handler.h +++ b/ortools/sat/drat_proof_handler.h @@ -18,8 +18,8 @@ #include #include -#include "ortools/base/span.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/span.h" #include "ortools/sat/drat_checker.h" #include "ortools/sat/drat_writer.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/drat_writer.cc b/ortools/sat/drat_writer.cc index 9ce505d5a90..4fefd751400 100644 --- a/ortools/sat/drat_writer.cc +++ b/ortools/sat/drat_writer.cc @@ -33,9 +33,7 @@ DratWriter::~DratWriter() { } } -void DratWriter::AddClause(absl::Span clause) { - WriteClause(clause); -} +void DratWriter::AddClause(absl::Span clause) { WriteClause(clause); } void DratWriter::DeleteClause(absl::Span clause) { buffer_ += "d "; diff --git a/ortools/sat/encoding.h b/ortools/sat/encoding.h index 196926f741e..e9c5e39fc84 100644 --- a/ortools/sat/encoding.h +++ b/ortools/sat/encoding.h @@ -21,10 +21,10 @@ #include #include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" #include "ortools/sat/boolean_problem.pb.h" #include "ortools/sat/pb_constraint.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/integer.cc b/ortools/sat/integer.cc index eac2f701282..392cff51cb1 100644 --- a/ortools/sat/integer.cc +++ b/ortools/sat/integer.cc @@ -740,7 +740,7 @@ bool IntegerTrail::EnqueueAssociatedLiteral( namespace { std::string ReasonDebugString(absl::Span literal_reason, - absl::Span integer_reason) { + absl::Span integer_reason) { std::string result = "literals:{"; for (const Literal l : literal_reason) { if (result.back() != '{') result += ","; @@ -1001,8 +1001,7 @@ std::vector IntegerTrail::ReasonFor(IntegerLiteral literal) const { return reason; } -bool IntegerTrail::AllLiteralsAreFalse( - absl::Span literals) const { +bool IntegerTrail::AllLiteralsAreFalse(absl::Span literals) const { for (const Literal lit : literals) { if (!trail_->Assignment().LiteralIsFalse(lit)) return false; } @@ -1137,7 +1136,7 @@ void IntegerTrail::MergeReasonIntoInternal(std::vector* output) const { } absl::Span IntegerTrail::Reason(const Trail& trail, - int trail_index) const { + int trail_index) const { const int index = boolean_trail_index_to_integer_one_[trail_index]; std::vector* reason = trail.GetEmptyVectorToStoreReason(trail_index); added_variables_.ClearAndResize(BooleanVariable(trail_->NumVariables())); @@ -1153,9 +1152,9 @@ absl::Span IntegerTrail::Reason(const Trail& trail, return *reason; } -void IntegerTrail::EnqueueLiteral( - Literal literal, absl::Span literal_reason, - absl::Span integer_reason) { +void IntegerTrail::EnqueueLiteral(Literal literal, + absl::Span literal_reason, + absl::Span integer_reason) { DCHECK(AllLiteralsAreFalse(literal_reason)); if (integer_search_levels_.empty()) { // Level zero. We don't keep any reason. diff --git a/ortools/sat/integer.h b/ortools/sat/integer.h index 2c98cbf1680..cf243319ee1 100644 --- a/ortools/sat/integer.h +++ b/ortools/sat/integer.h @@ -16,26 +16,26 @@ #include #include -#include #include #include #include #include +#include #include #include +#include "ortools/base/hash.h" +#include "ortools/base/inlined_vector.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/map_util.h" #include "ortools/base/port.h" -#include "ortools/base/inlined_vector.h" -#include "ortools/base/join.h" #include "ortools/base/span.h" #include "ortools/graph/iterators.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/map_util.h" -#include "ortools/base/hash.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_solver.h" @@ -429,8 +429,7 @@ class IntegerTrail : public SatPropagator { // correct state before calling any of its functions. bool Propagate(Trail* trail) final; void Untrail(const Trail& trail, int literal_trail_index) final; - absl::Span Reason(const Trail& trail, - int trail_index) const final; + absl::Span Reason(const Trail& trail, int trail_index) const final; // Returns the number of created integer variables. // @@ -550,18 +549,18 @@ class IntegerTrail : public SatPropagator { // TODO(user): If the given bound is equal to the current bound, maybe the new // reason is better? how to decide and what to do in this case? to think about // it. Currently we simply don't do anything. - MUST_USE_RESULT bool Enqueue( - IntegerLiteral i_lit, absl::Span literal_reason, - absl::Span integer_reason); + MUST_USE_RESULT bool Enqueue(IntegerLiteral i_lit, + absl::Span literal_reason, + absl::Span integer_reason); // Same as Enqueue(), but takes an extra argument which if smaller than // integer_trail_.size() is interpreted as the trail index of an old Enqueue() // that had the same reason as this one. Note that the given Span must still // be valid as they are used in case of conflict. - MUST_USE_RESULT bool Enqueue( - IntegerLiteral i_lit, absl::Span literal_reason, - absl::Span integer_reason, - int trail_index_with_same_reason); + MUST_USE_RESULT bool Enqueue(IntegerLiteral i_lit, + absl::Span literal_reason, + absl::Span integer_reason, + int trail_index_with_same_reason); // Enqueues the given literal on the trail. // See the comment of Enqueue() for the reason format. @@ -730,8 +729,8 @@ class IntegerTrail : public SatPropagator { RevMap> var_to_current_lb_interval_index_; std::unordered_map - var_to_end_interval_index_; // const entries. - std::vector all_intervals_; // const entries. + var_to_end_interval_index_; // const entries. + std::vector all_intervals_; // const entries. // Temporary data used by MergeReasonInto(). mutable std::vector tmp_queue_; diff --git a/ortools/sat/integer_expr.h b/ortools/sat/integer_expr.h index c7706ec8595..74a74abf0a3 100644 --- a/ortools/sat/integer_expr.h +++ b/ortools/sat/integer_expr.h @@ -17,10 +17,10 @@ #include #include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" #include "ortools/sat/integer.h" #include "ortools/sat/model.h" #include "ortools/sat/precedences.h" @@ -385,8 +385,8 @@ inline std::function WeightedSumNotEqual( // Model-based function to create an IntegerVariable that corresponds to the // given weighted sum of other IntegerVariables. // -// Note that this is templated so that it can seemlessly accept std::vector or -// std::vector. +// Note that this is templated so that it can seemlessly accept std::vector +// or std::vector. // // TODO(user): invert the coefficients/vars arguments. template diff --git a/ortools/sat/intervals.h b/ortools/sat/intervals.h index 709950af10e..ab0c7a78a80 100644 --- a/ortools/sat/intervals.h +++ b/ortools/sat/intervals.h @@ -17,11 +17,11 @@ #include #include +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/sat/cp_constraints.h" #include "ortools/sat/integer.h" #include "ortools/sat/integer_expr.h" diff --git a/ortools/sat/linear_programming_constraint.cc b/ortools/sat/linear_programming_constraint.cc index 390841e5ab5..fa44fb69651 100644 --- a/ortools/sat/linear_programming_constraint.cc +++ b/ortools/sat/linear_programming_constraint.cc @@ -18,13 +18,13 @@ #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/graph/strongly_connected_components.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/map_util.h" #include "ortools/glop/parameters.pb.h" #include "ortools/glop/status.h" +#include "ortools/graph/strongly_connected_components.h" namespace operations_research { namespace sat { diff --git a/ortools/sat/linear_programming_constraint.h b/ortools/sat/linear_programming_constraint.h index 5d58ead8390..eda4f1c7812 100644 --- a/ortools/sat/linear_programming_constraint.h +++ b/ortools/sat/linear_programming_constraint.h @@ -380,8 +380,7 @@ class LinearProgrammingConstraint : public PropagatorInterface, // // Important: only positive variable do appear here. class LinearProgrammingDispatcher - : public std::unordered_map { + : public std::unordered_map { public: explicit LinearProgrammingDispatcher(Model* model) {} }; diff --git a/ortools/sat/lp_utils.cc b/ortools/sat/lp_utils.cc index 3b8f26aa612..7e2ce84934e 100644 --- a/ortools/sat/lp_utils.cc +++ b/ortools/sat/lp_utils.cc @@ -20,10 +20,10 @@ #include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/logging.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/integral_types.h" +#include "ortools/base/logging.h" #include "ortools/glop/lp_solver.h" #include "ortools/glop/parameters.pb.h" #include "ortools/lp_data/lp_types.h" @@ -36,8 +36,8 @@ namespace sat { using glop::ColIndex; using glop::Fractional; -using glop::RowIndex; using glop::kInfinity; +using glop::RowIndex; using operations_research::MPConstraintProto; using operations_research::MPModelProto; @@ -530,7 +530,8 @@ bool SolveLpAndUseIntegerVariableToStartLNS(const glop::LinearProgram& lp, glop::LPSolver solver; const glop::ProblemStatus& status = solver.Solve(lp); if (status != glop::ProblemStatus::OPTIMAL && - status != glop::ProblemStatus::PRIMAL_FEASIBLE) return false; + status != glop::ProblemStatus::PRIMAL_FEASIBLE) + return false; int num_variable_fixed = 0; for (ColIndex col(0); col < lp.num_variables(); ++col) { const Fractional tolerance = 1e-5; diff --git a/ortools/sat/optimization.cc b/ortools/sat/optimization.cc index 115ff91cfc7..02158d24a35 100644 --- a/ortools/sat/optimization.cc +++ b/ortools/sat/optimization.cc @@ -24,19 +24,19 @@ #include #include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" +#include "ortools/base/join.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/map_util.h" #include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" -#include "ortools/base/join.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/int_type.h" -#include "ortools/base/map_util.h" #if !defined(__PORTABLE_PLATFORM__) #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" #endif // __PORTABLE_PLATFORM__ +#include "ortools/base/random.h" #include "ortools/port/proto_utils.h" #include "ortools/sat/boolean_problem.h" #include "ortools/sat/encoding.h" @@ -45,8 +45,6 @@ #include "ortools/sat/sat_parameters.pb.h" #include "ortools/sat/util.h" #include "ortools/util/time_limit.h" -#include "ortools/base/random.h" - namespace operations_research { namespace sat { @@ -73,7 +71,7 @@ class Logger { // Outputs the current objective value in the cnf output format. // Note that this function scale the given objective. std::string CnfObjectiveLine(const LinearBooleanProblem& problem, - Coefficient objective) { + Coefficient objective) { const double scaled_objective = AddOffsetAndScaleObjectiveValue(problem, objective); return absl::StrFormat("o %lld", static_cast(scaled_objective)); @@ -639,9 +637,10 @@ SatSolver::Status SolveWithWPM1(LogBehavior log, lower_bound += min_cost; // Print the search progress. - logger.Log(absl::StrFormat( - "c iter:%d core:%zu lb:%lld min_cost:%lld strat:%lld", iter, core.size(), - lower_bound.value(), min_cost.value(), stratified_lower_bound.value())); + logger.Log( + absl::StrFormat("c iter:%d core:%zu lb:%lld min_cost:%lld strat:%lld", + iter, core.size(), lower_bound.value(), + min_cost.value(), stratified_lower_bound.value())); // This simple line helps a lot on the packup-wpms instances! // @@ -1032,8 +1031,8 @@ SatSolver::Status SolveWithCardinalityEncodingAndCore( ? "" : absl::StrFormat(" gap:%lld", (upper_bound - lower_bound).value()); logger.Log( - absl::StrFormat("c iter:%d [%s] lb:%lld%s assumptions:%zu depth:%d", iter, - previous_core_info.c_str(), + absl::StrFormat("c iter:%d [%s] lb:%lld%s assumptions:%zu depth:%d", + iter, previous_core_info.c_str(), lower_bound.value() - offset.value() + static_cast(problem.objective().offset()), gap_string.c_str(), nodes.size(), max_depth)); @@ -1096,9 +1095,9 @@ namespace { void LogSolveInfo(SatSolver::Status result, const SatSolver& sat_solver, const WallTimer& wall_timer, const UserTimer& user_timer, int64 objective, int64 best_bound) { - printf("status: %s\n", - result == SatSolver::MODEL_SAT ? "OPTIMAL" - : SatStatusString(result).c_str()); + printf("status: %s\n", result == SatSolver::MODEL_SAT + ? "OPTIMAL" + : SatStatusString(result).c_str()); if (objective < kint64max) { printf("objective: %lld\n", objective); } else { @@ -1649,9 +1648,9 @@ SatSolver::Status MinimizeWithCoreAndLazyEncoding( max_depth = std::max(max_depth, new_depth); if (log_info) { LOG(INFO) << absl::StrFormat( - "core:%zu weight:[%lld,%lld] domain:[%lld,%lld] depth:%d", core.size(), - min_weight.value(), max_weight.value(), new_var_lb.value(), - new_var_ub.value(), new_depth); + "core:%zu weight:[%lld,%lld] domain:[%lld,%lld] depth:%d", + core.size(), min_weight.value(), max_weight.value(), + new_var_lb.value(), new_var_ub.value(), new_depth); } // We will "transfer" min_weight from all the variables of the core @@ -1740,12 +1739,12 @@ SatSolver::Status MinimizeWithHittingSetAndLazyEncoding( // This is the "generalized" hitting set problem we will solve. Each time // we find a core, a new constraint will be added to this problem. MPModelRequest request; - #if defined(USE_SCIP) +#if defined(USE_SCIP) request.set_solver_specific_parameters("limits/gap = 0"); request.set_solver_type(MPModelRequest::SCIP_MIXED_INTEGER_PROGRAMMING); - #else // USE_CBC - request.set_solver_type(MPModelRequest::CBC_MIXED_INTEGER_PROGRAMMING); - #endif // USE_CBC or USE_SCIP +#else // USE_CBC + request.set_solver_type(MPModelRequest::CBC_MIXED_INTEGER_PROGRAMMING); +#endif // USE_CBC or USE_SCIP MPModelProto& hs_model = *request.mutable_model(); const int num_variables = variables.size(); @@ -1762,12 +1761,12 @@ SatSolver::Status MinimizeWithHittingSetAndLazyEncoding( var_proto->set_is_integer(true); } - // The MIP solver. - #if defined(USE_SCIP) +// The MIP solver. +#if defined(USE_SCIP) MPSolver solver("HS solver", MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); - #else // USE_CBC - MPSolver solver("HS solver", MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); - #endif // USE_CBC or USE_SCIP +#else // USE_CBC + MPSolver solver("HS solver", MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); +#endif // USE_CBC or USE_SCIP MPSolutionResponse response; // This is used by the "stratified" approach. We will only consider terms with diff --git a/ortools/sat/overload_checker.h b/ortools/sat/overload_checker.h index e31c781d4ea..0263e276381 100644 --- a/ortools/sat/overload_checker.h +++ b/ortools/sat/overload_checker.h @@ -16,8 +16,8 @@ #include -#include "ortools/base/macros.h" #include "ortools/base/int_type.h" +#include "ortools/base/macros.h" #include "ortools/sat/integer.h" #include "ortools/sat/intervals.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/pb_constraint.cc b/ortools/sat/pb_constraint.cc index 25471367772..1597fb3d540 100644 --- a/ortools/sat/pb_constraint.cc +++ b/ortools/sat/pb_constraint.cc @@ -15,7 +15,6 @@ #include -#include "ortools/base/stringprintf.h" #include "ortools/base/stringprintf.h" #include "ortools/base/thorough_hash.h" #include "ortools/util/saturated_arithmetic.h" @@ -424,7 +423,7 @@ UpperBoundedLinearConstraint::UpperBoundedLinearConstraint( starts_.push_back(literals_.size()); hash_ = ThoroughHash(reinterpret_cast(cst.data()), - cst.size() * sizeof(LiteralWithCoeff)); + cst.size() * sizeof(LiteralWithCoeff)); } void UpperBoundedLinearConstraint::AddToConflict( @@ -963,7 +962,7 @@ void PbConstraints::Untrail(const Trail& trail, int trail_index) { } absl::Span PbConstraints::Reason(const Trail& trail, - int trail_index) const { + int trail_index) const { SCOPED_TIME_STAT(&stats_); const PbConstraintsEnqueueHelper::ReasonInfo& reason_info = enqueue_helper_.reasons[trail_index]; diff --git a/ortools/sat/pb_constraint.h b/ortools/sat/pb_constraint.h index 854ab735c8b..24cfc4fb66e 100644 --- a/ortools/sat/pb_constraint.h +++ b/ortools/sat/pb_constraint.h @@ -15,19 +15,19 @@ #define OR_TOOLS_SAT_PB_CONSTRAINT_H_ #include -#include #include #include #include +#include #include +#include "ortools/base/hash.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/span.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/util/bitset.h" @@ -532,8 +532,7 @@ class PbConstraints : public SatPropagator { bool Propagate(Trail* trail) final; void Untrail(const Trail& trail, int trail_index) final; - absl::Span Reason(const Trail& trail, - int trail_index) const final; + absl::Span Reason(const Trail& trail, int trail_index) const final; // Changes the number of variables. void Resize(int num_variables) { diff --git a/ortools/sat/precedences.cc b/ortools/sat/precedences.cc index 1e8db35ba44..eb9536f95ca 100644 --- a/ortools/sat/precedences.cc +++ b/ortools/sat/precedences.cc @@ -16,8 +16,8 @@ #include #include -#include "ortools/base/logging.h" #include "ortools/base/cleanup.h" +#include "ortools/base/logging.h" #include "ortools/base/stl_util.h" #include "ortools/sat/cp_constraints.h" @@ -611,8 +611,8 @@ bool PrecedencesPropagator::BellmanFordTarjan(Trail* trail) { // These vector are reset by CleanUpMarkedArcsAndParents() so resize is ok. bf_can_be_skipped_.resize(num_nodes, false); bf_parent_arc_of_.resize(num_nodes, ArcIndex(-1)); - const auto cleanup = - ::operations_research::util::MakeCleanup([this]() { CleanUpMarkedArcsAndParents(); }); + const auto cleanup = ::operations_research::util::MakeCleanup( + [this]() { CleanUpMarkedArcsAndParents(); }); // The queue initialization is done by InitializeBFQueueWithModifiedNodes(). while (!bf_queue_.empty()) { diff --git a/ortools/sat/precedences.h b/ortools/sat/precedences.h index 5d4bb6d0dcd..b2d9c0ee548 100644 --- a/ortools/sat/precedences.h +++ b/ortools/sat/precedences.h @@ -18,11 +18,11 @@ #include #include -#include "ortools/base/integral_types.h" -#include "ortools/base/macros.h" #include "ortools/base/inlined_vector.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/integral_types.h" +#include "ortools/base/macros.h" #include "ortools/sat/integer.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/restart.cc b/ortools/sat/restart.cc index 6a61dfbd985..2e4e6f8cee1 100644 --- a/ortools/sat/restart.cc +++ b/ortools/sat/restart.cc @@ -149,13 +149,14 @@ void RestartPolicy::OnConflict(int conflict_trail_index, } std::string RestartPolicy::InfoString() const { - std::string result = StringPrintf(" num restarts: %d\n", num_restarts_) + - StringPrintf(" conflict decision level avg: %f\n", - dl_running_average_.GlobalAverage()) + - StringPrintf(" conflict lbd avg: %f\n", - lbd_running_average_.GlobalAverage()) + - StringPrintf(" conflict trail size avg: %f\n", - trail_size_running_average_.GlobalAverage()); + std::string result = + StringPrintf(" num restarts: %d\n", num_restarts_) + + StringPrintf(" conflict decision level avg: %f\n", + dl_running_average_.GlobalAverage()) + + StringPrintf(" conflict lbd avg: %f\n", + lbd_running_average_.GlobalAverage()) + + StringPrintf(" conflict trail size avg: %f\n", + trail_size_running_average_.GlobalAverage()); return result; } diff --git a/ortools/sat/sat_base.h b/ortools/sat/sat_base.h index ba3f7f6f69a..fbeed0be027 100644 --- a/ortools/sat/sat_base.h +++ b/ortools/sat/sat_base.h @@ -22,14 +22,14 @@ #include #include +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" #include "ortools/base/port.h" #include "ortools/base/span.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" +#include "ortools/base/stringprintf.h" #include "ortools/sat/model.h" #include "ortools/util/bitset.h" @@ -475,7 +475,7 @@ class SatPropagator { // can use trail_.GetEmptyVectorToStoreReason() if it doesn't have a memory // location that already contains the reason. virtual absl::Span Reason(const Trail& trail, - int trail_index) const { + int trail_index) const { LOG(FATAL) << "Not implemented."; return {}; } diff --git a/ortools/sat/sat_solver.cc b/ortools/sat/sat_solver.cc index bb57305eb05..ffa47b35bfb 100644 --- a/ortools/sat/sat_solver.cc +++ b/ortools/sat/sat_solver.cc @@ -23,10 +23,10 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/sysinfo.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" +#include "ortools/base/stringprintf.h" +#include "ortools/base/sysinfo.h" #include "ortools/port/proto_utils.h" #include "ortools/port/sysinfo.h" #include "ortools/sat/util.h" @@ -70,9 +70,7 @@ SatSolver::SatSolver(Model* model) SetParameters(*parameters_); } -SatSolver::~SatSolver() { - IF_STATS_ENABLED(LOG(INFO) << stats_.StatString()); -} +SatSolver::~SatSolver() { IF_STATS_ENABLED(LOG(INFO) << stats_.StatString()); } void SatSolver::SetNumVariables(int num_variables) { SCOPED_TIME_STAT(&stats_); @@ -1467,7 +1465,8 @@ std::string SatSolver::RunningStatisticsString() const { "%6.2fs, mem:%s, fails:%" GG_LL_FORMAT "d, " "depth:%d, clauses:%lld, tmp:%lld, bin:%llu, restarts:%d, vars:%d", - time_in_s, MemoryUsage().c_str(), counters_.num_failures, CurrentDecisionLevel(), + time_in_s, MemoryUsage().c_str(), counters_.num_failures, + CurrentDecisionLevel(), clauses_propagator_.num_clauses() - clauses_propagator_.num_removable_clauses(), clauses_propagator_.num_removable_clauses(), @@ -1690,7 +1689,6 @@ void SatSolver::EnqueueNewDecision(Literal literal) { trail_->EnqueueSearchDecision(literal); } - void SatSolver::Untrail(int target_trail_index) { SCOPED_TIME_STAT(&stats_); DCHECK_LT(target_trail_index, trail_->Index()); diff --git a/ortools/sat/sat_solver.h b/ortools/sat/sat_solver.h index 425e2e152d7..5f9fb3afbd1 100644 --- a/ortools/sat/sat_solver.h +++ b/ortools/sat/sat_solver.h @@ -20,21 +20,21 @@ #define OR_TOOLS_SAT_SAT_SOLVER_H_ #include -#include #include #include #include +#include #include #include +#include "ortools/base/hash.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/timer.h" #include "ortools/base/span.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/base/hash.h" +#include "ortools/base/timer.h" #include "ortools/sat/clause.h" #include "ortools/sat/drat_proof_handler.h" #include "ortools/sat/model.h" diff --git a/ortools/sat/simplification.cc b/ortools/sat/simplification.cc index 872258de31a..5944633d86d 100644 --- a/ortools/sat/simplification.cc +++ b/ortools/sat/simplification.cc @@ -18,15 +18,15 @@ #include #include +#include "ortools/algorithms/dynamic_partition.h" +#include "ortools/base/adjustable_priority_queue-inl.h" #include "ortools/base/logging.h" +#include "ortools/base/random.h" +#include "ortools/base/stl_util.h" #include "ortools/base/timer.h" #include "ortools/graph/strongly_connected_components.h" -#include "ortools/base/stl_util.h" -#include "ortools/algorithms/dynamic_partition.h" #include "ortools/sat/util.h" #include "ortools/util/time_limit.h" -#include "ortools/base/adjustable_priority_queue-inl.h" -#include "ortools/base/random.h" namespace operations_research { namespace sat { @@ -1058,7 +1058,8 @@ void ProbeAndFindEquivalentLiteral( CHECK_EQ(Literal(LiteralIndex(partition.GetRootAndCompressPath( representative.Index().value()))), Literal(LiteralIndex(partition.GetRootAndCompressPath( - representative.NegatedIndex().value()))).Negated()); + representative.NegatedIndex().value()))) + .Negated()); } } diff --git a/ortools/sat/simplification.h b/ortools/sat/simplification.h index 21a8b07a0b8..b61fe1e0f68 100644 --- a/ortools/sat/simplification.h +++ b/ortools/sat/simplification.h @@ -24,17 +24,17 @@ #include #include +#include "ortools/base/adjustable_priority_queue.h" +#include "ortools/base/int_type.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/integral_types.h" #include "ortools/base/macros.h" #include "ortools/base/span.h" -#include "ortools/base/int_type.h" -#include "ortools/base/int_type_indexed_vector.h" #include "ortools/sat/drat_proof_handler.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_parameters.pb.h" #include "ortools/sat/sat_solver.h" #include "ortools/util/time_limit.h" -#include "ortools/base/adjustable_priority_queue.h" namespace operations_research { namespace sat { diff --git a/ortools/sat/symmetry.cc b/ortools/sat/symmetry.cc index ac168233b39..32a53979f7a 100644 --- a/ortools/sat/symmetry.cc +++ b/ortools/sat/symmetry.cc @@ -13,8 +13,8 @@ #include "ortools/sat/symmetry.h" -#include "ortools/base/logging.h" #include "ortools/base/int_type.h" +#include "ortools/base/logging.h" namespace operations_research { namespace sat { @@ -145,7 +145,7 @@ void SymmetryPropagator::Untrail(const Trail& trail, int trail_index) { } absl::Span SymmetryPropagator::Reason(const Trail& trail, - int trail_index) const { + int trail_index) const { SCOPED_TIME_STAT(&stats_); const ReasonInfo& reason_info = reasons_[trail_index]; std::vector* reason = trail.GetEmptyVectorToStoreReason(trail_index); diff --git a/ortools/sat/symmetry.h b/ortools/sat/symmetry.h index 5fafe1bcafd..c87bd7ba3b7 100644 --- a/ortools/sat/symmetry.h +++ b/ortools/sat/symmetry.h @@ -17,10 +17,10 @@ #include #include +#include "ortools/algorithms/sparse_permutation.h" +#include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/macros.h" #include "ortools/base/span.h" -#include "ortools/base/int_type_indexed_vector.h" -#include "ortools/algorithms/sparse_permutation.h" #include "ortools/sat/sat_base.h" #include "ortools/util/stats.h" @@ -65,8 +65,7 @@ class SymmetryPropagator : public SatPropagator { bool Propagate(Trail* trail) final; void Untrail(const Trail& trail, int trail_index) final; - absl::Span Reason(const Trail& trail, - int trail_index) const final; + absl::Span Reason(const Trail& trail, int trail_index) const final; // Adds a new permutation to this symmetry propagator. The ownership is // transferred. This must be an integer permutation such that: diff --git a/ortools/sat/table.cc b/ortools/sat/table.cc index 59dd0a797db..41af2f0b7b4 100644 --- a/ortools/sat/table.cc +++ b/ortools/sat/table.cc @@ -14,16 +14,14 @@ #include "ortools/sat/table.h" #include -#include -#include #include #include #include #include #include -#include "ortools/base/logging.h" #include "ortools/base/int_type.h" +#include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" #include "ortools/sat/sat_solver.h" @@ -52,7 +50,7 @@ std::vector> Transpose( // Converts the vector representation returned by FullDomainEncoding() to a map. std::unordered_map GetEncoding(IntegerVariable var, - Model* model) { + Model* model) { std::unordered_map encoding; IntegerEncoder* encoder = model->GetOrCreate(); for (const auto& entry : encoder->FullDomainEncoding(var)) { @@ -79,10 +77,10 @@ void FilterValues(IntegerVariable var, Model* model, // controling if the lines are possible or not. The column has the given values, // and the Literal of the column variable can be retrieved using the encoding // map. -void ProcessOneColumn( - const std::vector& line_literals, - const std::vector& values, - const std::unordered_map& encoding, Model* model) { +void ProcessOneColumn(const std::vector& line_literals, + const std::vector& values, + const std::unordered_map& encoding, + Model* model) { CHECK_EQ(line_literals.size(), values.size()); std::unordered_map> value_to_list_of_line_literals; diff --git a/ortools/sat/timetable.cc b/ortools/sat/timetable.cc index 338d740764f..77287860d37 100644 --- a/ortools/sat/timetable.cc +++ b/ortools/sat/timetable.cc @@ -17,8 +17,8 @@ #include #include -#include "ortools/base/logging.h" #include "ortools/base/int_type.h" +#include "ortools/base/logging.h" #include "ortools/util/sort.h" namespace operations_research { diff --git a/ortools/sat/timetable_edgefinding.cc b/ortools/sat/timetable_edgefinding.cc index 390cd3c67f6..5f9259268d3 100644 --- a/ortools/sat/timetable_edgefinding.cc +++ b/ortools/sat/timetable_edgefinding.cc @@ -18,9 +18,9 @@ #include #include +#include "ortools/base/int_type.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" -#include "ortools/base/int_type.h" #include "ortools/util/sort.h" namespace operations_research { @@ -329,9 +329,8 @@ bool TimeTableEdgeFinding::TimeTableEdgeFindingPass() { // Compute the length of the mandatory subpart of max_task that should be // considered as available. const IntegerValue mandatory_in = - std::max(IntegerValue(0), - std::min(end, end_min_[max_task]) - - std::max(begin, start_max_[max_task])); + std::max(IntegerValue(0), std::min(end, end_min_[max_task]) - + std::max(begin, start_max_[max_task])); // Compute the new minimum start time of max_task. const IntegerValue new_start = diff --git a/ortools/sat/timetable_edgefinding.h b/ortools/sat/timetable_edgefinding.h index 09c163743d4..f5bed8f2cce 100644 --- a/ortools/sat/timetable_edgefinding.h +++ b/ortools/sat/timetable_edgefinding.h @@ -16,8 +16,8 @@ #include -#include "ortools/base/macros.h" #include "ortools/base/int_type.h" +#include "ortools/base/macros.h" #include "ortools/sat/integer.h" #include "ortools/sat/intervals.h" #include "ortools/sat/sat_base.h" diff --git a/ortools/sat/util.h b/ortools/sat/util.h index 04fcea186a2..637d8bbd2cf 100644 --- a/ortools/sat/util.h +++ b/ortools/sat/util.h @@ -14,9 +14,9 @@ #ifndef OR_TOOLS_SAT_UTIL_H_ #define OR_TOOLS_SAT_UTIL_H_ +#include "ortools/base/random.h" #include "ortools/sat/sat_base.h" #include "ortools/sat/sat_parameters.pb.h" -#include "ortools/base/random.h" namespace operations_research { namespace sat { diff --git a/ortools/util/affine_relation.h b/ortools/util/affine_relation.h index 82ae2482b1f..73a5cb4d9ea 100644 --- a/ortools/util/affine_relation.h +++ b/ortools/util/affine_relation.h @@ -16,9 +16,9 @@ #include +#include "ortools/base/iterator_adaptors.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/iterator_adaptors.h" namespace operations_research { diff --git a/ortools/util/bitset.cc b/ortools/util/bitset.cc index 681a31ee0a3..7baf8b3f49f 100644 --- a/ortools/util/bitset.cc +++ b/ortools/util/bitset.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/util/bitset.h" #include "ortools/base/commandlineflags.h" diff --git a/ortools/util/bitset.h b/ortools/util/bitset.h index 5dbc1d1e545..9e9184cdd38 100644 --- a/ortools/util/bitset.h +++ b/ortools/util/bitset.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Various utility functions on bitsets. #ifndef OR_TOOLS_UTIL_BITSET_H_ @@ -85,7 +84,8 @@ inline int LeastSignificantBitPosition64DeBruijn(uint64 n) { 0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 52, 20, 58, 5, 17, 26, 56, 15, 38, 29, 40, 10, 49, 53, 31, 21, 34, 59, 42, 63, 6, 12, 18, 24, 27, 51, 57, 16, 55, 37, 39, 48, 30, 33, 41, - 62, 11, 23, 50, 54, 36, 47, 32, 61, 22, 35, 46, 60, 45, 44, 43, }; + 62, 11, 23, 50, 54, 36, 47, 32, 61, 22, 35, 46, 60, 45, 44, 43, + }; return kTab[((n & (~n + 1)) * kSeq) >> 58]; } @@ -142,10 +142,10 @@ inline int LeastSignificantBitPosition32Fast(uint32 n) { inline int LeastSignificantBitPosition32DeBruijn(uint32 n) { static const uint32 kSeq = 0x077CB531U; // de Bruijn sequence - static const int kTab[32] = { - // initialized by 'kTab[(kSeq << i) >> 27] = i - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, - 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; + static const int kTab[32] = {// initialized by 'kTab[(kSeq << i) >> 27] = i + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, + 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, + 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; return kTab[((n & (~n + 1)) * kSeq) >> 27]; } @@ -448,9 +448,7 @@ class Bitset64 { } // Sets all bits to 0. - void ClearAll() { - memset(data_.data(), 0, data_.size() * sizeof(int64)); - } + void ClearAll() { memset(data_.data(), 0, data_.size() * sizeof(int64)); } // Sets the bit at position i to 0. void Clear(IndexType i) { diff --git a/ortools/util/cached_log.cc b/ortools/util/cached_log.cc index 259aca98ada..88fab8b938c 100644 --- a/ortools/util/cached_log.cc +++ b/ortools/util/cached_log.cc @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/util/cached_log.h" #include "ortools/base/logging.h" @@ -24,7 +23,7 @@ CachedLog::~CachedLog() {} namespace { double FastLog2(int64 input) { - #if defined(_MSC_VER) || defined(__ANDROID__) +#if defined(_MSC_VER) || defined(__ANDROID__) return log(static_cast(input)) / log(2.0L); #else return log2(input); diff --git a/ortools/util/cached_log.h b/ortools/util/cached_log.h index 8da7be4d7fe..6b5b50e2954 100644 --- a/ortools/util/cached_log.h +++ b/ortools/util/cached_log.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_CACHED_LOG_H_ #define OR_TOOLS_UTIL_CACHED_LOG_H_ diff --git a/ortools/util/file_util.cc b/ortools/util/file_util.cc index c1697ec0638..45f536f34e6 100644 --- a/ortools/util/file_util.cc +++ b/ortools/util/file_util.cc @@ -13,18 +13,19 @@ #include "ortools/util/file_util.h" -#include "ortools/base/logging.h" -#include "ortools/base/file.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/descriptor.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" #include "google/protobuf/message.h" #include "google/protobuf/text_format.h" +#include "ortools/base/file.h" +#include "ortools/base/logging.h" namespace operations_research { using ::google::protobuf::TextFormat; -bool ReadFileToProto(absl::string_view filename, google::protobuf::Message* proto) { +bool ReadFileToProto(absl::string_view filename, + google::protobuf::Message* proto) { std::string data; CHECK_OK(file::GetContents(filename, &data, file::Defaults())); // Note that gzipped files are currently not supported. @@ -35,10 +36,11 @@ bool ReadFileToProto(absl::string_view filename, google::protobuf::Message* prot return false; } -bool WriteProtoToFile(absl::string_view filename, const google::protobuf::Message& proto, +bool WriteProtoToFile(absl::string_view filename, + const google::protobuf::Message& proto, ProtoWriteFormat proto_write_format, bool gzipped) { // Note that gzipped files are currently not supported. - gzipped = false; + gzipped = false; std::string file_type_suffix; std::string output_string; diff --git a/ortools/util/file_util.h b/ortools/util/file_util.h index a09874e7b7e..50b32dba6c9 100644 --- a/ortools/util/file_util.h +++ b/ortools/util/file_util.h @@ -17,16 +17,17 @@ #include #include +#include "google/protobuf/message.h" #include "ortools/base/file.h" #include "ortools/base/recordio.h" -#include "google/protobuf/message.h" #include "ortools/base/string_view.h" namespace operations_research { // Reads a proto from a file. Supports the following formats: binary, text, // JSON, all of those optionally gzipped. Returns false on failure. -bool ReadFileToProto(absl::string_view filename, google::protobuf::Message* proto); +bool ReadFileToProto(absl::string_view filename, + google::protobuf::Message* proto); template Proto ReadFileToProtoOrDie(absl::string_view filename) { @@ -42,7 +43,8 @@ enum class ProtoWriteFormat { kProtoText, kProtoBinary, kJson }; // If 'proto_write_format' is kProtoBinary, ".bin" is appended to file_name. If // 'proto_write_format' is kJson, ".json" is appended to file_name. If 'gzipped' // is true, ".gz" is appended to file_name. -bool WriteProtoToFile(absl::string_view filename, const google::protobuf::Message& proto, +bool WriteProtoToFile(absl::string_view filename, + const google::protobuf::Message& proto, ProtoWriteFormat proto_write_format, bool gzipped); namespace internal { @@ -61,7 +63,6 @@ std::vector ReadNumRecords(File* file, int expected_num_records) { ++num_read; } - if (expected_num_records >= 0) { CHECK_EQ(num_read, expected_num_records) << "There were less than the expected " << expected_num_records diff --git a/ortools/util/fp_utils.h b/ortools/util/fp_utils.h index ea93c423039..91c70f33752 100644 --- a/ortools/util/fp_utils.h +++ b/ortools/util/fp_utils.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Utility functions on IEEE floating-point numbers. // Implemented on float, double, and long double. // @@ -24,7 +23,7 @@ #define OR_TOOLS_UTIL_FP_UTILS_H_ #if defined(_MSC_VER) -#pragma fenv_access (on) // NOLINT +#pragma fenv_access(on) // NOLINT #else #include // NOLINT #endif @@ -60,7 +59,7 @@ namespace operations_research { class ScopedFloatingPointEnv { public: - ScopedFloatingPointEnv() { + ScopedFloatingPointEnv() { #if defined(_MSC_VER) // saved_control_ = _controlfp(0, 0); #elif defined(ARCH_K8) diff --git a/ortools/util/functions_swig_test_helpers.h b/ortools/util/functions_swig_test_helpers.h index 8e351c99141..0eaa6c4fdfc 100644 --- a/ortools/util/functions_swig_test_helpers.h +++ b/ortools/util/functions_swig_test_helpers.h @@ -28,7 +28,9 @@ namespace operations_research { class FunctionSwigTestHelpers { public: - static std::string NoOpVoidToString(std::function fun) { return fun(); } + static std::string NoOpVoidToString(std::function fun) { + return fun(); + } static int64 NoOpInt64ToInt64(std::function fun, int64 x) { return fun(x); @@ -67,7 +69,8 @@ class FunctionSwigTestHelpers { static void NoOpVoidToVoid(std::function fun) { fun(); } - static void NoOpStringToVoid(std::function fun, std::string x) { + static void NoOpStringToVoid(std::function fun, + std::string x) { fun(x); } }; diff --git a/ortools/util/graph_export.cc b/ortools/util/graph_export.cc index 9f40e316104..2f9fec86a4a 100644 --- a/ortools/util/graph_export.cc +++ b/ortools/util/graph_export.cc @@ -11,16 +11,15 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/util/graph_export.h" #include +#include "ortools/base/file.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/stringprintf.h" -#include "ortools/base/file.h" #include "ortools/base/status.h" +#include "ortools/base/stringprintf.h" namespace operations_research { @@ -33,10 +32,12 @@ class GraphSyntax { // Node in the right syntax. virtual std::string Node(const std::string& name, const std::string& label, - const std::string& shape, const std::string& color) = 0; + const std::string& shape, + const std::string& color) = 0; // Adds one link in the generated graph. - virtual std::string Link(const std::string& source, const std::string& destination, - const std::string& label) = 0; + virtual std::string Link(const std::string& source, + const std::string& destination, + const std::string& label) = 0; // File header. virtual std::string Header(const std::string& name) = 0; @@ -48,15 +49,16 @@ class DotSyntax : public GraphSyntax { public: ~DotSyntax() override {} - std::string Node(const std::string& name, const std::string& label, const std::string& shape, - const std::string& color) override { + std::string Node(const std::string& name, const std::string& label, + const std::string& shape, + const std::string& color) override { return StringPrintf("%s [shape=%s label=\"%s\" color=%s]\n", name.c_str(), shape.c_str(), label.c_str(), color.c_str()); } // Adds one link in the generated graph. std::string Link(const std::string& source, const std::string& destination, - const std::string& label) override { + const std::string& label) override { return StringPrintf("%s -> %s [label=%s]\n", source.c_str(), destination.c_str(), label.c_str()); } @@ -74,8 +76,9 @@ class GmlSyntax : public GraphSyntax { public: ~GmlSyntax() override {} - std::string Node(const std::string& name, const std::string& label, const std::string& shape, - const std::string& color) override { + std::string Node(const std::string& name, const std::string& label, + const std::string& shape, + const std::string& color) override { return StringPrintf( " node [\n" " name \"%s\"\n" @@ -90,7 +93,7 @@ class GmlSyntax : public GraphSyntax { // Adds one link in the generated graph. std::string Link(const std::string& source, const std::string& destination, - const std::string& label) override { + const std::string& label) override { return StringPrintf( " edge [\n" " label \"%s\"\n" @@ -122,8 +125,8 @@ class FileGraphExporter : public GraphExporter { ~FileGraphExporter() override {} // Write node in GML or DOT format. - void WriteNode(const std::string& name, const std::string& label, const std::string& shape, - const std::string& color) override { + void WriteNode(const std::string& name, const std::string& label, + const std::string& shape, const std::string& color) override { Append(syntax_->Node(name, label, shape, color)); } diff --git a/ortools/util/graph_export.h b/ortools/util/graph_export.h index 17248edf853..3501e27d4ae 100644 --- a/ortools/util/graph_export.h +++ b/ortools/util/graph_export.h @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_GRAPH_EXPORT_H_ #define OR_TOOLS_UTIL_GRAPH_EXPORT_H_ #include +#include "ortools/base/file.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" -#include "ortools/base/file.h" namespace operations_research { // ----- Export to graph file ----- @@ -44,10 +43,12 @@ class GraphExporter { // Write node in GML or DOT format. virtual void WriteNode(const std::string& name, const std::string& label, - const std::string& shape, const std::string& color) = 0; + const std::string& shape, + const std::string& color) = 0; // Adds one link in the generated graph. - virtual void WriteLink(const std::string& source, const std::string& destination, + virtual void WriteLink(const std::string& source, + const std::string& destination, const std::string& label) = 0; // Creates a graph exporter that will write to file with a given format. diff --git a/ortools/util/monoid_operation_tree.h b/ortools/util/monoid_operation_tree.h index c16e28cb798..38052f4f00c 100644 --- a/ortools/util/monoid_operation_tree.h +++ b/ortools/util/monoid_operation_tree.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_MONOID_OPERATION_TREE_H_ #define OR_TOOLS_UTIL_MONOID_OPERATION_TREE_H_ diff --git a/ortools/util/piecewise_linear_function.cc b/ortools/util/piecewise_linear_function.cc index 48c4f441e2c..3323041508c 100644 --- a/ortools/util/piecewise_linear_function.cc +++ b/ortools/util/piecewise_linear_function.cc @@ -20,7 +20,6 @@ #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" namespace operations_research { namespace { diff --git a/ortools/util/proto_tools.cc b/ortools/util/proto_tools.cc index d99f4cb973c..bca97965efb 100644 --- a/ortools/util/proto_tools.cc +++ b/ortools/util/proto_tools.cc @@ -26,8 +26,8 @@ using ::google::protobuf::Reflection; using ::google::protobuf::TextFormat; namespace { -void WriteFullProtocolMessage(const google::protobuf::Message& message, int indent_level, - std::string* out) { +void WriteFullProtocolMessage(const google::protobuf::Message& message, + int indent_level, std::string* out) { std::string temp_string; const std::string indent(indent_level * 2, ' '); const Descriptor* desc = message.GetDescriptor(); @@ -55,8 +55,8 @@ void WriteFullProtocolMessage(const google::protobuf::Message& message, int inde } } // namespace -std::string FullProtocolMessageAsString(const google::protobuf::Message& message, - int indent_level) { +std::string FullProtocolMessageAsString( + const google::protobuf::Message& message, int indent_level) { std::string message_str; WriteFullProtocolMessage(message, indent_level, &message_str); return message_str; diff --git a/ortools/util/proto_tools.h b/ortools/util/proto_tools.h index 49527caf52a..bd2bc837e5e 100644 --- a/ortools/util/proto_tools.h +++ b/ortools/util/proto_tools.h @@ -22,8 +22,8 @@ namespace operations_research { // Prints a proto2 message as a std::string, it behaves like TextFormat::Print() // but also prints the default values of unset fields which is useful for // printing parameters. -std::string FullProtocolMessageAsString(const google::protobuf::Message& message, - int indent_level); +std::string FullProtocolMessageAsString( + const google::protobuf::Message& message, int indent_level); } // namespace operations_research #endif // OR_TOOLS_UTIL_PROTO_TOOLS_H_ diff --git a/ortools/util/range_query_function.cc b/ortools/util/range_query_function.cc index 1c4aec0e8e5..ac33df34cdd 100644 --- a/ortools/util/range_query_function.cc +++ b/ortools/util/range_query_function.cc @@ -88,7 +88,7 @@ class LinearRangeIntToIntFunction : public RangeIntToIntFunction { }; std::vector FunctionToVector(const std::function& f, - int64 domain_start, int64 domain_end) { + int64 domain_start, int64 domain_end) { CHECK_LT(domain_start, domain_end); std::vector output(domain_end - domain_start, 0); for (int64 i = 0; i < domain_end - domain_start; ++i) { diff --git a/ortools/util/rational_approximation.h b/ortools/util/rational_approximation.h index 412fd99c71e..0e1c7b8f443 100644 --- a/ortools/util/rational_approximation.h +++ b/ortools/util/rational_approximation.h @@ -34,4 +34,3 @@ Fraction RationalApproximation(const double x, const double precision); } // namespace operations_research #endif // OR_TOOLS_UTIL_RATIONAL_APPROXIMATION_H_ - diff --git a/ortools/util/sigint.cc b/ortools/util/sigint.cc index ff239100d6b..6ae5b252850 100644 --- a/ortools/util/sigint.cc +++ b/ortools/util/sigint.cc @@ -36,14 +36,10 @@ void SigintHandler::Register(const std::function& f) { // This method will be called by the system after the SIGINT signal. // The parameter is the signal received. -void SigintHandler::ControlCHandler(int sig) { - handler_(); -} +void SigintHandler::ControlCHandler(int sig) { handler_(); } // Unregister the SIGINT handler. -SigintHandler::~SigintHandler() { - signal(SIGINT, SIG_DFL); -} +SigintHandler::~SigintHandler() { signal(SIGINT, SIG_DFL); } std::function SigintHandler::handler_; diff --git a/ortools/util/sorted_interval_list.cc b/ortools/util/sorted_interval_list.cc index 87f8bdae614..4a6933c5dc5 100644 --- a/ortools/util/sorted_interval_list.cc +++ b/ortools/util/sorted_interval_list.cc @@ -17,7 +17,6 @@ #include "ortools/base/logging.h" #include "ortools/base/stringprintf.h" -#include "ortools/base/stringprintf.h" #include "ortools/util/saturated_arithmetic.h" namespace operations_research { diff --git a/ortools/util/sorted_interval_list.h b/ortools/util/sorted_interval_list.h index 4a2833b3850..02021aee97d 100644 --- a/ortools/util/sorted_interval_list.h +++ b/ortools/util/sorted_interval_list.h @@ -39,7 +39,8 @@ struct ClosedInterval { } }; -// Returns a compact std::string of a vector of intervals like "[1,4][6][10,20]". +// Returns a compact std::string of a vector of intervals like +// "[1,4][6][10,20]". std::string IntervalsAsString(const std::vector& intervals); std::ostream& operator<<(std::ostream& out, const ClosedInterval& interval); diff --git a/ortools/util/stats.cc b/ortools/util/stats.cc index 642b9b21fe3..9d12069d06b 100644 --- a/ortools/util/stats.cc +++ b/ortools/util/stats.cc @@ -11,13 +11,11 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/util/stats.h" #include #include "ortools/base/stringprintf.h" - #include "ortools/base/stl_util.h" #include "ortools/port/sysinfo.h" #include "ortools/port/utf8.h" @@ -27,21 +25,18 @@ namespace operations_research { std::string MemoryUsage() { const int64 mem = operations_research::sysinfo::MemoryUsageProcess(); static const int64 kDisplayThreshold = 2; - static const int64 kKiloByte = 1024; - static const int64 kMegaByte = kKiloByte * kKiloByte; - static const int64 kGigaByte = kMegaByte * kKiloByte; - if (mem > kDisplayThreshold * kGigaByte) { - return StringPrintf("%.2lf GB", - mem * 1.0 / kGigaByte); - } else if (mem > kDisplayThreshold * kMegaByte) { - return StringPrintf("%.2lf MB", - mem * 1.0 / kMegaByte); - } else if (mem > kDisplayThreshold * kKiloByte) { - return StringPrintf("%2lf KB", - mem * 1.0 / kKiloByte); - } else { - return StringPrintf("%" GG_LL_FORMAT "d", mem); - } + static const int64 kKiloByte = 1024; + static const int64 kMegaByte = kKiloByte * kKiloByte; + static const int64 kGigaByte = kMegaByte * kKiloByte; + if (mem > kDisplayThreshold * kGigaByte) { + return StringPrintf("%.2lf GB", mem * 1.0 / kGigaByte); + } else if (mem > kDisplayThreshold * kMegaByte) { + return StringPrintf("%.2lf MB", mem * 1.0 / kMegaByte); + } else if (mem > kDisplayThreshold * kKiloByte) { + return StringPrintf("%2lf KB", mem * 1.0 / kKiloByte); + } else { + return StringPrintf("%" GG_LL_FORMAT "d", mem); + } } Stat::Stat(const std::string& name, StatsGroup* group) : name_(name) { diff --git a/ortools/util/stats.h b/ortools/util/stats.h index a46c0954019..dd490e24233 100644 --- a/ortools/util/stats.h +++ b/ortools/util/stats.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Helper classes to track statistics of a program component. // // Usage example: @@ -80,7 +79,8 @@ namespace operations_research { -// Returns the current thread's total memory usage in an human-readable std::string. +// Returns the current thread's total memory usage in an human-readable +// std::string. std::string MemoryUsage(); // Forward declaration. @@ -137,8 +137,8 @@ class StatsGroup { : name_(name), stats_(), time_distributions_() {} ~StatsGroup(); - // Registers a Stat, which will appear in the std::string returned by StatString(). - // The Stat object must live as long as this StatsGroup. + // Registers a Stat, which will appear in the std::string returned by + // StatString(). The Stat object must live as long as this StatsGroup. void Register(Stat* stat); // Returns this group name, followed by one line per Stat registered with this @@ -258,7 +258,8 @@ class TimeDistribution : public DistributionStat { // Statistic on the distribution of a sequence of ratios, displayed as %. class RatioDistribution : public DistributionStat { public: - explicit RatioDistribution(const std::string& name) : DistributionStat(name) {} + explicit RatioDistribution(const std::string& name) + : DistributionStat(name) {} RatioDistribution(const std::string& name, StatsGroup* group) : DistributionStat(name, group) {} std::string ValueAsString() const override; @@ -268,7 +269,8 @@ class RatioDistribution : public DistributionStat { // Statistic on the distribution of a sequence of doubles. class DoubleDistribution : public DistributionStat { public: - explicit DoubleDistribution(const std::string& name) : DistributionStat(name) {} + explicit DoubleDistribution(const std::string& name) + : DistributionStat(name) {} DoubleDistribution(const std::string& name, StatsGroup* group) : DistributionStat(name, group) {} std::string ValueAsString() const override; @@ -278,7 +280,8 @@ class DoubleDistribution : public DistributionStat { // Statistic on the distribution of a sequence of integers. class IntegerDistribution : public DistributionStat { public: - explicit IntegerDistribution(const std::string& name) : DistributionStat(name) {} + explicit IntegerDistribution(const std::string& name) + : DistributionStat(name) {} IntegerDistribution(const std::string& name, StatsGroup* group) : DistributionStat(name, group) {} std::string ValueAsString() const override; @@ -403,7 +406,8 @@ using ScopedInstructionCounter = DisabledScopedInstructionCounter; #ifdef HAS_PERF_SUBSYSTEM -inline std::string RemoveOperationsResearchAndGlop(const std::string& pretty_function) { +inline std::string RemoveOperationsResearchAndGlop( + const std::string& pretty_function) { return strings::GlobalReplaceSubstrings( pretty_function, {{"operations_research::", ""}, {"glop::", ""}}); } diff --git a/ortools/util/string_array.h b/ortools/util/string_array.h index 1d6e086c205..a38746a5dd0 100644 --- a/ortools/util/string_array.h +++ b/ortools/util/string_array.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_STRING_ARRAY_H_ #define OR_TOOLS_UTIL_STRING_ARRAY_H_ @@ -23,7 +22,7 @@ namespace operations_research { // See the straightforward (and unique) usage of this macro below. #define RETURN_STRINGIFIED_VECTOR(vector, separator, method) \ - std::string out; \ + std::string out; \ for (int i = 0; i < vector.size(); ++i) { \ if (i > 0) out += separator; \ out += vector[i] method; \ @@ -36,13 +35,15 @@ namespace operations_research { // Join v[i].DebugString(). template -std::string JoinDebugString(const std::vector& v, const std::string& separator) { +std::string JoinDebugString(const std::vector& v, + const std::string& separator) { RETURN_STRINGIFIED_VECTOR(v, separator, .DebugString()); } // Join v[i]->DebugString(). template -std::string JoinDebugStringPtr(const std::vector& v, const std::string& separator) { +std::string JoinDebugStringPtr(const std::vector& v, + const std::string& separator) { RETURN_STRINGIFIED_VECTOR(v, separator, ->DebugString()); } @@ -54,7 +55,8 @@ std::string JoinNamePtr(const std::vector& v, const std::string& separator) { // Join v[i]->name. template -std::string JoinNameFieldPtr(const std::vector& v, const std::string& separator) { +std::string JoinNameFieldPtr(const std::vector& v, + const std::string& separator) { RETURN_STRINGIFIED_VECTOR(v, separator, ->name); } diff --git a/ortools/util/time_limit.h b/ortools/util/time_limit.h index 1dcc43a473e..19aa7eaadd5 100644 --- a/ortools/util/time_limit.h +++ b/ortools/util/time_limit.h @@ -27,8 +27,8 @@ #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/port.h" -#include "ortools/base/timer.h" #include "ortools/base/time_support.h" +#include "ortools/base/timer.h" #include "ortools/util/running_stat.h" #ifdef HAS_PERF_SUBSYSTEM #include "exegesis/exegesis/itineraries/perf_subsystem.h" @@ -69,13 +69,14 @@ namespace operations_research { // small, without aborting too early. // // The deterministic time limit can be logged at a more granular level: the -// method TimeLimit::AdvanceDeterministicTime takes an optional std::string argument: -// the name of a counter. In debug mode, the time limit object computes also the -// elapsed time for each named counter separately, and these values can be used -// to determine the coefficients for computing the deterministic duration from -// the number of operations. The values of the counters can be printed using -// TimeLimit::DebugString(). There is no API to access the values of the -// counters directly, because they do not exist in optimized mode. +// method TimeLimit::AdvanceDeterministicTime takes an optional std::string +// argument: the name of a counter. In debug mode, the time limit object +// computes also the elapsed time for each named counter separately, and these +// values can be used to determine the coefficients for computing the +// deterministic duration from the number of operations. The values of the +// counters can be printed using TimeLimit::DebugString(). There is no API to +// access the values of the counters directly, because they do not exist in +// optimized mode. // // The basic steps for determining coefficients for the deterministic time are: // 1. Run the code in debug mode to collect the values of the deterministic time @@ -352,7 +353,6 @@ class NestedTimeLimit { DISALLOW_COPY_AND_ASSIGN(NestedTimeLimit); }; - // ################## Implementations below ##################### inline TimeLimit::TimeLimit(double limit_in_seconds, double deterministic_limit, diff --git a/ortools/util/tuple_set.h b/ortools/util/tuple_set.h index 6476668bb6a..da543454e04 100644 --- a/ortools/util/tuple_set.h +++ b/ortools/util/tuple_set.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Set of integer tuples (fixed-size arrays, all of the same size) with // a basic API. // It supports several types of integer arrays transparently, with an @@ -39,11 +38,11 @@ #include #include +#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" #include "ortools/base/map_util.h" -#include "ortools/base/hash.h" namespace operations_research { // ----- Main IntTupleSet class ----- diff --git a/ortools/util/vector_map.h b/ortools/util/vector_map.h index 34a2a07e1b1..9dfb8878bb7 100644 --- a/ortools/util/vector_map.h +++ b/ortools/util/vector_map.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - // Vector with map from element to index in the vector. #ifndef OR_TOOLS_UTIL_VECTOR_MAP_H_ diff --git a/ortools/util/xml_helper.cc b/ortools/util/xml_helper.cc index 51979cf2e25..535d814e60a 100644 --- a/ortools/util/xml_helper.cc +++ b/ortools/util/xml_helper.cc @@ -11,15 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. - #include "ortools/util/xml_helper.h" #include #include +#include "ortools/base/join.h" #include "ortools/base/stringprintf.h" #include "ortools/base/strutil.h" -#include "ortools/base/join.h" namespace operations_research { @@ -46,7 +45,8 @@ void XmlHelper::AddAttribute(const std::string& key, int value) { void XmlHelper::AddAttribute(const std::string& key, const std::string& value) { std::ostringstream escaped_value; - for (std::string::const_iterator it = value.begin(); it != value.end(); ++it) { + for (std::string::const_iterator it = value.begin(); it != value.end(); + ++it) { unsigned char c = (unsigned char)*it; switch (c) { diff --git a/ortools/util/xml_helper.h b/ortools/util/xml_helper.h index 38219f34b0b..dd2c9e3a9d8 100644 --- a/ortools/util/xml_helper.h +++ b/ortools/util/xml_helper.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_XML_HELPER_H_ #define OR_TOOLS_UTIL_XML_HELPER_H_ diff --git a/ortools/util/zvector.h b/ortools/util/zvector.h index 364ac8a12fb..0195c534820 100644 --- a/ortools/util/zvector.h +++ b/ortools/util/zvector.h @@ -11,7 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. - #ifndef OR_TOOLS_UTIL_ZVECTOR_H_ #define OR_TOOLS_UTIL_ZVECTOR_H_