Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ file(COPY
DESTINATION ${PYTHON_PROJECT_DIR}/sat/colab)
file(COPY
ortools/util/python/solve_interrupter.py
ortools/util/python/status_streaming.py
DESTINATION ${PYTHON_PROJECT_DIR}/util/python)

# Adds py.typed to make typed packages.
Expand Down
23 changes: 22 additions & 1 deletion ortools/java/com/google/ortools/mathopt/SolverType.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,28 @@ public enum SolverType {
*
* <p>Supports LP, MIP, and nonconvex integer quadratic problems. Need a special license.
*/
XPRESS(SolverTypeProto.SOLVER_TYPE_XPRESS);
XPRESS(SolverTypeProto.SOLVER_TYPE_XPRESS),

/**
* Google's Min-Cost Flow solver.
*
* <p>Uses a specialized solver for Min-Cost Flow problems (see
* https://developers.google.com/optimization/flow/mincostflow). Supports LP problems that match
* the structure of a Min-Cost Flow problem (see go/mathopt-min-cost-flow).
*
* <p>Requirements:
*
* <ul>
* <li>The constraint matrix must be the node-arc incidence matrix of a digraph, that is, each
* variable appears in exactly two constraints, with coefficients +1 and -1.
* <li>Only linear constraints are allowed.
* <li>All linear constraints must be equality constraints.
* <li>All variable lower bounds must be 0.
* <li>All variables and constraints must have integer bounds and costs.
* <li>The objective must be linear.
* </ul>
*/
MIN_COST_FLOW(SolverTypeProto.SOLVER_TYPE_MIN_COST_FLOW);

private static class ProtoMap {
private static final EnumMap<SolverTypeProto, SolverType> map =
Expand Down
3 changes: 1 addition & 2 deletions ortools/javatests/com/google/ortools/mathopt/SolveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ public void indicatorConstraintWithNonIntegerIndicator_throws() {
model.addLeIndicatorConstraint(z, false, Expressions.linExpr(x), 5.0, "c");

// Expect error during solve.
assertThrows(IllegalArgumentException.class,
() -> { SolveResult unused = Solve.solve(model, SolverType.GSCIP); });
assertThrows(IllegalArgumentException.class, () -> Solve.solve(model, SolverType.GSCIP));
}
}
1 change: 1 addition & 0 deletions ortools/math_opt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ proto_library(
":model_update_proto",
":parameters_proto",
":result_proto",
"//ortools/util:status_proto",
],
)

