Skip to content

Commit 7e98e7b

Browse files
committed
[CP-SAT] improve no_overlap_2d cuts; more no_overlap_2d cuts; bugfixes; add sat/c_api subdirectory
1 parent 9f4bf2a commit 7e98e7b

31 files changed

+931
-304
lines changed

ortools/base/macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <cstdlib> // for size_t.
1818

19-
#include "ortools/base/base_export.h" // for OR_DLL
19+
#include "ortools/base/base_export.h" // for OR_DLL
2020

2121
#define COMPILE_ASSERT(x, msg)
2222

ortools/graph/shortest_paths.h

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ class GenericPathContainer {
116116
using NodeIndex = typename GraphType::NodeIndex;
117117
using Impl = internal::PathContainerImpl<NodeIndex, GraphType::kNilNode>;
118118

119-
// TODO(b/385094969): Remove this when all clients are migrated, and use
120-
// factory functions instead.
121-
GenericPathContainer();
122-
123119
// This type is neither copyable nor movable.
124120
GenericPathContainer(const GenericPathContainer&) = delete;
125121
GenericPathContainer& operator=(const GenericPathContainer&) = delete;
@@ -153,9 +149,6 @@ class GenericPathContainer {
153149
// Builds a path container which only stores distances between path nodes.
154150
static GenericPathContainer BuildPathDistanceContainer();
155151

156-
ABSL_DEPRECATED("Use factory function BuildPathDistanceContainer instead.")
157-
static void BuildPathDistanceContainer(GenericPathContainer* path_container);
158-
159152
// Builds a path container which stores explicit paths and distances between
160153
// path nodes in a memory-compact representation.
161154
// In this case `GetPenultimateNodeInPath()` is `O(log(path_tree_size))`,
@@ -168,11 +161,6 @@ class GenericPathContainer {
168161
// `O(log(path_tree_size) * path_size)`.
169162
static GenericPathContainer BuildInMemoryCompactPathContainer();
170163

171-
ABSL_DEPRECATED(
172-
"Use factory function BuildInMemoryCompactPathContainer instead.")
173-
static void BuildInMemoryCompactPathContainer(
174-
GenericPathContainer* path_container);
175-
176164
// TODO(user): Add save-to-disk container.
177165
// TODO(user): Add `BuildInMemoryFastPathContainer()`, which does
178166
// `GetPenultimateNodeInPath()` in `O(1)`.
@@ -230,12 +218,12 @@ void ComputeOneToAllShortestPaths(
230218
// Computes shortest paths from the node `source` to nodes in `destinations`.
231219
// TODO(b/385094969): Remove second template parameter when all clients are
232220
// migrated.
233-
template <class GraphType, class PathContainerGraphType>
221+
template <class GraphType>
234222
void ComputeOneToManyShortestPaths(
235223
const GraphType& graph, const std::vector<PathDistance>& arc_lengths,
236224
typename GraphType::NodeIndex source,
237225
const std::vector<typename GraphType::NodeIndex>& destinations,
238-
GenericPathContainer<PathContainerGraphType>* const path_container) {
226+
GenericPathContainer<GraphType>* const path_container) {
239227
std::vector<typename GraphType::NodeIndex> sources(1, source);
240228
ComputeManyToManyShortestPathsWithMultipleThreads(
241229
graph, arc_lengths, sources, destinations, 1, path_container);
@@ -282,13 +270,10 @@ void ComputeManyToAllShortestPathsWithMultipleThreads(
282270
}
283271

284272
// Computes shortest paths between all nodes of the graph.
285-
// TODO(b/385094969): Remove second template parameter when all clients are
286-
// migrated.
287-
template <class GraphType, class PathContainerGraphType>
273+
template <class GraphType>
288274
void ComputeAllToAllShortestPathsWithMultipleThreads(
289275
const GraphType& graph, const std::vector<PathDistance>& arc_lengths,
290-
int num_threads,
291-
GenericPathContainer<PathContainerGraphType>* const path_container) {
276+
int num_threads, GenericPathContainer<GraphType>* const path_container) {
292277
std::vector<typename GraphType::NodeIndex> all_nodes;
293278
GetGraphNodesFromGraph<GraphType>(graph, &all_nodes);
294279
ComputeManyToManyShortestPathsWithMultipleThreads(
@@ -635,15 +620,13 @@ bool InsertOrUpdateEntry(
635620
// using a binary heap-based Dijkstra algorithm.
636621
// TODO(user): Investigate alternate implementation which wouldn't use
637622
// AdjustablePriorityQueue.
638-
// TODO(b/385094969): Remove second template parameter when all clients are
639-
// migrated.
640-
template <class GraphType, class PathContainerGraphType>
623+
template <class GraphType>
641624
void ComputeOneToManyOnGraph(
642625
const GraphType* const graph,
643626
const std::vector<PathDistance>* const arc_lengths,
644627
typename GraphType::NodeIndex source,
645628
const std::vector<typename GraphType::NodeIndex>* const destinations,
646-
typename GenericPathContainer<PathContainerGraphType>::Impl* const paths) {
629+
typename GenericPathContainer<GraphType>::Impl* const paths) {
647630
using NodeIndex = typename GraphType::NodeIndex;
648631
using ArcIndex = typename GraphType::ArcIndex;
649632
using NodeEntryT = NodeEntry<NodeIndex, GraphType::kNilNode>;
@@ -715,9 +698,6 @@ void ComputeOneToManyOnGraph(
715698

716699
} // namespace internal
717700

718-
template <class GraphType>
719-
GenericPathContainer<GraphType>::GenericPathContainer() = default;
720-
721701
template <class GraphType>
722702
GenericPathContainer<GraphType>::~GenericPathContainer() = default;
723703

@@ -744,22 +724,6 @@ void GenericPathContainer<GraphType>::GetPath(
744724
container_->GetPath(from, to, path);
745725
}
746726

747-
template <class GraphType>
748-
void GenericPathContainer<GraphType>::BuildPathDistanceContainer(
749-
GenericPathContainer* const path_container) {
750-
CHECK(path_container != nullptr);
751-
path_container->container_ = std::make_unique<
752-
internal::DistanceContainer<NodeIndex, GraphType::kNilNode>>();
753-
}
754-
755-
template <class GraphType>
756-
void GenericPathContainer<GraphType>::BuildInMemoryCompactPathContainer(
757-
GenericPathContainer* const path_container) {
758-
CHECK(path_container != nullptr);
759-
path_container->container_ = std::make_unique<
760-
internal::InMemoryCompactPathContainer<NodeIndex, GraphType::kNilNode>>();
761-
}
762-
763727
template <class GraphType>
764728
GenericPathContainer<GraphType>
765729
GenericPathContainer<GraphType>::BuildPathDistanceContainer() {
@@ -776,22 +740,12 @@ GenericPathContainer<GraphType>::BuildInMemoryCompactPathContainer() {
776740
NodeIndex, GraphType::kNilNode>>());
777741
}
778742

779-
// TODO(b/385094969): Remove second template parameter when all clients are
780-
// migrated.
781-
template <class GraphType, class PathContainerGraphType>
743+
template <class GraphType>
782744
void ComputeManyToManyShortestPathsWithMultipleThreads(
783745
const GraphType& graph, const std::vector<PathDistance>& arc_lengths,
784746
const std::vector<typename GraphType::NodeIndex>& sources,
785747
const std::vector<typename GraphType::NodeIndex>& destinations,
786-
int num_threads,
787-
GenericPathContainer<PathContainerGraphType>* const paths) {
788-
static_assert(std::is_same_v<typename GraphType::NodeIndex,
789-
typename PathContainerGraphType::NodeIndex>,
790-
"use an explicit `GenericPathContainer<T>` instead of using "
791-
"`PathContainer`");
792-
static_assert(GraphType::kNilNode == PathContainerGraphType::kNilNode,
793-
"use an explicit `GenericPathContainer<T>` instead of using "
794-
"`PathContainer`");
748+
int num_threads, GenericPathContainer<GraphType>* const paths) {
795749
if (graph.num_nodes() > 0) {
796750
CHECK_EQ(graph.num_arcs(), arc_lengths.size())
797751
<< "Number of arcs in graph must match arc length vector size";
@@ -812,10 +766,8 @@ void ComputeManyToManyShortestPathsWithMultipleThreads(
812766
pool->StartWorkers();
813767
for (int i = 0; i < unique_sources.size(); ++i) {
814768
pool->Schedule(absl::bind_front(
815-
&internal::ComputeOneToManyOnGraph<GraphType,
816-
PathContainerGraphType>,
817-
&graph, &arc_lengths, unique_sources[i], &unique_destinations,
818-
container));
769+
&internal::ComputeOneToManyOnGraph<GraphType>, &graph, &arc_lengths,
770+
unique_sources[i], &unique_destinations, container));
819771
}
820772
}
821773
container->Finalize();

ortools/init/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ package(default_visibility = ["//visibility:public"])
1515

1616
cc_library(
1717
name = "init",
18-
hdrs = ["init.h"],
1918
srcs = ["init.cc"],
19+
hdrs = ["init.h"],
2020
deps = [
2121
"//ortools/base",
2222
"//ortools/gurobi:environment",

ortools/init/init.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,24 @@
2222
#include "ortools/sat/cp_model_solver_helpers.h"
2323

2424
namespace operations_research {
25-
void CppBridge::InitLogging(const std::string& usage) {
26-
absl::SetProgramUsageMessage(usage);
27-
absl::InitializeLog();
28-
}
25+
void CppBridge::InitLogging(const std::string& usage) {
26+
absl::SetProgramUsageMessage(usage);
27+
absl::InitializeLog();
28+
}
2929

30-
void CppBridge::SetFlags(const CppFlags& flags) {
31-
absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
32-
absl::EnableLogPrefix(flags.log_prefix);
33-
if (!flags.cp_model_dump_prefix.empty()) {
34-
absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
35-
}
36-
absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
37-
absl::SetFlag(&FLAGS_cp_model_dump_submodels,
38-
flags.cp_model_dump_submodels);
39-
absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
30+
void CppBridge::SetFlags(const CppFlags& flags) {
31+
absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
32+
absl::EnableLogPrefix(flags.log_prefix);
33+
if (!flags.cp_model_dump_prefix.empty()) {
34+
absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);
4035
}
36+
absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models);
37+
absl::SetFlag(&FLAGS_cp_model_dump_submodels, flags.cp_model_dump_submodels);
38+
absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response);
39+
}
4140

42-
bool CppBridge::LoadGurobiSharedLibrary(const std::string& full_library_path) {
43-
return LoadGurobiDynamicLibrary({full_library_path}).ok();
44-
}
41+
bool CppBridge::LoadGurobiSharedLibrary(const std::string& full_library_path) {
42+
return LoadGurobiDynamicLibrary({full_library_path}).ok();
43+
}
4544

4645
} // namespace operations_research

ortools/linear_solver/model_exporter.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class MPModelProtoExporter {
140140
// into two constraints, one for the left hand side (_lhs) and one for right
141141
// hand side (_rhs).
142142
bool AppendConstraint(const MPConstraintProto& ct_proto,
143-
const std::string& name, LineBreaker& line_breaker,
143+
absl::string_view name, LineBreaker& line_breaker,
144144
std::vector<bool>& show_variable, std::string* output);
145145

146146
// Clears "output" and writes a term to it, in "LP" format. Returns false on
@@ -159,8 +159,8 @@ class MPModelProtoExporter {
159159

160160
// Same as AppendMpsLineHeader. Appends an extra new-line at the end the
161161
// string pointed to by output.
162-
void AppendMpsLineHeaderWithNewLine(const std::string& id,
163-
const std::string& name,
162+
void AppendMpsLineHeaderWithNewLine(absl::string_view id,
163+
absl::string_view name,
164164
std::string* output) const;
165165

166166
// Appends an MPS term in various contexts. The term consists of a head name,
@@ -186,7 +186,7 @@ class MPModelProtoExporter {
186186
// Appends a line describing the bound of a variablenew-line if two columns
187187
// are already present on the MPS line.
188188
// Used by and in complement to AppendMpsTermWithContext.
189-
void AppendMpsBound(const std::string& bound_type, const std::string& name,
189+
void AppendMpsBound(absl::string_view bound_type, absl::string_view name,
190190
double value, std::string* output) const;
191191

192192
const MPModelProto& proto_;
@@ -392,7 +392,7 @@ std::string DoubleToString(double d) { return absl::StrCat((d)); }
392392
} // namespace
393393

394394
bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto,
395-
const std::string& name,
395+
absl::string_view name,
396396
LineBreaker& line_breaker,
397397
std::vector<bool>& show_variable,
398398
std::string* output) {
@@ -414,7 +414,7 @@ bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto,
414414
absl::StrAppend(output, " ", name, ": ", line_breaker.GetOutput());
415415
} else {
416416
if (ub != +kInfinity) {
417-
std::string rhs_name = name;
417+
std::string rhs_name(name);
418418
if (lb != -kInfinity) {
419419
absl::StrAppend(&rhs_name, "_rhs");
420420
}
@@ -427,7 +427,7 @@ bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto,
427427
absl::StrAppend(output, relation);
428428
}
429429
if (lb != -kInfinity) {
430-
std::string lhs_name = name;
430+
std::string lhs_name(name);
431431
if (ub != +kInfinity) {
432432
absl::StrAppend(&lhs_name, "_lhs");
433433
}
@@ -462,7 +462,7 @@ bool IsBoolean(const MPVariableProto& var) {
462462
floor(var.upper_bound()) == 1.0;
463463
}
464464

465-
void UpdateMaxSize(const std::string& new_string, int* size) {
465+
void UpdateMaxSize(absl::string_view new_string, int* size) {
466466
const int new_size = new_string.size();
467467
if (new_size > *size) *size = new_size;
468468
}
@@ -687,7 +687,7 @@ void MPModelProtoExporter::AppendMpsLineHeader(absl::string_view id,
687687
}
688688

689689
void MPModelProtoExporter::AppendMpsLineHeaderWithNewLine(
690-
const std::string& id, const std::string& name, std::string* output) const {
690+
absl::string_view id, absl::string_view name, std::string* output) const {
691691
AppendMpsLineHeader(id, name, output);
692692
absl::StripTrailingAsciiWhitespace(output);
693693
absl::StrAppend(output, "\n");
@@ -704,8 +704,8 @@ void MPModelProtoExporter::AppendMpsTermWithContext(absl::string_view head_name,
704704
AppendNewLineIfTwoColumns(output);
705705
}
706706

707-
void MPModelProtoExporter::AppendMpsBound(const std::string& bound_type,
708-
const std::string& name, double value,
707+
void MPModelProtoExporter::AppendMpsBound(absl::string_view bound_type,
708+
absl::string_view name, double value,
709709
std::string* output) const {
710710
AppendMpsLineHeader(bound_type, "BOUND", output);
711711
AppendMpsPair(name, value, output);

ortools/pdlp/primal_dual_hybrid_gradient.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ std::optional<TerminationReason> PreprocessSolver::ApplyPresolveIfEnabled(
12621262
// set it for completeness.
12631263
presolved_qp->objective_scaling_factor = glop_lp.objective_scaling_factor();
12641264
sharded_qp_ = ShardedQuadraticProgram(std::move(*presolved_qp), num_threads_,
1265-
num_shards_);
1265+
num_shards_, params.scheduler_type());
12661266
// A status of `INIT` means the preprocessor created a (usually) smaller
12671267
// problem that needs solving. Other statuses mean the preprocessor solved
12681268
// the problem completely.

0 commit comments

Comments
 (0)