Add vector reserve to examples/cpp
This commit is contained in:
committed by
Corentin Le Molgat
parent
c8d7710fd7
commit
30a7baee6d
@@ -98,6 +98,7 @@ void CostasHard(const int dim) {
|
||||
// create the variables
|
||||
std::vector<IntVar> vars;
|
||||
Domain domain(1, dim);
|
||||
vars.reserve(dim);
|
||||
for (int i = 0; i < dim; ++i) {
|
||||
vars.push_back(
|
||||
cp_model.NewIntVar(domain).WithName(absl::StrCat("var_", i)));
|
||||
|
||||
@@ -567,6 +567,7 @@ void HardFapSolver(const absl::btree_map<int, FapVariable>& data_variables,
|
||||
static_cast<int>(variables.size()), &cardinality);
|
||||
solver.AddConstraint(solver.MakeDistribute(variables, values, cardinality));
|
||||
std::vector<IntVar*> value_not_assigned;
|
||||
value_not_assigned.reserve(values.size());
|
||||
for (int val = 0; val < values.size(); ++val) {
|
||||
value_not_assigned.push_back(
|
||||
solver.MakeIsEqualCstVar(cardinality[val], 0));
|
||||
|
||||
@@ -279,6 +279,7 @@ void CreateAlternativeTasks(
|
||||
|
||||
// Exactly one alternative interval is present.
|
||||
std::vector<BoolVar> interval_presences;
|
||||
interval_presences.reserve(alternatives.size());
|
||||
for (const AlternativeTaskData& alternative : alternatives) {
|
||||
interval_presences.push_back(alternative.presence);
|
||||
}
|
||||
|
||||
@@ -377,9 +377,11 @@ class NetworkRoutingSolver {
|
||||
CpModelBuilder cp_model;
|
||||
std::vector<IntVar> arc_vars;
|
||||
std::vector<IntVar> node_vars;
|
||||
node_vars.reserve(max_length);
|
||||
for (int i = 0; i < max_length; ++i) {
|
||||
node_vars.push_back(cp_model.NewIntVar(Domain(0, num_nodes() - 1)));
|
||||
}
|
||||
arc_vars.reserve(max_length - 1);
|
||||
for (int i = 0; i < max_length - 1; ++i) {
|
||||
arc_vars.push_back(cp_model.NewIntVar(Domain(-1, count_arcs() - 1)));
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ void SolveQap() {
|
||||
// Occupy each location exactly once.
|
||||
for (int l = 0; l < n; ++l) {
|
||||
std::vector<BoolVar> tmp;
|
||||
tmp.reserve(n);
|
||||
for (int f = 0; f < n; ++f) {
|
||||
tmp.push_back(place_vars[f][l]);
|
||||
}
|
||||
|
||||
@@ -95,10 +95,12 @@ void SlitherLink(absl::Span<const std::vector<int>> data) {
|
||||
CpModelBuilder builder;
|
||||
|
||||
std::vector<BoolVar> horizontal_arcs;
|
||||
horizontal_arcs.reserve(2 * num_horizontal_arcs);
|
||||
for (int arc = 0; arc < 2 * num_horizontal_arcs; ++arc) {
|
||||
horizontal_arcs.push_back(builder.NewBoolVar());
|
||||
}
|
||||
std::vector<BoolVar> vertical_arcs;
|
||||
vertical_arcs.reserve(2 * num_vertical_arcs);
|
||||
for (int arc = 0; arc < 2 * num_vertical_arcs; ++arc) {
|
||||
vertical_arcs.push_back(builder.NewBoolVar());
|
||||
}
|
||||
|
||||
@@ -246,6 +246,7 @@ void FixtureModel(int num_teams) {
|
||||
for (int other = 0; other < num_teams; ++other) {
|
||||
if (team == other) continue;
|
||||
std::vector<BoolVar> possible_days;
|
||||
possible_days.reserve(num_days);
|
||||
for (int d = 0; d < num_days; ++d) {
|
||||
possible_days.push_back(fixtures[d][team][other]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user