fix example

This commit is contained in:
Laurent Perron
2021-11-19 10:33:29 +01:00
parent 7826f2a8a0
commit 65951e1b13
2 changed files with 16 additions and 4 deletions

View File

@@ -525,10 +525,18 @@ void CreateObjective(
}
// Add the objective to the model.
cp_model.Minimize(LinearExpr::ScalProd(objective_vars, objective_coeffs)
.AddConstant(objective_offset));
if (problem.has_scaling_factor()) {
cp_model.ScaleObjectiveBy(problem.scaling_factor().value());
std::vector<double> double_objective_coeffs;
for (const int64_t coeff : objective_coeffs) {
double_objective_coeffs.push_back(1.0 * coeff /
problem.scaling_factor().value());
}
cp_model.Minimize(
DoubleLinearExpr::ScalProd(objective_vars, double_objective_coeffs)
.AddConstant(objective_offset));
} else {
cp_model.Minimize(LinearExpr::ScalProd(objective_vars, objective_coeffs)
.AddConstant(objective_offset));
}
}

View File

@@ -36,6 +36,8 @@ ABSL_FLAG(std::string, solver, "sat", "Solver to use: sat, scip");
ABSL_FLAG(double, time_limit, 900.0, "Time limit in seconds");
ABSL_FLAG(int, threads, 1, "Number of threads");
ABSL_FLAG(bool, display_proto, false, "Print the input protobuf");
ABSL_FLAG(int, max_bins, -1,
"Maximum number of bins: default = -1 meaning no limits");
namespace operations_research {
void ParseAndSolve(const std::string& filename, const std::string& solver,
@@ -64,6 +66,7 @@ void ParseAndSolve(const std::string& filename, const std::string& solver,
<< "Ignoring max_bins value. The feasibility problem is not supported.";
}
LOG(INFO) << "Solving vector packing problem '" << data.name() << "' with "
<< data.item_size() << " item types, and "
<< data.resource_capacity_size() << " dimensions.";
@@ -77,7 +80,8 @@ void ParseAndSolve(const std::string& filename, const std::string& solver,
packing::vbp::VectorBinPackingSolution solution =
packing::SolveVectorBinPackingWithArcFlow(data, solver_type, params,
absl::GetFlag(FLAGS_time_limit),
absl::GetFlag(FLAGS_threads));
absl::GetFlag(FLAGS_threads),
absl::GetFlag(FLAGS_max_bins));
if (!solution.bins().empty()) {
for (int b = 0; b < solution.bins_size(); ++b) {
LOG(INFO) << "Bin " << b;