-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
43 lines (35 loc) · 1.87 KB
/
main.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
40
41
42
43
#!/usr/bin/env python3
import logging
from argparse import ArgumentParser
from enum import Enum
from lot_sizing.model import MipModel, Input
class Linearisation(Enum):
COMPACT = 1 # based on Liberti's linearisation
EXTENDED = 2 # based on network flow formulation
SIMPLE = 3 # based on Glover-Woolsey linearisation
module_logger = logging.getLogger('main')
cmd_parser = ArgumentParser(
description='Integer programming formulations for the discrete, single-machine, multi-item, single-level lot sizing problem.')
cmd_parser.add_argument('-f', '--file', metavar="input_file", type=str,
help='File containing the input data',
required=True)
cmd_parser.add_argument('--lin', type=int, choices=range(1, 4), required=True,
help='Specifies which linearisation should be used: 1-compact, 2-extended, 3-glover_woolsey')
cmd_parser.add_argument('-s', '--solver', type=str, default='SCIP',
help='Specifies the solver used by ortools. Default is SCIP.')
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
cmd_args = cmd_parser.parse_args()
prob_input = Input.read_file(cmd_args.file)
linearisation = Linearisation(cmd_args.lin)
if linearisation == Linearisation.COMPACT:
mip_model = MipModel.build_liberti_formulation(prob_input, cmd_args.solver)
elif linearisation == Linearisation.EXTENDED:
mip_model = MipModel.build_network_flow_formulation(prob_input, cmd_args.solver)
elif linearisation == Linearisation.SIMPLE:
mip_model = MipModel.build_glover_woolsey_formulation(prob_input, cmd_args.solver)
else:
raise RuntimeError('Unexpected linearisation.')
schedule, cost = mip_model.compute_optimal_schedule()
module_logger.info(f'Computed schedule: {schedule}')
module_logger.info(f'Objective value: {cost}')