Skip to content

Commit

Permalink
Cleaned up some cover code
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlofberg committed Sep 1, 2023
1 parent ba56fba commit 24a4ea1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 3 additions & 9 deletions modules/global/knapsack_cover_lift_balas.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
function q = knapsack_cover_lift_balas(a,Cset)
Nset = setdiff(1:length(a),Cset);
S = cumsum(sort(a(Cset),'descend'));
S = [0 S(:)'];
q = zeros(1,length(a));
q(Cset)=1;
for k = Nset
j = max(find(a(k) >= S));
if ~isempty(j)
j2 = min(find(a(k) < S));
if isempty(j2)
'Weird, a variable should be 0'
else
q(k)=0;
end
end
lambda = max(find(a(k) >= S))-1;
q(k) = lambda;
end
11 changes: 10 additions & 1 deletion modules/global/knapsack_create_cover_cut.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if ~all(a)
nz = find(a);
a_ = a(nz);
cut_ = knapsack_create_cover_cut(a_,b,x(nz),alg);
cut_ = knapsack_create_cover_cut(a_,b,x(nz),alg);
if ~isempty(cut_)
cut = spalloc(1,length(a)+1,0);
cut(1) = cut_(1);
Expand Down Expand Up @@ -65,11 +65,20 @@

% Apply Balas lifting
q = knapsack_cover_lift_balas(a,loc(1:C));
%q = extendcover(q,a);
% Return row where row*[1;x] hopefully is violated
cut = spalloc(1,length(a)+1,0);
cut(1) = C-1;
cut(2:end)=-q;

function q = extendcover(q,a);
if any(q)
a_C_max = max(a(find(q)));
s = find(a >= a_C_max);
q(s) = 1;
end





0 comments on commit 24a4ea1

Please sign in to comment.