Search code examples
mathematical-optimizationapache-commons-math

Possible to get shadow prices with org.apache.commons.math3.optim?


I have a large LP problem looking like:

max z = c^T * x
s.t. A*x    <= b
and  Aeq * x = beq

After writing the constraints the code looks like:

import org.apache.commons.math3.optim.linear.LinearConstraint;
import org.apache.commons.math3.optim.linear.Relationship;
import org.apache.commons.math3.exception.TooManyIterationsException;
import org.apache.commons.math3.optim.OptimizationData;
import org.apache.commons.math3.optim.PointValuePair;
import org.apache.commons.math3.optim.linear.LinearConstraintSet;
import org.apache.commons.math3.optim.linear.LinearObjectiveFunction;
import org.apache.commons.math3.optim.linear.NoFeasibleSolutionException;
import org.apache.commons.math3.optim.linear.NonNegativeConstraint;
import org.apache.commons.math3.optim.linear.SimplexSolver;
import org.apache.commons.math3.optim.linear.UnboundedSolutionException;
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;

LinearObjectiveFunction objective = new LinearObjectiveFunction(objectiveCoefficients, 0);

SimplexSolver solver = new SimplexSolver(epsilon, maxUlps, cutOff);

LinearConstraintSet constraintSet = new LinearConstraintSet(constraints);

NonNegativeConstraint nonnegative = new NonNegativeConstraint(true);

GoalType maximization = GoalType.MAXIMIZE;

OptimizationData[] optData = new OptimizationData[]{maximization, objective, constraintSet, nonnegative};

try{

PointValuePair solution = solver.optimize(optData);

}catch ...

works pretty fine. However, I am not able to get the values of the dual problem, i.e. the shadow prices of my constraints without solving the dual problem separately.

Is there a possibility to get both, the x values of my primal problem and the shadow prices of the constraints with org.apache.commons.math3.optim?

Thx in advance


Solution

  • It does not return duals. You can probably retrieve them from the final tableau but that may require some plumbing.

    It is noted that this is not a good solver for any but the smallest LP problems. It is not a serious algorithm but rather a textbook chapter 1 implementation of the full tableau simplex method. Not recommended for large problems.