[37] | 1 | function [c,Q,f,onlyfeasible] = createobjective(h,G,options,quad_info) |
---|
| 2 | %CREATEOBJECTIVE Internal function to extract data related to objective function |
---|
| 3 | |
---|
| 4 | % Author Johan Löfberg |
---|
| 5 | % $Id: createobjective.m,v 1.7 2006/05/23 11:43:13 joloef Exp $ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | onlyfeasible = 0; |
---|
| 9 | nvars = yalmip('nvars'); |
---|
| 10 | if isempty(h) |
---|
| 11 | c=zeros(nvars,1); |
---|
| 12 | Q = spalloc(nvars,nvars,0); |
---|
| 13 | f = 0; |
---|
| 14 | if isempty(G) |
---|
| 15 | onlyfeasible = 1; |
---|
| 16 | end |
---|
| 17 | else |
---|
| 18 | [n,m]=size(h); |
---|
| 19 | if n*m>1 |
---|
| 20 | error('Scalar expression to minimize please.'); |
---|
| 21 | else |
---|
| 22 | % Should check quadratic!! |
---|
| 23 | if ~(options.relax == 1 | options.relax == 3) & ~isempty(quad_info) |
---|
| 24 | Qh = quad_info.Q; |
---|
| 25 | ch = quad_info.c; |
---|
| 26 | f = quad_info.f; |
---|
| 27 | xvar = quad_info.x; |
---|
| 28 | lmi_variables = getvariables(xvar); |
---|
| 29 | c = zeros(nvars,1); |
---|
| 30 | Q = spalloc(nvars,nvars,0); |
---|
| 31 | for i=1:length(lmi_variables) |
---|
| 32 | c(lmi_variables(i))=ch(i); |
---|
| 33 | end |
---|
| 34 | if nnz(Qh)>0 |
---|
| 35 | [i,j,k] = find(Qh); |
---|
| 36 | i = lmi_variables(i); |
---|
| 37 | j = lmi_variables(j); |
---|
| 38 | Q = sparse(i,j,k,nvars,nvars); |
---|
| 39 | % This has to be sped up... |
---|
| 40 | % for i = 1:length(lmi_variables) |
---|
| 41 | % for j = 1:length(lmi_variables) |
---|
| 42 | % Q(lmi_variables(i),lmi_variables(j))=Qh(i,j); |
---|
| 43 | % end |
---|
| 44 | % end |
---|
| 45 | end |
---|
| 46 | else |
---|
| 47 | % A relaxed problem should not calculate quadratic |
---|
| 48 | % decomposistion, fix! |
---|
| 49 | c=zeros(nvars,1); |
---|
| 50 | lmi_variables = getvariables(h); |
---|
| 51 | base = getbase(h);base= base(2:end); |
---|
| 52 | c(lmi_variables) = base; |
---|
| 53 | Q = spalloc(nvars,nvars,0); |
---|
| 54 | f = full(getbasematrix(h,0)); |
---|
| 55 | end |
---|
| 56 | end |
---|
| 57 | end |
---|