make code robust in one of CLP/CBC/GLPK is not used with or-tools
This commit is contained in:
@@ -21,9 +21,9 @@ from google.apputils import app
|
||||
from linear_solver import pywraplp
|
||||
|
||||
|
||||
def RunLinearExampleNaturalLanguageAPI(optimization_problem_type):
|
||||
def RunLinearExampleAlgebraicAPI(optimization_problem_type):
|
||||
"""Example of simple linear program with natural language API."""
|
||||
solver = pywraplp.Solver('RunLinearExampleNaturalLanguageAPI',
|
||||
solver = pywraplp.Solver('RunLinearExampleAlgebraicAPI',
|
||||
optimization_problem_type)
|
||||
infinity = solver.infinity()
|
||||
# x1, x2 and x3 are continuous non-negative variables.
|
||||
@@ -107,22 +107,26 @@ def SolveAndPrint(solver, variable_list, constraint_list):
|
||||
(i, constraint.dual_value(), constraint.activity()))
|
||||
|
||||
|
||||
def RunAllLinearExampleNaturalLanguageAPI():
|
||||
print '---- Linear programming example with GLPK (natural language API) ----'
|
||||
RunLinearExampleNaturalLanguageAPI(pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
|
||||
print '---- Linear programming example with CLP (natural language API) ----'
|
||||
RunLinearExampleNaturalLanguageAPI(pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
|
||||
def RunAllLinearExampleAlgebraicAPI():
|
||||
if hasattr(pywraplp.Solver, 'GLPK_LINEAR_PROGRAMMING'):
|
||||
print '---- Linear programming example with GLPK (algebraic API) ----'
|
||||
RunLinearExampleAlgebraicAPI(pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
|
||||
if hasattr(pywraplp.Solver, 'CLP_LINEAR_PROGRAMMING'):
|
||||
print '---- Linear programming example with CLP (algebraic API) ----'
|
||||
RunLinearExampleAlgebraicAPI(pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
|
||||
|
||||
|
||||
def RunAllLinearExampleCppStyleAPI():
|
||||
print '---- Linear programming example with GLPK (C++ style API) ----'
|
||||
RunLinearExampleCppStyleAPI(pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
|
||||
print '---- Linear programming example with CLP (C++ style API) ----'
|
||||
RunLinearExampleCppStyleAPI(pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
|
||||
if hasattr(pywraplp.Solver, 'GLPK_LINEAR_PROGRAMMING'):
|
||||
print '---- Linear programming example with GLPK (C++ style API) ----'
|
||||
RunLinearExampleCppStyleAPI(pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
|
||||
if hasattr(pywraplp.Solver, 'CLP_LINEAR_PROGRAMMING'):
|
||||
print '---- Linear programming example with CLP (C++ style API) ----'
|
||||
RunLinearExampleCppStyleAPI(pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
|
||||
|
||||
|
||||
def main(unused_argv):
|
||||
RunAllLinearExampleNaturalLanguageAPI()
|
||||
RunAllLinearExampleAlgebraicAPI()
|
||||
RunAllLinearExampleCppStyleAPI()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user