apache - Implementing nonlinear optimization with nonlinear inequality constraints with java -
how implement nonlinear optimization nonlinear constraints in java? using org.apache.commons.math3.optim.nonlinear.scalar.noderiv, , have read none of optimizers (such 1 working with, simplexoptimizer) take constraints default, instead 1 must map constrained parameters unconstrained ones implementing multivariatefunctionpenaltyadapter or multivariatefunctionmappingadapter classes. however, far can tell, using these wrappers, 1 can still implement linear or "simple" constraints. wondering if there way include nonlinear inequality constraints?
for example, suppose objective function function of 3 parameters: a,b,and c (depending on them non-linearly) , additionally these parameters subject constraint ab
any advice solve problem using apache commons great, suggestions extending existing classes or augmenting package welcome of course.
my best attempt far @ implementing cobyla package given below:
public static double[] optimize(double[][] contractdatamatrix,double[] mindata, double[] maxdata,double[] modeldata,string modeltype,string weighttype){ objectivefunction objective = new objectivefunction(contractdatamatrix,modeltype,weighttype); double rhobeg = 0.5; double rhoend = 1.0e-6; int iprint = 3; int maxfun = 3500; int n = modeldata.length; calcfc calcfc = new calcfc(){ @override public double compute(int n, int m, double[] x, double[] con){ con[0]=x[3]*x[3]-2*x[0]*x[1]; system.out.println("constraint: "+(x[3]*x[3]-2*x[0]*x[1])); return objective.value(x); } }; cobylaexitstatus result = cobyla.findminimum(calcfc, n, 1, modeldata, rhobeg, rhoend, iprint, maxfun); return modeldata; }
the issue still getting illegal values in optimization. can see, within anonymous override of compute function, printing out value of constraint. result negative. shouldn't value constrainted non-negative?
edit: found bug in code, unrelated optimizer rather implementation.
best,
paul
you might want consider optimizer not available in apache commons math. cobyla derivative-free method relatively small optimization problems (less 100 variables) nonlinear constraints. have ported original fortran code java, source code here.
Comments
Post a Comment