From 66a7436036d144cc600a36e85de15bae247d5436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20L=C3=B6fberg?= Date: Wed, 26 Sep 2018 13:42:39 +0200 Subject: [PATCH] Catch interrupts in cutsdp/gurobi --- modules/global/cutsdp.m | 32 ++++++++++++++++++++------------ solvers/callgurobi.m | 2 ++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/modules/global/cutsdp.m b/modules/global/cutsdp.m index a8df6a38..af5cb34e 100644 --- a/modules/global/cutsdp.m +++ b/modules/global/cutsdp.m @@ -143,19 +143,23 @@ %% START CUTTING % ************************************************************************* cutsdpsolvertime = clock; -[x_min,solved_nodes,lower,feasible,D_struc] = cutting(p); +[x_min,solved_nodes,lower,feasible,D_struc,interrupted] = cutting(p); % ************************************************************************* %% CREATE SOLUTION % ************************************************************************* -output.problem = 0; -if ~feasible - output.problem = 1; -end -if solved_nodes == p.options.cutsdp.maxiter - output.problem = 3; -elseif etime(clock,cutsdpsolvertime) > p.options.cutsdp.maxtime - output.problem = 3; +if interrupted + output.problem = 16; +else + output.problem = 0; + if ~feasible + output.problem = 1; + end + if solved_nodes == p.options.cutsdp.maxiter + output.problem = 3; + elseif etime(clock,cutsdpsolvertime) > p.options.cutsdp.maxtime + output.problem = 3; + end end output.solved_nodes = solved_nodes; output.Primal = x_min; @@ -170,8 +174,9 @@ output.solvertime = etime(clock,bnbsolvertime); %% -- -function [x,solved_nodes,lower,feasible,D_struc] = cutting(p) +function [x,solved_nodes,lower,feasible,D_struc,interrupted] = cutting(p) +interrupted = 0; % ************************************************************************* %% Sanity check % ************************************************************************* @@ -383,7 +388,7 @@ ptemp.integer_variables = []; output = feval(cutsolver,ptemp); end - + % Remove upper bounds if we added those (avoid accumulating them) if ~isinf(upper) && (nnz(p_lp.Q)==0) p_lp.K.l = p_lp.K.l - 1; @@ -494,6 +499,7 @@ end goon = goon && gap >= p.options.cutsdp.gaptol; goon = goon && (etime(clock,cutsdpsolvertime) < p.options.cutsdp.maxtime); + goon = goon && ~(output.problem == 16); end solved_nodes = solved_nodes + 1; @@ -518,7 +524,9 @@ end end D_struc = []; - +if output.problem == 16 + interrupted = 1; +end function [p_lp,worstinfeasibility,infeasible_sdp_cones,eig_computation_failure] = add_sdp_cut(p,p_lp,x,infeasibility_in,p_original); diff --git a/solvers/callgurobi.m b/solvers/callgurobi.m index 4d3eb465..00c09795 100644 --- a/solvers/callgurobi.m +++ b/solvers/callgurobi.m @@ -62,6 +62,8 @@ problem = 4; case 'INF_OR_UNBD' problem = 12; + case 'INTERRUPTED'; + problem = 16; otherwise problem = -1; end