remove name from MPSolver.CreateSolver API; simplify underlying code
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<MPSolver::OptimizationProblemType>(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<int, double> var_and_coeff : linear_term) {
|
||||
for (const std::pair<int, double>& var_and_coeff : linear_term) {
|
||||
constraint_proto->add_var_index(var_and_coeff.first);
|
||||
constraint_proto->add_coefficient(var_and_coeff.second);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -36,7 +36,7 @@ public class AssignmentMip
|
||||
|
||||
// Model.
|
||||
// [START model]
|
||||
Solver solver = Solver.CreateSolver("AssignmentMip", "CBC");
|
||||
Solver solver = Solver.CreateSolver("SCIP");
|
||||
// [END model]
|
||||
|
||||
// Variables.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#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"
|
||||
|
||||
Reference in New Issue
Block a user