아파치 공유지 계산에는 Simplex 솔버가 있습니다.
이 라이브러리를 사용하여이 같은 문제를 해결할 수 있습니다
@Test
public void testMathStackOverflow() {
// maximize 3x1+5x2
// subject to
// 2x1+8x2<=13
// 5x1-x2<=11
// x1>=0
// x2>=0
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 3, 5}, 0);
ArrayList<LinearConstraint> constraints = new ArrayList<>();
constraints.add(new LinearConstraint(new double[] {2, 8}, Relationship.LEQ, 13));
constraints.add(new LinearConstraint(new double[] {5, -1}, Relationship.LEQ, 11));
double epsilon = 1e-6;
SimplexSolver solver = new SimplexSolver();
PointValuePair solution = solver.optimize(f, new LinearConstraintSet(constraints),
GoalType.MAXIMIZE,
new NonNegativeConstraint(true),
PivotSelectionRule.BLAND);
System.out.printf("x1: %f; x2: %f; max: %f", solution.getPoint()[0], solution.getPoint()[1], solution.getValue());
}
결과는 다음과 같습니다의 더 많은 예를 들어
<groupId>org.apache.commons</groupId>
<artifactId>commons-math4</artifactId>
<version>4.0-SNAPSHOT</version>
:
x1: 2.404762; x2: 1.023810; max: 12.333333
나는이 종속성을 사용했습니다를 이 라이브러리에서 Simplex 솔버를 사용하면 소스 코드를 다운로드하고 패키지 :
org.apache.commons.math4.optim.linear
내 답변에 대한 의견을 보내 주시겠습니까? 부정적인 의견이나 긍정적 인 의견은 피드백이 전혀없는 것보다 낫습니다. –