The class NewtonLEUnconstrainedISP implements a (linear) equality constrained Newton optimizer (see S.Boyd and L.Vandenberghe, "Convex Optimization", p. 521 for more details), and can be used to solve the following problem:

minimize x f ( x )  s.t.
     Ax = b

where f :  R n  R is convex and twice differentiable, and A  R p x n with  rank A = p < n , given a starting point x  dom f .

Code example

Consider the following quadratic problem:

minimize x 1 2 x T Px + q T x + r  s.t.
     Ax = b
where P = 0.01522 2 1.68 0.34 0.38 0.34 3.09 - 1.59 0.38 - 1.59 1.54 , q = - 0.018 - 0.025 - 0.01 , r = 0
and A = ( 1 1 1 ) , b = ( 1 )

It can be solved like this:
		
		//commons-math client code
		RealMatrix Pmatrix = new Array2DRowRealMatrix(new double[][] { 
				{ 1.68, 0.34, 0.38 },
				{ 0.34, 3.09, -1.59 }, 
				{ 0.38, -1.59, 1.54 } });
		RealVector qVector = new ArrayRealVector(new double[] { 0.018, 0.025, 0.01 });

		// Objective function
		double theta = 0.01522;
		RealMatrix P = Pmatrix.scalarMultiply(theta);
		RealVector q = qVector.mapMultiply(-1);
		PDQuadraticMultivariateRealFunction objectiveFunction = new PDQuadraticMultivariateRealFunction(P.getData(), q.toArray(), 0);

		OptimizationRequest or = new OptimizationRequest();
		or.setF0(objectiveFunction);
		or.setInitialPoint(new double[] { 0.1, 0.1, 0.1 });//LE-infeasible starting point
		or.setA(new double[][] { { 1, 1, 1 } });
		or.setB(new double[] { 1 });

		// optimization
		NewtonLEConstrainedISP opt = new NewtonLEConstrainedISP();
		opt.setOptimizationRequest(or);
		opt.optimize();
		
This will give the solution:
				double[] sol = opt.getOptimizationResponse().solution;
				sol[0] = 0.04632311556;
				sol[1] = 0.50863084610;
				sol[2] = 0.44504603834;
				

Download test source bundle

Download the entire test source bundle from here.

Back to top

Reflow Maven skin maintained by Olivier Lamy.