source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/modules/global/feaspump.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.3 KB
Line 
1function [upper,x_min] = feaspump(p,x)
2
3% Assume we fail
4upper = inf;
5x_min = x;
6
7% These should be integer
8intvars = [p.integer_variables(:);p.binary_variables(:)];
9n = length(p.c);
10
11% Create rounded goal variable
12xround = x;
13xround(intvars) =  round(xround(intvars));
14
15p.c = [0*p.c;ones(n,1)];
16p.Q = blkdiag(0*p.Q,spalloc(n,n,0));
17
18f1 = [p.F_struc(1:p.K.f,:) zeros(p.K.f,n)];
19f2 = [p.F_struc(1+p.K.f:end,:) zeros(size(p.F_struc,1)-p.K.f,n)];
20p.F_struc = [f1;xround -eye(n) eye(n);-xround eye(n) eye(n);f2];
21p.K.l = p.K.l + 2*n;
22p.lb = [p.lb;-inf(n,1)];
23p.ub = [p.ub;inf(n,1)];
24
25% Append model with absolute value terms
26c = p.c;
27Q = p.Q;
28p.c = [0*p.c;ones(n,1)];
29p.Q = blkdiag(0*p.Q,spalloc(n,n,0));
30p.F_struc = [p.F_struc(1:p.K.f,:) zeros(p.K.f,n);
31    xround -eye(n) eye(n);
32    -xround eye(n) eye(n);
33    p.F_struc zeros(size(p.F_struc,1)-p.K.f,n)];
34p.monomtable = blkdiag(p.monomtable,eye(n));
35p.variabletype = [p.variabletype zeros(1,n)];
36p.K.l = p.K.l + 2*n;
37p.lb = [p.lb;-inf(n,1)];
38p.ub = [p.ub;inf(n,1)];
39
40iter = 1;
41xold = x;
42while iter < 10 & isinf(upper)
43
44    % Append model with absolute value terms
45    ii = p.integer_variables;
46    jj = p.binary_variables;
47    p.integer_variables = [];
48    p.binary_variables = [];
49    p.F_struc(1+p.K.f:p.K.f+2*n,1) = [xround;-xround];
50       
51    pumpsol = feval(p.solver.lower.call,p);
52    p.integer_variables = ii;
53    p.binary_variables = jj;
54   
55    % Fix the varying data
56    p.F_struc(1+p.K.f:1+p.K.f+2*n-1,1) = [xround;-xround];
57   
58    % Solve pumping problem
59    pumpsol = feval(p.solver.lower.call,p);
60   
61    % New solution (extract original variables)
62    xnew = pumpsol.Primal(1:n);
63   
64    if all(abs(xnew(intvars)-round(xnew(intvars))) < 1e-5)
65        % Feasible
66        upper = c'*xnew + xnew'*Q*xnew;
67        x_min = xnew(1:n);
68    else
69        % Stall?
70        if norm(xold-xnew) < 1e-3
71            % Yep, so flip the goal on some integers
72            [ii,jj] = sort(abs(xnew(intvars)-xround(intvars)));
73            flips = jj(end-(1+ceil(5*rand(1))):end);
74          %  for i  =1:length(jj)
75                xround(intvars(flips)) = (xround(intvars(flips))-1).^2;
76          %  end
77        else
78            xround = xnew;xold = xnew;
79            xround(intvars) =  round(xround(intvars));
80        end
81    end
82    iter = iter + 1;
83end
Note: See TracBrowser for help on using the repository browser.