obj := createobject("testopt");
obj.fx0 := Array(1,1);//初始值
obj.flb := array(0,0); //设置下界
obj.fub := array(5,5); //设置上界
obj.foptions := array('tolx':1.0e-6,'tolcon':1.0e-6,'tolfun':1.0e-6);//设置计算参数
obj.prog();
return obj.fresult;
type testopt=class(tsoptimizer)
function obj(x); virtual; //重写目标
begin
return 2*x[0]^2-4*x[0]*x[1]+4*x[1]^2-6*x[0]-3*x[1];
End
function con(x);virtual; //重写约束
begin
ne := array();
e := array() ;
ne[0]:= x[0]+x[1]^2-5;
e[0]:=x[1]^2+x[0]^2-4;
return array(ne,e);
End
End