Skip to content

Commit 4747585

Browse files
author
Ehsan Khodabandeh
committed
added parameter to control display of solver's progress on the screen
1 parent 5343522 commit 4747585

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

optimization_model_pulp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def optimize(self):
104104
logger.info('Optimization starts!')
105105
_solver = pulp.PULP_CBC_CMD(keepFiles=model_params['write_log'],
106106
fracGap=model_params['mip_gap'],
107-
maxSeconds=model_params['time_limit'])
107+
maxSeconds=model_params['time_limit'],
108+
msg=model_params['display_log'])
108109

109110
if model_params['solver'] == 'gurobi':
110111
_solver = pulp.GUROBI(msg=model_params['write_log'],
@@ -116,7 +117,8 @@ def optimize(self):
116117
set_mip_gap = "set mip tolerances mipgap {}".format(model_params['mip_gap'])
117118
options.append(set_mip_gap)
118119
_solver = pulp.CPLEX_CMD(keepFiles=model_params['write_log'],
119-
options=options, timelimit=model_params['time_limit'])
120+
options=options, timelimit=model_params['time_limit'],
121+
msg=model_params['display_log'])
120122
elif model_params['solver'] == 'glpk':
121123
# Read more about glpk options: https://en.wikibooks.org/wiki/GLPK/Using_GLPSOL
122124
options = []
@@ -126,7 +128,8 @@ def optimize(self):
126128
if model_params['time_limit']:
127129
set_time_limit = "--tmlim {}".format(model_params['time_limit'])
128130
options.append(set_time_limit)
129-
_solver = pulp.GLPK_CMD(keepFiles=model_params['write_log'], options=options)
131+
_solver = pulp.GLPK_CMD(keepFiles=model_params['write_log'], options=options,
132+
msg=model_params['display_log'])
130133

131134
self.model.solve(solver=_solver)
132135

parameters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
'solver': None, # default is None for 'cbc'; can also be 'gurobi', 'cplex', 'glpk'
66
'module': None, # default is None for pulp; 'gurobi' for using gurobi
77
'write_lp': True, # whether to write the model .lp file
8-
'write_log': False, # whether to write the output .log file
8+
'write_log': False, # whether to keep the output files such as .sol or .mps (or .log for cplex or gurobi)
9+
'display_log': False, # displays information from the solver to stdout
910
'mip_gap': None, # default is None to use the solver's default value. Can be any float less than 1.0
1011
'time_limit': None, # in seconds
1112
}

0 commit comments

Comments
 (0)