1 | function [upper,x_min] = rounder(p,relaxedsolution) |
---|
2 | |
---|
3 | % Extremely simple heuristic for finding integer |
---|
4 | % solutions. |
---|
5 | % |
---|
6 | % Rounds up and down, fixes etc. |
---|
7 | |
---|
8 | % This was the relaxed solution |
---|
9 | x = relaxedsolution.Primal; |
---|
10 | |
---|
11 | % Assume we fail |
---|
12 | upper = inf; |
---|
13 | x_min = x; |
---|
14 | |
---|
15 | % These should be integer |
---|
16 | intvars = [p.integer_variables(:);p.binary_variables(:)]; |
---|
17 | p.options.rounding = [1 1 1 1]; |
---|
18 | |
---|
19 | % b=p.F_struc(:,1); |
---|
20 | % A=-p.F_struc(:,2:end); |
---|
21 | % c=p.c; |
---|
22 | % |
---|
23 | % %x=rand(length(p.c),1) |
---|
24 | % xtilde = round(x(intvars)); |
---|
25 | % xplus=sdpvar(length(xtilde),1); |
---|
26 | % xminus=sdpvar(length(xtilde),1); |
---|
27 | % xj=sdpvar(length(xtilde),1); |
---|
28 | % t=sdpvar(1,1); |
---|
29 | % |
---|
30 | % while 1 |
---|
31 | % goneup = find(xtilde==p.ub(intvars)); |
---|
32 | % gonedown = find(xtilde==p.lb(intvars)); |
---|
33 | % F=set([]);%xplus>0)+set(xminus>0)+set(xj==xtilde+xplus-xminus); |
---|
34 | % F=F + set(b(1:p.K.l) -A(1:p.K.l,:)*[t;xj]>0); |
---|
35 | % F = F + set(reshape(b(p.K.l+1:end) -A(p.K.l+1:end,:)*[t;xj],14,14) > 0) |
---|
36 | % solvesdp(F+set(0<xj<1),-sum(xj(goneup))+sum(xj(gonedown)));%+sum(xplus)+sum(xminus)); |
---|
37 | % |
---|
38 | % xtilde=round(double(xj)); |
---|
39 | % end |
---|
40 | |
---|
41 | if p.options.rounding(1) |
---|
42 | % Round, update nonlinear terms, and compute feasibility |
---|
43 | xtemp = x;xtemp(intvars) = round(xtemp(intvars)); |
---|
44 | xtemp(p.binary_variables(:)) = min(1,xtemp(p.binary_variables(:))); |
---|
45 | xtemp(p.binary_variables(:)) = max(0,xtemp(p.binary_variables(:))); |
---|
46 | xtemp = setnonlinearvariables(p,xtemp); |
---|
47 | if checkfeasiblefast(p,xtemp,p.options.bnb.feastol)%res>-p.options.bnb.feastol |
---|
48 | x_min = xtemp; |
---|
49 | upper = p.f+x_min'*p.Q*x_min + p.corig'*x_min; |
---|
50 | return |
---|
51 | end |
---|
52 | end |
---|
53 | |
---|
54 | if p.options.rounding(2) |
---|
55 | % Do same using fix instead |
---|
56 | xtemp = x;xtemp(intvars) = fix(xtemp(intvars)); |
---|
57 | xtemp(p.binary_variables(:)) = min(1,xtemp(p.binary_variables(:))); |
---|
58 | xtemp(p.binary_variables(:)) = max(0,xtemp(p.binary_variables(:))); |
---|
59 | xtemp = setnonlinearvariables(p,xtemp); |
---|
60 | if checkfeasiblefast(p,xtemp,p.options.bnb.feastol)%if res>-p.options.bnb.feastol |
---|
61 | x_min = xtemp; |
---|
62 | upper = p.f+x_min'*p.Q*x_min + p.corig'*x_min; |
---|
63 | return |
---|
64 | end |
---|
65 | end |
---|
66 | |
---|
67 | if p.options.rounding(3) |
---|
68 | % ...or ceil |
---|
69 | xtemp = x;xtemp(intvars) = ceil(xtemp(intvars)); |
---|
70 | xtemp(p.binary_variables(:)) = min(1,xtemp(p.binary_variables(:))); |
---|
71 | xtemp(p.binary_variables(:)) = max(0,xtemp(p.binary_variables(:))); |
---|
72 | xtemp = setnonlinearvariables(p,xtemp); |
---|
73 | if checkfeasiblefast(p,xtemp,p.options.bnb.feastol)%if res>-p.options.bnb.feastol |
---|
74 | x_min = xtemp; |
---|
75 | upper = p.f+x_min'*p.Q*x_min + p.corig'*x_min; |
---|
76 | return |
---|
77 | end |
---|
78 | end |
---|
79 | |
---|
80 | if p.options.rounding(4) |
---|
81 | % or floor |
---|
82 | xtemp = x;xtemp(intvars) = floor(xtemp(intvars)); |
---|
83 | xtemp(p.binary_variables(:)) = min(1,xtemp(p.binary_variables(:))); |
---|
84 | xtemp(p.binary_variables(:)) = max(0,xtemp(p.binary_variables(:))); |
---|
85 | xtemp = setnonlinearvariables(p,xtemp); |
---|
86 | if checkfeasiblefast(p,xtemp,p.options.bnb.feastol)%if res>-p.options.bnb.feastol |
---|
87 | x_min = xtemp; |
---|
88 | upper = p.f+x_min'*p.Q*x_min + p.corig'*x_min; |
---|
89 | return |
---|
90 | end |
---|
91 | end |
---|