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

    function property_value = get(obj, property_name)
%GET Get optimization properties.
%   V = GET(OPTIMSTORE, 'PropertyName') returns the value of the specified
%   property in the optimization.
%
%   GET(OPTIMSTORE) displays all property names and a description of each
%   property for the OPTIMSTORE object.
%
%   S = GET(OPTIMSTORE) returns a structure where each field name is the
%   name of a property of OPTIMSTORE and each field contains the
%   description of that property.
%
%   This method is obsolete. Please use the GETXXX methods instead. 
%
%   See also CGOPTIMSTORE/GETXXX

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


% Tell the user to use the GETXXX methods in future 
if ~isv2mode(obj)
    warning(message('mbc:cgoptimstore:obsolete'));
end
    

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note that this method will try and support pre MBC 3 scripts where      %
% possible. For example get(optimstore, 'numfreevariables') will return   %
% the number of free variable labels (the expected behaviour from version %
% 2.x) and not the actual number of free variables                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin==1
    % return what user can get
    property_value.NumFreeVariables = 'Number of free variables in this optimization';
    property_value.NumDataSets = 'Number of data sets in this optimization';
    property_value.NumObjectiveFuncs = 'Number of objective functions in this optimization';
    property_value.NumConstraints = 'Number of constraints in this optimization';
    property_value.A = 'Matrix for linear constraints A*x <= b';
    property_value.b = 'Vector for linear constraints A*x <= b';
    property_value.NonLinearConstraints = 'Labels for the non-linear constraints';
    property_value.ObjectiveSums = 'Labels for the objective sums';
    property_value.ConstraintSums = 'Labels for the constraint sums';
    property_value.LB = 'Lower bounds for free variables';
    property_value.UB = 'Upper bounds for free variables';
    property_value.ObjectiveFuncTypes = 'Character array of objective function types';
else
    switch upper(property_name)
        case 'NUMFREEVARIABLES'
            property_value = getNumFreeVariableLabels(obj);
        case 'NUMDATASETS'
            property_value = getNumHelperDatasets(obj);
        case 'NUMOBJECTIVEFUNCS'
            property_value = getNumObjectiveLabels(obj);
        case 'NUMCONSTRAINTS'
            property_value = length([getNonlcon(obj), getLcon(obj)]);
        case 'A'
            % returns the matrix A  AX <= B
            property_value = getA(obj);
        case 'B'
            % returns the matrix B AX <= B
            if ~isv2mode(obj) || isConstantLinCon(obj.OptimRunner)
                property_value = getB(obj);
            else
                error(message('mbc:cgoptimstore:InvalidState1'));
            end
        case 'NONLINEARCONSTRAINTS'
            property_value = getNonlcon(obj);
        case 'OBJECTIVESUMS'
            % This is primarily here to support MBC Version 2.0 scripts
            property_value = getObjectiveNames(obj.OptimRunner, 'sum');
        case 'CONSTRAINTSUMS'
            % This is primarily here to support MBC Version 2.0 scripts
            property_value = getConstraintNames(obj.OptimRunner, 'sum');
        case 'LB'
            % returns the lower bounds for the free variables
            property_value = getLB(obj);
        case 'UB'
            % returns the upper bounds for the free variables
            property_value = getUB(obj);
        case 'OBJECTIVEFUNCTYPES'
            property_value = getObjectiveTypes(obj.OptimRunner);
            property_value = strrep(property_value, 'Maximize', 'max');
            property_value = strrep(property_value, 'Minimize', 'min');
        case 'LABELS'
            property_value = i_getLabels(obj);            
        otherwise
            error(message('mbc:cgoptimstore:InvalidPropertyName'));
    end
end

%--------------------------------------------------------------------------
function out = i_getLabels(optsobj)
%--------------------------------------------------------------------------

options = getOptimOptions(optsobj);
if ~isempty(options)
    out.freelab = getFreeVariables(options);
    dsinfo = getOperatingPointSets(options);
    out.datasetlab = dsinfo.label;
    out.dsinputlab = dsinfo.vars;
    objinfo = getObjectives(options);
    out.objlab = i_labelStructToCell(objinfo);
    nconinfo = getNonlcon(options);
    out.conlab = i_labelStructToCell(nconinfo);
    lconinfo = getLinearConstraints(options);
    lconlab = i_labelStructToCell(lconinfo);
    out.conlab = [out.conlab, lconlab];
    out.name = getName(options);
else
    out = [];
end

%--------------------------------------------------------------------------
function out = i_labelStructToCell(labStruct)
%--------------------------------------------------------------------------

out = cell(1, length(labStruct));
[out{:}] = deal(labStruct.label);