www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@des_respsurf/gui_optimset.m
function [dout,ret]=gui_optimset(des,action,varargin) %GUI_OPTIMSET GUI for altering optimisation settings % % [D, RET]=GUI_OPTIMSET(D) creates a modal GUI for altering optimisation % settings and stopping criteria. % LYT='GUI_OPTIMSET(D,'layout',FIG,P) creates a layout object in the % specified figure which dynamically updates the pointer P. If instead of % FIG a previously created layout is specified then the displayed values % are changed to reflect and update the new pointer P. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<2 action='figure'; end switch action case 'figure' [dout,ret] = i_createfig(des); case 'layout' dout=i_createlyt(varargin{:}); case 'enable' i_doenable(varargin{:}); case 'finalise' % no finalise actions for this gui dout=des; ret=1; end function [dout,ret]=i_createfig(des) dlg = mbcgui.container.Dialog('Name','Optimization Settings',... 'Buttons','OK_CANCEL',... 'Resize','off',... 'Size',[335 365],... 'tag','OptimSettings'); figh = dlg.Figure; p=xregpointer(des); dlg.Content=i_createlyt(figh,p); tg=dlg.showDialog(); if strcmpi(tg, 'ok') dout=p.info; ret=1; else dout=des; ret=0; end freeptr(p); delete(dlg); function lyt=i_createlyt(figh,p,varargin) if ~isa(figh,'xregcontainer') frm1=mbcgui.container.layoutpanel(... 'Parent', figh,... 'BorderType', 'etchedin', ... 'Title','Optimization parameters',... 'LayoutBorder',[10 0 10 5]); frm2=mbcgui.container.layoutpanel(... 'Parent', figh,... 'BorderType', 'etchedin', ... 'Visible','off', ... 'Title','Stopping criteria',... 'LayoutBorder',[10 0 10 5]); txt(2) = uicontrol('Parent',frm1,... 'Style','text',... 'HorizontalAlignment','left',... 'String','Augmentation method:'); txt(3) = uicontrol('Parent',frm1,... 'Style','text',... 'HorizontalAlignment','left',... 'String','Deletion method:'); txt(4) = uicontrol('Parent',frm1,... 'Style','text',... 'HorizontalAlignment','left',... 'String','p - number of points to alter per iteration:'); txt(5) = uicontrol('Parent',frm2,... 'Style','text',... 'HorizontalAlignment','left',... 'String','Delta - value below which the change in optimality criterion triggers an increment in q:'); txt(6) = uicontrol('Parent',frm2,... 'Style','text',... 'HorizontalAlignment','left',... 'String','q - number of consecutive non-productive iterations which trigger a stop:'); txt(7) = uicontrol('Parent',frm2,... 'Style','text',... 'HorizontalAlignment','left',... 'String','Maximum number of iterations to perform:'); ud.augpop=uicontrol('Parent',frm1,... 'Style','popupmenu',... 'BackgroundColor','w',... 'String',{'Random','Optimal'}); ud.delpop=uicontrol('Parent',frm1,... 'Style','popupmenu',... 'BackgroundColor','w',... 'String',{'Random','Optimal'}); ud.pclick=mbcgui.widget.Spinner('Parent', frm1,... 'Min',1,... 'ClickIncrement',1,... 'Rule','int'); ud.deltaclick=mbcgui.widget.Spinner('Parent', frm2,... 'Min',0,... 'ClickIncrementMode','auto'); ud.qclick=mbcgui.widget.Spinner('Parent', frm2,... 'Min',1,... 'ClickIncrement',1,... 'Rule','int'); ud.iterclick=mbcgui.widget.Spinner('Parent', frm2,... 'Min',1,... 'ClickIncrement',1,... 'Rule','int'); ud.spacefilled = uicontrol('Parent',frm2,... 'Style','text',... 'HorizontalAlignment','left',... 'String','here I am',... 'Tag', 'SpaceFilledString'); ud.pointer=p; ud.figure=figh; ud.callback=''; if nargin>2 for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' ud.callback=varargin{n+1}; end end end ptr=xregGui.RunTimePointer; % set up callbacks set(ud.augpop,'Callback',{@i_optset,ptr}); set(ud.delpop,'Callback',{@i_optset,ptr}); set(ud.pclick,'Callback',{@i_optset,ptr}); set(ud.deltaclick,'Callback',{@i_stopset,ptr}); set(ud.qclick,'Callback',{@i_stopset,ptr}); set(ud.iterclick,'Callback',{@i_stopset,ptr}); % update data in objects i_setvalues(ud,p); % do layouts grd=xreggridbaglayout(frm1,'packstatus','off',... 'dimension',[11,2],... 'gapx',5,... 'rowsizes',[3 15 2 5 3 15 2 5 3 15 2],... 'colratios',[20 9],... 'mergeblock',{[1 3],[2 2]},... 'mergeblock',{[5 7],[2 2]},... 'mergeblock',{[9 11],[2 2]},... 'elements',{... [],ud.augpop;... txt(2),[];... [],[];... [],[];... [],ud.delpop;... txt(3),[];... [],[];... [],[];... [],ud.pclick;... txt(4),[];... [],[];... }); set(frm1, 'LayoutComponent', {grd}); grd=xreggridbaglayout(frm2,'packstatus','off',... 'dimension',[15,2],... 'gapx',5,... 'rowsizes',[5 20 5 5 5 20 5 5 3 15 2 10 2 10 -1],... 'colratios',[20 9],... 'mergeblock',{[1 3],[1 1]},... 'mergeblock',{[5 7],[1 1]},... 'mergeblock',{[9 11],[2 2]},... 'mergeblock',{[13 13],[1 2]},... 'mergeblock',{[15 15],[1 2]},... 'elements',{... txt(5),[];... [],ud.deltaclick;... [],[];... [],[];... txt(6),[];... [],ud.qclick;... [],[];... [],[];... [],ud.iterclick;... txt(7),[];... [],[];... [],[];... xregGui.dividerline('parent',frm2),[];... [],[];... ud.spacefilled,[];... }); set(frm2, 'LayoutComponent', {grd}); lyt=xreggridlayout(figh,... 'correctalg','on',... 'dimension',[2 1],... 'rowratios',[3 5],... 'gapy', 10, ... 'elements',{frm1,frm2},... 'userdata',ptr); ptr.info=ud; else % layout already exists: update udh=get(figh,'UserData'); ud=udh.info; ud.pointer=p; if nargin>2 for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' ud.callback=varargin{n+1}; end end end udh.info=ud; i_setvalues(ud,p); lyt=figh; end function i_setvalues(ud,p) % setup the values in the controls from the pointer p des=p.info; [pn,aug,del] = getoptimal(des); [d,q,maxiter] = getstop(des); pmax=ncand(des); if ~allowreps(des) pmax=ncand(des)-npoints(des); pmax=max(1,pmax); end val_a=find(strcmpi(aug,{'random','optimal'})); set(ud.augpop,'Value',val_a); val=find(strcmpi(del,{'random','optimal'})); set(ud.delpop,'Value',val); set(ud.pclick,'Max',pmax,'Value',pn); set(ud.qclick,'Value',q); set(ud.deltaclick,'Value',d); set(ud.iterclick,'Value',maxiter); if val_a>1 str='The current configuration will visit the entire candidate set during the optimal augmentation.'; else [pv,pc]=pointsvisited(p.info); str=['The current configuration will visit a maximum of ' int2str(pv) ' unique candidate points,',... ' which corresponds to ' sprintf('%5.2f',pc) ' percent of the candidate set.']; end set(ud.spacefilled,'String',str); function i_optset(src,evt,udh) % change optimise options ud=udh.info; val_a=get(ud.augpop,'Value'); str={'random','optimal'}; aug=str{val_a}; val=get(ud.delpop,'Value'); str={'random','optimal'}; del=str{val}; pn=get(ud.pclick,'Value'); p=ud.pointer; p.info = setoptimal(p.info,pn,aug,del); if val_a>1 && val>1 set(ud.qclick,'Enable','off'); else set(ud.qclick,'Enable','on'); end if val_a==2 str='The current configuration will visit the entire candidate set during the optimal augmentation.'; else [pv,pc]=pointsvisited(p.info); str=['The current configuration will visit a maximum of ' int2str(pv) ' unique candidate points,',... ' which corresponds to ' sprintf('%5.2f',pc) ' percent of the candidate set.']; end set(ud.spacefilled,'String',str); xregcallback(ud.callback,[],[]); function i_stopset(src,evt,udh) % change stopping criteria ud=udh.info; delta=get(ud.deltaclick,'Value'); q=get(ud.qclick,'Value'); maxiter=get(ud.iterclick,'Value'); p=ud.pointer; p.info = setstop(p.info,delta,q,maxiter); % update data string at bottom val_a=get(ud.augpop,'Value'); if val_a==2 str='The current configuration will visit the entire candidate set during the optimal augmentation.'; else [pv,pc]=pointsvisited(p.info); str=['The current configuration will visit a maximum of ' int2str(pv) ' unique candidate points,',... ' which corresponds to ' sprintf('%5.2f',pc) ' percent of the candidate set.']; end set(ud.spacefilled,'String',str); xregcallback(ud.callback,[],[]); function i_doenable(lyt,en) if strcmp(en, 'off') set(lyt,'Enable','off'); else udh=get(lyt,'UserData'); ud=udh.info; set(lyt,'Enable','on'); if get(ud.augpop,'Value')==2 && get(ud.delpop,'Value')==2 set(ud.qclick,'Enable','off'); end end