diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index 0ff47303e5..5378e18008 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -40,9 +40,9 @@ cc_library( "version.h", ], copts = [ - "-DOR_TOOLS_MAJOR=9999", - "-DOR_TOOLS_MINOR=0", - "-DOR_TOOLS_PATCH=0", + "-DOR_TOOLS_MAJOR=9", + "-DOR_TOOLS_MINOR=5", + "-DOR_TOOLS_PATCH=9999", ], deps = [ ":basictypes", diff --git a/ortools/glop/BUILD.bazel b/ortools/glop/BUILD.bazel index 17a60e1cef..590a7a13cb 100644 --- a/ortools/glop/BUILD.bazel +++ b/ortools/glop/BUILD.bazel @@ -385,7 +385,7 @@ cc_library( copts = SAFE_FP_CODE, deps = [ ":parameters_cc_proto", - ":preprocessor", + ":revised_simplex", ":status", "//ortools/base", "//ortools/lp_data", diff --git a/ortools/glop/lp_solver.cc b/ortools/glop/lp_solver.cc index 7df41bdeed..3300759432 100644 --- a/ortools/glop/lp_solver.cc +++ b/ortools/glop/lp_solver.cc @@ -20,13 +20,11 @@ #include #include -#include "absl/memory/memory.h" -#include "absl/strings/match.h" +#include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" -#include "ortools/base/timer.h" +#include "ortools/base/version.h" #include "ortools/glop/preprocessor.h" #include "ortools/glop/status.h" #include "ortools/lp_data/lp_types.h" @@ -113,6 +111,10 @@ void DumpLinearProgramIfRequiredByFlags(const LinearProgram& linear_program, LPSolver::LPSolver() : num_solves_(0) {} +std::string LPSolver::GlopVersion() { + return absl::StrCat("Glop ", OrToolsVersionString()); +} + void LPSolver::SetParameters(const GlopParameters& parameters) { parameters_ = parameters; #ifndef __PORTABLE_PLATFORM__ diff --git a/ortools/glop/lp_solver.h b/ortools/glop/lp_solver.h index 1a5e107462..2c11ad42b1 100644 --- a/ortools/glop/lp_solver.h +++ b/ortools/glop/lp_solver.h @@ -15,9 +15,10 @@ #define OR_TOOLS_GLOP_LP_SOLVER_H_ #include +#include #include "ortools/glop/parameters.pb.h" -#include "ortools/glop/preprocessor.h" +#include "ortools/glop/revised_simplex.h" #include "ortools/lp_data/lp_data.h" #include "ortools/lp_data/lp_types.h" #include "ortools/util/logging.h" @@ -37,6 +38,9 @@ class LPSolver { const GlopParameters& GetParameters() const; GlopParameters* GetMutableParameters(); + // Returns a string that describes the version of the solver. + static std::string GlopVersion(); + // Solves the given linear program and returns the solve status. See the // ProblemStatus documentation for a description of the different values. // @@ -61,7 +65,7 @@ class LPSolver { // Puts the solver in a clean state. // // Calling Solve() for the first time, or calling Clear() then Solve() on the - // same problem is guaranted to be deterministic and to always give the same + // same problem is guaranteed to be deterministic and to always give the same // result, assuming that no time limit was specified. void Clear(); diff --git a/ortools/glop/parameters.proto b/ortools/glop/parameters.proto index b72999aba4..77fe78de20 100644 --- a/ortools/glop/parameters.proto +++ b/ortools/glop/parameters.proto @@ -373,7 +373,7 @@ message GlopParameters { // That is, the variable values are unchanged for the primal simplex or the // reduced cost are unchanged for the dual simplex. However, instead of doing // a step of length zero, it seems to be better on degenerate problems to do a - // small positive step. This is what is recommanded in the EXPAND procedure + // small positive step. This is what is recommended in the EXPAND procedure // described in: // P. E. Gill, W. Murray, M. A. Saunders, and M. H. Wright. "A practical anti- // cycling procedure for linearly constrained optimization". diff --git a/ortools/glop/parameters_validation.cc b/ortools/glop/parameters_validation.cc index a0041d634e..e8ec1dd930 100644 --- a/ortools/glop/parameters_validation.cc +++ b/ortools/glop/parameters_validation.cc @@ -20,9 +20,19 @@ namespace operations_research::glop { -#define TEST_NOT_NAN(name) \ - if (std::isnan(params.name())) { \ - return absl::StrCat("parameter '", #name, "' is NaN"); \ +#define TEST_FINITE_AND_NON_NEGATIVE(name) \ + if (!std::isfinite(params.name())) { \ + return absl::StrCat("parameter '", #name, "' is NaN or not finite"); \ + } \ + if (params.name() < 0) { \ + return absl::StrCat("Parameters '", #name, "' must be non-negative"); \ + } + +// We need an integer version of the test as std::isnan can fail to compile +// on windows platforms when passed integer values. +#define TEST_INTEGER_NON_NEGATIVE(name) \ + if (params.name() < 0) { \ + return absl::StrCat("Parameters '", #name, "' must be non-negative"); \ } #define TEST_NON_NEGATIVE(name) \ @@ -33,17 +43,9 @@ namespace operations_research::glop { return absl::StrCat("Parameters '", #name, "' must be non-negative"); \ } -#define TEST_INTEGER_NON_NEGATIVE(name) \ - if (params.name() < 0) { \ - return absl::StrCat("Parameters '", #name, "' must be non-negative"); \ - } - -#define TEST_FINITE_AND_NON_NEGATIVE(name) \ - if (!std::isfinite(params.name())) { \ - return absl::StrCat("parameter '", #name, "' is NaN or not finite"); \ - } \ - if (params.name() < 0) { \ - return absl::StrCat("Parameters '", #name, "' must be non-negative"); \ +#define TEST_NOT_NAN(name) \ + if (std::isnan(params.name())) { \ + return absl::StrCat("parameter '", #name, "' is NaN"); \ } std::string ValidateParameters(const GlopParameters& params) { @@ -89,10 +91,9 @@ std::string ValidateParameters(const GlopParameters& params) { return ""; } -#undef TEST_FINITE_AND_NON_NEGATIVE +#undef TEST_NOT_NAN #undef TEST_INTEGER_NON_NEGATIVE #undef TEST_NON_NEGATIVE -#undef TEST_NOT_NAN +#undef TEST_FINITE_AND_NON_NEGATIVE } // namespace operations_research::glop - diff --git a/ortools/gurobi/environment.cc b/ortools/gurobi/environment.cc index fd29d56276..33099b08ce 100644 --- a/ortools/gurobi/environment.cc +++ b/ortools/gurobi/environment.cc @@ -44,78 +44,175 @@ bool GurobiIsCorrectlyInstalled() { // See the comment at the top of the script. // This is the 'define' section. -std::function GRBisqp = nullptr; -std::function GRBisattravailable = nullptr; -std::function GRBgetintattr = nullptr; -std::function GRBsetintattr = nullptr; -std::function GRBgetintattrelement = nullptr; -std::function GRBsetintattrelement = nullptr; -std::function GRBgetintattrarray = nullptr; -std::function GRBsetintattrarray = nullptr; -std::function GRBsetintattrlist = nullptr; -std::function GRBgetcharattrelement = nullptr; -std::function GRBsetcharattrelement = nullptr; -std::function GRBgetcharattrarray = nullptr; -std::function GRBsetcharattrarray = nullptr; -std::function GRBsetcharattrlist = nullptr; -std::function GRBgetdblattr = nullptr; -std::function GRBsetdblattr = nullptr; -std::function GRBgetdblattrelement = nullptr; -std::function GRBsetdblattrelement = nullptr; -std::function GRBgetdblattrarray = nullptr; -std::function GRBsetdblattrarray = nullptr; -std::function GRBsetdblattrlist = nullptr; -std::function GRBgetstrattr = nullptr; -std::function GRBsetstrattr = nullptr; -std::function GRBsetcallbackfunc = nullptr; -std::function GRBcbget = nullptr; -std::function GRBcbsolution = nullptr; -std::function GRBcbcut = nullptr; -std::function GRBcblazy = nullptr; -std::function GRBgetvars = nullptr; -std::function GRBoptimize = nullptr; -std::function GRBwrite = nullptr; -std::function GRBnewmodel = nullptr; -std::function GRBaddvar = nullptr; -std::function GRBaddvars = nullptr; -std::function GRBaddconstr = nullptr; -std::function GRBaddconstrs = nullptr; -std::function GRBaddrangeconstr = nullptr; -std::function GRBaddsos = nullptr; -std::function GRBaddgenconstrMax = nullptr; -std::function GRBaddgenconstrMin = nullptr; -std::function GRBaddgenconstrAbs = nullptr; -std::function GRBaddgenconstrAnd = nullptr; -std::function GRBaddgenconstrOr = nullptr; -std::function GRBaddgenconstrIndicator = nullptr; -std::function GRBaddqconstr = nullptr; -std::function GRBaddqpterms = nullptr; -std::function GRBdelvars = nullptr; -std::function GRBdelconstrs = nullptr; -std::function GRBdelsos = nullptr; -std::function GRBdelgenconstrs = nullptr; -std::function GRBdelqconstrs = nullptr; -std::function GRBdelq = nullptr; -std::function GRBchgcoeffs = nullptr; -std::function GRBupdatemodel = nullptr; -std::function GRBfreemodel = nullptr; -std::function GRBterminate = nullptr; -std::function GRBsetobjectiven = nullptr; -std::function GRBgetintparam = nullptr; -std::function GRBgetdblparam = nullptr; -std::function GRBgetstrparam = nullptr; -std::function GRBsetparam = nullptr; -std::function GRBsetintparam = nullptr; -std::function GRBsetdblparam = nullptr; -std::function GRBsetstrparam = nullptr; -std::function GRBresetparams = nullptr; -std::function GRBcopyparams = nullptr; -std::function GRBloadenv = nullptr; -std::function GRBgetenv = nullptr; -std::function GRBfreeenv = nullptr; -std::function GRBgeterrormsg = nullptr; -std::function GRBversion = nullptr; -std::function GRBplatform = nullptr; +std::function + GRBisqp = nullptr; +std::function GRBisattravailable = + nullptr; +std::function + GRBgetintattr = nullptr; +std::function + GRBsetintattr = nullptr; +std::function + GRBgetintattrelement = nullptr; +std::function + GRBsetintattrelement = nullptr; +std::function + GRBgetintattrarray = nullptr; +std::function + GRBsetintattrarray = nullptr; +std::function + GRBsetintattrlist = nullptr; +std::function + GRBgetcharattrelement = nullptr; +std::function + GRBsetcharattrelement = nullptr; +std::function + GRBgetcharattrarray = nullptr; +std::function + GRBsetcharattrarray = nullptr; +std::function + GRBsetcharattrlist = nullptr; +std::function + GRBgetdblattr = nullptr; +std::function + GRBsetdblattr = nullptr; +std::function + GRBgetdblattrelement = nullptr; +std::function + GRBsetdblattrelement = nullptr; +std::function + GRBgetdblattrarray = nullptr; +std::function + GRBsetdblattrarray = nullptr; +std::function + GRBsetdblattrlist = nullptr; +std::function + GRBgetstrattr = nullptr; +std::function + GRBsetstrattr = nullptr; +std::function + GRBsetcallbackfunc = nullptr; +std::function GRBcbget = + nullptr; +std::function + GRBcbsolution = nullptr; +std::function + GRBcbcut = nullptr; +std::function + GRBcblazy = nullptr; +std::function + GRBgetvars = nullptr; +std::function GRBoptimize = nullptr; +std::function GRBwrite = nullptr; +std::function + GRBnewmodel = nullptr; +std::function + GRBaddvar = nullptr; +std::function + GRBaddvars = nullptr; +std::function + GRBaddconstr = nullptr; +std::function + GRBaddconstrs = nullptr; +std::function + GRBaddrangeconstr = nullptr; +std::function + GRBaddsos = nullptr; +std::function + GRBaddgenconstrMax = nullptr; +std::function + GRBaddgenconstrMin = nullptr; +std::function + GRBaddgenconstrAbs = nullptr; +std::function + GRBaddgenconstrAnd = nullptr; +std::function + GRBaddgenconstrOr = nullptr; +std::function + GRBaddgenconstrIndicator = nullptr; +std::function + GRBaddqconstr = nullptr; +std::function + GRBaddqpterms = nullptr; +std::function GRBdelvars = nullptr; +std::function GRBdelconstrs = nullptr; +std::function GRBdelsos = nullptr; +std::function GRBdelgenconstrs = + nullptr; +std::function GRBdelqconstrs = nullptr; +std::function GRBdelq = nullptr; +std::function + GRBchgcoeffs = nullptr; +std::function GRBupdatemodel = nullptr; +std::function GRBfreemodel = nullptr; +std::function GRBterminate = nullptr; +std::function + GRBsetobjectiven = nullptr; +std::function + GRBgetintparam = nullptr; +std::function + GRBgetdblparam = nullptr; +std::function + GRBgetstrparam = nullptr; +std::function + GRBsetparam = nullptr; +std::function + GRBsetintparam = nullptr; +std::function + GRBsetdblparam = nullptr; +std::function + GRBsetstrparam = nullptr; +std::function GRBresetparams = nullptr; +std::function GRBcopyparams = nullptr; +std::function GRBloadenv = nullptr; +std::function GRBgetenv = nullptr; +std::function GRBfreeenv = nullptr; +std::function GRBgeterrormsg = nullptr; +std::function GRBversion = + nullptr; +std::function GRBplatform = nullptr; void LoadGurobiFunctions(DynamicLibrary* gurobi_dynamic_library) { // This was generated with the parse_header.py script. @@ -123,29 +220,44 @@ void LoadGurobiFunctions(DynamicLibrary* gurobi_dynamic_library) { // This is the 'assign' section. gurobi_dynamic_library->GetFunction(&GRBisqp, "GRBisqp"); - gurobi_dynamic_library->GetFunction(&GRBisattravailable, "GRBisattravailable"); + gurobi_dynamic_library->GetFunction(&GRBisattravailable, + "GRBisattravailable"); gurobi_dynamic_library->GetFunction(&GRBgetintattr, "GRBgetintattr"); gurobi_dynamic_library->GetFunction(&GRBsetintattr, "GRBsetintattr"); - gurobi_dynamic_library->GetFunction(&GRBgetintattrelement, "GRBgetintattrelement"); - gurobi_dynamic_library->GetFunction(&GRBsetintattrelement, "GRBsetintattrelement"); - gurobi_dynamic_library->GetFunction(&GRBgetintattrarray, "GRBgetintattrarray"); - gurobi_dynamic_library->GetFunction(&GRBsetintattrarray, "GRBsetintattrarray"); + gurobi_dynamic_library->GetFunction(&GRBgetintattrelement, + "GRBgetintattrelement"); + gurobi_dynamic_library->GetFunction(&GRBsetintattrelement, + "GRBsetintattrelement"); + gurobi_dynamic_library->GetFunction(&GRBgetintattrarray, + "GRBgetintattrarray"); + gurobi_dynamic_library->GetFunction(&GRBsetintattrarray, + "GRBsetintattrarray"); gurobi_dynamic_library->GetFunction(&GRBsetintattrlist, "GRBsetintattrlist"); - gurobi_dynamic_library->GetFunction(&GRBgetcharattrelement, "GRBgetcharattrelement"); - gurobi_dynamic_library->GetFunction(&GRBsetcharattrelement, "GRBsetcharattrelement"); - gurobi_dynamic_library->GetFunction(&GRBgetcharattrarray, "GRBgetcharattrarray"); - gurobi_dynamic_library->GetFunction(&GRBsetcharattrarray, "GRBsetcharattrarray"); - gurobi_dynamic_library->GetFunction(&GRBsetcharattrlist, "GRBsetcharattrlist"); + gurobi_dynamic_library->GetFunction(&GRBgetcharattrelement, + "GRBgetcharattrelement"); + gurobi_dynamic_library->GetFunction(&GRBsetcharattrelement, + "GRBsetcharattrelement"); + gurobi_dynamic_library->GetFunction(&GRBgetcharattrarray, + "GRBgetcharattrarray"); + gurobi_dynamic_library->GetFunction(&GRBsetcharattrarray, + "GRBsetcharattrarray"); + gurobi_dynamic_library->GetFunction(&GRBsetcharattrlist, + "GRBsetcharattrlist"); gurobi_dynamic_library->GetFunction(&GRBgetdblattr, "GRBgetdblattr"); gurobi_dynamic_library->GetFunction(&GRBsetdblattr, "GRBsetdblattr"); - gurobi_dynamic_library->GetFunction(&GRBgetdblattrelement, "GRBgetdblattrelement"); - gurobi_dynamic_library->GetFunction(&GRBsetdblattrelement, "GRBsetdblattrelement"); - gurobi_dynamic_library->GetFunction(&GRBgetdblattrarray, "GRBgetdblattrarray"); - gurobi_dynamic_library->GetFunction(&GRBsetdblattrarray, "GRBsetdblattrarray"); + gurobi_dynamic_library->GetFunction(&GRBgetdblattrelement, + "GRBgetdblattrelement"); + gurobi_dynamic_library->GetFunction(&GRBsetdblattrelement, + "GRBsetdblattrelement"); + gurobi_dynamic_library->GetFunction(&GRBgetdblattrarray, + "GRBgetdblattrarray"); + gurobi_dynamic_library->GetFunction(&GRBsetdblattrarray, + "GRBsetdblattrarray"); gurobi_dynamic_library->GetFunction(&GRBsetdblattrlist, "GRBsetdblattrlist"); gurobi_dynamic_library->GetFunction(&GRBgetstrattr, "GRBgetstrattr"); gurobi_dynamic_library->GetFunction(&GRBsetstrattr, "GRBsetstrattr"); - gurobi_dynamic_library->GetFunction(&GRBsetcallbackfunc, "GRBsetcallbackfunc"); + gurobi_dynamic_library->GetFunction(&GRBsetcallbackfunc, + "GRBsetcallbackfunc"); gurobi_dynamic_library->GetFunction(&GRBcbget, "GRBcbget"); gurobi_dynamic_library->GetFunction(&GRBcbsolution, "GRBcbsolution"); gurobi_dynamic_library->GetFunction(&GRBcbcut, "GRBcbcut"); @@ -160,12 +272,17 @@ void LoadGurobiFunctions(DynamicLibrary* gurobi_dynamic_library) { gurobi_dynamic_library->GetFunction(&GRBaddconstrs, "GRBaddconstrs"); gurobi_dynamic_library->GetFunction(&GRBaddrangeconstr, "GRBaddrangeconstr"); gurobi_dynamic_library->GetFunction(&GRBaddsos, "GRBaddsos"); - gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMax, "GRBaddgenconstrMax"); - gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMin, "GRBaddgenconstrMin"); - gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAbs, "GRBaddgenconstrAbs"); - gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAnd, "GRBaddgenconstrAnd"); + gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMax, + "GRBaddgenconstrMax"); + gurobi_dynamic_library->GetFunction(&GRBaddgenconstrMin, + "GRBaddgenconstrMin"); + gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAbs, + "GRBaddgenconstrAbs"); + gurobi_dynamic_library->GetFunction(&GRBaddgenconstrAnd, + "GRBaddgenconstrAnd"); gurobi_dynamic_library->GetFunction(&GRBaddgenconstrOr, "GRBaddgenconstrOr"); - gurobi_dynamic_library->GetFunction(&GRBaddgenconstrIndicator, "GRBaddgenconstrIndicator"); + gurobi_dynamic_library->GetFunction(&GRBaddgenconstrIndicator, + "GRBaddgenconstrIndicator"); gurobi_dynamic_library->GetFunction(&GRBaddqconstr, "GRBaddqconstr"); gurobi_dynamic_library->GetFunction(&GRBaddqpterms, "GRBaddqpterms"); gurobi_dynamic_library->GetFunction(&GRBdelvars, "GRBdelvars"); diff --git a/ortools/gurobi/environment.h b/ortools/gurobi/environment.h index 56cf7809dc..430b3e8c65 100644 --- a/ortools/gurobi/environment.h +++ b/ortools/gurobi/environment.h @@ -21,6 +21,12 @@ #include "ortools/base/dynamic_library.h" #include "ortools/base/logging.h" +#if defined(_MSC_VER) +#define GUROBI_STDCALL __stdcall +#else +#define GUROBI_STDCALL +#endif + extern "C" { typedef struct _GRBmodel GRBmodel; typedef struct _GRBenv GRBenv; @@ -29,13 +35,7 @@ typedef struct _GRBsvec { int* ind; double* val; } GRBsvec; -} - -#if defined(_MSC_VER) -#define GUROBI_STDCALL __stdcall -#else -#define GUROBI_STDCALL -#endif +} namespace operations_research { diff --git a/ortools/linear_solver/glop_interface.cc b/ortools/linear_solver/glop_interface.cc index 41986f46bd..4eb7cea426 100644 --- a/ortools/linear_solver/glop_interface.cc +++ b/ortools/linear_solver/glop_interface.cc @@ -18,7 +18,6 @@ #include #include "absl/base/attributes.h" -#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/glop/lp_solver.h" @@ -29,7 +28,6 @@ #include "ortools/lp_data/lp_types.h" #include "ortools/port/proto_utils.h" #include "ortools/util/time_limit.h" - namespace operations_research { namespace {} // Anonymous namespace @@ -262,8 +260,7 @@ bool GLOPInterface::IsLP() const { return true; } bool GLOPInterface::IsMIP() const { return false; } std::string GLOPInterface::SolverVersion() const { - // TODO(user): Decide how to version glop. Add a GetVersion() to LPSolver. - return "Glop-0.0"; + return glop::LPSolver::GlopVersion(); } void* GLOPInterface::underlying_solver() { return &lp_solver_; } diff --git a/ortools/linear_solver/proto_solver/sat_proto_solver.cc b/ortools/linear_solver/proto_solver/sat_proto_solver.cc index 02bd4f8c7b..987e80010d 100644 --- a/ortools/linear_solver/proto_solver/sat_proto_solver.cc +++ b/ortools/linear_solver/proto_solver/sat_proto_solver.cc @@ -435,4 +435,6 @@ std::string EncodeSatParametersAsString(const sat::SatParameters& parameters) { return ProtobufShortDebugString(parameters); } +std::string SatSolverVersion() { return sat::CpSatSolverVersion(); } + } // namespace operations_research diff --git a/ortools/linear_solver/proto_solver/sat_proto_solver.h b/ortools/linear_solver/proto_solver/sat_proto_solver.h index bc025d4752..59da3f5d66 100644 --- a/ortools/linear_solver/proto_solver/sat_proto_solver.h +++ b/ortools/linear_solver/proto_solver/sat_proto_solver.h @@ -70,6 +70,9 @@ absl::StatusOr SatSolveProto( // you should always use this function to set the specific parameters. std::string EncodeSatParametersAsString(const sat::SatParameters& parameters); +// Returns a string that describes the version of the CP-SAT solver. +std::string SatSolverVersion(); + } // namespace operations_research #endif // OR_TOOLS_LINEAR_SOLVER_PROTO_SOLVER_SAT_PROTO_SOLVER_H_ diff --git a/ortools/linear_solver/python/linear_solver.i b/ortools/linear_solver/python/linear_solver.i index e42bc6491d..321c37834e 100644 --- a/ortools/linear_solver/python/linear_solver.i +++ b/ortools/linear_solver/python/linear_solver.i @@ -258,6 +258,7 @@ PY_CONVERT(MPVariable); // Strip the "MP" prefix from the exposed classes. %rename (Solver) operations_research::MPSolver; %rename (Solver) operations_research::MPSolver::MPSolver; +%unignore operations_research::MPSolver::SolverVersion; %rename (Constraint) operations_research::MPConstraint; %rename (Variable) operations_research::MPVariable; %rename (Objective) operations_research::MPObjective; diff --git a/ortools/linear_solver/samples/simple_lp_program.py b/ortools/linear_solver/samples/simple_lp_program.py index 4aae1e27b5..3b87b2a835 100755 --- a/ortools/linear_solver/samples/simple_lp_program.py +++ b/ortools/linear_solver/samples/simple_lp_program.py @@ -51,6 +51,7 @@ def main(): # [END objective] # [START solve] + print(f'Solving with {solver.SolverVersion()}') status = solver.Solve() # [END solve] diff --git a/ortools/linear_solver/samples/simple_mip_program.py b/ortools/linear_solver/samples/simple_mip_program.py index ea8541cf6f..f656c380f2 100755 --- a/ortools/linear_solver/samples/simple_mip_program.py +++ b/ortools/linear_solver/samples/simple_mip_program.py @@ -21,7 +21,7 @@ from ortools.linear_solver import pywraplp def main(): # [START solver] # Create the mip solver with the SCIP backend. - solver = pywraplp.Solver.CreateSolver('SCIP') + solver = pywraplp.Solver.CreateSolver('SAT') if not solver: return # [END solver] @@ -51,6 +51,7 @@ def main(): # [END objective] # [START solve] + print(f'Solving with {solver.SolverVersion()}') status = solver.Solve() # [END solve] diff --git a/ortools/linear_solver/sat_interface.cc b/ortools/linear_solver/sat_interface.cc index b142466b51..c5603667a5 100644 --- a/ortools/linear_solver/sat_interface.cc +++ b/ortools/linear_solver/sat_interface.cc @@ -21,7 +21,6 @@ #include "absl/base/attributes.h" #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/linear_solver/linear_solver.h" @@ -29,19 +28,9 @@ #include "ortools/linear_solver/proto_solver/sat_proto_solver.h" #include "ortools/port/proto_utils.h" #include "ortools/sat/cp_model.pb.h" -#include "ortools/sat/cp_model_solver.h" -#include "ortools/sat/lp_utils.h" -#include "ortools/sat/model.h" -#include "ortools/util/time_limit.h" namespace operations_research { -#if defined(PROTOBUF_INTERNAL_IMPL) -using google::protobuf::Message; -#else -using google::protobuf::Message; -#endif - class SatInterface : public MPSolverInterface { public: explicit SatInterface(MPSolver* const solver); @@ -254,9 +243,7 @@ bool SatInterface::IsContinuous() const { return false; } bool SatInterface::IsLP() const { return false; } bool SatInterface::IsMIP() const { return true; } -std::string SatInterface::SolverVersion() const { - return "SAT Based MIP Solver"; -} +std::string SatInterface::SolverVersion() const { return SatSolverVersion(); } void* SatInterface::underlying_solver() { return nullptr; } diff --git a/ortools/sat/cp_model_solver.cc b/ortools/sat/cp_model_solver.cc index 097cf79a34..a239645198 100644 --- a/ortools/sat/cp_model_solver.cc +++ b/ortools/sat/cp_model_solver.cc @@ -169,6 +169,11 @@ ABSL_FLAG(bool, cp_model_fingerprint_model, true, "Fingerprint the model."); namespace operations_research { namespace sat { +std::string CpSatSolverVersion() { + return absl::StrCat("CP-SAT solver v", OrToolsMajorVersion(), ".", + OrToolsMinorVersion(), ".", OrToolsPatchVersion()); +} + namespace { // Makes the string fit in one line by cutting it in the middle if necessary. @@ -3440,8 +3445,7 @@ CpSolverResponse SolveCpModel(const CpModelProto& model_proto, Model* model) { #endif // __PORTABLE_PLATFORM__ SOLVER_LOG(logger, ""); - SOLVER_LOG(logger, "Starting CP-SAT solver v", OrToolsMajorVersion(), ".", - OrToolsMinorVersion(), ".", OrToolsPatchVersion()); + SOLVER_LOG(logger, "Starting ", CpSatSolverVersion()); SOLVER_LOG(logger, "Parameters: ", params.ShortDebugString()); // Update params.num_workers() if the old field was used. diff --git a/ortools/sat/cp_model_solver.h b/ortools/sat/cp_model_solver.h index 8096d2951c..de66ca1eaf 100644 --- a/ortools/sat/cp_model_solver.h +++ b/ortools/sat/cp_model_solver.h @@ -26,6 +26,9 @@ namespace operations_research { namespace sat { +/// Returns a string that describes the version of the solver. +std::string CpSatSolverVersion(); + /// Solves the given CpModelProto and returns an instance of CpSolverResponse. CpSolverResponse Solve(const CpModelProto& model_proto);