File: initial_point.m

package info (click to toggle)
sdpa 7.3.20-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,688 kB
  • sloc: cpp: 15,021; sh: 4,870; makefile: 318; ansic: 81
file content (193 lines) | stat: -rw-r--r-- 4,256 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
function [x0,X0,Y0] = initial_point(filename,mDIM,nBLOCK,bLOCKsTRUCT)
%
% Read in a sparse initial point file
%
% [x0,X0,Y0] = initial_point(fname, mDIM, nBLOCK, bLOCKsTRUCT)
%
% <INPUT>
% - filename   : string ; filename of initial point file
% - mDIM       : integer; number of primal variables
% - nBLOCK     : integer; number of blocks of F
% - bLOCKsTRUCT: vector ; represetns the block structure of F
%
% <OUTPUT>
% - x0: vector    ; initial point of x
% - X0: cell array; initial point of X
% - Y0: cell array; initial point of Y
%

% This file is a component of SDPA
% Copyright (C) 2004-2020 SDPA Project
% 
% 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
% 
% SDPA-M: $Revision: 6.2 $
% $Id: initial_point.m,v 6.2 2005/05/28 02:36:40 drophead Exp $

% check the validity of arguments
if nargin ~= 4
  error('input arguments must be 4.');
else
  if ~ischar(filename)
    error('1st argument must be a filename.');
  end
end

% identify whether a file is sparse format or not.
bsparse=0;
len=length(filename);
if len >= 2
  str=filename(end-1:end);
  if strncmp(str,'-s',2) 
    bsparse=1;
  end
end
% disp(sprintf('sparse=%d',bsparse));

fid=fopen(filename,'r');
if fid == -1
  error(sprintf('Cannot open %s',filename));
end

x0=zeros(mDIM,1);
X0=cell(nBLOCK,1);
Y0=cell(nBLOCK,1);

% read initial point x0
for idx=1:mDIM
  x0(idx)=fscanf(fid,'%*[^0-9+-]%lg',1);
end

% read initial points X0, Y0
if bsparse
  % sparse format case
  while 1
    [k,cnt]=fscanf(fid,'%*[^0-9+-]%d',1);
    [l,cnt]=fscanf(fid,'%*[^0-9+-]%d',1);
    [i,cnt]=fscanf(fid,'%*[^0-9+-]%d',1);
    [j,cnt]=fscanf(fid,'%*[^0-9+-]%d',1);
    [value,cnt]=fscanf(fid,'%*[^0-9+-]%lg',1);
    if cnt
      if k == 1
	% X0
	if isempty(X0{l})
	  size=abs(bLOCKsTRUCT(l));
	  if bLOCKsTRUCT(l) < 0
	    X0{l}=sparse(zeros(size,1));
	  else
	    X0{l}=sparse(zeros(size));
	  end
	end
	if bLOCKsTRUCT(l) < 0
	  X0{l}(i)=value;
	else
	  if i < j
	    X0{l}(i,j)=value;
	    X0{l}(j,i)=value;
	  elseif i == j
	    X0{l}(i,j)=value;
	  end
	end
      elseif k==2
	% Y0
	if isempty(Y0{l})
	  size=abs(bLOCKsTRUCT(l));
	  if bLOCKsTRUCT(l) < 0
	    Y0{l}=sparse(zeros(size,1));
	  else
	    Y0{l}=sparse(zeros(size));
	  end
	end
	if bLOCKsTRUCT(l) < 0
	  Y0{l}(i)=value;
	else
	  if i < j
	    Y0{l}(i,j)=value;
	    Y0{l}(j,i)=value;
	  elseif i == j
	    Y0{l}(i,j)=value;
	  end
	end
      end
    else 
      break;
    end
  end
else
  % dense format case
  
  % X0
  for l=1:nBLOCK
    size=abs(bLOCKsTRUCT(l));
    if bLOCKsTRUCT(l) > 0
      X0{l}=zeros(size);
      for i=1:size
	for j=1:size
	  [value,cnt]=fscanf(fid,'%*[^0-9+-]%lg',1);
	  if cnt
	    X0{l}(i,j)=value;
	  else
	    error(sprintf('Failed to read an element X0 at %d %d %d'),...
	      l,i,j);
	  end
	end
      end
    else
      X0{l}=zeros(size,1);
      for i=1:size
	[value,cnt]=fscanf(fid,'%*[^0-9+-]%lg',1);
	if cnt
	  X0{l}(i)=value;
	else
	  error(sprintf('Failed to read an element X0 at %d %d %d'),...
	    l,i,i);
	end
      end
    end
  end
  
  % Y0
  for l=1:nBLOCK
    size=abs(bLOCKsTRUCT(l));
    if bLOCKsTRUCT(l) > 0
      Y0{l}=zeros(size);
      for i=1:size
	for j=1:size
	  [value,cnt]=fscanf(fid,'%*[^0-9+-]%lg',1);
	  if cnt
	    Y0{l}(i,j)=value;
	  else
	    error(sprintf('Failed to read an element Y0 at %d %d %d'),...
	      l,i,j);
	  end
	end
      end
    else
      Y0{l}=zeros(size,1);
      for i=1:size
	[value,cnt]=fscanf(fid,'%*[^0-9+-]%lg',1);
	if cnt
	  Y0{l}(i)=value;
	else
	  error(sprintf('Failed to read an element Y0 at %d %d %d'),...
	    l,i,i);
	end
      end
    end
  end
end
fclose(fid);

% End of File