Home > matpower7.1 > mp-opt-model > .github > osqp > validateSettings.m

validateSettings

PURPOSE ^

don't allow these fields to be changed

SYNOPSIS ^

function currentSettings = validateSettings(this,isInitialization,varargin)

DESCRIPTION ^

don't allow these fields to be changed

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function currentSettings = validateSettings(this,isInitialization,varargin)
0002 
0003 %don't allow these fields to be changed
0004 unmodifiableFields = {'scaling', 'linsys_solver'};
0005 
0006 %get the current settings
0007 if(isInitialization)
0008     currentSettings = osqp_mex('default_settings', this.objectHandle);
0009 else
0010     currentSettings = osqp_mex('current_settings', this.objectHandle);
0011 end
0012 
0013 %no settings passed -> return defaults
0014 if(isempty(varargin))
0015     return;
0016 end
0017 
0018 %check for structure style input
0019 if(isstruct(varargin{1}))
0020     newSettings = varargin{1};
0021     assert(length(varargin) == 1, 'too many input arguments');
0022 else
0023     newSettings = struct(varargin{:});
0024 end
0025 
0026 %get the osqp settings fields
0027 currentFields = fieldnames(currentSettings);
0028 
0029 %get the requested fields in the update
0030 newFields = fieldnames(newSettings);
0031 
0032 %check for unknown parameters
0033 badFieldsIdx = find(~ismember(newFields,currentFields));
0034 if(~isempty(badFieldsIdx))
0035     error('Unrecognized solver setting ''%s'' detected',newFields{badFieldsIdx(1)});
0036 end
0037 
0038 %convert linsys_solver string to integer
0039 if ismember('linsys_solver',newFields)
0040    if ~ischar(newSettings.linsys_solver)
0041        error('Setting linsys_solver is required to be a string.');
0042    end
0043    % Convert linsys_solver to number
0044     newSettings.linsys_solver = string_to_linsys_solver(newSettings.linsys_solver);
0045 end
0046 
0047 
0048 %check for disallowed fields if this in not an initialization call
0049 if(~isInitialization)
0050     badFieldsIdx = find(ismember(newFields,unmodifiableFields));
0051     for i = badFieldsIdx(:)'
0052         if(~isequal(newSettings.(newFields{i}),currentSettings.(newFields{i})))
0053             error('Solver setting ''%s'' can only be changed at solver initialization.', newFields{i});
0054         end
0055     end
0056 end
0057 
0058 
0059 %check that everything is a nonnegative scalar (this check is already
0060 %performed in C)
0061 % for i = 1:length(newFields)
0062 %     val = double(newSettings.(newFields{i}));
0063 %     assert(isscalar(val) & isnumeric(val) & val >= 0, ...
0064 %         'Solver setting ''%s'' not specified as nonnegative scalar', newFields{i});
0065 % end
0066 
0067 %everything checks out - merge the newSettings into the current ones
0068 for i = 1:length(newFields)
0069     currentSettings.(newFields{i}) = double(newSettings.(newFields{i}));
0070 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005