| 1 | %
|
|---|
| 2 | % constructor for the linear_equality_constraint class.
|
|---|
| 3 | %
|
|---|
| 4 | % [lec]=linear_equality_constraint(varargin)
|
|---|
| 5 | %
|
|---|
| 6 | % where the required varargin are:
|
|---|
| 7 | % matrix (double row, variable coefficients, NaN)
|
|---|
| 8 | % target (double vector, target values, 0.)
|
|---|
| 9 | % and the optional varargin and defaults are:
|
|---|
| 10 | % scale_type (char, scaling type, 'none')
|
|---|
| 11 | % scale (double, scaling factor, 1.)
|
|---|
| 12 | %
|
|---|
| 13 | % note that zero arguments constructs a default instance; one
|
|---|
| 14 | % argument of the class copies the instance; and two or more
|
|---|
| 15 | % arguments constructs a new instance from the arguments.
|
|---|
| 16 | %
|
|---|
| 17 | % "Copyright 2009, by the California Institute of Technology.
|
|---|
| 18 | % ALL RIGHTS RESERVED. United States Government Sponsorship
|
|---|
| 19 | % acknowledged. Any commercial use must be negotiated with
|
|---|
| 20 | % the Office of Technology Transfer at the California Institute
|
|---|
| 21 | % of Technology. (J. Schiermeier, NTR 47078)
|
|---|
| 22 | %
|
|---|
| 23 | % This software may be subject to U.S. export control laws.
|
|---|
| 24 | % By accepting this software, the user agrees to comply with
|
|---|
| 25 | % all applicable U.S. export laws and regulations. User has the
|
|---|
| 26 | % responsibility to obtain export licenses, or other export
|
|---|
| 27 | % authority as may be required before exporting such information
|
|---|
| 28 | % to foreign countries or providing access to foreign persons."
|
|---|
| 29 | %
|
|---|
| 30 | classdef linear_equality_constraint
|
|---|
| 31 | properties
|
|---|
| 32 | matrix = NaN;
|
|---|
| 33 | target = 0.;
|
|---|
| 34 | scale_type='none';
|
|---|
| 35 | scale = 1.;
|
|---|
| 36 | end
|
|---|
| 37 |
|
|---|
| 38 | methods
|
|---|
| 39 | function [lec]=linear_equality_constraint(varargin)
|
|---|
| 40 |
|
|---|
| 41 | switch nargin
|
|---|
| 42 |
|
|---|
| 43 | % create a default object
|
|---|
| 44 |
|
|---|
| 45 | case 0
|
|---|
| 46 |
|
|---|
| 47 | % copy the object
|
|---|
| 48 |
|
|---|
| 49 | case 1
|
|---|
| 50 | if isa(varargin{1},'linear_equality_constraint')
|
|---|
| 51 | lec=varargin{1};
|
|---|
| 52 | else
|
|---|
| 53 | error('Object ''%s'' is a ''%s'' class object, not ''%s''.',...
|
|---|
| 54 | inputname(1),class(varargin{1}),'linear_equality_constraint');
|
|---|
| 55 | end
|
|---|
| 56 |
|
|---|
| 57 | % create the object from the input
|
|---|
| 58 |
|
|---|
| 59 | otherwise
|
|---|
| 60 | if (size(varargin{1},1) == array_numel(varargin{2:min(nargin,4)}) || ...
|
|---|
| 61 | size(varargin{1},1) == 1)
|
|---|
| 62 | asizec=num2cell(array_size(varargin{2:min(nargin,4)}));
|
|---|
| 63 | elseif (array_numel(varargin{2:min(nargin,4)}) == 1)
|
|---|
| 64 | asizec=num2cell([size(varargin{1},1) 1]);
|
|---|
| 65 | else
|
|---|
| 66 | error('Matrix for object of class ''%s'' has inconsistent number of rows.',...
|
|---|
| 67 | class(lec));
|
|---|
| 68 | end
|
|---|
| 69 | lec(asizec{:})=linear_equality_constraint;
|
|---|
| 70 | clear asizec
|
|---|
| 71 |
|
|---|
| 72 | for i=1:numel(lec)
|
|---|
| 73 | if (size(varargin{1},1) > 1)
|
|---|
| 74 | lec(i).matrix =varargin{1}(i,:);
|
|---|
| 75 | else
|
|---|
| 76 | lec(i).matrix =varargin{1};
|
|---|
| 77 | end
|
|---|
| 78 | end
|
|---|
| 79 |
|
|---|
| 80 | if (nargin >= 2)
|
|---|
| 81 | for i=1:numel(lec)
|
|---|
| 82 | if (numel(varargin{2}) > 1)
|
|---|
| 83 | lec(i).target =varargin{2}(i);
|
|---|
| 84 | else
|
|---|
| 85 | lec(i).target =varargin{2};
|
|---|
| 86 | end
|
|---|
| 87 | end
|
|---|
| 88 | if (nargin >= 3)
|
|---|
| 89 | if ischar(varargin{3})
|
|---|
| 90 | varargin{3}=cellstr(varargin{3});
|
|---|
| 91 | end
|
|---|
| 92 | for i=1:numel(lec)
|
|---|
| 93 | if (numel(varargin{3}) > 1)
|
|---|
| 94 | lec(i).scale_type=varargin{3}{i};
|
|---|
| 95 | else
|
|---|
| 96 | lec(i).scale_type=char(varargin{3});
|
|---|
| 97 | end
|
|---|
| 98 | end
|
|---|
| 99 | if (nargin >= 4)
|
|---|
| 100 | for i=1:numel(lec)
|
|---|
| 101 | if (numel(varargin{4}) > 1)
|
|---|
| 102 | lec(i).scale =varargin{4}(i);
|
|---|
| 103 | else
|
|---|
| 104 | lec(i).scale =varargin{4};
|
|---|
| 105 | end
|
|---|
| 106 | end
|
|---|
| 107 |
|
|---|
| 108 | if (nargin > 4)
|
|---|
| 109 | warning('linear_equality_constraint:extra_arg',...
|
|---|
| 110 | 'Extra arguments for object of class ''%s''.',...
|
|---|
| 111 | class(lec));
|
|---|
| 112 | end
|
|---|
| 113 | end
|
|---|
| 114 | end
|
|---|
| 115 | end
|
|---|
| 116 | end
|
|---|
| 117 | end
|
|---|
| 118 |
|
|---|
| 119 | function []=disp(lec)
|
|---|
| 120 |
|
|---|
| 121 | % display the object
|
|---|
| 122 |
|
|---|
| 123 | disp(sprintf('\n'));
|
|---|
| 124 | for i=1:numel(lec)
|
|---|
| 125 | disp(sprintf('class ''%s'' object ''%s%s'' = \n',...
|
|---|
| 126 | class(lec),inputname(1),string_dim(lec,i)));
|
|---|
| 127 | disp(sprintf(' matrix: %s' ,string_vec(lec(i).matrix)));
|
|---|
| 128 | disp(sprintf(' target: %g' ,lec(i).target));
|
|---|
| 129 | disp(sprintf(' scale_type: ''%s''' ,lec(i).scale_type));
|
|---|
| 130 | disp(sprintf(' scale: %g\n' ,lec(i).scale));
|
|---|
| 131 | end
|
|---|
| 132 |
|
|---|
| 133 | end
|
|---|
| 134 |
|
|---|
| 135 | function [matrix]=prop_matrix(lec)
|
|---|
| 136 | matrix=zeros(numel(lec),0);
|
|---|
| 137 | for i=1:numel(lec)
|
|---|
| 138 | matrix(i,1:size(lec(i).matrix,2))=lec(i).matrix(1,:);
|
|---|
| 139 | end
|
|---|
| 140 | end
|
|---|
| 141 | function [lower] =prop_lower(lec)
|
|---|
| 142 | lower=[];
|
|---|
| 143 | end
|
|---|
| 144 | function [upper] =prop_upper(lec)
|
|---|
| 145 | upper=[];
|
|---|
| 146 | end
|
|---|
| 147 | function [target]=prop_target(lec)
|
|---|
| 148 | target=zeros(size(lec));
|
|---|
| 149 | for i=1:numel(lec)
|
|---|
| 150 | target(i)=lec(i).target;
|
|---|
| 151 | end
|
|---|
| 152 | target=allequal(target,0.);
|
|---|
| 153 | end
|
|---|
| 154 | function [stype] =prop_stype(lec)
|
|---|
| 155 | stype=cell(size(lec));
|
|---|
| 156 | for i=1:numel(lec)
|
|---|
| 157 | stype(i)=cellstr(lec(i).scale_type);
|
|---|
| 158 | end
|
|---|
| 159 | stype=allequal(stype,'none');
|
|---|
| 160 | end
|
|---|
| 161 | function [scale] =prop_scale(lec)
|
|---|
| 162 | scale=zeros(size(lec));
|
|---|
| 163 | for i=1:numel(lec)
|
|---|
| 164 | scale(i)=lec(i).scale;
|
|---|
| 165 | end
|
|---|
| 166 | scale=allequal(scale,1.);
|
|---|
| 167 | end
|
|---|
| 168 | end
|
|---|
| 169 |
|
|---|
| 170 | methods (Static)
|
|---|
| 171 | function []=dakota_write(fidi,dvar)
|
|---|
| 172 |
|
|---|
| 173 | % collect only the variables of the appropriate class
|
|---|
| 174 |
|
|---|
| 175 | lec=struc_class(dvar,'linear_equality_constraint');
|
|---|
| 176 |
|
|---|
| 177 | % write constraints
|
|---|
| 178 |
|
|---|
| 179 | lclist_write(fidi,'linear_equality_constraints','linear_equality',lec);
|
|---|
| 180 | end
|
|---|
| 181 | end
|
|---|
| 182 | end
|
|---|