0001 function currentSettings = validateSettings(this,isInitialization,varargin)
0002
0003
0004 unmodifiableFields = {'scaling', 'linsys_solver'};
0005
0006
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
0014 if(isempty(varargin))
0015 return;
0016 end
0017
0018
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
0027 currentFields = fieldnames(currentSettings);
0028
0029
0030 newFields = fieldnames(newSettings);
0031
0032
0033 badFieldsIdx = find(~ismember(newFields,currentFields));
0034 if(~isempty(badFieldsIdx))
0035 error('Unrecognized solver setting ''%s'' detected',newFields{badFieldsIdx(1)});
0036 end
0037
0038
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
0044 newSettings.linsys_solver = string_to_linsys_solver(newSettings.linsys_solver);
0045 end
0046
0047
0048
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
0060
0061
0062
0063
0064
0065
0066
0067
0068 for i = 1:length(newFields)
0069 currentSettings.(newFields{i}) = double(newSettings.(newFields{i}));
0070 end