math_opt: update

This commit is contained in:
Corentin Le Molgat
2024-02-21 18:28:57 +01:00
parent ab654ac3f3
commit 2925d1508c
26 changed files with 104 additions and 64 deletions

View File

@@ -423,6 +423,7 @@ cc_library(
":math_opt",
":update_result",
":variable_and_expressions",
"//ortools/base:gmock",
"//ortools/base:logging",
"//ortools/base:message_matchers",
"//ortools/base:status_matchers",
@@ -432,7 +433,6 @@ cc_library(
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
"@com_google_googletest//:gtest",
],
)

View File

@@ -27,8 +27,8 @@
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/base/message_matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -99,8 +99,8 @@
#include "absl/container/flat_hash_map.h"
#include "absl/status/statusor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/status_matchers.h"
#include "ortools/math_opt/cpp/linear_constraint.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -90,6 +90,24 @@ MessageCallback PrinterMessageCallback(std::ostream& output_stream,
[=](const std::vector<std::string>& messages) { impl->Call(messages); };
}
MessageCallback InfoLoggerMessageCallback(const absl::string_view prefix,
const absl::SourceLocation loc) {
return [=](const std::vector<std::string>& messages) {
for (const std::string& message : messages) {
LOG(INFO).AtLocation(loc.file_name(), loc.line()) << prefix << message;
}
};
}
MessageCallback VLoggerMessageCallback(int level, absl::string_view prefix,
absl::SourceLocation loc) {
return [=](const std::vector<std::string>& messages) {
for (const std::string& message : messages) {
VLOG(level).AtLocation(loc.file_name(), loc.line()) << prefix << message;
}
};
}
MessageCallback VectorMessageCallback(std::vector<std::string>* sink) {
CHECK(sink != nullptr);
// Here we must use an std::shared_ptr since std::function requires that its

View File

@@ -51,6 +51,28 @@ using MessageCallback = std::function<void(const std::vector<std::string>&)>;
MessageCallback PrinterMessageCallback(std::ostream& output_stream = std::cout,
absl::string_view prefix = "");
// Returns a message callback function that prints each line to LOG(INFO),
// prefixing each line with the given prefix.
//
// Usage:
//
// SolveArguments args;
// args.message_callback = InfoLoggerMessageCallback("[solver] ");
MessageCallback InfoLoggerMessageCallback(
absl::string_view prefix = "",
absl::SourceLocation loc = absl::SourceLocation::current());
// Returns a message callback function that prints each line to VLOG(level),
// prefixing each line with the given prefix.
//
// Usage:
//
// SolveArguments args;
// args.message_callback = VLoggerMessageCallback(1, "[solver] ");
MessageCallback VLoggerMessageCallback(
int level, absl::string_view prefix = "",
absl::SourceLocation loc = absl::SourceLocation::current());
// Returns a message callback function that aggregates all messages in the
// provided vector.
//

View File

@@ -19,10 +19,10 @@ cc_library(
srcs = ["base_solver_test.cc"],
hdrs = ["base_solver_test.h"],
deps = [
"//ortools/base:gmock",
"//ortools/base:linked_hash_map",
"//ortools/math_opt/cpp:math_opt",
"@com_google_absl//absl/log",
"@com_google_googletest//:gtest",
],
)
@@ -33,6 +33,7 @@ cc_library(
hdrs = ["lp_tests.h"],
deps = [
":base_solver_test",
"//ortools/base:gmock",
"//ortools/math_opt:solution_cc_proto",
"//ortools/math_opt/core:solver",
"//ortools/math_opt/cpp:matchers",
@@ -40,7 +41,6 @@ cc_library(
"//ortools/port:proto_utils",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -54,13 +54,13 @@ cc_library(
deps = [
":test_models",
"//ortools/base",
"//ortools/base:gmock",
"//ortools/math_opt:parameters_cc_proto",
"//ortools/math_opt:result_cc_proto",
"//ortools/math_opt:solution_cc_proto",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -73,6 +73,7 @@ cc_library(
hdrs = ["invalid_input_tests.h"],
deps = [
":base_solver_test",
"//ortools/base:gmock",
"//ortools/base:status_matchers",
"//ortools/math_opt:model_cc_proto",
"//ortools/math_opt:model_update_cc_proto",
@@ -84,7 +85,6 @@ cc_library(
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -98,11 +98,11 @@ cc_library(
deps = [
":base_solver_test",
"//ortools/base",
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -115,13 +115,13 @@ cc_library(
hdrs = ["ip_model_solve_parameters_tests.h"],
deps = [
":base_solver_test",
"//ortools/base:gmock",
"//ortools/base:status_macros",
"//ortools/math_opt:parameters_cc_proto",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -133,11 +133,11 @@ cc_library(
srcs = ["ip_multiple_solutions_tests.cc"],
hdrs = ["ip_multiple_solutions_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -151,10 +151,10 @@ cc_library(
deps = [
":base_solver_test",
":test_models",
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -166,6 +166,7 @@ cc_library(
srcs = ["lp_parameter_tests.cc"],
hdrs = ["lp_parameter_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/base:status_macros",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
@@ -175,7 +176,6 @@ cc_library(
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -188,11 +188,11 @@ cc_library(
hdrs = ["lp_initial_basis_tests.h"],
deps = [
":base_solver_test",
"//ortools/base:gmock",
"//ortools/math_opt:solution_cc_proto",
"//ortools/math_opt/cpp:math_opt",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -204,6 +204,7 @@ cc_library(
srcs = ["multi_objective_tests.cc"],
hdrs = ["multi_objective_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/base:status_macros",
"//ortools/math_opt:model_cc_proto",
"//ortools/math_opt:model_update_cc_proto",
@@ -214,7 +215,6 @@ cc_library(
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:string_view",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -227,12 +227,12 @@ cc_library(
hdrs = ["qp_tests.h"],
deps = [
"//ortools/base",
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -244,13 +244,13 @@ cc_library(
srcs = ["qc_tests.cc"],
hdrs = ["qc_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -262,13 +262,13 @@ cc_library(
srcs = ["second_order_cone_tests.cc"],
hdrs = ["second_order_cone_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -280,6 +280,7 @@ cc_library(
srcs = ["logical_constraint_tests.cc"],
hdrs = ["logical_constraint_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/math_opt:model_update_cc_proto",
"//ortools/math_opt:result_cc_proto",
"//ortools/math_opt/cpp:matchers",
@@ -288,7 +289,6 @@ cc_library(
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
@@ -306,31 +306,31 @@ cc_library(
],
)
# missing InfoLoggerMessageCallback
#cc_library(
# name = "generic_tests",
# testonly = True,
# srcs = ["generic_tests.cc"],
# hdrs = ["generic_tests.h"],
# deps = [
# ":test_models",
# "//ortools/base:logging",
# "//ortools/math_opt/core:inverted_bounds",
# "//ortools/math_opt/cpp:matchers",
# "//ortools/math_opt/cpp:math_opt",
# "//ortools/port:proto_utils",
# "@com_google_absl//absl/base:log_severity",
# "@com_google_absl//absl/container:flat_hash_set",
# "@com_google_absl//absl/log",
# "@com_google_absl//absl/status:statusor",
# "@com_google_absl//absl/strings",
# "@com_google_absl//absl/synchronization",
# "@com_google_absl//absl/time",
# "@com_google_googletest//:gtest",
# ],
# # Make sure the tests are included when using --dynamic_mode=off.
# alwayslink = 1,
#)
cc_library(
name = "generic_tests",
testonly = True,
srcs = ["generic_tests.cc"],
hdrs = ["generic_tests.h"],
deps = [
":test_models",
"//ortools/base:gmock",
"//ortools/base:logging",
"//ortools/math_opt/core:inverted_bounds",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:proto_utils",
"//ortools/port:scoped_std_stream_capture",
"@com_google_absl//absl/base:log_severity",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/log",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,
)
cc_library(
name = "infeasible_subsystem_tests",
@@ -338,6 +338,7 @@ cc_library(
srcs = ["infeasible_subsystem_tests.cc"],
hdrs = ["infeasible_subsystem_tests.h"],
deps = [
"//ortools/base:gmock",
"//ortools/math_opt:infeasible_subsystem_cc_proto",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
@@ -346,7 +347,6 @@ cc_library(
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
# Make sure the tests are included when using --dynamic_mode=off.
alwayslink = 1,

View File

@@ -31,8 +31,8 @@
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/span.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/base/map_util.h"
#include "ortools/base/status_macros.h"

View File

@@ -30,8 +30,8 @@
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/math_opt/core/inverted_bounds.h"
#include "ortools/math_opt/cpp/matchers.h"

View File

@@ -23,8 +23,8 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_join.h"
#include "absl/time/time.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/math_opt/infeasible_subsystem.pb.h"

View File

@@ -21,8 +21,8 @@
#include "absl/status/status.h"
#include "absl/strings/str_join.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/status_matchers.h"
#include "ortools/math_opt/core/solver.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -20,8 +20,8 @@
#include <vector>
#include "absl/status/statusor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -18,8 +18,8 @@
#include <ostream>
#include "absl/strings/str_cat.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/port/proto_utils.h"

View File

@@ -77,8 +77,8 @@
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/matchers.h"

View File

@@ -22,8 +22,8 @@
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/math_opt/model_update.pb.h"

View File

@@ -23,8 +23,8 @@
#include <vector>
#include "absl/strings/str_cat.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -17,8 +17,8 @@
#include <ostream>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/math_opt/solver_tests/base_solver_test.h"

View File

@@ -36,8 +36,8 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/matchers.h"

View File

@@ -26,8 +26,8 @@
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/core/solver.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -23,8 +23,8 @@
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -20,8 +20,8 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -22,8 +22,8 @@
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/port/proto_utils.h"

View File

@@ -21,8 +21,8 @@
#include <utility>
#include "absl/status/status.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/logging.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -22,8 +22,8 @@
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/port/proto_utils.h"

View File

@@ -23,8 +23,8 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/status_macros.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -15,8 +15,8 @@
#include <memory>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/cpp/matchers.h"
#include "ortools/math_opt/cpp/math_opt.h"

View File

@@ -16,8 +16,8 @@
#include <string>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/core/solver_interface.h"
#include "ortools/math_opt/parameters.pb.h"