www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimoutput/guiWeightsEditor.m

    function [outobj, ok] = guiWeightsEditor(outobj)
%GUIWEIGHTSEDITOR Edit Pareto weights via a simple GUI
%
%   [OUTOBJ, OK] = EDITWEIGHTS(OUTOBJ) edits the weights used in the weighted
%   pareto view of the optimization output.  The optimization must have been
%   run for this function to work.

%   Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.


% Some information from the optimization 
NSOL = getNumSolutions(outobj);
[~, sModels] = getSolution(outobj, 1, 'OutputFormat', 'matrix', ...
    'OutputContents', {'Objectives'});

dlg = mbcgui.container.Dialog('Name','Pareto Weights Editor',...
    'Size',[400 380],...
    'HelpCode','CGOPTIMEDITPARETOWEIGHTS',...
    'Resize', 'off');
fig = dlg.Figure;

sc = xregGui.SystemColorsDbl;
udh = xregGui.RunTimePointer;
udh.LinkToObject(fig);

% Dataset used to offer the option of columns of output data as weights
[data, sAll] = getSolution(outobj, 1, 'OutputFormat', 'matrix', ...
    'OutputContents', {'FixedVars', 'FreeVars', 'Objectives', 'Constraints'});

% Create GUI components
txt1 = uicontrol('Parent', fig, ...
    'Style', 'text', ...
    'Enable', 'inactive', ...
    'HorizontalAlignment', 'left', ...
    'String', 'Objectives:');
hList = uicontrol('Parent', fig, ...
    'Style', 'listbox', ...
    'String', sModels, ...
    'Value', 1, ...
    'BackgroundColor', sc.WINDOW_BG, ...
    'HorizontalAlignment', 'left', ...
    'Callback', {@i_modelchange, udh});
ud.hWeightText = uicontrol('Parent', fig, ...
    'Style', 'text', ...
    'Enable', 'inactive', ...
    'HorizontalAlignment', 'left', ...
    'String', ['Weights for ' sModels{1} ':']);
ud.hEditor = cgoptimgui.vectorEditor('Parent', fig, ...
    'LayoutStyle', 'narrow', ...
    'Vector', outobj.outputWeights(:, 1), ...
    'DataTypeLabel', 'Output', ...
    'DataValues', data, ...
    'DataNames', sAll);
sol = mbcgui.widget.Spinner('Parent', fig, ...
    'Min', 1, ...
    'Max', NSOL, ...
    'Value', 1, ...
    'Rule', 'int', ...
    'Callback', {@i_solutionchange, udh});
ud.hSolution = xregGui.labelcontrol('parent', fig, ...
    'Control', sol, ...
    'ControlSize', 50, ...
    'String', 'Select data from solution:');

uppergrid = xreggridbaglayout(fig, 'packstatus', 'off', ...
    'dimension', [3 2], ...
    'gapx', 20, ...
    'colratios', [1 1], ...
    'rowsizes', [15 -1 20], ...
    'gapy', 3, ...
    'mergeblock', {[2 3], [1 1]}, ...
    'elements', {txt1, hList,[],  ud.hWeightText, ud.hEditor, ud.hSolution});
dlg.Content = uppergrid;



ud.outobj = outobj;
ud.displayindex = 1;
udh.info = ud;

tg = dlg.showDialog();
if strcmpi(tg, 'ok')
    % get the last set of weight changes
    i_modelchange(hList, [], udh);
    ud = udh.info;
    outobj = ud.outobj;
    ok = true;
else
    ok = false;
end
delete(fig);

function i_modelchange(src, ~, udh)
ud = udh.info;
indModel = get(src, 'Value');
strModel = get(src, 'String');
ud.outobj.outputWeights(:,ud.displayindex) = ud.hEditor.Vector;
ud.hEditor.Vector = ud.outobj.outputWeights(:,indModel);
ud.displayindex = indModel;
set(ud.hWeightText, 'String', ['Weights for ' strModel{indModel} ':']);
udh.info = ud;



function i_solutionchange(src, ~, udh)
ud = udh.info;
data = getSolution(ud.outobj, get(src, 'Value'), ...
    'OutputFormat', 'matrix', 'OutputContents', ...
    {'FixedVars', 'FreeVars', 'Objectives', 'Constraints'});
ud.hEditor.DataValues = data;