1 | function output = callfminsearch(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: callfminsearch.m,v 1.2 2005/05/07 13:53:20 joloef Exp $ |
---|
5 | |
---|
6 | % Retrieve needed data |
---|
7 | options = interfacedata.options; |
---|
8 | F_struc = interfacedata.F_struc; |
---|
9 | c = interfacedata.c; |
---|
10 | K = interfacedata.K; |
---|
11 | x0 = interfacedata.x0; |
---|
12 | Q = interfacedata.Q; |
---|
13 | lb = interfacedata.lb; |
---|
14 | ub = interfacedata.ub; |
---|
15 | monomtable = interfacedata.monomtable; |
---|
16 | |
---|
17 | switch options.verbose |
---|
18 | case 0 |
---|
19 | options.fmincon.Display = 'off'; |
---|
20 | case 1 |
---|
21 | options.fmincon.Display = 'final'; |
---|
22 | otherwise |
---|
23 | options.fmincon.Display = 'iter'; |
---|
24 | end |
---|
25 | |
---|
26 | % Do some pre-calc to be used in calls from fmincon |
---|
27 | temp = sum(interfacedata.monomtable,2)>1; |
---|
28 | nonlinearindicies = find(temp); |
---|
29 | linearindicies = find(~temp); |
---|
30 | interfacedata.nonlinearindicies = nonlinearindicies; |
---|
31 | interfacedata.linearindicies = linearindicies; |
---|
32 | |
---|
33 | Aeq = []; |
---|
34 | beq = []; |
---|
35 | A = []; |
---|
36 | b = []; |
---|
37 | |
---|
38 | if isfield(options.fminsearch,'LargeScale') |
---|
39 | if isequal(options.fminsearch.LargeScale,'off') |
---|
40 | A = full(A); |
---|
41 | b = full(b); |
---|
42 | Aeq = full(Aeq); |
---|
43 | beq = full(beq); |
---|
44 | end |
---|
45 | end |
---|
46 | |
---|
47 | if isempty(x0) |
---|
48 | x0 = zeros(length(linearindicies),1); |
---|
49 | else |
---|
50 | x0 = x0(linearindicies); |
---|
51 | end |
---|
52 | |
---|
53 | if options.savedebug |
---|
54 | ops = options.fminsearch; |
---|
55 | save fmincondebug interfacedata A b Aeq beq x0 ops |
---|
56 | end |
---|
57 | |
---|
58 | showprogress('Calling FMINSEARCH',options.showprogress); |
---|
59 | fmincon_fun([],[],[],interfacedata); % initialize persistent |
---|
60 | fmincon_con([],[],[],interfacedata); % initialize persistent |
---|
61 | solvertime = clock; |
---|
62 | [xout,fmin,flag,output] = fminsearch('fmincon_fun',x0,options.fminsearch); |
---|
63 | solvertime = etime(clock,solvertime); |
---|
64 | |
---|
65 | if isempty(nonlinearindicies) |
---|
66 | x = xout(:); |
---|
67 | else |
---|
68 | x = zeros(length(interfacedata.c),1); |
---|
69 | for i = 1:length(linearindicies) |
---|
70 | x(linearindicies(i)) = xout(i); |
---|
71 | end |
---|
72 | end |
---|
73 | |
---|
74 | problem = 0; |
---|
75 | |
---|
76 | % Internal format for duals |
---|
77 | D_struc = []; |
---|
78 | |
---|
79 | % Check, currently not exhaustive... |
---|
80 | if flag==0 |
---|
81 | problem = 3; |
---|
82 | else |
---|
83 | if flag>0 |
---|
84 | problem = 0; |
---|
85 | else |
---|
86 | if isempty(x) |
---|
87 | x = repmat(nan,length(c),1); |
---|
88 | end |
---|
89 | if 0%any((A*x-b)>sqrt(eps)) | any( abs(Aeq*x-beq)>sqrt(eps)) |
---|
90 | problem = 1; % Likely to be infeasible |
---|
91 | else |
---|
92 | if c'*x<-1e10 % Likely unbounded |
---|
93 | problem = 2; |
---|
94 | else % Probably convergence issues |
---|
95 | problem = 5; |
---|
96 | end |
---|
97 | end |
---|
98 | end |
---|
99 | end |
---|
100 | infostr = yalmiperror(problem,'FMINSEARCH'); |
---|
101 | |
---|
102 | % Save all data sent to solver? |
---|
103 | if options.savesolverinput |
---|
104 | solverinput.A = A; |
---|
105 | solverinput.b = b; |
---|
106 | solverinput.Aeq = Aq; |
---|
107 | solverinput.beq = beq; |
---|
108 | solverinput.c = c; |
---|
109 | solverinput.H = Q; |
---|
110 | solverinput.options = options.quadprog; |
---|
111 | else |
---|
112 | solverinput = []; |
---|
113 | end |
---|
114 | |
---|
115 | % Save all data from the solver? |
---|
116 | if options.savesolveroutput |
---|
117 | solveroutput.x = x; |
---|
118 | solveroutput.fmin = fmin; |
---|
119 | solveroutput.flag = flag; |
---|
120 | solveroutput.output=output; |
---|
121 | solveroutput.lambda=lambda; |
---|
122 | else |
---|
123 | solveroutput = []; |
---|
124 | end |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | % Standard interface |
---|
129 | output.Primal = x; |
---|
130 | output.Dual = D_struc; |
---|
131 | output.Slack = []; |
---|
132 | output.problem = problem; |
---|
133 | output.infostr = infostr; |
---|
134 | output.solverinput = solverinput; |
---|
135 | output.solveroutput= solveroutput; |
---|
136 | output.solvertime = solvertime; |
---|