




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、function errmsg,Z,X,t,c,fail =BNB18(fun,x0,xstat,xl,xu,A,B,Aeq,Beq,nonlcon,setts,options1,options2,maxSQPit,varargin);% ?D?6 y1? £ Di ?6 ?a ?§?,.?心 u ' u ? 一?£ ?u MATLAB5.3?De 1 o ?£ ?De Optimizat ion toolbox 2.0?§ 3?% Minimize F(x)%subject to: xlb <= x <=xub%A*x &
2、lt;= B%Aeq*x=Beq%C(x)<=0%Ceq(x)=0%x(i)?e ?aa ?D?± ?a ?£?e y£?o 1 i ? 一?心% e 1 o ? e ?%errmsg,Z,X=BNB18('fun',x0,xstat,xl,xu,A,B,Aeq,Beq,'nonlcon',setts)%fun£o M?t? £ ?± i e ?x?D? ?± e o e yf=fun(x)%x0:a D?o a ?£?+ i e ?± ?a ?3?心%xstat &
3、#163; o a D?o ? ?£ ?xstat(i)=0 ± i e ?x(i)?a & ?D?± ?a ?£?1 ± i e ?e y£?2± i e ?1 i ? 一 ? %xl£o a D?6 a ?£ ?± i e ?± ?a ?%xu:a D?o a ?£?+ i e ?± ?a ?e ?%A:? o , ± i e ?D?2? fi e e ? e ? e y%B:a D?o ? ?, ± i e ?D?2? e e ?
4、e ? e ?%Aeq:? o , ± i e ?D? i e e ? e ? e y%Beg:a D?o ? ?, ± i e ?D?2? e e ? 6 ? 6 6 ?心%nonlcon:M?t?£?± i e ? - ?D?e ?o e yC,Ceq=nonlin(x),?DC(x)?a2? e e ? e % Ceq(x)?ae e ? e ?%setts: ? " e e ?%errmsq:,心?' i ? o i a e ?%Z: ? ?+ 6 o 6 yx ?D?a%X:心?x ?6 ?a%d y i a% max x1*
5、x2*x3% -x1+2*x2+2*x3>=0% x1+2*x2+2*x3<=72% 10<=x2<=20% x1-x2=10% ?6 D' Mo e ydiscfun.m%function f=discfun(x)%f=-x(1)*x(2)*x(3);%?6 ?a% clear;x0=25,15,10'xstat=1 1 1'% xl=20 10 -10'xu=30 20 20'% A=1 -2 -2;1 2 2;B=0 72'Aeq=1 -1 0;Beq=10;% err,Z,X=BNB18('discfun&
6、#39;,x0,xstat,xl,xu,A,B,Aeq,Beq);% XMAX=X',ZMAX=-Z% BNB18 Finds the constrained minimum of a function of several possibly integer variables.% Usage: errmsg,Z,X,t,c,fail =%BNB18(fun,x0,xstatus,xlb,xub,A,B,Aeq,Beq,nonlcon,settings,options1,options2,maxSQPiter,P1,P2,.)% BNB solves problems of the f
7、orm:% Minimize F(x) subject to: xlb <= x0 <=xub%A*x <= B Aeq*x=Beq%C(x)<=0 Ceq(x)=0%x(i) is continuous for xstatus(i)=0%x(i) integer for xstatus(i)=1%x(i) fixed for xstatus(i)=2% BNB uses:% Optimization Toolbox Version 2.0 (R11) 09-Oct-1998% From this toolbox fmincon.m is called. For mor
8、e info type help fmincon.% fun is the function to be minimized and should return a scalar.F(x)=feval(fun,x).% x0 is the starting point for x. x0 should be a column vector.% xstatus is a column vector describing the status of every variable x(i).% xlb and xub are column vectors with lower and upper b
9、ounds for x.% A and Aeq are matrices for the linear constrains.% B and Beq are column vectors for the linear constrains.% nonlcon is the function for the nonlinear constrains.% C(x);Ceq(x)=feval(nonlcon,x). Both C(x) and Ceq(x) should be column vectors.% errmsg is a string containing an error messag
10、e if BNB found an error in the input.% Z is the scalar result of the minimization, X the values of the accompanying variables.% t is the time elapsed while the algorithm BNB has run, c is the numberof BNB cycles and% fail is the number of unsolved leaf sub-problems.% settings is a row vector with se
11、ttings for BNB:% settings(1) (standard 0) if 1: use phase 1 by relaxation. This sometimes makes the algorithm% faster, because phase 1 means the algorithm first checks if there is a feasible solution% for a sub-problem before trying to find a best solution. If there is no feasible solution BNB% will
12、 not try to find a best solution.% settings(2) (standard 0) if 1: if the sub-problem did not converge do not branch. If a sub-% problem did not converge this means BNB did not find a solution for it.Normally BNB will% branch the problem so it can try again to find a solution.% A sub-problem that is
13、a leaf of the branch-and-bound-three can not be branched. If such% a problem does not converge it will be considered unfeasible and the parameter fail will be% raised by one.% settings(3) (standard 0) if 1: if 1 a sub-problem that did not converge but did return a feasible% point will be considered
14、convergent. This might be useful if fmincon is having a hard time with% a certain problem but you do want some results.% options1 and options2 are options structures for phase 1 and phase 2.% For details about the options structure type help optimset.% maxSQPiter is a global variable used by fmincon
15、 (if modified as described in bnb18.m).% maxSQPiter is 1000 by default.% P1,P2,. are parameters to be passed to fun and nonlcon.% F(x)=feval(fun,x,P1,P2,.). C(x);Ceq(x)=feval(nonlcon,x,P1,P2,.).% Type edit BNB18 for more info.% E.C. Kuipers% e-mail E.C.Kuiperscpedu.rug.nl% FI-Lab% Applied Physics% R
16、ijksuniversiteit Groningen % To get rid of bugs and to stop fmincon from hanging make the following chances: % In optim/private/nlconst.m($Revision:1.20 $ $Date:1998/08/2413:46:15$):% Get EXITFLAG independent of verbosity.% After the lines:disp(' less than 2*options.TolFun butconstraints are not
17、 satisfied.')%end%EXITFLAG = -1;%end%end%status=1;% add the line: if (strncmp(howqp, 'i',1) & mg > 0), EXITFLAG = -1; end; % % In optim/private/qpsub.m ($Revision: 1.21 $ $Date: 1998/09/01 21:37:56 $):% Stop qpsub from hanging.% After the line: % Andy Grace 7-9-90. Mary Ann Branch
18、 9-30-96.% add the line: global maxSQPiter;% and changed the line: maxSQPiters = Inf;elseworks% to the line: if exist('maxSQPiter','var'),maxSQPiters = maxSQPiter;maxSQPiters=inf; end;% I guess there was a reason to put maxSQPiters at infinity, but this fine for me.global maxSQPiter;
19、% STEP 0 CHECKING INPUT Z=; X=; t=0; c=0; fail=0;if nargin<2, errmsg=if isempty(fun), errmsg=if isempty(x0), errmsg='BNB needs at least 2 input arguments.'return ; end ;'No fun found.''No x0 found.' return; return ;end ;elseif size(x0,2)>1, errmsg= xstatus=zeros(size(x0
20、);if nargin>2 & isempty(xstat)if all(size(xstat)<=size(x0) xstatus(1:size(xstat)=xstat;else errmsg= 'xstatus end ;'x0 must be a column vector.'must be a column vector thesame sizereturn ; end ;as x0.' ; returnif any(xstatus=round(xstatus) | xstatus<0 | 2<xstatus)errms
21、g= end ;'xstatus must consist of the integers 0,1 en 2.'returnend ;xlb=zeros(size(x0);xlb(find(xstatus=0)=-inf;if nargin>3 & isempty(xl)if all(size(xl)<=size(x0) xlb(1:size(xl,1)=xl;else errmsg= 'xlb must be a column vector the same size as x0.' returnend ;end ;if any(x0<
22、;xlb)errmsg= 'x0 must be in the range xlb <= x0.' return ;elseif any(xstatus=1 & (isfinite(xlb) | xlb=round(xlb)errmsg= 'xlb(i) must be an integer if x(i) is an integer variabele.'return ;end ;xlb(find(xstatus=2)=x0(find(xstatus=2);xub=ones(size(x0);xub(find(xstatus=0)=inf;if
23、nargin>4 & isempty(xu)if all(size(xu)<=size(x0)xub(1:size(xu,1)=xu;else errmsg= 'xub must be a column vector the same size as x0.' returnend ;end ;if any(x0>xub)errmsg= 'x0 must be in the range x0 <=xub.' return ;elseif any(xstatus=1 & (isfinite(xub) | xub=round(x
24、ub)errmsg= 'xub(i) must be an integer if x(i) is an integer variabale.' return end ;xub(find(xstatus=2)=x0(find(xstatus=2);if nargin>5errmsg= 'Matrix A not correct.1), errmsg= 'Column vector B not'A and B should only be nonemptyif isempty(A) & size(A,2)=size(x0,1), return
25、; end ;else A=; end ; if nargin>6if isempty(B) & any(size(B)=size(A,1) correct.' ; return ; end ;else B=; end ;if isempty(A) & isempty(B), errmsg= together.' ; return ; end ;if isempty(B) & isempty(A), B=zeros(size(A,1),1);end ;if nargin>7 & isempty(Aeq)if size(Aeq,2)=s
26、ize(x0,1), errmsg='Matrix Aeq not correct.' returnend ;else Aeq=; end ;if nargin>8if isempty(Beq) & any(size(Beq)=size(Aeq,1) 1), errmsg='Columnvector Beq not correct.' return ; end ;else Beq=; end ;only be nonemptyif isempty(Aeq) & isempty(Beq), errmsg= 'Aeq and Beq s
27、hould together' ; return ; end ;if isempty(Beq) & isempty(Aeq), Beq=zeros(size(Aeq,1),1);end ;if nargin<10, nonlcon='' ; end ;settings = 0 0 0;if nargin>10 & isempty(setts)if all(size(setts)<=size(settings)settings(setts=0)=setts(setts=0);else errmsg= 'settings shoul
28、d be a row vector of length 3.' ; return ; end ; end ;if nargin<12, options1=;end ;options1=optimset(optimset('fmincon'),options1);if nargin<13, options2=;end ;options2=optimset(optimset('fmincon'),options2);if nargin<14, maxSQPiter=1000;elseif isnumeric(maxSQPit) &
29、all(size(maxSQPit)=1 & maxSQPit>0 &round(maxSQPit)=maxSQPitmaxSQPiter=maxSQPit;else errmsg= 'maxSQPiter must be an integer >0' return ; end ;eval( 'z=' ,fun, '(x0,varargin:);', 'errmsg=''fun caused error.''return;' );if isempty(nonlcon)ev
30、al( 'C, Ceq=' ,nonlcon, '(x0,varargin:);', 'errmsg=''nonlconcaused error.'' return;');if size(C,2)>1| size(Ceq,2)>1, errmsg= 'C en Ceq must be column vectors.' ;return ; end ;end ;% STEP 1 INITIALISATIONcurrentwarningstate=warning;warning off ;ti
31、c;lx = size(x0,1);z_incumbent=inf;x_incumbent=inf*ones(size(x0);I =ceil(sum(log2(xub(find(xstatus=1)-xlb(find(xstatus=1)+1)+size(find(xstatus=1),1)+1);stackx0=zeros(lx,I);stackx0(:,1)=x0;stackxlb=zeros(lx,I);stackxlb(:,1)=xlb;stackxub=zeros(lx,I);stackxub(:,1)=xub;stacksize=1;xchoice=zeros(size(x0);
32、if isempty(Aeq)j=0;for i=1:size(Aeq,1)if Beq(i)=1 & all(Aeq(i,:)=0 | Aeq(i,:)=1)J=find(Aeq(i,:)=1);if all(xstatus(J)=0 & xchoice(J)=0 & xlb(J)=0 & xub(J)=1)if all(xstatus(J)=2) | all(x0(J(find(xstatus(J)=2)=0)j=j+1;xchoice(J)=j;if sum(x0(J)=0, errmsg='x0 not correct.' return
33、; end ;end ;end ;end ;end ;end ;errx=optimget(options2,'TolX' );errcon=optimget(options2,'TolCon' );fail=0;c=0;% STEP 2 TERMINIATIONwhile stacksize>0c=c+1;% STEP 3 LOADING OF CSPx0=stackx0(:,stacksize);xlb=stackxlb(:,stacksize);xub=stackxub(:,stacksize);x0(find(x0<xlb)=xlb(find
34、(x0<xlb);x0(find(x0>xub)=xub(find(x0>xub);stacksize=stacksize-1;% STEP 4 RELAXATION% PHASE 1con=BNBCON(x0,A,B,Aeq,Beq,xlb,xub,nonlcon,varargin:);if abs(con)>errcon & settings(1)=0x1 dummyfeasflag=fmincon( '0' ,x0,A,B,Aeq,Beq,xlb,xub,nonlcon,options1,varargin :);if settings(3)
35、 & feasflag=0con=BNBCON(x1,A,B,Aeq,Beq,xlb,xub,nonlcon,varargin:);if con<errcon, feasflag=1;end ;end ;else x1=x0; feasflag=1;end ;% PHASE 2if feasflag>0x zconvflag=fmincon(fun,x1,A,B,Aeq,Beq,xlb,xub,nonlcon,options2,varargin :);if settings(3) & convflag=0con=BNBCON(x,A,B,Aeq,Beq,xlb,xu
36、b,nonlcon,varargin:);if con<errcon, convflag=1;end ;end ;else convflag=feasflag;end ;% STEP 5 FATHOMINGK = find(xstatus=1 & xlb=xub);separation=1;if convflag<0 | (convflag=0 & settings(2)% FC 1separation=0;elseif z>=z_incumbent & convflag>0% FC 2separation=0;elseif all(abs(ro
37、und(x(K)-x(K)<errx) & convflag>0% FC 3z_incumbent = z;x_incumbent = x;separation = 0;end ;% STEP 6 SELECTIONif separation = 1 & isempty(K)dzsep=-1;for i=1:size(K,1)dxsepc = abs(round(x(K(i)-x(K(i);if dxsepc>=errx | convflag=0xsepc = x; xsepc(K(i)=round(x(K(i);dzsepc = abs(feval(fun,
38、xsepc,varargin:)-z);if dzsepc>dzsepdzsep=dzsepc;ixsep=K(i);end ;end ;end ;% STEP 7 SEPARATIONif xchoice(ixsep)=0% XCHOICE=0branch=1;domain=xlb(ixsep) xub(ixsep);while branch=1xboundary=(domain(1)+domain(2)/2;if x(ixsep)<xboundarydomainA=domain(1) floor(xboundary);domainB=floor(xboundary+1) dom
39、ain(2); elsedomainA=floor(xboundary+1) domain(2);domainB=domain(1) floor(xboundary);end ;stacksize=stacksize+1;stackx0(:,stacksize)=x;stackxlb(:,stacksize)=xlb;stackxlb(ixsep,stacksize)=domainB(1);stackxub(:,stacksize)=xub;stackxub(ixsep,stacksize)=domainB(2);if domainA(1)=domainA(2)stacksize=stacksize+1;stackx0(:,stacksize)=x;stackxlb(:,stacksize)=xlb;stackxlb(ixsep,stacksize)=doma
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 外科創傷手術規范化診療
- 內鏡中心麻醉流程管理標準化體系
- 部編版語文五年級下冊《梅花魂》課件
- 2025夏季電商零售行業內需崛起挖掘新消費的情緒曲線
- 2025年氫燃料電池汽車關鍵零部件國產化市場競爭力分析報告
- 2025年農村電商物流“最后一公里”配送挑戰及創新模式分析報告
- 線下演出市場復蘇后的演出市場競爭格局研究報告
- 2025年零售與電商行業移動支付安全風險防控報告
- 聚焦2025年:銀發消費市場養老服務需求細分領域分析報告
- 廢舊塑料回收利用技術革命:產業升級與可持續發展報告
- 廠內機動車輛(叉車)安全檢查表參考模板范本
- 全套QHSE管理體系文件
- 煉鋼-精煉-連鑄過程鋼水頁PPT課件
- 【北師大版】七年級上冊數學 第四章 圖形的全等 單元檢測(含答案)
- 《教育學原理》期末考試試卷試題A及答案
- 安全知識進校園宣傳課件——XX小學
- 陳倍生妙派風水秘訣筆記
- 《掃除道》樊登讀書文字版
- 鈉冷快堆中的結構材料
- 教學演示文稿,建筑企業科技創新方法講座()
- 中國傳統節日文化中現代德育價值的研究課題結題報告
評論
0/150
提交評論