www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conboolean/conboolean.m
function con = conboolean( op, varargin) %CONBOOLEAN Boolean combination of constraint objects % % CON = CONBOOLEAN(CIF) % CON = CONBOOLEAN('And', CON1, CON2, ...) % CON = CONBOOLEAN('Not', CON1) % CON = CONBOOLEAN('Or', CON1, CON2, ...) % CON = CONBOOLEAN('Xor', CON1, CON2) % % CONBOOLEAN are constraint objects that combine other constraint obejcts using % boolean operators, i.e, and, or, xor and not. % % CONBOOLEAN constraints contain a number of other constraints. For 'Not' % objects there can only be one contained constraint. For 'And' and 'Or' % constraints there are two or more contained constraints. For 'Xor' % constraints there are two contained constraints. % % Note that and is equivalent to intersection and or is equivalent to union. % % Object strcuture: % Constraints: cell array of constraints (sub-classes of conbase) % Not: (boolean) indicates if the negative should be taken % Op: 'None'|'And'|'Or'|'Xor', boolean operation to perform % Version: 2 % conbase: Parent object (conbase) % % See also CONBASE, CONINPUTFACTOR, % CONBASE/AND, CONBASE/OR, CONBASE/XOR, CONBASE/NOT, % CONBOOLEAN/AND, CONBOOLEAN/OR, CONBOOLEAN/XOR, CONBOOLEAN/NOT. % Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~nargin, % no input arguments [con, parent] = i_Structure( 'Not', {conlinear} ); elseif isa( op, 'conboolean' ), con = op; return elseif isstruct( op ), con = op; parent = con.conbase; con = mv_rmfield( con, 'conbase' ); elseif isa( op, 'coninputfactor' ), [con, parent] = i_Structure( 'Not', {conlinear( op )} ); elseif ischar( op ), [con, parent] = i_Structure( op, varargin ); else error(message('mbc:conboolean:InvalidArgument2')); end con = class( con, 'conboolean', parent ); % superiorto( 'conbase' ); inferiorto( 'conbase' ); %------------------------------------------------------------------------------| function [con, parent] = i_Structure( op, constraints ) parent = conbase( getInputFactors( constraints{1} ) ); con = struct( ... 'Version', 2, ... 'Constraints', {constraints}, ... 'Not', false, ... 'Op', 'None' ); switch lower( op ), case 'not', if length( constraints ) ~= 1, error(message('mbc:conboolean:InvalidArgument3')); end con.Not = true; case 'xor', if length( constraints ) ~= 2, error(message('mbc:conboolean:InvalidArgument4')); end con.Op = 'Xor'; case {'and', 'or'}, if length( constraints ) < 2, error(message('mbc:conboolean:InvalidArgument5', op)); end con.Op = op; otherwise error(message('mbc:conboolean:InvalidArgument6', op)); end %------------------------------------------------------------------------------| % EOF %------------------------------------------------------------------------------|