python: Fix tests when SCIP and COINOR are disabled (#3261)

This commit is contained in:
Corentin Le Molgat
2022-06-03 17:09:29 +02:00
parent fd9820265d
commit 1ba0177af5
32 changed files with 91 additions and 132 deletions

View File

@@ -32,19 +32,11 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
print('Solver: ', sol)
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCBC',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -48,14 +48,12 @@ def main(sol='CBC'):
# Create the solver.
print('Solver: ', sol)
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('GLPK')
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCBC',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CBC')
if not solver:
return
#
# data

View File

@@ -31,14 +31,12 @@ def main(sol='CBC'):
print('Solver: ', sol)
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('GLPK')
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCBC',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CBC')
if not solver:
return
#
# data

View File

@@ -47,12 +47,9 @@ def main(unused_argv):
# Create the solver.
# using CBC
solver = pywraplp.Solver('CoinsGridCBC',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
# Using CLP
# solver = pywraplp.Solver('CoinsGridCLP',
# pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CBC')
if not solver:
return
# data
n = 31 # the grid size

View File

@@ -43,17 +43,10 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
print('Solver: ', sol)
if sol == 'GLPK':
# using GLPK
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -43,15 +43,9 @@ def main(sol='CBC'):
# Create the solver.
print('Solver: ', sol)
if sol == 'GLPK':
# using GLPK
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -30,15 +30,9 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
else:
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
# data
rows = 3

View File

@@ -28,17 +28,10 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
print('Solver: ', sol)
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CBC
solver = pywraplp.Solver('CoinsGridCBC',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -31,15 +31,9 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
else:
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
# data
# number of points

View File

@@ -28,6 +28,8 @@ from ortools.constraint_solver import pywrapcp
def main(n, limit):
# Create the solver.
solver = pywrapcp.Solver("n-queens")
if not solver:
return
#
# data

View File

@@ -52,19 +52,11 @@ from ortools.linear_solver import pywraplp
def main(n=3, sol='CBC', use_output_matrix=0):
# Create the solver.
print('Solver: ', sol)
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -28,15 +28,9 @@ from ortools.linear_solver import pywraplp
def main(sol='CBC'):
# Create the solver.
# using GLPK
if sol == 'GLPK':
solver = pywraplp.Solver('CoinsGridGLPK',
pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
else:
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -122,19 +122,11 @@ from ortools.linear_solver import pywraplp
def main(sol="CBC"):
# Create the solver.
print("Solver: ", sol)
# using GLPK
if sol == "GLPK":
solver = pywraplp.Solver("CoinsGridGLPK",
pywraplp.Solver.GLPK_MIXED_INTEGER_PROGRAMMING)
else:
# Using CLP
solver = pywraplp.Solver("CoinsGridCLP",
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver(sol)
if not solver:
return
#
# data

View File

@@ -33,8 +33,9 @@ def main(unused_argv):
# pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CLP')
if not solver:
return
# data

View File

@@ -34,8 +34,9 @@ def main(unused_argv):
# pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CLP')
if not solver:
return
# data
num_products = 2

View File

@@ -34,8 +34,9 @@ def main(unused_argv):
# pywraplp.Solver.GLPK_LINEAR_PROGRAMMING)
# Using CLP
solver = pywraplp.Solver('CoinsGridCLP',
pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CLP')
if not solver:
return
# data
num_products = 2

View File

@@ -116,8 +116,9 @@ def AggregateItemCollectionsOptimally(item_collections, max_num_collections,
- and its associated "num_selections" is the number of times it was
selected.
"""
solver = pywraplp.Solver('Select',
pywraplp.Solver.SCIP_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return []
n = len(ideal_item_ratios)
num_distinct_collections = len(item_collections)
max_num_items_per_collection = 0
@@ -238,10 +239,12 @@ def solve_appointments(_):
print()
print('%d installations planned' % installed)
for a in demand:
name = a[1]
per_type = installed_per_type[name]
print((' %d (%.2f%%) installations of type %s planned' %
(per_type, per_type * 100.0 / installed, name)))
name = a[1]
per_type = installed_per_type[name]
if installed != 0:
print(f' {per_type} ({per_type * 100.0 / installed}%) installations of type {name} planned')
else:
print(f' {per_type} installations of type {name} planned')
# [END print_solution]

View File

@@ -705,8 +705,9 @@ def steel_mill_slab_with_mip_column_generation(problem):
# create model and decision variables.
start_time = time.time()
solver = pywraplp.Solver('Steel',
pywraplp.Solver.SCIP_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
selected = [
solver.IntVar(0.0, 1.0, 'selected_%i' % i) for i in all_valid_slabs
]

View File

@@ -5,7 +5,7 @@ from ortools.linear_solver import pywraplp
def main():
cp = pywrapcp.Solver("test")
lp = pywraplp.Solver("test", pywraplp.Solver.CLP_LINEAR_PROGRAMMING)
lp = pywraplp.Solver.CreateSolver('GLOP')
if __name__ == "__main__":

View File

@@ -46,8 +46,9 @@ class PyWrapLp(unittest.TestCase):
def test_proto(self):
input_proto = linear_solver_pb2.MPModelProto()
text_format.Merge(TEXT_MODEL, input_proto)
solver = pywraplp.Solver('solveFromProto',
pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('CBC')
if not solver:
return
# For now, create the model from the proto by parsing the proto
errors = solver.LoadModelFromProto(input_proto)
self.assertFalse(errors)
@@ -61,8 +62,7 @@ class PyWrapLp(unittest.TestCase):
self.assertEqual(solution.best_objective_bound, 3.0)
def test_external_api(self):
solver = pywraplp.Solver('TestExternalAPI',
pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('GLOP')
infinity = solver.Infinity()
infinity2 = solver.infinity()
self.assertEqual(infinity, infinity2)

View File

@@ -70,6 +70,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# Variables

View File

@@ -36,7 +36,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# Variables

View File

@@ -45,7 +45,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# Variables

View File

@@ -42,6 +42,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# Variables

View File

@@ -23,6 +23,8 @@ def main():
# [START solver]
# Create the linear solver with the GLOP backend.
solver = pywraplp.Solver.CreateSolver('GLOP')
if not solver:
return
# [END solver]
# [START variables]

View File

@@ -42,7 +42,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# [START program_part2]

View File

@@ -23,7 +23,8 @@ def IntegerProgrammingExample():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# [START variables]

View File

@@ -23,6 +23,8 @@ def LinearProgrammingExample():
# Instantiate a Glop solver, naming it LinearExample.
# [START solver]
solver = pywraplp.Solver.CreateSolver('GLOP')
if not solver:
return
# [END solver]
# Create the two variables and let them take on any non-negative value.

View File

@@ -46,6 +46,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# [START program_part2]

View File

@@ -22,6 +22,8 @@ def main():
# [START solver]
# Create the linear solver with the GLOP backend.
solver = pywraplp.Solver.CreateSolver('GLOP')
if not solver:
return
# [END solver]
# [START variables]

View File

@@ -22,6 +22,8 @@ def main():
# [START solver]
# Create the mip solver with the SCIP backend.
solver = pywraplp.Solver.CreateSolver('SCIP')
if not solver:
return
# [END solver]
# [START variables]

View File

@@ -224,8 +224,9 @@ def main():
# [START solver]
# Instantiate a Glop solver and naming it.
solver = pywraplp.Solver('StiglerDietExample',
pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
solver = pywraplp.Solver.CreateSolver('GLOP')
if not solver:
return
# [END solver]
# [START variables]