forked from rte-france/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto_solve.py
39 lines (27 loc) · 1018 Bytes
/
proto_solve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from absl import app
from absl import flags
from ortools.linear_solver.python import model_builder
FLAGS = flags.FLAGS
_INPUT = flags.DEFINE_string('input', '', 'Input file to load and solve.')
_PARAMS = flags.DEFINE_string('params', '', 'Solver parameters in string format.')
_SOLVER = flags.DEFINE_string('solver', 'sat', 'Solver type to solve the model with.')
def main(_):
model = model_builder.ModelBuilder()
# Load MPS file.
if not model.import_from_mps_file(_INPUT.value):
print(f'Cannot import MPS file: \'{_INPUT.value}\'')
return
# Create solver.
solver = model_builder.ModelSolver(_SOLVER.value)
if not solver:
print(f'Cannot create solver with name \'{_SOLVER.value}\'')
return
# Set parameters.
if _PARAMS.value:
solver.set_solver_specific_parameters(_PARAMS.value)
# Enable the output of the solver.
solver.enable_output(True)
# And solve.
solver.solve(model)
if __name__ == '__main__':
app.run(main)