gpconstraint.m

来自「HERE IS A GOOD PSO TOOL BOX」· M 代码 · 共 52 行

M
52
字号
function constr = gpconstraint(varargin)% GPCONSTRAINT is a GP constraint class constructor.%%	Inequality operators between GP objects, such as positive%	scalars, GP variables, monomials, posynomials, and generalized%	posynomials (when valid) return GPCONSTRAINT objects.%	These GPCONSTRAINT objects can be assigned to variables, for example,%	  constr1 = x*y <= z;%	  constr2 = x^5 == 1;%	are two valid GP constraints.%%	A set of constraint is represented as an array of GP constraints, i.e.,%	  constr_set = [constr1 constr2];%%	You can also define GP constraints using:%	  constr = gpconstraint('constraint string')%if nargin == 0 % create an empty constraint  constr.lhs    = [];  constr.type   = [];  constr.rhs    = [];  constr.gpvars = {};  constr = class(constr,'gpconstraint');  return;endif nargin == 1 % one argument  % invoke copy constructor if the new object is gpconstraint  if isa(varargin{1},'gpconstraint')    constr = varargin{1};    return;  endendif nargin == 3  % standard argument list  constr.lhs      = varargin{1};  constr.type     = varargin{2};  constr.rhs      = monomial(varargin{3});  if( isnumeric(constr.lhs) )    constr.lhs    = monomial(constr.lhs);    constr.gpvars = constr.rhs.gpvars;  elseif( isa(constr.lhs,'gpvar') )    constr.lhs    = monomial(constr.lhs);    constr.gpvars = union(constr.lhs.gpvars, constr.rhs.gpvars );  else    constr.gpvars = union(constr.lhs.gpvars, constr.rhs.gpvars);  end  constr = class(constr,'gpconstraint');  return;end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?