1 | function p = preprocess_eval_bounds(p); |
---|
2 | if ~isempty(p.evalVariables) |
---|
3 | for i = 1:length(p.evalMap) |
---|
4 | arg = p.evalMap{i}.variableIndex; |
---|
5 | xL = p.lb(arg); |
---|
6 | xU = p.ub(arg); |
---|
7 | switch p.evalMap{i}.fcn |
---|
8 | case 'exp' |
---|
9 | p.lb(p.evalVariables(i)) = max([0 p.lb(p.evalVariables(i)) exp(xL)]); |
---|
10 | p.ub(p.evalVariables(i)) = min([p.ub(p.evalVariables(i)) exp(xU)]); |
---|
11 | case {'cos','sin'} |
---|
12 | if isequal(p.evalMap{i}.fcn,'cos') |
---|
13 | xL = xL + pi/2; |
---|
14 | xU = xU + pi/2; |
---|
15 | end |
---|
16 | |
---|
17 | neg = 0; |
---|
18 | if xL > 0 |
---|
19 | n = floor((xL/(2*pi))); |
---|
20 | xL = xL - n*2*pi; |
---|
21 | xU = xU - n*2*pi; |
---|
22 | else |
---|
23 | n = floor((-xL/(2*pi))); |
---|
24 | xL = xL + n*2*pi; |
---|
25 | xU = xU + n*2*pi; |
---|
26 | neg = 1; |
---|
27 | end |
---|
28 | yL = sin(xL); |
---|
29 | yU = sin(xU); |
---|
30 | L = min([yL yU]); |
---|
31 | U = max([yL yU]); |
---|
32 | if xL<pi/2 & xU>pi/2 |
---|
33 | U = 1; |
---|
34 | end |
---|
35 | if xL < 3*pi/2 & xU > 3*pi/2 |
---|
36 | L = -1; |
---|
37 | end |
---|
38 | if neg |
---|
39 | t = L; |
---|
40 | L = -U; |
---|
41 | U = -t; |
---|
42 | end |
---|
43 | p.lb(p.evalVariables(i)) = max([p.lb(p.evalVariables(i)) L]); |
---|
44 | p.ub(p.evalVariables(i)) = min([p.ub(p.evalVariables(i)) U]); |
---|
45 | |
---|
46 | case 'tan' |
---|
47 | n1 = fix((xL+pi/2)/(pi)); |
---|
48 | n2 = fix((xU+pi/2)/(pi)); |
---|
49 | if n1==n2 |
---|
50 | L = tan(xL); |
---|
51 | U = tan(xU); |
---|
52 | else |
---|
53 | L = -inf; |
---|
54 | U = inf; |
---|
55 | end |
---|
56 | p.lb(p.evalVariables(i)) = max([p.lb(p.evalVariables(i)) L]); |
---|
57 | p.ub(p.evalVariables(i)) = min([p.ub(p.evalVariables(i)) U]); |
---|
58 | |
---|
59 | |
---|
60 | case 'sdpfun' |
---|
61 | % We know nothing... |
---|
62 | % To get some kind of bounds, we jsut sample the function |
---|
63 | % and pick the min and max from there |
---|
64 | % this only works for simple functions |
---|
65 | if length(xL)>1 |
---|
66 | disp([p.evalMap{i}.fcn ' is not supported in the global solver (only scalar functions support)']) |
---|
67 | error([p.evalMap{i}.fcn ' is not supported in the global solver']) |
---|
68 | end |
---|
69 | xtest = linspace(xL,xU,100); |
---|
70 | values = feval(p.evalMap{i}.arg{2},xtest); |
---|
71 | [minval,minpos] = min(values); |
---|
72 | [maxval,maxpos] = min(values); |
---|
73 | xtestmin = linspace(xtest(max([1 minpos-5])),xtest(min([100 minpos+5])),100); |
---|
74 | xtestmax = linspace(xtest(max([1 maxpos-5])),xtest(min([100 maxpos+5])),100); |
---|
75 | values1 = feval(p.evalMap{i}.arg{2},xtestmin); |
---|
76 | values2 = feval(p.evalMap{i}.arg{2},linspace(xL,xU,100)); |
---|
77 | p.lb(p.evalVariables(i)) = max([p.lb(p.evalVariables(i)) min([values1 values2])]); |
---|
78 | p.ub(p.evalVariables(i)) = min([p.ub(p.evalVariables(i)) max([values1 values2])]); |
---|
79 | otherwise |
---|
80 | disp([p.evalMap{i}.fcn ' is not supported in the global solver']) |
---|
81 | error([p.evalMap{i}.fcn ' is not supported in the global solver']) |
---|
82 | end |
---|
83 | end |
---|
84 | end |
---|