Skip to content

Commit

Permalink
Catch interrupts in cutsdp/gurobi
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlofberg committed Sep 26, 2018
1 parent a800017 commit 66a7436
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 20 additions & 12 deletions modules/global/cutsdp.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
% *************************************************************************
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions solvers/callgurobi.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
problem = 4;
case 'INF_OR_UNBD'
problem = 12;
case 'INTERRUPTED';
problem = 16;
otherwise
problem = -1;
end
Expand Down

0 comments on commit 66a7436

Please sign in to comment.