diff --git a/examples/cpp/integer_programming.cc b/examples/cpp/integer_programming.cc index cc433326ea..fc7e9f79a5 100644 --- a/examples/cpp/integer_programming.cc +++ b/examples/cpp/integer_programming.cc @@ -18,19 +18,21 @@ #include "ortools/linear_solver/linear_solver.h" namespace operations_research { -void RunIntegerProgrammingExample( - const std::string& optimization_problem_type) { - LOG(INFO) << "---- Integer programming example with " - << optimization_problem_type << " ----"; +void RunIntegerProgrammingExample(const std::string& solver_id) { + LOG(INFO) << "---- Integer programming example with " << solver_id << " ----"; - if (!MPSolver::ParseAndCheckSupportForProblemType( - optimization_problem_type)) { - LOG(INFO) << " support for solver not linked in."; + MPSolver::OptimizationProblemType problem_type; + if (!MPSolver::ParseSolverType(solver_id, &problem_type)) { + LOG(INFO) << "Solver id " << solver_id << " not recognized"; return; } - MPSolver solver("IntegerProgrammingExample", - MPSolver::ParseSolverTypeOrDie(optimization_problem_type)); + if (!MPSolver::SupportsProblemType(problem_type)) { + LOG(INFO) << "Supports for solver " << solver_id << " not linked in."; + return; + } + + MPSolver solver("IntegerProgrammingExample", problem_type); const double infinity = solver.infinity(); // x and y are integer non-negative variables. @@ -80,7 +82,6 @@ void RunAllExamples() { RunIntegerProgrammingExample("GUROBI"); RunIntegerProgrammingExample("GLPK"); RunIntegerProgrammingExample("CPLEX"); - RunIntegerProgrammingExample("XPRESS"); } } // namespace operations_research diff --git a/examples/cpp/linear_programming.cc b/examples/cpp/linear_programming.cc index 54ea2ee4ed..fe7e6d2e90 100644 --- a/examples/cpp/linear_programming.cc +++ b/examples/cpp/linear_programming.cc @@ -19,17 +19,20 @@ #include "ortools/linear_solver/linear_solver.pb.h" namespace operations_research { -void RunLinearProgrammingExample(const std::string& optimization_problem_type) { - LOG(INFO) << "---- Linear programming example with " - << optimization_problem_type << " ----"; - if (!MPSolver::ParseAndCheckSupportForProblemType( - optimization_problem_type)) { - LOG(INFO) << " support for solver not linked in."; +void RunLinearProgrammingExample(const std::string& solver_id) { + LOG(INFO) << "---- Linear programming example with " << solver_id << " ----"; + MPSolver::OptimizationProblemType problem_type; + if (!MPSolver::ParseSolverType(solver_id, &problem_type)) { + LOG(INFO) << "Solver id " << solver_id << " not recognized"; return; } - MPSolver solver("IntegerProgrammingExample", - MPSolver::ParseSolverTypeOrDie(optimization_problem_type)); + if (!MPSolver::SupportsProblemType(problem_type)) { + LOG(INFO) << "Supports for solver " << solver_id << " not linked in."; + return; + } + + MPSolver solver("IntegerProgrammingExample", problem_type); const double infinity = solver.infinity(); // x1, x2 and x3 are continuous non-negative variables. diff --git a/examples/dotnet/csintegerprogramming.cs b/examples/dotnet/csintegerprogramming.cs index 9db0b328d4..3c38fb4701 100644 --- a/examples/dotnet/csintegerprogramming.cs +++ b/examples/dotnet/csintegerprogramming.cs @@ -18,7 +18,7 @@ public class CsIntegerProgramming { private static void RunIntegerProgrammingExample(String solverType) { - Solver solver = Solver.CreateSolver("IntegerProgramming", solverType); + Solver solver = Solver.CreateSolver(solverType); if (solver == null) { Console.WriteLine("Could not create solver " + solverType); @@ -65,7 +65,7 @@ public class CsIntegerProgramming private static void RunIntegerProgrammingExampleNaturalApi(String solverType) { - Solver solver = Solver.CreateSolver("IntegerProgramming", solverType); + Solver solver = Solver.CreateSolver(solverType); if (solver == null) { Console.WriteLine("Could not create solver " + solverType); @@ -113,6 +113,8 @@ public class CsIntegerProgramming RunIntegerProgrammingExample("SCIP"); Console.WriteLine("---- Linear programming example with SAT ----"); RunIntegerProgrammingExample("SAT"); + Console.WriteLine("---- Linear programming example with GUROBI ----"); + RunIntegerProgrammingExample("GUROBI"); Console.WriteLine( "---- Integer programming example (Natural API) with GLPK ----"); RunIntegerProgrammingExampleNaturalApi("GLPK"); @@ -125,5 +127,8 @@ public class CsIntegerProgramming Console.WriteLine( "---- Linear programming example (Natural API) with SAT ----"); RunIntegerProgrammingExampleNaturalApi("SAT"); + Console.WriteLine( + "---- Linear programming example (Natural API) with GUROBI ----"); + RunIntegerProgrammingExampleNaturalApi("GUROBI"); } } diff --git a/examples/dotnet/cslinearprogramming.cs b/examples/dotnet/cslinearprogramming.cs index b58611f1bc..2b4a160ee7 100644 --- a/examples/dotnet/cslinearprogramming.cs +++ b/examples/dotnet/cslinearprogramming.cs @@ -20,7 +20,7 @@ public class CsLinearProgramming { Console.WriteLine($"---- Linear programming example with {solverType} ----"); - Solver solver = Solver.CreateSolver("IntegerProgramming", solverType); + Solver solver = Solver.CreateSolver(solverType); if (solver == null) { Console.WriteLine("Could not create solver " + solverType); @@ -101,7 +101,7 @@ public class CsLinearProgramming Console.WriteLine( $"---- Linear programming example (Natural API) with {solverType} ----"); - Solver solver = Solver.CreateSolver("IntegerProgramming", solverType); + Solver solver = Solver.CreateSolver(solverType); if (solver == null) { Console.WriteLine("Could not create solver " + solverType); diff --git a/examples/java/IntegerProgramming.java b/examples/java/IntegerProgramming.java index 353cd50ee1..aec090ccb9 100644 --- a/examples/java/IntegerProgramming.java +++ b/examples/java/IntegerProgramming.java @@ -29,7 +29,7 @@ public class IntegerProgramming { } private static void runIntegerProgrammingExample(String solverType) { - MPSolver solver = MPSolver.createSolver("IntegerProgramming", solverType); + MPSolver solver = MPSolver.createSolver(solverType); if (solver == null) { System.out.println("Could not create solver " + solverType); return; diff --git a/examples/java/LinearProgramming.java b/examples/java/LinearProgramming.java index 271674d75e..d190f4a390 100644 --- a/examples/java/LinearProgramming.java +++ b/examples/java/LinearProgramming.java @@ -29,7 +29,7 @@ public class LinearProgramming { } private static void runLinearProgrammingExample(String solverType, boolean printModel) { - MPSolver solver = MPSolver.createSolver("IntegerProgramming", solverType); + MPSolver solver = MPSolver.createSolver(solverType); if (solver == null) { System.out.println("Could not create solver " + solverType); return; diff --git a/examples/python/integer_programming.py b/examples/python/integer_programming.py index e1693eac48..9f40381439 100644 --- a/examples/python/integer_programming.py +++ b/examples/python/integer_programming.py @@ -25,8 +25,7 @@ def Announce(solver, api_type): def RunIntegerExampleNaturalLanguageAPI(optimization_problem_type): """Example of simple integer program with natural language API.""" - solver = pywraplp.Solver.CreateSolver('RunIntegerExampleNaturalLanguageAPI', - optimization_problem_type) + solver = pywraplp.Solver.CreateSolver(optimization_problem_type) if not solver: return @@ -45,8 +44,7 @@ def RunIntegerExampleNaturalLanguageAPI(optimization_problem_type): def RunIntegerExampleCppStyleAPI(optimization_problem_type): """Example of simple integer program with the C++ style API.""" - solver = pywraplp.Solver.CreateSolver('RunIntegerExampleCppStyleAPI', - optimization_problem_type) + solver = pywraplp.Solver.CreateSolver(optimization_problem_type) if not solver: return diff --git a/examples/python/linear_programming.py b/examples/python/linear_programming.py index 62da7bc23e..0a8d16b698 100644 --- a/examples/python/linear_programming.py +++ b/examples/python/linear_programming.py @@ -24,8 +24,7 @@ def Announce(solver, api_type): def RunLinearExampleNaturalLanguageAPI(optimization_problem_type): """Example of simple linear program with natural language API.""" - solver = pywraplp.Solver.CreateSolver('RunLinearExampleNaturalLanguageAPI', - optimization_problem_type) + solver = pywraplp.Solver.CreateSolver(optimization_problem_type) if not solver: return @@ -51,8 +50,7 @@ def RunLinearExampleNaturalLanguageAPI(optimization_problem_type): def RunLinearExampleCppStyleAPI(optimization_problem_type): """Example of simple linear program with the C++ style API.""" - solver = pywraplp.Solver.CreateSolver('RunLinearExampleCppStyle', - optimization_problem_type) + solver = pywraplp.Solver.CreateSolver(optimization_problem_type) if not solver: return diff --git a/examples/tests/lp_test.py b/examples/tests/lp_test.py index c373fd395d..512140c8d3 100644 --- a/examples/tests/lp_test.py +++ b/examples/tests/lp_test.py @@ -228,6 +228,10 @@ class PyWrapLpTest(unittest.TestCase): result_status = solver.Solve() print(result_status) # outputs: 0 + def testSolveFromProto(self): + solver = pywraplp.Solver('', pywraplp.Solver.GLOP_LINEAR_PROGRAMMING) + solver.LoadSolutionFromProto(linear_solver_pb2.MPSolutionResponse()) + if __name__ == '__main__': unittest.main() diff --git a/ortools/linear_solver/csharp/SolverHelper.cs b/ortools/linear_solver/csharp/SolverHelper.cs index 85b654b820..9746b39070 100644 --- a/ortools/linear_solver/csharp/SolverHelper.cs +++ b/ortools/linear_solver/csharp/SolverHelper.cs @@ -180,16 +180,6 @@ public partial class Solver { return matrix; } - public static int GetSolverEnum(String solverType) { - System.Reflection.FieldInfo fieldInfo = - typeof(Solver).GetField(solverType); - if (fieldInfo != null) { - return (int)fieldInfo.GetValue(null); - } else { - throw new System.ApplicationException("Solver not supported"); - } - } - public Constraint Add(LinearConstraint constraint) { return constraint.Extract(this); } diff --git a/ortools/linear_solver/csharp/linear_solver.i b/ortools/linear_solver/csharp/linear_solver.i index 8ee9c7e7ac..4601a0180b 100644 --- a/ortools/linear_solver/csharp/linear_solver.i +++ b/ortools/linear_solver/csharp/linear_solver.i @@ -126,7 +126,6 @@ CONVERT_VECTOR(operations_research::MPVariable, MPVariable) %unignore operations_research::MPSolver::~MPSolver; %newobject operations_research::MPSolver::CreateSolver; %unignore operations_research::MPSolver::CreateSolver; -%unignore operations_research::MPSolver::ParseAndCheckSupportForProblemType; %unignore operations_research::MPSolver::MakeBoolVar; %unignore operations_research::MPSolver::MakeIntVar; %unignore operations_research::MPSolver::MakeNumVar; diff --git a/ortools/linear_solver/gurobi_interface.cc b/ortools/linear_solver/gurobi_interface.cc index add7d51f2d..191ed9fb20 100644 --- a/ortools/linear_solver/gurobi_interface.cc +++ b/ortools/linear_solver/gurobi_interface.cc @@ -27,6 +27,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/map_util.h" +#include "ortools/base/statusor.h" #include "ortools/base/timer.h" #include "ortools/linear_solver/gurobi_environment.h" #include "ortools/linear_solver/gurobi_proto_solver.h" @@ -1218,4 +1219,3 @@ void GurobiInterface::SetCallback(MPCallback* mp_callback) { } } // namespace operations_research - diff --git a/ortools/linear_solver/java/linear_solver.i b/ortools/linear_solver/java/linear_solver.i index 469e30ed74..9820ae0642 100644 --- a/ortools/linear_solver/java/linear_solver.i +++ b/ortools/linear_solver/java/linear_solver.i @@ -287,8 +287,6 @@ PROTO2_RETURN( %unignore operations_research::MPSolver::~MPSolver; %newobject operations_research::MPSolver::CreateSolver; %rename (createSolver) operations_research::MPSolver::CreateSolver; -%rename (parseAndCheckSupportForProblemType) - operations_research::MPSolver::ParseAndCheckSupportForProblemType; %unignore operations_research::MPConstraint; %unignore operations_research::MPVariable; diff --git a/ortools/linear_solver/linear_solver.cc b/ortools/linear_solver/linear_solver.cc index b608992e42..67ffb068f0 100644 --- a/ortools/linear_solver/linear_solver.cc +++ b/ortools/linear_solver/linear_solver.cc @@ -35,6 +35,7 @@ #include "ortools/base/logging.h" #include "ortools/base/map_util.h" #include "ortools/base/status_macros.h" +#include "ortools/base/statusor.h" #include "ortools/base/stl_util.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/linear_solver/model_exporter.h" @@ -207,7 +208,7 @@ void MPObjective::OptimizeLinearExpr(const LinearExpr& linear_expr, CheckLinearExpr(*interface_->solver_, linear_expr); interface_->ClearObjective(); coefficients_.clear(); - offset_ = linear_expr.offset(); + SetOffset(linear_expr.offset()); for (const auto& kv : linear_expr.terms()) { SetCoefficient(kv.first, kv.second); } @@ -216,7 +217,7 @@ void MPObjective::OptimizeLinearExpr(const LinearExpr& linear_expr, void MPObjective::AddLinearExpr(const LinearExpr& linear_expr) { CheckLinearExpr(*interface_->solver_, linear_expr); - offset_ += linear_expr.offset(); + SetOffset(offset_ + linear_expr.offset()); for (const auto& kv : linear_expr.terms()) { SetCoefficient(kv.first, GetCoefficient(kv.first) + kv.second); } @@ -519,11 +520,11 @@ constexpr {MPSolver::CBC_MIXED_INTEGER_PROGRAMMING, "cbc"}, {MPSolver::SAT_INTEGER_PROGRAMMING, "sat"}, {MPSolver::BOP_INTEGER_PROGRAMMING, "bop"}, - {MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING, "gurobi_mip"}, - {MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING, "glpk_mip"}, + {MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING, "gurobi"}, + {MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING, "glpk"}, {MPSolver::KNAPSACK_MIXED_INTEGER_PROGRAMMING, "knapsack"}, - {MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING, "cplex_mip"}, - {MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING, "xpress_mip"}, + {MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING, "cplex"}, + {MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING, "xpress"}, }; // static @@ -533,59 +534,35 @@ bool MPSolver::ParseSolverType(absl::string_view solver_id, const std::string id = absl::StrReplaceAll(absl::AsciiStrToUpper(solver_id), {{"-", "_"}}); - if (id == "CLP_LINEAR_PROGRAMMING" || id == "CLP") { - *type = MPSolver::CLP_LINEAR_PROGRAMMING; + // Support the full enum name + MPModelRequest::SolverType solver_type; + if (MPModelRequest::SolverType_Parse(id, &solver_type)) { + *type = static_cast(solver_type); return true; - } else if (id == "CBC_MIXED_INTEGER_PROGRAMMING" || id == "CBC") { - *type = MPSolver::CBC_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "GLOP_LINEAR_PROGRAMMING" || id == "GLOP") { - *type = MPSolver::GLOP_LINEAR_PROGRAMMING; - return true; - } else if (id == "BOP_INTEGER_PROGRAMMING" || id == "BOP") { - *type = MPSolver::BOP_INTEGER_PROGRAMMING; - return true; - } else if (id == "SAT_INTEGER_PROGRAMMING" || id == "SAT" || id == "CP_SAT") { - *type = MPSolver::SAT_INTEGER_PROGRAMMING; - return true; - } else if (id == "SCIP_MIXED_INTEGER_PROGRAMMING" || id == "SCIP") { - *type = MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "GUROBI_LINEAR_PROGRAMMING" || id == "GUROBI_LP") { - *type = MPSolver::GUROBI_LINEAR_PROGRAMMING; - return true; - } else if (id == "GUROBI_MIXED_INTEGER_PROGRAMMING" || id == "GUROBI_MIP" || - id == "GUROBI") { - *type = MPSolver::GUROBI_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "CPLEX_MIXED_INTEGER_PROGRAMMING" || id == "CPLEX_MIP" || - id == "CPLEX") { - *type = MPSolver::CPLEX_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "CPLEX_LINEAR_PROGRAMMING" || id == "CPLEX_LP") { - *type = MPSolver::CPLEX_LINEAR_PROGRAMMING; - return true; - } else if (id == "XPRESS_MIXED_INTEGER_PROGRAMMING" || id == "XPRESS" || - id == "XPRESS_MIP") { - *type = MPSolver::XPRESS_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "XPRESS_LINEAR_PROGRAMMING" || id == "XPRESS_LP") { - *type = MPSolver::XPRESS_LINEAR_PROGRAMMING; - return true; - - } else if (id == "GLPK_MIXED_INTEGER_PROGRAMMING" || id == "GLPK_MIP" || - id == "GLPK") { - *type = MPSolver::GLPK_MIXED_INTEGER_PROGRAMMING; - return true; - } else if (id == "GLPK_LINEAR_PROGRAMMING" || id == "GLPK_LP") { - *type = MPSolver::GLPK_LINEAR_PROGRAMMING; - return true; - } else if (id == "KNAPSACK_MIXED_INTEGER_PROGRAMMING" || id == "KNAPSACK") { - *type = MPSolver::KNAPSACK_MIXED_INTEGER_PROGRAMMING; - return true; - } else { - return false; } + + // Names are stored in lower case. + std::string lower_id = absl::AsciiStrToLower(id); + + // Remove any "_mip" suffix, since they are optional. + if (absl::EndsWith(lower_id, "_mip")) { + lower_id = lower_id.substr(0, lower_id.size() - 4); + } + + // Rewrite CP-SAT into SAT. + if (lower_id == "cp_sat") { + lower_id = "sat"; + } + + // Reverse lookup in the kOptimizationProblemTypeNames[] array. + for (auto& named_solver : kOptimizationProblemTypeNames) { + if (named_solver.name == lower_id) { + *type = named_solver.problem_type; + return true; + } + } + + return false; } const absl::string_view ToString( @@ -612,25 +589,16 @@ bool AbslParseFlag(const absl::string_view text, return result; } -/* static */ -bool MPSolver::ParseAndCheckSupportForProblemType( - const std::string& solver_id) { - MPSolver::OptimizationProblemType problem_type; - return MPSolver::ParseSolverType(solver_id, &problem_type) && - MPSolver::SupportsProblemType(problem_type); -} - /* static */ MPSolver::OptimizationProblemType MPSolver::ParseSolverTypeOrDie( const std::string& solver_id) { MPSolver::OptimizationProblemType problem_type; - CHECK(MPSolver::ParseSolverType(solver_id, &problem_type)); + CHECK(MPSolver::ParseSolverType(solver_id, &problem_type)) << solver_id; return problem_type; } /* static */ -MPSolver* MPSolver::CreateSolver(const std::string& name, - const std::string& solver_id) { +MPSolver* MPSolver::CreateSolver(const std::string& solver_id) { MPSolver::OptimizationProblemType problem_type; if (!MPSolver::ParseSolverType(solver_id, &problem_type)) { LOG(WARNING) << "Unrecognized solver type: " << solver_id; @@ -641,7 +609,7 @@ MPSolver* MPSolver::CreateSolver(const std::string& name, << " not linked in, or the license was not found."; return nullptr; } - return new MPSolver(name, problem_type); + return new MPSolver("", problem_type); } MPVariable* MPSolver::LookupVariableOrNull(const std::string& var_name) const { @@ -983,7 +951,7 @@ void MPSolver::ExportModelToProto(MPModelProto* output_model) const { // few terms. std::sort(linear_term.begin(), linear_term.end()); // Now use linear term. - for (const std::pair var_and_coeff : linear_term) { + for (const std::pair& var_and_coeff : linear_term) { constraint_proto->add_var_index(var_and_coeff.first); constraint_proto->add_coefficient(var_and_coeff.second); } diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index c11b712978..fc80d36ebd 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -248,8 +248,7 @@ class MPSolver { * - GLPK_LINEAR_PROGRAMMING or GLPK_LP * - GLPK_MIXED_INTEGER_PROGRAMMING or GLPK or GLPK_MIP */ - static MPSolver* CreateSolver(const std::string& name, - const std::string& solver_id); + static MPSolver* CreateSolver(const std::string& solver_id); /** * Whether the given problem type is supported (this will depend on the @@ -260,6 +259,7 @@ class MPSolver { /** * Parses the name of the solver. Returns true if the solver type is * successfully parsed as one of the OptimizationProblemType. + * See the documentation of CreateSolver() for the list of supported names. */ static bool ParseSolverType(absl::string_view solver_id, OptimizationProblemType* type); @@ -271,12 +271,6 @@ class MPSolver { static OptimizationProblemType ParseSolverTypeOrDie( const std::string& solver_id); - /** - * Parses the name of the solver. Returns true if the solver type is - * recognized and support for the solver is actually linked in. - */ - static bool ParseAndCheckSupportForProblemType(const std::string& solver_id); - bool IsMIP() const; /// Returns the name of the model set at construction. @@ -534,6 +528,12 @@ class MPSolver { * If you want to keep the MPSolver alive (for debugging, or for incremental * solving), you should write another version of this function that creates * the MPSolver object on the heap and returns it. + * + * Note(user): This attempts to first use `DirectlySolveProto()` (if + * implemented). Consequently, this most likely does *not* override any of + * the default parameters of the underlying solver. This behavior *differs* + * from `MPSolver::Solve()` which by default sets the feasibility tolerance + * and the gap limit (as of 2020/02/11, to 1e-7 and 0.0001, respectively). */ static void SolveWithProto(const MPModelRequest& model_request, MPSolutionResponse* response); @@ -1107,8 +1107,6 @@ class MPVariable { */ MPSolver::BasisStatus basis_status() const; - /** Returns the branching priority, or 0 if it was not set. */ - int branching_priority() const { return branching_priority_; } /** * Advanced usage: Certain MIP solvers (e.g. Gurobi or SCIP) allow you to set * a per-variable priority for determining which variable to branch on. @@ -1119,6 +1117,7 @@ class MPVariable { * support setting branching priority; all other solvers will simply ignore * this annotation. */ + int branching_priority() const { return branching_priority_; } void SetBranchingPriority(int priority); protected: diff --git a/ortools/linear_solver/samples/AssignmentMip.cs b/ortools/linear_solver/samples/AssignmentMip.cs index 52606a1e06..777d2fe684 100644 --- a/ortools/linear_solver/samples/AssignmentMip.cs +++ b/ortools/linear_solver/samples/AssignmentMip.cs @@ -36,7 +36,7 @@ public class AssignmentMip // Model. // [START model] - Solver solver = Solver.CreateSolver("AssignmentMip", "CBC"); + Solver solver = Solver.CreateSolver("SCIP"); // [END model] // Variables. diff --git a/ortools/linear_solver/samples/AssignmentMip.java b/ortools/linear_solver/samples/AssignmentMip.java index 364526ae45..9668a6ee55 100644 --- a/ortools/linear_solver/samples/AssignmentMip.java +++ b/ortools/linear_solver/samples/AssignmentMip.java @@ -42,8 +42,8 @@ public class AssignmentMip { // Solver // [START solver] - // Create the linear solver with the CBC backend. - MPSolver solver = MPSolver.createSolver("AssignmentMip", "CBC"); + // Create the linear solver with the SCIP backend. + MPSolver solver = MPSolver.createSolver("SCIP"); // [END solver] // Variables diff --git a/ortools/linear_solver/samples/BinPackingMip.cs b/ortools/linear_solver/samples/BinPackingMip.cs index 3eaee73fe5..073926d776 100644 --- a/ortools/linear_solver/samples/BinPackingMip.cs +++ b/ortools/linear_solver/samples/BinPackingMip.cs @@ -37,8 +37,8 @@ public class BinPackingMip // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - Solver solver = Solver.CreateSolver("BinPackingMip", "CBC"); + // Create the linear solver with the SCIP backend. + Solver solver = Solver.CreateSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/BinPackingMip.java b/ortools/linear_solver/samples/BinPackingMip.java index 1574ae9c0e..0e148f972f 100644 --- a/ortools/linear_solver/samples/BinPackingMip.java +++ b/ortools/linear_solver/samples/BinPackingMip.java @@ -44,8 +44,8 @@ public class BinPackingMip { // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - MPSolver solver = MPSolver.createSolver("BinPackingMip", "CBC"); + // Create the linear solver with the SCIP backend. + MPSolver solver = MPSolver.createSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/LinearProgrammingExample.cs b/ortools/linear_solver/samples/LinearProgrammingExample.cs index dee9d58e80..9b84ea3647 100644 --- a/ortools/linear_solver/samples/LinearProgrammingExample.cs +++ b/ortools/linear_solver/samples/LinearProgrammingExample.cs @@ -20,7 +20,7 @@ public class LinearProgrammingExample static void Main() { // [START solver] - Solver solver = Solver.CreateSolver("LinearProgrammingExample", "GLOP"); + Solver solver = Solver.CreateSolver("GLOP"); // [END solver] // x and y are continuous non-negative variables. // [START variables] diff --git a/ortools/linear_solver/samples/LinearProgrammingExample.java b/ortools/linear_solver/samples/LinearProgrammingExample.java index a280ade296..82fdd817c9 100644 --- a/ortools/linear_solver/samples/LinearProgrammingExample.java +++ b/ortools/linear_solver/samples/LinearProgrammingExample.java @@ -27,7 +27,7 @@ public class LinearProgrammingExample { public static void main(String[] args) throws Exception { // [START solver] - MPSolver solver = MPSolver.createSolver("LinearProgrammingExample", "GLOP"); + MPSolver solver = MPSolver.createSolver("GLOP"); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/MipVarArray.cs b/ortools/linear_solver/samples/MipVarArray.cs index 2518a96887..c854c2c3c9 100644 --- a/ortools/linear_solver/samples/MipVarArray.cs +++ b/ortools/linear_solver/samples/MipVarArray.cs @@ -43,8 +43,8 @@ public class MipVarArray // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - Solver solver = Solver.CreateSolver("MipVarArray", "CBC"); + // Create the linear solver with the SCIP backend. + Solver solver = Solver.CreateSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/MipVarArray.java b/ortools/linear_solver/samples/MipVarArray.java index c6f287edb2..bf84f8a5f4 100644 --- a/ortools/linear_solver/samples/MipVarArray.java +++ b/ortools/linear_solver/samples/MipVarArray.java @@ -49,8 +49,8 @@ public class MipVarArray { // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - MPSolver solver = MPSolver.createSolver("MipVarArray", "CBC"); + // Create the linear solver with the SCIP backend. + MPSolver solver = MPSolver.createSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/MultipleKnapsackMip.cs b/ortools/linear_solver/samples/MultipleKnapsackMip.cs index 509bf66b5f..bbd9fe3930 100644 --- a/ortools/linear_solver/samples/MultipleKnapsackMip.cs +++ b/ortools/linear_solver/samples/MultipleKnapsackMip.cs @@ -40,8 +40,8 @@ public class MultipleKnapsackMip // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - Solver solver = Solver.CreateSolver("MultipleKnapsackMip", "CBC"); + // Create the linear solver with the SCIP backend. + Solver solver = Solver.CreateSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/MultipleKnapsackMip.java b/ortools/linear_solver/samples/MultipleKnapsackMip.java index cca0ecd76c..6ad9bb58db 100644 --- a/ortools/linear_solver/samples/MultipleKnapsackMip.java +++ b/ortools/linear_solver/samples/MultipleKnapsackMip.java @@ -45,8 +45,8 @@ public class MultipleKnapsackMip { // [END program_part1] // [START solver] - // Create the linear solver with the CBC backend. - MPSolver solver = MPSolver.createSolver("MultipleKnapsackMip", "CBC"); + // Create the linear solver with the SCIP backend. + MPSolver solver = MPSolver.createSolver("SCIP"); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/SimpleLpProgram.cs b/ortools/linear_solver/samples/SimpleLpProgram.cs index 80ab61ffd1..8711896a35 100644 --- a/ortools/linear_solver/samples/SimpleLpProgram.cs +++ b/ortools/linear_solver/samples/SimpleLpProgram.cs @@ -22,7 +22,7 @@ public class SimpleLpProgram { // [START solver] // Create the linear solver with the GLOP backend. - Solver solver = Solver.CreateSolver("SimpleLpProgram", "GLOP"); + Solver solver = Solver.CreateSolver("GLOP"); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/SimpleLpProgram.java b/ortools/linear_solver/samples/SimpleLpProgram.java index ff4c340f4f..6dbba1acbb 100644 --- a/ortools/linear_solver/samples/SimpleLpProgram.java +++ b/ortools/linear_solver/samples/SimpleLpProgram.java @@ -30,7 +30,7 @@ public class SimpleLpProgram { public static void main(String[] args) throws Exception { // [START solver] // Create the linear solver with the GLOP backend. - MPSolver solver = MPSolver.createSolver("SimpleLpProgram", "GLOP"); + MPSolver solver = MPSolver.createSolver("GLOP"); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/SimpleMipProgram.cs b/ortools/linear_solver/samples/SimpleMipProgram.cs index b39e9d08af..2b3fd2d2a3 100644 --- a/ortools/linear_solver/samples/SimpleMipProgram.cs +++ b/ortools/linear_solver/samples/SimpleMipProgram.cs @@ -22,8 +22,8 @@ public class SimpleMipProgram static void Main() { // [START solver] - // Create the linear solver with the CBC backend. - Solver solver = Solver.CreateSolver("SimpleMipProgram", "CBC"); + // Create the linear solver with the SCIP backend. + Solver solver = Solver.CreateSolver("SCIP"); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/SimpleMipProgram.java b/ortools/linear_solver/samples/SimpleMipProgram.java index 7dd394b716..188adb8d39 100644 --- a/ortools/linear_solver/samples/SimpleMipProgram.java +++ b/ortools/linear_solver/samples/SimpleMipProgram.java @@ -29,8 +29,8 @@ public class SimpleMipProgram { public static void main(String[] args) throws Exception { // [START solver] - // Create the linear solver with the CBC backend. - MPSolver solver = MPSolver.createSolver("SimpleMipProgram", "CBC"); + // Create the linear solver with the SCIP backend. + MPSolver solver = MPSolver.createSolver("SCIP"); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/assignment_mip.cc b/ortools/linear_solver/samples/assignment_mip.cc index f48bf9a567..0fb00e1908 100644 --- a/ortools/linear_solver/samples/assignment_mip.cc +++ b/ortools/linear_solver/samples/assignment_mip.cc @@ -33,9 +33,8 @@ void AssignmentMip() { // Solver // [START solver] - // Create the mip solver with the CBC backend. - MPSolver solver("AssignmentMip", - MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); + // Create the mip solver with the SCIP backend. + MPSolver solver("assignment_mip", MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); // [END solver] // Variables diff --git a/ortools/linear_solver/samples/assignment_mip.py b/ortools/linear_solver/samples/assignment_mip.py index 3115b7e234..8b1f17d51b 100644 --- a/ortools/linear_solver/samples/assignment_mip.py +++ b/ortools/linear_solver/samples/assignment_mip.py @@ -33,8 +33,8 @@ def main(): # Solver # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('assignment_mip', 'CBC') + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [END solver] diff --git a/ortools/linear_solver/samples/bin_packing_mip.py b/ortools/linear_solver/samples/bin_packing_mip.py index 42674b8738..676d2a3c4c 100644 --- a/ortools/linear_solver/samples/bin_packing_mip.py +++ b/ortools/linear_solver/samples/bin_packing_mip.py @@ -42,8 +42,8 @@ def main(): # [END program_part1] # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('bin_packing_mip', 'CBC') + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [END solver] diff --git a/ortools/linear_solver/samples/integer_programming_example.cc b/ortools/linear_solver/samples/integer_programming_example.cc index 4e4deab999..8ffe27e851 100644 --- a/ortools/linear_solver/samples/integer_programming_example.cc +++ b/ortools/linear_solver/samples/integer_programming_example.cc @@ -20,9 +20,9 @@ namespace operations_research { void IntegerProgrammingExample() { // [START solver] - // Create the mip solver with the CBC backend. + // Create the mip solver with the SCIP backend. MPSolver solver("integer_programming_example", - MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); + MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/integer_programming_example.py b/ortools/linear_solver/samples/integer_programming_example.py index 0c219bc011..66b3a593f2 100644 --- a/ortools/linear_solver/samples/integer_programming_example.py +++ b/ortools/linear_solver/samples/integer_programming_example.py @@ -21,8 +21,8 @@ from ortools.linear_solver import pywraplp def IntegerProgrammingExample(): """Integer programming sample.""" # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('integer_programming_example', 'CBC') + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [END solver] diff --git a/ortools/linear_solver/samples/linear_programming_example.py b/ortools/linear_solver/samples/linear_programming_example.py index 9508c6414a..ba17cdab27 100644 --- a/ortools/linear_solver/samples/linear_programming_example.py +++ b/ortools/linear_solver/samples/linear_programming_example.py @@ -23,7 +23,7 @@ def LinearProgrammingExample(): """Linear programming sample.""" # Instantiate a Glop solver, naming it LinearExample. # [START solver] - solver = pywraplp.Solver.CreateSolver('linear_programming_examples', 'GLOP') + solver = pywraplp.Solver.CreateSolver('GLOP') # [END solver] # Create the two variables and let them take on any non-negative value. diff --git a/ortools/linear_solver/samples/mip_var_array.cc b/ortools/linear_solver/samples/mip_var_array.cc index 05fdad057e..d60a63efef 100644 --- a/ortools/linear_solver/samples/mip_var_array.cc +++ b/ortools/linear_solver/samples/mip_var_array.cc @@ -40,8 +40,8 @@ void MipVarArray() { // [END program_part1] // [START solver] - // Create the mip solver with the CBC backend. - MPSolver solver("mip_var_array", MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); + // Create the mip solver with the SCIP backend. + MPSolver solver("mip_var_array", MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); // [END solver] // [START program_part2] diff --git a/ortools/linear_solver/samples/mip_var_array.py b/ortools/linear_solver/samples/mip_var_array.py index 549a782a06..ad1cc729e5 100644 --- a/ortools/linear_solver/samples/mip_var_array.py +++ b/ortools/linear_solver/samples/mip_var_array.py @@ -46,9 +46,8 @@ def main(): # [END data] # [END program_part1] # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('mip_var_array', 'CBC') - # [END solver] + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [START program_part2] # [START variables] diff --git a/ortools/linear_solver/samples/multiple_knapsack_mip.py b/ortools/linear_solver/samples/multiple_knapsack_mip.py index 6fb868a467..f660840a76 100644 --- a/ortools/linear_solver/samples/multiple_knapsack_mip.py +++ b/ortools/linear_solver/samples/multiple_knapsack_mip.py @@ -46,8 +46,8 @@ def main(): # [END program_part1] # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('multiple_knapsack_mip', 'CBC') + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [END solver] # [START program_part2] diff --git a/ortools/linear_solver/samples/simple_lp_program.py b/ortools/linear_solver/samples/simple_lp_program.py index c112e8a96a..010ba7e959 100644 --- a/ortools/linear_solver/samples/simple_lp_program.py +++ b/ortools/linear_solver/samples/simple_lp_program.py @@ -21,7 +21,7 @@ from ortools.linear_solver import pywraplp def main(): # [START solver] # Create the linear solver with the GLOP backend. - solver = pywraplp.Solver.CreateSolver('simple_lp_program', 'GLOP') + solver = pywraplp.Solver.CreateSolver('GLOP') # [END solver] # [START variables] diff --git a/ortools/linear_solver/samples/simple_mip_program.cc b/ortools/linear_solver/samples/simple_mip_program.cc index 52e730ae00..dbfc2cab34 100644 --- a/ortools/linear_solver/samples/simple_mip_program.cc +++ b/ortools/linear_solver/samples/simple_mip_program.cc @@ -20,9 +20,9 @@ namespace operations_research { void SimpleMipProgram() { // [START solver] - // Create the mip solver with the CBC backend. + // Create the mip solver with the SCIP backend. MPSolver solver("simple_mip_program", - MPSolver::CBC_MIXED_INTEGER_PROGRAMMING); + MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING); // [END solver] // [START variables] diff --git a/ortools/linear_solver/samples/simple_mip_program.py b/ortools/linear_solver/samples/simple_mip_program.py index 28cd43d806..e2a31d5bc9 100644 --- a/ortools/linear_solver/samples/simple_mip_program.py +++ b/ortools/linear_solver/samples/simple_mip_program.py @@ -20,8 +20,8 @@ from ortools.linear_solver import pywraplp def main(): # [START solver] - # Create the mip solver with the CBC backend. - solver = pywraplp.Solver.CreateSolver('simple_mip_program', 'CBC') + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') # [END solver] # [START variables] diff --git a/ortools/linear_solver/sat_interface.cc b/ortools/linear_solver/sat_interface.cc index 720e62ea51..d26b81289b 100644 --- a/ortools/linear_solver/sat_interface.cc +++ b/ortools/linear_solver/sat_interface.cc @@ -19,6 +19,7 @@ #include "ortools/base/hash.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/statusor.h" #include "ortools/linear_solver/linear_solver.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/linear_solver/sat_proto_solver.h" diff --git a/ortools/linear_solver/sat_proto_solver.cc b/ortools/linear_solver/sat_proto_solver.cc index 58f5d01acf..00c9292f59 100644 --- a/ortools/linear_solver/sat_proto_solver.cc +++ b/ortools/linear_solver/sat_proto_solver.cc @@ -15,6 +15,7 @@ #include +#include "ortools/base/statusor.h" #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/linear_solver/model_validator.h" #include "ortools/linear_solver/sat_solver_utils.h"