www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/checkrun.m
function [OK, msg] = checkrun(optim, checkType) %CHECKRUN Check whether optimization can be run % % [OK, MSG] = CHECKRUN(OPTIM, CHECKTYPE) checks to see if the run method % can be called on cgoptim, that is all oppoint, values, objective, % constraint fields are filled and valid. % % Inputs: OPTIM : Current optimisation object. % CHECKTYPE : String either 'precheck' or 'fullcheck'. These perform % before run-time and run-time checks respectively on % whether the optimisation is ready to run. % % Outputs: OK : true or false to indicate if the optimisation can be % run or not. % MSG : String that gives reason why the script cannot run. % Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc. OK = true; msg = ''; % Always do precheck items % Check oppoints [dsstatus, dsmsg] = checkDatasets(optim); [OK, msg] = i_getOverallStatus(dsstatus, dsmsg); if ~OK return end % Check objectives nobjectives = numObjectives(optim.OptimSetup); if ~nobjectives % Do we have any objectives ? OK = 0; msg = 'Optimization must have at least one objective'; return end [objstatus, objmsg] = checkObjectives(optim); [OK, msg] = i_getOverallStatus(objstatus, objmsg); if ~OK return end % Check constraints [constatus, conmsg] = checkConstraints(optim); [OK, msg] = i_getOverallStatus(constatus, conmsg); if ~OK return end if strcmpi(checkType, 'fullcheck') % Perform some extra checks % Check function file [funcstatus, msg] = checkFunctionFile(optim); OK = (funcstatus==0); if ~OK return end % Check free variables [varstatus, varmsg] = checkFreeValues(optim); [OK, msg] = i_getOverallStatus(varstatus, varmsg); if ~OK return end % Check sizes of items [sizestatus, msg] = checkSizes(optim); OK = (sizestatus==0); if ~OK return end end % Generate a single OK flag and a single message from a set of statuses function [OK, msg] = i_getOverallStatus(Status, Message) OK = all(Status<2); msg = ''; if ~OK msg = Message{find(Status==2, 1, 'first')}; end