Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled warm-start flag for MOSEK10 and moved var initialization to _add_vars #2647

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions pyomo/solvers/plugins/solvers/mosek_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

mosek, mosek_available = attempt_import('mosek')


class DegreeError(ValueError):
pass

Expand Down Expand Up @@ -566,6 +567,16 @@ def _add_block(self, block):
"support multiple objectives.")
self._set_objective(obj)

def _set_whichsol(self):
itr_soltypes = [mosek.problemtype.qo, mosek.problemtype.qcqo,
mosek.problemtype.conic]
if (self._solver_model.getnumintvar() >= 1):
self._whichsol = mosek.soltype.itg
elif (self._solver_model.getprobtype() in itr_soltypes):
self._whichsol = mosek.soltype.itr
elif (self._solver_model.getprobtype() == mosek.problemtype.lo):
self._whichsol = mosek.soltype.bas

def _postsolve(self):

extract_duals = False
Expand All @@ -589,19 +600,15 @@ def _postsolve(self):

msk_task = self._solver_model

itr_soltypes = [mosek.problemtype.qo, mosek.problemtype.qcqo,
mosek.problemtype.conic]
self._set_whichsol()

if (msk_task.getnumintvar() >= 1):
self._whichsol = mosek.soltype.itg
if (self._whichsol == mosek.soltype.itg):
if extract_reduced_costs:
logger.warning("Cannot get reduced costs for MIP.")
if extract_duals:
logger.warning("Cannot get duals for MIP.")
extract_reduced_costs = False
extract_duals = False
elif (msk_task.getprobtype() in itr_soltypes):
self._whichsol = mosek.soltype.itr

whichsol = self._whichsol
sol_status = msk_task.getsolsta(whichsol)
Expand Down Expand Up @@ -975,11 +982,15 @@ def warm_start_capable(self):
return True

def _warm_start(self):
self._set_whichsol()
for pyomo_var, mosek_var in self._pyomo_var_to_solver_var_map.items():
if pyomo_var.value is not None:
for solType in mosek.soltype.values:
self._solver_model.putxxslice(
solType, mosek_var, mosek_var + 1, [(pyomo_var.value)])
self._solver_model.putxxslice(
self._whichsol, mosek_var, mosek_var + 1, [(pyomo_var.value)])

if (self._version[0] > 9) & (self._whichsol == mosek.soltype.itg):
self._solver_model.putintparam(
mosek.iparam.mio_construct_sol, mosek.onoffkey.on)

def _load_vars(self, vars_to_load=None):
var_map = self._pyomo_var_to_solver_var_map
Expand Down