Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Jun 8, 2018
1 parent 1ec337d commit 70e73d8
Show file tree
Hide file tree
Showing 331 changed files with 7,470 additions and 7,822 deletions.
99 changes: 40 additions & 59 deletions examples/cpp/acp_challenge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,9 +129,7 @@ class AcpData {
}
break;
}
default: {
LOG(ERROR) << "Should not be here";
}
default: { LOG(ERROR) << "Should not be here"; }
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -241,9 +239,7 @@ class RandomIntervalLns : public BaseLns {
class Swap : public IntVarLocalSearchOperator {
public:
explicit Swap(const std::vector<IntVar*>& variables)
: IntVarLocalSearchOperator(variables),
index1_(0),
index2_(0) {}
: IntVarLocalSearchOperator(variables), index1_(0), index2_(0) {}

virtual ~Swap() {}

Expand Down Expand Up @@ -277,9 +273,7 @@ class Swap : public IntVarLocalSearchOperator {
class Reverse : public IntVarLocalSearchOperator {
public:
explicit Reverse(const std::vector<IntVar*>& variables)
: IntVarLocalSearchOperator(variables),
start_(-1),
len_(3) {}
: IntVarLocalSearchOperator(variables), start_(-1), len_(3) {}

virtual ~Reverse() {}

Expand All @@ -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;
}
Expand All @@ -313,10 +307,8 @@ class Reverse : public IntVarLocalSearchOperator {

class NRandomSwaps : public IntVarLocalSearchOperator {
public:
explicit NRandomSwaps(const std::vector<IntVar*>& variables,
int num_swaps,
int num_rounds,
int ls_seed)
explicit NRandomSwaps(const std::vector<IntVar*>& variables, int num_swaps,
int num_rounds, int ls_seed)
: IntVarLocalSearchOperator(variables),
num_swaps_(num_swaps),
num_rounds_(num_rounds),
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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_) {
Expand Down Expand 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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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<IntVar*> 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<IntVar*> deliveries;
std::vector<int> due_dates;
LOG(INFO) << " - build inventory costs";
Expand Down Expand Up @@ -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);

Expand All @@ -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<LocalSearchOperator*> operators;
operators.push_back(swap);
operators.push_back(reverse);
Expand All @@ -857,18 +839,17 @@ void Solve(const std::string& filename, const std::string& solution_file) {

std::vector<LocalSearchFilter*> 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<int> offsets(data.num_products() + 1, 0);
for (int i = 0; i < data.num_products(); ++i) {
Expand All @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions examples/cpp/acp_challenge_routing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -98,9 +98,7 @@ class AcpData {
}
break;
}
default: {
LOG(ERROR) << "Should not be here";
}
default: { LOG(ERROR) << "Should not be here"; }
}
}

Expand Down Expand Up @@ -170,7 +168,7 @@ int Evaluate(const AcpData& data, const std::vector<int>& 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) {
Expand All @@ -184,7 +182,6 @@ int64 OneDistance(RoutingModel::NodeIndex from, RoutingModel::NodeIndex to) {
return 1;
}


class ProductMatrix {
public:
ProductMatrix(const AcpData& data, const std::vector<int>& item_to_product)
Expand All @@ -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;
Expand Down
21 changes: 10 additions & 11 deletions examples/cpp/code_samples_sat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ void BinpackingProblem() {
const int kSlackCapacity = 20;
const int kNumBins = 10;

const std::vector<std::vector<int>> items =
{ {20, 12}, {15, 12}, {30, 8}, {45, 5} };
const std::vector<std::vector<int>> items = {
{20, 12}, {15, 12}, {30, 8}, {45, 5}};
const int num_items = items.size();

// Model.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions examples/cpp/costas_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
#include <utility>
#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.");
Expand Down Expand Up @@ -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++]);
Expand All @@ -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++]);
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions examples/cpp/cryptarithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Loading

0 comments on commit 70e73d8

Please sign in to comment.