-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsosprogram.m
More file actions
executable file
·192 lines (166 loc) · 6.29 KB
/
sosprogram.m
File metadata and controls
executable file
·192 lines (166 loc) · 6.29 KB
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
function sos = sosprogram(vartable,decvartable)
% SOSPROGRAM --- Initialize a new sum of squares program.
%
% SOSP = sosprogram(VARTABLE,DECVARTABLE)
%
% SOSP is a new sum of squares program.
% VARTABLE is a vector of independent variables.
% DECVARTABLE is a vector of decision variables (optional).
%
% Both VARTABLE and DECVARTABLE are either symbolic or polynomial objects.
%
% This file is part of SOSTOOLS - Sum of Squares Toolbox ver 4.00.
%
% Copyright (C)2002, 2004, 2013, 2016, 2018, 2021
% A. Papachristodoulou (1), J. Anderson (1),
% G. Valmorbida (2), S. Prajna (3),
% P. Seiler (4), P. A. Parrilo (5),
% M. Peet (6), D. Jagt (6)
% (1) Department of Engineering Science, University of Oxford, Oxford, U.K.
% (2) Laboratoire de Signaux et Systmes, CentraleSupelec, Gif sur Yvette,
% 91192, France
% (3) Control and Dynamical Systems - California Institute of Technology,
% Pasadena, CA 91125, USA.
% (4) Aerospace and Engineering Mechanics Department, University of
% Minnesota, Minneapolis, MN 55455-0153, USA.
% (5) Laboratory for Information and Decision Systems, M.I.T.,
% Massachusetts, MA 02139-4307
% (6) Cybernetic Systems and Controls Laboratory, Arizona State University,
% Tempe, AZ 85287-6106, USA.
%
% Send bug reports and feedback to: sostools@cds.caltech.edu
%
% 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, see <http://www.gnu.org/licenses/>.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Change log and developer notes
% 12/24/01 - SP
% 01/07/02 - SP
% 02/21/02 - SP -- Symbolic polynomial
% 10/10/02 - SP -- Path checking
% 12/15/21 - DJ -- Correction for 'sos.var.idx{1}' specification in dpvar case
% 02/09/22 - DJ -- Add check for mosek solver
% 05/04/23 - DJ -- Convert 'decvartable' to row vector in 'sym' case.
% 09/08/24 - DJ -- Ensure 'sym' sos.decvartable has opening and closing brackets
if ~exist('sedumi') && ~exist('sqlp') && ~exist('csdp') &&...
~exist('sdpnal') && ~exist('sdpnalplus') && ~exist('sdpam') &&...
~exist('cdcs') && ~exist('mosekopt')
error('No SDP solvers found.') ;
end
if ~exist('getpolysym')
dd = which('sosprogram');
dd = strrep(dd,'/sosprogram.m','/');
dd = strrep(dd,'\sosprogram.m','\');
pp = genpath(dd);
addpath(pp);
end
% Distinguish 'sym' and 'dpvar'/'pvar' implementation.
if isa(vartable,'sym')
% Initialize an empty optimization program
sos.var.num = 0;
sos.var.type = {};
sos.var.Z = {};
sos.var.ZZ = {};
sos.var.T = {};
sos.expr.num = 0;
sos.expr.type = {};
sos.expr.At = {};
sos.expr.b = {};
sos.expr.Z = {};
sos.extravar.num = 0;
sos.extravar.Z = {};
sos.extravar.ZZ = {};
sos.extravar.T = {};
sos.extravar.idx = {};
sos.objective = []; % 01/07/02
sos.solinfo.x = [];
sos.solinfo.y = [];
sos.solinfo.RRx = [];
sos.solinfo.RRy = [];
sos.solinfo.info = [];
% Set the independent variables.
assume(vartable,'real'); % DJ - 05/04/23
if ~isrow(vartable) %AP 30092020
vartable = vartable.';
end
sos.vartable = converttochar(vartable); % 30/09/2020 AP
% sos.vartable = sym2chartable(vartable); % 02/21/02
% if size(vartable,2) > 1
% vartable = vartable.';
% end;
sos.symvartable = vartable;
sos.varmat.vartable = '[]'; %JA&GV 06/06/13
sos.varmat.symvartable = [];
sos.varmat.count = 0;
% Set the decision variables.
if (nargin == 2 && ~isempty(decvartable))
assume(decvartable,'real'); % DJ - 05/04/23
if ~isrow(decvartable)
decvartable = decvartable.';
end
sos.objective = sparse(length(decvartable),1);
sos.decvartable = converttochar(decvartable); % 09/08/24
if size(decvartable,2) > 1
decvartable = decvartable.';%the transpose of a matrix of decision varibles
%it is put under this form in
%sos.symdecvartable (next line)
end
sos.symdecvartable = decvartable;
sos.var.idx{1} = length(find(sos.decvartable==','))+2;
else
sos.decvartable = '[]';
sos.symdecvartable = [];
sos.var.idx{1} = 1;
end
else
% Initialize an empty optimization program.
sos.var.num = 0;
sos.var.type = {};
sos.var.Z = {};
sos.var.ZZ = {};
sos.var.T = {};
sos.expr.num = 0;
sos.expr.type = {};
sos.expr.At = {};
sos.expr.b = {};
sos.expr.Z = {};
sos.extravar.num = 0;
sos.extravar.Z = {};
sos.extravar.ZZ = {};
sos.extravar.T = {};
sos.extravar.idx = {};
sos.objective = []; % 01/07/02
sos.solinfo.x = [];
sos.solinfo.y = [];
sos.solinfo.RRx = [];
sos.solinfo.RRy = [];
sos.solinfo.info = [];
% Set the independent variables.
sos.vartable = sort(vartable.varname);
sos.varmat.vartable = []; % PJS 9/9/2013
sos.varmat.symvartable = [];
sos.varmat.count = 0;
% Set the decision variables.
if (nargin == 2 && ~isempty(decvartable))
sos.objective = sparse(length(decvartable),1);
if isa(decvartable,'dpvar')
sos.decvartable = sort(decvartable.dvarname);
else
sos.decvartable = sort(decvartable.varname);
end
sos.var.idx{1} = length(sos.decvartable)+1; % DJ, 12/15/21
else
sos.decvartable = {};
sos.var.idx{1} = 1;
end
end