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

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

Added original make3d

File size: 3.3 KB
Line 
1function [Matrices,infeasible]  = derive_bounds(Matrices,options)
2
3A = [Matrices.G -Matrices.E];
4b = [Matrices.W];
5Aeq = [Matrices.Aeq Matrices.Beq];
6beq = [Matrices.beq];
7lb = Matrices.lb;
8ub = Matrices.ub;
9
10oldlb = lb;
11oldub = ub;
12
13fixed = find(lb == ub);
14notfixed = setdiff(1:length(ub),fixed);
15
16if ~isempty(fixed)
17    AA = A;
18    bb = b;
19    nn =     lb(fixed);
20    b = b-A(:,fixed)*lb(fixed);
21    A(:,fixed) = [];
22
23    lb = lb(notfixed);
24    ub = ub(notfixed);
25end
26
27if ~isempty(fixed) & ~isempty(Aeq)
28    beq = beq-Aeq(:,fixed)*nn;
29    Aeq(:,fixed) = [];
30end
31
32n = size(A,2);
33In = eye(n);
34
35% Detect slacks and avoid maximizing them (they are unbounded)
36trivially_unbounded_above = zeros(n,1);
37trivially_unbounded_above(find(sum(A,1) == -sum(abs(A),1) & isinf(ub)')) = 1;
38trivially_unbounded_below = zeros(n,1);
39trivially_unbounded_below(find(sum(A,1) == sum(abs(A),1) & isinf(lb)')) = 1;
40if ~isempty(Aeq)
41    trivially_unbounded_below(find(any(Matrices.Aeq,1))) = 0;
42    trivially_unbounded_above(find(any(Matrices.Aeq,1))) = 0;
43end
44
45reset_to_minus_inf = find(isinf(ub(find(trivially_unbounded_below))));
46reset_to_inf = find(isinf(ub(find(trivially_unbounded_above))));
47
48lb=max(-1e7,lb);
49ub=min(1e7,ub);
50u = ub;
51l = lb;
52
53for i=1:n,
54
55    if ~trivially_unbounded_above(i)
56        f=-In(:,i);
57
58        finite_lb = find(~isinf(l));
59        finite_ub = find(~isinf(u));
60        Abounds = [A;In(finite_ub,:);-In(finite_lb,:)];
61        bbounds = [b;u(finite_ub,:);-l(finite_lb,:)];
62
63        Abounds = [A;eye(n);-eye(n)];
64        bbounds = [b;u;-l];
65
66        [x,fval,lambda,exitflag,how]=mpt_solveLP(f(:)',Abounds,bbounds,[],[],[],options.mpt.lpsolver);
67        if isequal(how,'infeasible')
68            Matrices.lb = repmat(inf,length(oldlb),1);
69            Matrices.ub = repmat(-inf,length(oldlb),1);
70            infeasible = 1;
71            return
72        end
73        u(i,1)=min(u(i,1),x(i));
74    end
75
76    if ~trivially_unbounded_below(i)
77        f=In(:,i);
78        finite_lb = find(~isinf(l));
79        finite_ub = find(~isinf(u));
80        Abounds = [A;In(finite_ub,:);-In(finite_lb,:)];
81        bbounds = [b;u(finite_ub,:);-l(finite_lb,:)];
82
83        Abounds = [A;eye(n);-eye(n)];
84        bbounds = [b;u;-l];
85
86        [x,fval,lambda,exitflag,how]=mpt_solveLP(f(:)',Abounds,bbounds,[],[],[],options.mpt.lpsolver);
87        if isequal(how,'infeasible')
88            Matrices.lb = repmat(inf,length(oldlb),1);
89            Matrices.ub = repmat(-inf,length(oldlb),1);
90            infeasible = 1;
91            return
92        end
93        l(i,1)=max(lb(i),x(i));
94    end
95
96end
97
98ll = oldlb;
99if ~isempty(notfixed)
100    ll(notfixed) = l;
101end
102l = ll;
103uu = oldub;
104if ~isempty(notfixed)
105    uu(notfixed) = u;
106end
107u = uu;
108infeasible = 0;
109
110% Now find bounds from equalities
111candidates = find(sum(Aeq | Aeq,2)==1);
112if length(candidates)>0
113    for i = candidates(:)'
114        j = find(Aeq(i,:));
115        new_bound = beq(i)/Aeq(i,j);
116        if any(u(j) < new_bound) | any(l(j)> new_bound)
117            infeasible = 1;
118            return
119        else
120            u(j)=new_bound;
121            l(j)=new_bound;
122        end
123    end
124end
125
126trivially_unbounded_below = find(trivially_unbounded_below);
127trivially_unbounded_above = find(trivially_unbounded_above);
128lb(trivially_unbounded_below(reset_to_minus_inf)) = -inf;
129ub(trivially_unbounded_above(reset_to_inf)) = inf;
130Matrices.lb = lb;
131Matrices.ub = ub;
Note: See TracBrowser for help on using the repository browser.