我有一个很大的LP问题,看起来像:
max z = c^T * x
s.t. A*x <= b
and Aeq * x = beq
编写约束后,代码如下:
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 ...
效果很好。但是,如果不单独解决双重问题,我将无法获得双重问题的价值,即约束的影子价格。
是否有可能同时获得我的原始问题的x值和使用org.apache.commons.math3.optim
的约束的影子价格?
提前谢谢
答案 0 :(得分:0)
它不返回对偶。您可能可以从最终画面中检索它们,但这可能需要一些管道。
请注意,这不是解决所有LP问题的好方法,但是最小的LP问题。它不是一种严肃的算法,而是完整的表格单纯形方法的教科书第1章实现。不建议用于大问题。