www.gusucode.com > 使用Matlab在优化方面的程序项目 > 暂时没用的例子/bnbexample.m

    %一般非线性整数型优化问题
% 使用bnb20工具箱优化,函数调用形式只能使用下述方式,不能采用inline函数形式
% 使用平台 - Matlab7.0
%by akjuan
%all rights preserved by www.4math.cn
%2008.11




clear all, clc
display('一般非线性整数型优化问题,测试平台为matlab7版本')
display('designed by akjuan')
display('源代码可以在:www.4math.cn网站获得')
disp('按任意键开始执行')
pause();
display('正在求解........')
fun        = 'myfuntest';
x0         = [1 1]';
xstat      = [0 0]';
xl         = -100*[1 1]';
xu         = 100*[1  1]';
a          = [];
b          = [];
aeq        = [];         
beq        = [];         
nonlc      = 'confun';
setts      = [];
opts       = optimset('display','off','MaxSQPIter',1000);

[errmsg,Z,X,t,c,fail]=bnb20(fun,x0,xstat,xl,xu,a,b,aeq,beq,[],setts,opts);
Y_bnb20=Z;
disp('solution:'), X




disp('下面采用fmincon求解,进行比较,按任意键开始:')
pause();

options=optimset('MaxFunEvals',1e5,'MaxIter',1e10,'TolFun',1e-8,'TolX',1e-8);
[xmincon,fval,exitflag,output] = fmincon(@myfuntest,x0,a,b,aeq,beq,xl,xu,[],options);
X_fmincon=xmincon';Y_fmincon=fval;
disp('采用bnb20的结果和fmicon的结果比较,按任意键显示:')
pause();
X_bnb20=X'
Y_bnb20
X_fmincon
Y_fmincon