⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fromsdpa.m

📁 matlab中uwb波形优化算法经常会使用的工具包:SeDuMi_1_1R3.
💻 M
字号:
function [At,b,c,K]=fromsdpa(fname)% readsdpa Reads SDP problem from sparse SDPA-formatted input file.%    [At,b,c,K] = readsdpa(fname) produces conic optimization problem%    data, as can be used by sedumi. "fname" contains a full pathname%    to the SDPA 4.10-formatted file. (SDPA is a stand-alone solver for%    semidefinite programming, by Fujisawa, Kojima and Nakata.  It is%    used as a standard format in the collection SDPLIB by Borchers.)%%    To read and solve the problem "arch0", you may type%%    [At,b,c,K] = readsdpa('arch0.dat-s');%    [x,y,info] = sedumi(At,b,c,K);%%    The above 2 lines assume that arch0.dat-s is somewhere in your MATLAB%    search path, that it is not compressed, and that you know the extension%    'dat-s'.  To alleviate these conditions, you may like to use the script%    GETPROBLEM.%% SEE ALSO SeDuMi, getproblem, frompack, prelp.%% This file is part of SeDuMi 1.1 by Imre Polik and Oleksandr Romanko% Copyright (C) 2005 McMaster University, Hamilton, CANADA  (since 1.1)%% This program is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA% 02110-1301, USA%fid = fopen(fname,'r');if fid == -1    error('File not found.')end%The number of equality constraintsm='';while(isempty(m))    m = fscanf(fid,'%d',1);    if fgetl(fid)==-1;        error('Invalid SDPA file.')    endend%The number of blocksnblocks = fscanf(fid,'%d',1);if isempty(nblocks)    error('Invalid SDPA file.')endfgetl(fid);%The dimension of the blocks%Negative means diagonal block, we convert that to linear%.,(){} are omitteddims=sscanf(regexprep(fgetl(fid),'[\.\,(){}]',' '),'%d',nblocks)';if length(dims(dims==0))>0 | length(dims)~=nblocks    error('Invalid SDPA file.')endN=-sum(dims(dims<0))+sum(dims(dims>0).^2);nblocks=length(dims);%Create a vector with the offsets of the blocks.%This is one less than the blockstart!%Diagonal and one dimensional blocks are coming firstloffset=0;sdpoffset=sum(abs(dims(dims<=1)));offset=zeros(1,nblocks);for i=1:nblocks    if dims(i)<=1        offset(i)=loffset;        loffset=loffset+abs(dims(i));    else        offset(i)=sdpoffset;        sdpoffset=sdpoffset+dims(i)^2;    endend%This is needed so that we can compute where the second column startsstride=dims;stride(stride<0)=0;%Vector b%,(){} are omittedb = sscanf(regexprep(fgetl(fid),'[\,(){}]',' '),'%f',m);if length(b)~=m    error('Invalid SDPA file.')endif nnz(b)/m<0.1    b=sparse(b);end%CoefficientsE = fscanf(fid,'%d %d %d %d %f',[5. inf]);fclose(fid);%Extract the objectivecE=E(:,E(1,:)==0);%Repeating indices in the sparse matrix structure create the sum of%elements, we need to clear one for the diagonalsdata2=cE(5,:);data2(cE(3,:)==cE(4,:))=0;c=-sparse([offset(cE(2,:))+(cE(3,:)-1).*stride(cE(2,:))+cE(4,:),offset(cE(2,:))+(cE(4,:)-1).*stride(cE(2,:))+cE(3,:)],1,[cE(5,:),data2],N,1);clear cE data2AtE=E(:,E(1,:)~=0);clear Edata2=AtE(5,:);data2(AtE(3,:)==AtE(4,:))=0;At=sparse([offset(AtE(2,:))+(AtE(3,:)-1).*stride(AtE(2,:))+AtE(4,:),offset(AtE(2,:))+(AtE(4,:)-1).*stride(AtE(2,:))+AtE(3,:)],[AtE(1,:),AtE(1,:)],[AtE(5,:),data2],N,m);clear AtE data2K.l=-sum(dims(dims<0))+sum(dims==1);K.s=dims(dims>1);%Finally, let us correct the sparsity[i,j,v]=find(c);c=sparse(i,1,v,N,1);[i,j,v]=find(At);At=sparse(i,j,v,N,m);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -