gscip cleanup; linear_solver samples reident

This commit is contained in:
Laurent Perron
2025-06-17 12:47:23 +02:00
parent 7b67f855e6
commit ac0fe62544
20 changed files with 37 additions and 43 deletions

View File

@@ -49,19 +49,6 @@ cc_library(
],
)
cc_library(
name = "legacy_scip_params",
srcs = ["legacy_scip_params.cc"],
hdrs = ["legacy_scip_params.h"],
deps = [
"//ortools/linear_solver:scip_helper_macros",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@scip",
],
)
cc_library(
name = "gscip",
srcs = [
@@ -76,7 +63,6 @@ cc_library(
":gscip_cc_proto",
":gscip_message_handler",
":gscip_parameters",
":legacy_scip_params",
"//ortools/base",
"//ortools/base:status_builder",
"//ortools/base:status_macros",

View File

@@ -40,7 +40,6 @@
#include "ortools/gscip/gscip.pb.h"
#include "ortools/gscip/gscip_event_handler.h"
#include "ortools/gscip/gscip_parameters.h"
#include "ortools/gscip/legacy_scip_params.h"
#include "ortools/linear_solver/scip_helper_macros.h"
#include "ortools/port/proto_utils.h"
#include "ortools/util/status_macros.h"
@@ -294,8 +293,7 @@ const GScipConstraintOptions& DefaultGScipConstraintOptions() {
return constraint_options;
}
absl::Status GScip::SetParams(const GScipParameters& params,
absl::string_view legacy_params) {
absl::Status GScip::SetParams(const GScipParameters& params) {
if (params.has_silence_output()) {
SCIPsetMessagehdlrQuiet(scip_, params.silence_output());
}
@@ -350,10 +348,6 @@ absl::Status GScip::SetParams(const GScipParameters& params,
RETURN_IF_SCIP_ERROR(
SCIPsetRealParam(scip_, real_param.first.c_str(), real_param.second));
}
if (!legacy_params.empty()) {
RETURN_IF_ERROR(
LegacyScipSetSolverSpecificParameters(legacy_params, scip_));
}
return absl::OkStatus();
}
@@ -929,8 +923,7 @@ absl::StatusOr<GScipHintResult> GScip::SuggestHint(
}
absl::StatusOr<GScipResult> GScip::Solve(
const GScipParameters& params, absl::string_view legacy_params,
const GScipMessageHandler message_handler,
const GScipParameters& params, const GScipMessageHandler message_handler,
const Interrupter* const interrupter) {
if (InErrorState()) {
return absl::InvalidArgumentError(
@@ -950,7 +943,7 @@ absl::StatusOr<GScipResult> GScip::Solve(
GScipResult result;
// Step 1: apply parameters.
const absl::Status param_status = SetParams(params, legacy_params);
const absl::Status param_status = SetParams(params);
if (!param_status.ok()) {
result.gscip_output.set_status(GScipOutput::INVALID_SOLVER_PARAMETERS);
// Conversion to std::string for open source build.

View File

@@ -178,8 +178,7 @@ class GScip {
static std::string ScipVersion();
// After Solve() the parameters are reset and SCIP stage is restored to
// PROBLEM. "legacy_params" are in the format of legacy_scip_params.h and are
// applied after "params". Use of "legacy_params" is discouraged.
// PROBLEM.
//
// The returned StatusOr will contain an error only if an:
// * An underlying function from SCIP fails.
@@ -192,7 +191,6 @@ class GScip {
// returns.
absl::StatusOr<GScipResult> Solve(
const GScipParameters& params = GScipParameters(),
absl::string_view legacy_params = "",
GScipMessageHandler message_handler = nullptr,
const Interrupter* interrupter = nullptr);
@@ -480,8 +478,7 @@ class GScip {
// Releases SCIP memory.
absl::Status CleanUp();
absl::Status SetParams(const GScipParameters& params,
absl::string_view legacy_params);
absl::Status SetParams(const GScipParameters& params);
absl::Status FreeTransform();
// Returns an error if |d| >= ScipInf().

View File

@@ -311,7 +311,7 @@ cc_library(
"//conditions:default": [],
}) + select({
":use_scip": [
"//ortools/gscip:legacy_scip_params",
"//ortools/linear_solver/proto_solver:scip_params",
"//ortools/linear_solver/proto_solver:scip_proto_solver",
"@scip",
],

View File

@@ -15,7 +15,6 @@
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
@@ -24,10 +23,7 @@
#include <vector>
#include "absl/base/attributes.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_format.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/hash.h"
#include "ortools/base/logging.h"
#include "ortools/base/timer.h"
#include "ortools/glpk/glpk_env_deleter.h"

View File

@@ -110,6 +110,19 @@ cc_library(
],
)
cc_library(
name = "scip_params",
srcs = ["scip_params.cc"],
hdrs = ["scip_params.h"],
deps = [
"//ortools/linear_solver:scip_helper_macros",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@scip",
],
)
cc_library(
name = "scip_proto_solver",
srcs = ["scip_proto_solver.cc"],
@@ -121,10 +134,10 @@ cc_library(
deps = [
"//ortools/base",
"//ortools/base:timer",
"//ortools/gscip:legacy_scip_params",
"//ortools/linear_solver:linear_solver_cc_proto",
"//ortools/linear_solver:model_validator",
"//ortools/linear_solver:scip_helper_macros",
"//ortools/linear_solver/proto_solver:scip_params",
"//ortools/util:lazy_mutable_copy",
"@abseil-cpp//absl/cleanup",
"@abseil-cpp//absl/container:btree",

View File

@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ortools/gscip/legacy_scip_params.h"
#include "ortools/linear_solver/proto_solver/scip_params.h"
#include <cstdint>
#include <string>

View File

@@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef OR_TOOLS_GSCIP_LEGACY_SCIP_PARAMS_H_
#define OR_TOOLS_GSCIP_LEGACY_SCIP_PARAMS_H_
#ifndef OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_SCIP_PARAMS_H_
#define OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_SCIP_PARAMS_H_
#include <string>
@@ -27,4 +27,4 @@ absl::Status LegacyScipSetSolverSpecificParameters(absl::string_view parameters,
SCIP* scip);
}
#endif // OR_TOOLS_GSCIP_LEGACY_SCIP_PARAMS_H_
#endif // OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_SCIP_PARAMS_H_

View File

@@ -41,9 +41,9 @@
#include "absl/time/time.h"
#include "ortools/base/status_macros.h"
#include "ortools/base/timer.h"
#include "ortools/gscip/legacy_scip_params.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/linear_solver/model_validator.h"
#include "ortools/linear_solver/proto_solver/scip_params.h"
#include "ortools/linear_solver/scip_helper_macros.h"
#include "ortools/util/lazy_mutable_copy.h"
#include "scip/cons_and.h"

View File

@@ -24,7 +24,7 @@
// solver.Maximize(10 * x1 + 6 * x2)
//
// USAGE EXAMPLES:
// - ortools/python/linear_programming.py
// - examples/python/linear_programming.py
// - ./pywraplp_test.py
//
// TODO(user): test all the APIs that are currently marked as 'untested'.

View File

@@ -16,6 +16,7 @@
"""Solve assignment problem for given group of workers."""
# [START import]
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -20,6 +20,7 @@ import io
import pandas as pd
from ortools.linear_solver.python import model_builder
# [END import]

View File

@@ -16,6 +16,7 @@
# [START program]
# [START import]
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -16,6 +16,7 @@
"""MIP example that solves an assignment problem."""
# [START import]
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -16,6 +16,7 @@
"""MIP example that solves an assignment problem."""
# [START import]
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -17,6 +17,7 @@
# [START import]
from ortools.init.python import init
from ortools.linear_solver import pywraplp
# [END import]

View File

@@ -20,6 +20,7 @@ import io
import pandas as pd
from ortools.linear_solver.python import model_builder
# [END import]

View File

@@ -16,6 +16,7 @@
# [START program]
# [START import]
from ortools.linear_solver import pywraplp
# [END import]
@@ -31,6 +32,7 @@ def create_data_model():
data["bin_capacity"] = 100
return data
# [END data_model]

View File

@@ -35,11 +35,11 @@
#include "ortools/base/logging.h"
#include "ortools/base/status_macros.h"
#include "ortools/base/timer.h"
#include "ortools/gscip/legacy_scip_params.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/linear_solver/linear_solver_callback.h"
#include "ortools/linear_solver/proto_solver/proto_utils.h"
#include "ortools/linear_solver/proto_solver/scip_params.h"
#include "ortools/linear_solver/proto_solver/scip_proto_solver.h"
#include "ortools/linear_solver/scip_callback.h"
#include "ortools/linear_solver/scip_helper_macros.h"

View File

@@ -32,7 +32,7 @@
// CP-SAT parameters:
//
// solve --solver=sat \
// --params="max_time_in_seconds:600, num_search_workers:8"
// --params="max_time_in_seconds:600, num_workers:8"
// --stderrthreshold=0 \
// --input=/tmp/foo.mps \
// 2>/tmp/foo.err