Expand Down
1 change: 1 addition & 0 deletions ortools/math_opt/constraints/quadratic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cc_test(
"//ortools/base:gmock",
"//ortools/base:gmock_main",
"//ortools/base:strong_int",
"//ortools/math_opt/constraints/util:model_util",
"//ortools/math_opt/cpp:math_opt",
"//ortools/math_opt/storage:model_storage",
"//ortools/math_opt/storage:sparse_coefficient_map",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <utility>

#include "ortools/base/strong_int.h"
#include "ortools/math_opt/cpp/variable_and_expressions.h"
#include "ortools/math_opt/storage/model_storage.h"
#include "ortools/math_opt/storage/sparse_coefficient_map.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "absl/strings/str_cat.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/strong_int.h"
#include "ortools/math_opt/constraints/util/model_util.h"
#include "ortools/math_opt/cpp/math_opt.h"
#include "ortools/math_opt/storage/model_storage.h"
#include "ortools/math_opt/storage/sparse_coefficient_map.h"
Expand Down
1 change: 0 additions & 1 deletion ortools/math_opt/constraints/quadratic/storage_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/base/strong_int.h"
#include "ortools/math_opt/model.pb.h"
#include "ortools/math_opt/sparse_containers.pb.h"
#include "ortools/math_opt/storage/model_storage_types.h"
Expand Down
1 change: 0 additions & 1 deletion ortools/math_opt/constraints/quadratic/validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <cstdint>
#include <initializer_list>
#include <limits>
#include <type_traits>

#include "absl/log/check.h"
#include "absl/status/status.h"
Expand Down
6 changes: 6 additions & 0 deletions ortools/math_opt/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ cc_test(
deps = [
":non_streamable_solver_init_arguments",
"//ortools/base:gmock_main",
"//ortools/math_opt:parameters_cc_proto",
"@abseil-cpp//absl/base:core_headers",
],
)

Expand Down Expand Up @@ -346,6 +348,7 @@ cc_library(
hdrs = ["solver_interface_testing.h"],
deps = [
":solver_interface",
"//ortools/math_opt:parameters_cc_proto",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
Expand All @@ -359,6 +362,8 @@ cc_test(
":solver_interface",
":solver_interface_testing",
"//ortools/base:gmock",
"//ortools/math_opt:model_cc_proto",
"//ortools/math_opt:parameters_cc_proto",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
Expand Down Expand Up @@ -453,6 +458,7 @@ cc_test(
":empty_bounds",
":model_summary",
"//ortools/base:gmock_main",
"//ortools/math_opt:result_cc_proto",
"//ortools/math_opt/validators:result_validator",
],
)
Expand Down
1 change: 1 addition & 0 deletions ortools/math_opt/core/empty_bounds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "ortools/math_opt/core/empty_bounds.h"

#include <cstdint>
#include <limits>

#include "absl/strings/str_cat.h"
Expand Down
1 change: 1 addition & 0 deletions ortools/math_opt/core/empty_bounds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/core/model_summary.h"
#include "ortools/math_opt/result.pb.h"
#include "ortools/math_opt/validators/result_validator.h"

namespace operations_research::math_opt {
Expand Down
1 change: 0 additions & 1 deletion ortools/math_opt/core/inverted_bounds_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "ortools/math_opt/core/inverted_bounds.h"

#include <cstddef>
#include <cstdint>
#include <sstream>
#include <vector>

Expand Down
1 change: 0 additions & 1 deletion ortools/math_opt/core/model_summary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "ortools/math_opt/core/model_summary.h"

#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include <string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#include <memory>
#include <utility>

#include "absl/base/attributes.h"
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/parameters.pb.h"

namespace operations_research::math_opt {
namespace {
Expand Down
1 change: 1 addition & 0 deletions ortools/math_opt/core/solver_interface_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "ortools/math_opt/core/solver_interface.h"
#include "ortools/math_opt/parameters.pb.h"

namespace operations_research::math_opt {

Expand Down
2 changes: 2 additions & 0 deletions ortools/math_opt/core/solver_interface_testing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "gtest/gtest.h"
#include "ortools/base/gmock.h"
#include "ortools/math_opt/core/solver_interface.h"
#include "ortools/math_opt/model.pb.h"
#include "ortools/math_opt/parameters.pb.h"

namespace operations_research::math_opt {
namespace {
Expand Down
2 changes: 0 additions & 2 deletions ortools/math_opt/core/sparse_submatrix_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#include <cstdint>
#include <optional>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions ortools/math_opt/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ cc_test(
"no_test_android",
"no_test_darwin_x86_64",
"no_test_wasm",
"noci",
],
deps = [
":formatters",
Expand Down
123 changes: 123 additions & 0 deletions ortools/math_opt/cpp/executor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "executor_init_args",
hdrs = ["executor_init_args.h"],
deps = [
"//ortools/math_opt/cpp:math_opt",
"//ortools/util:solve_interrupter",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/time",
],
)

cc_library(
name = "solve_executor",
hdrs = ["solve_executor.h"],
deps = [
":executor_init_args",
"//ortools/math_opt/cpp:math_opt",
"@abseil-cpp//absl/status:statusor",
],
)

cc_library(
name = "time_limit_util",
srcs = ["time_limit_util.cc"],
hdrs = ["time_limit_util.h"],
deps = [
"//ortools/math_opt/cpp:math_opt",
"@abseil-cpp//absl/time",
],
)

cc_test(
name = "time_limit_util_test",
srcs = ["time_limit_util_test.cc"],
deps = [
":time_limit_util",
"//ortools/base:gmock_main",
"//ortools/math_opt/cpp:math_opt",
"@abseil-cpp//absl/time",
],
)

cc_library(
name = "local_solve_executor",
srcs = ["local_solve_executor.cc"],
hdrs = ["local_solve_executor.h"],
deps = [
":executor_init_args",
":solve_executor",
":time_limit_util",
"//ortools/base:status_macros",
"//ortools/math_opt/cpp:math_opt",
"//ortools/util:solve_interrupter",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/time",
],
)

cc_test(
name = "local_solve_executor_test",
srcs = ["local_solve_executor_test.cc"],
deps = [
":local_solve_executor",
":solve_executor_tests",
"//ortools/base:gmock_main",
"//ortools/math_opt/solvers:glop_solver",
"//ortools/math_opt/solvers:gscip_solver",
],
)

cc_test(
name = "local_solve_executor_gurobi_test",
srcs = ["local_solve_executor_gurobi_test.cc"],
tags = [
"local",
"manual",
"not_build:arm",
"not_run:arm",
],
deps = [
":local_solve_executor",
":solve_executor_gurobi_tests",
"//ortools/base:gmock_main",
],
)

cc_library(
name = "solve_executor_tests",
testonly = True,
srcs = ["solve_executor_tests.cc"],
hdrs = ["solve_executor_tests.h"],
deps = [
":solve_executor",
"//ortools/base:gmock",
"//ortools/math_opt/cpp:matchers",
"//ortools/math_opt/cpp:math_opt",
"//ortools/port:scoped_std_stream_capture",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
],
)
26 changes: 26 additions & 0 deletions ortools/math_opt/cpp/executor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Solve Executor

The **Solve Executor** library is an extension of the MathOpt C++ API designed
to make different execution modes interoperable without imposing compile-time
dependencies on specific modes.

## Overview

The API mirrors the standard MathOpt in-process solving API. Instead of directly
calling `Solve(Model, SolverType, SolveArguments, SolverInitArguments)`, you:
1. Create a `SolveExecutor`.
2. Call `SolveExecutor::Solve(Model, SolverType, SolveArguments, ExecutorSolverInitArguments)`.

This virtual interface allows different implementations to execute solves
differently.

## Implementations

The open-source version includes:

* `LocalSolveExecutor`: Solves the model in-process using the standard `Solve()` function.

## Incremental Solving

You can also create an `ExecutorIncrementalSolver` (similar to
`IncrementalSolver`) for cases where you need to solve a model incrementally.
Loading
Loading