minor reindent; fix binpacking_2d_sat corner case

This commit is contained in:
Laurent Perron
2024-03-14 15:04:39 +01:00
parent 20bc70d8e0
commit 61914c7c0b
7 changed files with 37 additions and 19 deletions

View File

@@ -26,6 +26,7 @@
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -171,7 +172,7 @@ absl::btree_set<int> FindFixedItems(
}
// Solves a subset sum problem to find the maximum reachable max size.
int64_t MaxSubsetSumSize(const std::vector<int64_t>& sizes, int64_t max_size) {
int64_t MaxSubsetSumSize(absl::Span<const int64_t> sizes, int64_t max_size) {
CpModelBuilder builder;
LinearExpr weighed_sum;
for (const int size : sizes) {
@@ -280,7 +281,7 @@ void LoadAndSolve(const std::string& file_name, int instance) {
const absl::btree_set<int> fixed_items = FindFixedItems(problem);
// Fix the fixed_items to the first fixed_items.size() bins.
CHECK_LT(fixed_items.size(), max_bins)
CHECK_LE(fixed_items.size(), max_bins)
<< "Infeasible problem, increase max_bins";
int count = 0;
for (const int item : fixed_items) {
@@ -437,9 +438,10 @@ void LoadAndSolve(const std::string& file_name, int instance) {
// Objective definition.
cp_model.Minimize(obj);
for (int b = trivial_lb; b + 1 < max_bins; ++b) {
CHECK_GT(trivial_lb, 0);
for (int b = trivial_lb; b < max_bins; ++b) {
cp_model.AddGreaterOrEqual(obj, b + 1).OnlyEnforceIf(bin_is_used[b]);
cp_model.AddImplication(bin_is_used[b + 1], bin_is_used[b]);
cp_model.AddImplication(bin_is_used[b], bin_is_used[b - 1]);
}
if (absl::GetFlag(FLAGS_symmetry_breaking)) {

View File

@@ -43,8 +43,7 @@ void RunConstraintProgrammingExample() {
solver.NewSearch(db);
while (solver.NextSolution()) {
LOG(INFO) << "Solution"
<< ": x = " << x->Value() << "; y = " << y->Value()
LOG(INFO) << "Solution" << ": x = " << x->Value() << "; y = " << y->Value()
<< "; z = " << z->Value();
}
solver.EndSearch();

View File

@@ -81,7 +81,7 @@ void CheckConstraintViolators(absl::Span<const int64_t> vars,
}
// Check that all pairwise differences are unique
bool CheckCostas(const std::vector<int64_t>& vars) {
bool CheckCostas(absl::Span<const int64_t> vars) {
std::vector<int> violators;
CheckConstraintViolators(vars, &violators);

View File

@@ -322,7 +322,7 @@ std::vector<std::vector<MachineTaskData>> GetDataPerMachine(
void CreateMachines(
const JsspInputProblem& problem,
const std::vector<std::vector<std::vector<AlternativeTaskData>>>&
absl::Span<const std::vector<std::vector<AlternativeTaskData>>>
job_task_to_alternatives,
IntervalVar makespan_interval, CpModelBuilder& cp_model) {
const int num_jobs = problem.jobs_size();
@@ -733,12 +733,6 @@ void Solve(const JsspInputProblem& problem) {
// Setup parameters.
SatParameters parameters;
parameters.set_log_search_progress(true);
// Parse the --params flag.
if (!absl::GetFlag(FLAGS_params).empty()) {
CHECK(google::protobuf::TextFormat::MergeFromString(
absl::GetFlag(FLAGS_params), &parameters))
<< absl::GetFlag(FLAGS_params);
}
// Prefer objective_shaving_search over objective_lb_search.
if (parameters.num_workers() >= 16 && parameters.num_workers() < 24) {
@@ -751,6 +745,13 @@ void Solve(const JsspInputProblem& problem) {
parameters.set_push_all_tasks_toward_start(true);
parameters.set_use_dynamic_precedence_in_disjunctive(true);
// Parse the --params flag.
if (!absl::GetFlag(FLAGS_params).empty()) {
CHECK(google::protobuf::TextFormat::MergeFromString(
absl::GetFlag(FLAGS_params), &parameters))
<< absl::GetFlag(FLAGS_params);
}
const CpSolverResponse response =
SolveWithParameters(cp_model.Build(), parameters);

View File

@@ -66,7 +66,7 @@ void PrintSolution(absl::Span<const std::vector<int>> data,
std::cout << last_line << std::endl;
}
void SlitherLink(const std::vector<std::vector<int>>& data) {
void SlitherLink(absl::Span<const std::vector<int>> data) {
const int num_rows = data.size();
const int num_columns = data[0].size();

View File

@@ -18,14 +18,20 @@
#include <vector>
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/types/span.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/sat/cp_model.h"
#include "ortools/sat/cp_model.pb.h"
#include "ortools/sat/cp_model_solver.h"
#include "ortools/sat/model.h"
#include "ortools/sat/sat_parameters.pb.h"
#include "ortools/util/filelineiter.h"
#include "ortools/util/sorted_interval_list.h"
ABSL_FLAG(std::string, input, "examples/cpp/wt40.txt", "wt data file name.");
ABSL_FLAG(int, size, 40, "Size of the problem in the wt file.");