This commit is contained in:
Laurent Perron
2024-04-02 16:15:21 +02:00
parent cc71b3ee57
commit 9a1fd0f602
16 changed files with 77 additions and 22 deletions

View File

@@ -11,9 +11,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
package(default_visibility = ["//visibility:public"])

View File

@@ -11,12 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
# Python wrapper for ..
load("@pip_deps//:requirements.bzl", "requirement")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", "py_test")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_test")
# OSS solvers
bool_flag(

View File

@@ -240,7 +240,8 @@ namespace {
class NoOpErrorCollector : public google::protobuf::io::ErrorCollector {
public:
~NoOpErrorCollector() override = default;
void RecordError(int line, int column, absl::string_view message) override {}
void RecordError(int /*line*/, int /*column*/,
absl::string_view /*message*/) override {}
};
} // namespace

View File

@@ -11,8 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
package(default_visibility = ["//visibility:public"])
@@ -397,6 +397,7 @@ cc_library(
":dag_shortest_path",
":graph",
":topologicalsorter",
"//ortools/base:threadpool",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:log_severity",
"@com_google_absl//absl/log:check",

View File

@@ -13,9 +13,9 @@
# Description: java wrapping of the C++ code at ../
load("//bazel:swig_java.bzl", "ortools_java_wrap_cc")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@contrib_rules_jvm//java:defs.bzl", "java_junit5_test")
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//bazel:swig_java.bzl", "ortools_java_wrap_cc")
ortools_java_wrap_cc(
name = "graph",

View File

@@ -247,7 +247,7 @@ class SimpleMaxFlow {
// instance that uses it.
typedef ::util::ReverseArcStaticGraph<NodeIndex, ArcIndex> Graph;
std::unique_ptr<Graph> underlying_graph_;
std::unique_ptr<GenericMaxFlow<Graph> > underlying_max_flow_;
std::unique_ptr<GenericMaxFlow<Graph>> underlying_max_flow_;
};
// Specific but efficient priority queue implementation. The priority type must
@@ -294,13 +294,13 @@ class PriorityQueueWithRestrictedPush {
private:
// Helper function to get the last element of a vector and pop it.
Element PopBack(std::vector<std::pair<Element, IntegerPriority> >* queue);
Element PopBack(std::vector<std::pair<Element, IntegerPriority>>* queue);
// This is the heart of the algorithm. basically we split the elements by
// parity of their priority and the precondition on the Push() ensures that
// both vectors are always sorted by increasing priority.
std::vector<std::pair<Element, IntegerPriority> > even_queue_;
std::vector<std::pair<Element, IntegerPriority> > odd_queue_;
std::vector<std::pair<Element, IntegerPriority>> even_queue_;
std::vector<std::pair<Element, IntegerPriority>> odd_queue_;
};
// We want an enum for the Status of a max flow run, and we want this
@@ -660,6 +660,26 @@ class GenericMaxFlow : public MaxFlowStatusClass {
#if !SWIG
// Note: SWIG does not seem to understand explicit template specialization and
// instantiation declarations.
template <>
const FlowQuantity GenericMaxFlow<StarGraph>::kMaxFlowQuantity;
template <>
const FlowQuantity
GenericMaxFlow<::util::ReverseArcListGraph<>>::kMaxFlowQuantity;
template <>
const FlowQuantity
GenericMaxFlow<::util::ReverseArcStaticGraph<>>::kMaxFlowQuantity;
template <>
const FlowQuantity
GenericMaxFlow<::util::ReverseArcMixedGraph<>>::kMaxFlowQuantity;
extern template class GenericMaxFlow<StarGraph>;
extern template class GenericMaxFlow<::util::ReverseArcListGraph<>>;
extern template class GenericMaxFlow<::util::ReverseArcStaticGraph<>>;
extern template class GenericMaxFlow<::util::ReverseArcMixedGraph<>>;
// Default instance MaxFlow that uses StarGraph. Note that we cannot just use a
// typedef because of dependent code expecting MaxFlow to be a real class.
// TODO(user): Modify this code and remove it.
@@ -716,7 +736,7 @@ Element PriorityQueueWithRestrictedPush<Element, IntegerPriority>::Pop() {
template <typename Element, typename IntegerPriority>
Element PriorityQueueWithRestrictedPush<Element, IntegerPriority>::PopBack(
std::vector<std::pair<Element, IntegerPriority> >* queue) {
std::vector<std::pair<Element, IntegerPriority>>* queue) {
DCHECK(!queue->empty());
Element element = queue->back().first;
queue->pop_back();
@@ -724,4 +744,5 @@ Element PriorityQueueWithRestrictedPush<Element, IntegerPriority>::PopBack(
}
} // namespace operations_research
#endif // OR_TOOLS_GRAPH_MAX_FLOW_H_

View File

@@ -673,6 +673,22 @@ class GenericMinCostFlow : public MinCostFlowBase {
#if !SWIG
// Note: SWIG does not seem to understand explicit template specialization and
// instantiation declarations.
extern template class GenericMinCostFlow<StarGraph>;
extern template class GenericMinCostFlow<::util::ReverseArcListGraph<>>;
extern template class GenericMinCostFlow<::util::ReverseArcStaticGraph<>>;
extern template class GenericMinCostFlow<::util::ReverseArcMixedGraph<>>;
extern template class GenericMinCostFlow<
::util::ReverseArcStaticGraph<uint16_t, int32_t>>;
extern template class GenericMinCostFlow<
::util::ReverseArcListGraph<int64_t, int64_t>, int64_t, int64_t>;
extern template class GenericMinCostFlow<
::util::ReverseArcStaticGraph<uint16_t, int32_t>,
/*ArcFlowType=*/int16_t,
/*ArcScaledCostType=*/int32_t>;
// Default MinCostFlow instance that uses StarGraph.
// New clients should use SimpleMinCostFlow if they can.
class MinCostFlow : public GenericMinCostFlow<StarGraph> {

View File

@@ -72,6 +72,7 @@ def main():
for arc in range(smcf.num_arcs()):
# Can ignore arcs leading out of source or into sink.
if smcf.tail(arc) != source and smcf.head(arc) != sink:
# Arcs in the solution have a flow value of 1. Their start and end nodes
# give an assignment of worker to task.
if smcf.flow(arc) > 0:

View File

@@ -103,6 +103,7 @@ def main():
and smcf.tail(arc) != 12
and smcf.head(arc) != sink
):
# Arcs in the solution will have a flow value of 1.
# There start and end nodes give an assignment of worker to task.
if smcf.flow(arc) > 0:

View File

@@ -30,6 +30,7 @@
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/file.h"
#include "ortools/base/filesystem.h"
@@ -98,7 +99,7 @@ void ConvertFlowModelToDimacs(const FlowModelProto& flow_model,
// Note(user): Going from Dimacs to flow adds an extra copy, but for now we
// don't really care of the Dimacs file reading performance.
// Returns true if the file was converted correctly.
bool ConvertDimacsToFlowModel(const std::string& file,
bool ConvertDimacsToFlowModel(absl::string_view file,
FlowModelProto* flow_model) {
flow_model->Clear();
FlowModelProto::ProblemType problem_type;

View File

@@ -18,6 +18,7 @@
#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "ortools/base/logging.h"
#include "ortools/util/filelineiter.h"
@@ -30,7 +31,7 @@ BinPacking2dParser::BinPacking2dParser()
num_items_(0),
instances_seen_(0) {}
bool BinPacking2dParser::Load2BPFile(const std::string& file_name,
bool BinPacking2dParser::Load2BPFile(absl::string_view file_name,
int instance) {
if (load_status_ != NOT_STARTED) {
return false;

View File

@@ -17,6 +17,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "ortools/base/types.h"
#include "ortools/packing/multiple_dimensions_bin_packing.pb.h"
@@ -50,7 +51,7 @@ class BinPacking2dParser {
// file. The instance are 1 based (first is 1).
// Only one call to a Load*() function is supported. All the subsequent
// calls will do nothing and return false.
bool Load2BPFile(const std::string& file_name, int instance);
bool Load2BPFile(absl::string_view file_name, int instance);
MultipleDimensionsBinPackingProblem problem() const { return problem_; }
private:

View File

@@ -992,6 +992,9 @@ SolverResult PreprocessSolver::PreprocessAndSolve(
WallTimer timer;
timer.Start();
SolveLog solve_log;
if (params.verbosity_level() >= 1) {
SOLVER_LOG(&logger_, "Solving with PDLP parameters: ", params);
}
if (Qp().problem_name.has_value()) {
solve_log.set_instance_name(*Qp().problem_name);
}

View File

@@ -13,9 +13,9 @@
# Python wrapper for pdlp libraries.
load("@pip_deps//:requirements.bzl", "requirement")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", "py_test")
load("@pip_deps//:requirements.bzl", "requirement")
pybind_extension(
name = "pdlp",

View File

@@ -76,6 +76,7 @@ def small_proto_qp():
class QuadraticProgramTest(absltest.TestCase):
def test_validate_quadratic_program_dimensions_for_empty_qp(self):
qp = pdlp.QuadraticProgram()
qp.resize_and_initialize(3, 2)
@@ -189,6 +190,7 @@ def test_lp():
class PrimalDualHybridGradientTest(absltest.TestCase):
def test_iteration_limit(self):
params = solvers_pb2.PrimalDualHybridGradientParams()
params.termination_criteria.iteration_limit = 1

View File

@@ -36,11 +36,16 @@ class TextFormatErrorCollector : public google::protobuf::io::ErrorCollector {
TextFormatErrorCollector() = default;
~TextFormatErrorCollector() override = default;
void RecordError(int line, int column, absl::string_view message) override {
collected_errors_.push_back({false, line, column, std::string(message)});
void RecordError(const int line, const int column,
absl::string_view message) override {
collected_errors_.push_back(
{/*warning=*/false, line, column, std::string(message)});
}
void RecordWarning(int line, int column, absl::string_view message) override {
collected_errors_.push_back({true, line, column, std::string(message)});
void RecordWarning(const int line, const int column,
absl::string_view message) override {
collected_errors_.push_back(
{/*warning=*/true, line, column, std::string(message)});
}
// Returns a string listing each collected error. When an error is associated
@@ -80,7 +85,7 @@ bool ParseTextProtoForFlag(const absl::string_view text,
TextFormatErrorCollector errors;
google::protobuf::TextFormat::Parser parser;
parser.RecordErrorsTo(&errors);
const bool success = parser.ParseFromString(text, message_out);
const bool success = parser.ParseFromString(std::string(text), message_out);
*error_out = errors.RenderErrorMessage(text);
return success;
}