- 积分
- 852
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 25
- 最后登录
- 1970-1-1
该用户从未签到
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
% make sure platform matches
if strcmp(computer, '$ANS_EXPECTED_PLATFORM') ~= 1
h = msgbox('32/64 platform does not match calling application, exiting')
uiwait(h)
exit
end
% add installation dir to search path so .mex file can be found
originalpath = addpath('$ANS_EXEDIR')
% connect back to opticomengine
callbackinterface = optimex('connect', '$ANS_CONNECTIONSTRING')
% make sure the optimization toolbox license can be checkout out
if license('checkout','optimization_toolbox') ~= 1
h = msgbox('Optimization Toolbox not licensed, exiting')
uiwait(h)
exit
end
% set up optimization
% variables are: $ANS_VARIABLELIST
startingpoint = $ANS_STARTINGPOINT
options = optimset('MaxIter', $ANS_MAXITERATIONS)
iterationCallbackWrapper = @(x, optimValues, state) optimex('notifyiterationcomplete', callbackinterface, x, optimValues.fval, state)
options = optimset(options, 'OutputFcn', iterationCallbackWrapper)
% halt execution so debugger can be attached
% h = msgbox('attach debugger if desired')
% uiwait(h)
% attributes that user can pass to optimization algorithm
% variables are: $ANS_VARIABLELIST
% this is the objective function which returns cost
wrapperfunc = @(x)optimex('eval', callbackinterface, x)
% this is our non linear constraint function, returns no constraints
returnempty = @(x)[];
nlcon = @(x) deal(returnempty(x), returnempty(x));
% DO NOT EDIT THIS LINE - START OPTIONS SECTION
% customers can add their own options below
options = optimset(options, 'display', 'iter')
options = optimset(options, 'Algorithm', 'interior-point')
% options = optimset(options, 'PlotFcns', @optimplotfval)
% DO NOT EDIT THIS LINE - END OPTIONS SECTION
% DO NOT EDIT THIS LINE - START OPTIMIZATION ALGO SECTION
% invoke optimization
[x,fval,exitflag,output] = fmincon(wrapperfunc, startingpoint, $ANS_A_MATRIX, $ANS_B_MATRIX, [], [], $ANS_MINVAL, $ANS_MAXVAL, nlcon, options)
% DO NOT EDIT THIS LINE - END OPTIMIZATION ALGO SECTION
% write exit message to Ansoft message window (warning=0,error=1,info=2)
optimex('postansoftmessage', callbackinterface, 2, output.message)
% notify opticomengine that optimization is finished
optimex('optimizationfinished', callbackinterface, exitflag)
% restore original path
path = originalpath
% note: comment below line if you want MATLAB to remain
% running after optimization
exit |
评分
-
查看全部评分
|