Home > utilities > sed2pen.m

# sed2pen

## PURPOSE

%*******************************************************************

## SYNOPSIS

function pen=sed2pen(fname, compressed);

## DESCRIPTION

    %*******************************************************************
     SED2PEN converts problem data in SeDuMi format to expanded SDPA format.

     [pen] = sdpa2pen(fname)

     Input: fname...name of the file containing SDP data in SDPA format

     Output: pen...structure with data arrays in PENLIB format

     Copyright (c) 2002 by M. Kocvara and M. Stingl
     Version 02/12/2002
    ******************************************************************

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 %%*******************************************************************
    0002 % SED2PEN converts problem data in SeDuMi format to expanded SDPA format.
    0003 %
    0004 % [pen] = sdpa2pen(fname)
    0005 %
    0006 % Input: fname...name of the file containing SDP data in SDPA format
    0007 %
    0008 % Output: pen...structure with data arrays in PENLIB format
    0009 %
    0010 % Copyright (c) 2002 by M. Kocvara and M. Stingl
    0011 % Version 02/12/2002
    0012 %******************************************************************
    0013
    0014   function pen=sed2pen(fname, compressed);
    0015 %%
    0016 %  First, load the matlab file containing At, c, b, and K
    0017 %%
    0018
    0019 clear pen;
    0020
    0021   K.q = [];
    0022   K.l = [];
    0023   A = 0;
    0024   At = 0;
    0025   AAk = 0;
    0026   ii = 0;
    0027   ss = 0;
    0028   fname2 = strcat(fname,'.dat-s');
    0029
    0030   compressed=0;
    0031   if (compressed == 1);
    0032      fprintf('** Unzip Problem. \n');
    0033      unix(['gunzip ', fname,'.mat.gz']);
    0034   elseif (compressed == 2);
    0035      unix(['uncompress ', fname,'.mat.Z']);
    0036   end
    0037   if exist([fname,'.mat']) | exist(fname)
    0038      eval(['load ', fname]);
    0039   else
    0040      fprintf('** Problem not found, please specify the correct path. \n');
    0041      return;
    0042   end
    0043   if (compressed == 1)
    0044      unix(['gzip ', fname,'.mat']);
    0045   elseif (compressed == 2)
    0046      unix(['compress ', fname,'.mat']);
    0047   end
    0048
    0049 %%
    0050   if (size(c,1) == 1), c = c'; end;
    0051   if (size(b,1) == 1), b = b'; end;
    0052   if (At == 0), At = A'; end;  clear A;
    0053 %  if (At == 0), At = A'; end;  clear A;
    0054   [nn,mm] = size(At);
    0055   if length(b)==nn, At=At'; [nn,mm] = size(At); end
    0056   if (max(size(c)) == 1); c = c*ones(nn,1); end;
    0057
    0058   if ~isfield(K,'l'); K.l = 0; end
    0059   if ~isfield(K,'f'); K.f = 0; end
    0060   %if ~isfield(K,'q'); K.q = 0; end
    0061   if ~isfield(K,'s'); K.s = 0; end
    0062   if isempty(K.l) | K.l == 0; K.l = 0; end;
    0063   if isempty(K.f) | K.f == 0; K.f = 0; end;
    0064   %if sum(K.q) == 0 | isempty(K.q); K.q = 0; end
    0065   if sum(K.s) == 0 | isempty(K.s); K.s = 0; end
    0066   m = length(b);
    0067   pen.vars = m;
    0068   %fprintf(fid,'%d\n',m);
    0069   llen = 0;
    0070   offset1 = 0;
    0071   offset2 = 0;
    0072   if(K.l > 0); llen = llen + length(K.l); end;
    0073   offset1 = llen;
    0074   %if(K.q > 0); llen = llen + length(K.q); end;
    0075   offset2 = llen;
    0076   if(K.s > 0); llen = llen + length(K.s); end;
    0077   %fprintf(fid,'%d\n',llen);
    0078
    0079   pen.fobj = full(b);
    0080
    0081   rowidx = 0;  idxblk = 0;  aidx = 0; bk1 = 1; hidx = 0;
    0082
    0083   pen.constr = 0; pen.ci = 0; pen.bi_dim = 0; pen.bi_idx = 0; pen.bi_val = 0;
    0084    if ~(K.l == 0) | ~(K.f == 0)
    0085       len = K.l + K.f;
    0086       pen.constr = len + K.f;
    0087       pen.ci = c(1:len);
    0088       if (K.l == 0)
    0089          if (K.f ~= 0), pen.ci = full([c(1:K.f);-c(1:K.f)]);end;
    0090       else
    0091          if (K.f ~= 0), pen.ci = full([c(1:K.f);-c(1:K.f)';c(K.f+1,len)]);end;
    0092       end
    0093       idxblk = idxblk + 1;
    0094       if(K.f == 0)
    0095          for k = 1:len
    0096              Atmp = At(rowidx+k,:);
    0097             [ii,jj,ss] = find(Atmp);
    0098             pen.bi_dim(k) = nnz(Atmp);
    0099             pen.bi_idx(bk1:bk1+nnz(Atmp)-1) = jj-1;
    0100             pen.bi_val(bk1:bk1+nnz(Atmp)-1) = -ss;
    0101             bk1 = bk1 + nnz(Atmp);
    0102             % for kk = 1:nnz(Atmp)
    0103            %    fprintf(fid,'%5d %5d %5d %5d %.16f\n',jj(kk),1,k,k,-ss(kk));
    0104            % end
    0105          end
    0106       else
    0107          for k = 1:K.f
    0108              Atmp = At(rowidx+k,:);
    0109             [ii,jj,ss] = find(Atmp);
    0110             pen.bi_dim(k) = nnz(Atmp);
    0111             pen.bi_idx(bk1:bk1+nnz(Atmp)-1) = jj-1;
    0112             pen.bi_val(bk1:bk1+nnz(Atmp)-1) = -ss;
    0113             bk1 = bk1 + nnz(Atmp);
    0114              % for kk = 1:nnz(Atmp)
    0115             %    fprintf(fid,'%5d %5d %5d %5d %.16f\n',jj(kk),1,k,k,-ss(kk));
    0116             % end
    0117          end
    0118          for k = 1:K.f
    0119              Atmp = At(rowidx+k,:);
    0120             [ii,jj,ss] = find(Atmp);
    0121             pen.bi_dim(K.f+k) = nnz(Atmp);
    0122             pen.bi_idx(bk1:bk1+nnz(Atmp)-1) = jj-1;
    0123             pen.bi_val(bk1:bk1+nnz(Atmp)-1) = ss;
    0124             bk1 = bk1 + nnz(Atmp);
    0125              % for kk = 1:nnz(Atmp)
    0126             %    fprintf(fid,'%5d %5d %5d %5d %.16f\n',jj(kk),1,k,k,-ss(kk));
    0127             % end
    0128          end
    0129          if (K.l ~= 0)
    0130             for k = K.f+1,len
    0131                 Atmp = At(rowidx+k,:);
    0132                [ii,jj,ss] = find(Atmp);
    0133                pen.bi_dim(K.f+k) = nnz(Atmp);
    0134                pen.bi_idx(bk1:bk1+nnz(Atmp)-1) = jj-1;
    0135                pen.bi_val(bk1:bk1+nnz(Atmp)-1) = -ss;
    0136                bk1 = bk1 + nnz(Atmp);
    0137                 % for kk = 1:nnz(Atmp)
    0138                %    fprintf(fid,'%5d %5d %5d %5d %.16f\n',jj(kk),1,k,k,-ss(kk));
    0139                % end
    0140             end
    0141          end
    0142       end
    0143       rowidx = rowidx + len;
    0144    end
    0145
    0146    if ~(K.s == 0)
    0147       blksize = K.s;
    0148       if size(blksize,2) == 1; blksize = blksize'; end
    0149       pen.ai_dim = zeros(1,length(blksize));
    0150       pen.msizes = blksize;
    0151       pen.mconstr = length(blksize);
    0152       blknnz = [0 cumsum(blksize.*blksize)];
    0153       for p = 1:length(blksize)
    0154              idxblk = idxblk + 1;
    0155           n = blksize(p);
    0156           Ctmp = c(rowidx+blknnz(p)+[1:n*n]);
    0157           nn = nnz(Ctmp);
    0158           if(nn>0)
    0159              aidx = aidx + 1;
    0160              pen.ai_dim(p) = 1;
    0161              pen.ai_idx(aidx) = 0;
    0162              [ii,jj,ss] = find(Ctmp);
    0163              iinz = 0;
    0164              for kk = 1:nn
    0165                 idxi = fix(((ii(kk)-1)./n)+1);
    0166                 idxj = mod(ii(kk)-1,n)+1;
    0167                 if ~(idxi > idxj)
    0168                    hidx = hidx + 1;
    0169                    iinz = iinz + 1;
    0170                    pen.ai_val(hidx) = -ss(kk);
    0171                    pen.ai_row(hidx) = idxi-1;
    0172                    pen.ai_col(hidx) = idxj-1;
    0173                    %fprintf(fid,'%5d %5d %5d %5d %.16f\n',0,p+offset2,idxi,idxj,-ss(kk));
    0174                 end
    0175              end
    0176              pen.ai_nzs(aidx) = iinz;
    0177           end
    0178
    0179           Atmp = At(rowidx+blknnz(p)+[1:n*n],:);
    0180           for k = 1:m
    0181              AAk = Atmp(:,k);
    0182              nn = nnz(AAk);
    0183              if(nn>0)
    0184                 aidx = aidx + 1;
    0185                 pen.ai_dim(p) = pen.ai_dim(p) + 1;
    0186                 pen.ai_idx(aidx) = k;
    0187                 iinz = 0;
    0188                 [ii,jj,ss] = find(AAk);
    0189                 for kk = 1:nn
    0190                    idxi = fix(((ii(kk)-1)./n)+1);
    0191                    idxj = mod(ii(kk)-1,n)+1;
    0192                    if ~(idxi > idxj)
    0193                       hidx = hidx + 1;
    0194                       iinz = iinz + 1;
    0195                       pen.ai_val(hidx) = -ss(kk);
    0196                       pen.ai_row(hidx) = idxi-1;
    0197                       pen.ai_col(hidx) = idxj-1;
    0198                       %fprintf(fid,'%5d %5d %5d %5d %.16f\n',k,p+offset2,idxi,idxj,-ss(kk));
    0199                    end
    0200                 end
    0201                 pen.ai_nzs(aidx) = iinz;
    0202              end
    0203           end
    0204        end
    0205     end
    0206 %%
    0207 pen.x0 = zeros(1,pen.vars);
    0208
    0209 %pen.ioptions = [0];
    0210
    0211 %pen.foptions = [0];
    0212
    0213
    0214 pen.ioptions = [1 50 100 2 0 1 0 0 3 2 0 0 2 1 1];
    0215
    0216 pen.foptions = [1 0.7 0.1 1.0E-4 1.0E-7 1.0E-14 1.0E-2 1.0 0.5 1.0 1.0e-6 0.05];