42
40
SimplexSolver solver = new SimplexSolver();
43
41
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);
45
assertEquals(0.0, solution.getPoint()[0], .0000001);
46
assertEquals(1.0, solution.getPoint()[1], .0000001);
47
assertEquals(1.0, solution.getPoint()[2], .0000001);
48
assertEquals(3.0, solution.getValue(), .0000001);
43
Assert.assertEquals(0.0, solution.getPoint()[0], .0000001);
44
Assert.assertEquals(1.0, solution.getPoint()[1], .0000001);
45
Assert.assertEquals(1.0, solution.getPoint()[2], .0000001);
46
Assert.assertEquals(3.0, solution.getValue(), .0000001);
50
public void testMath286() throws OptimizationException {
51
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.6, 0.4 }, 0 );
52
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
53
constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 23.0));
54
constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 23.0));
55
constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0, 0, 0 }, Relationship.GEQ, 10.0));
56
constraints.add(new LinearConstraint(new double[] { 0, 0, 1, 0, 0, 0 }, Relationship.GEQ, 8.0));
57
constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 1, 0 }, Relationship.GEQ, 5.0));
59
SimplexSolver solver = new SimplexSolver();
60
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
62
Assert.assertEquals(25.8, solution.getValue(), .0000001);
63
Assert.assertEquals(23.0, solution.getPoint()[0] + solution.getPoint()[2] + solution.getPoint()[4], 0.0000001);
64
Assert.assertEquals(23.0, solution.getPoint()[1] + solution.getPoint()[3] + solution.getPoint()[5], 0.0000001);
65
Assert.assertTrue(solution.getPoint()[0] >= 10.0 - 0.0000001);
66
Assert.assertTrue(solution.getPoint()[2] >= 8.0 - 0.0000001);
67
Assert.assertTrue(solution.getPoint()[4] >= 5.0 - 0.0000001);
71
public void testDegeneracy() throws OptimizationException {
72
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.7 }, 0 );
73
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
74
constraints.add(new LinearConstraint(new double[] { 1, 1 }, Relationship.LEQ, 18.0));
75
constraints.add(new LinearConstraint(new double[] { 1, 0 }, Relationship.GEQ, 10.0));
76
constraints.add(new LinearConstraint(new double[] { 0, 1 }, Relationship.GEQ, 8.0));
78
SimplexSolver solver = new SimplexSolver();
79
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
80
Assert.assertEquals(13.6, solution.getValue(), .0000001);
84
public void testMath288() throws OptimizationException {
85
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 7, 3, 0, 0 }, 0 );
86
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
87
constraints.add(new LinearConstraint(new double[] { 3, 0, -5, 0 }, Relationship.LEQ, 0.0));
88
constraints.add(new LinearConstraint(new double[] { 2, 0, 0, -5 }, Relationship.LEQ, 0.0));
89
constraints.add(new LinearConstraint(new double[] { 0, 3, 0, -5 }, Relationship.LEQ, 0.0));
90
constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0 }, Relationship.LEQ, 1.0));
91
constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0 }, Relationship.LEQ, 1.0));
93
SimplexSolver solver = new SimplexSolver();
94
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
95
Assert.assertEquals(10.0, solution.getValue(), .0000001);
99
public void testMath290GEQ() throws OptimizationException {
100
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 1, 5 }, 0 );
101
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
102
constraints.add(new LinearConstraint(new double[] { 2, 0 }, Relationship.GEQ, -1.0));
103
SimplexSolver solver = new SimplexSolver();
104
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true);
105
Assert.assertEquals(0, solution.getValue(), .0000001);
106
Assert.assertEquals(0, solution.getPoint()[0], .0000001);
107
Assert.assertEquals(0, solution.getPoint()[1], .0000001);
110
@Test(expected=NoFeasibleSolutionException.class)
111
public void testMath290LEQ() throws OptimizationException {
112
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 1, 5 }, 0 );
113
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
114
constraints.add(new LinearConstraint(new double[] { 2, 0 }, Relationship.LEQ, -1.0));
115
SimplexSolver solver = new SimplexSolver();
116
solver.optimize(f, constraints, GoalType.MINIMIZE, true);
120
public void testMath293() throws OptimizationException {
121
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 );
122
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
123
constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0));
124
constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0));
125
constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, 10.0));
126
constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, 10.0));
127
constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, 10.0));
129
SimplexSolver solver = new SimplexSolver();
130
RealPointValuePair solution1 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
132
Assert.assertEquals(15.7143, solution1.getPoint()[0], .0001);
133
Assert.assertEquals(0.0, solution1.getPoint()[1], .0001);
134
Assert.assertEquals(14.2857, solution1.getPoint()[2], .0001);
135
Assert.assertEquals(0.0, solution1.getPoint()[3], .0001);
136
Assert.assertEquals(0.0, solution1.getPoint()[4], .0001);
137
Assert.assertEquals(30.0, solution1.getPoint()[5], .0001);
138
Assert.assertEquals(40.57143, solution1.getValue(), .0001);
140
double valA = 0.8 * solution1.getPoint()[0] + 0.2 * solution1.getPoint()[1];
141
double valB = 0.7 * solution1.getPoint()[2] + 0.3 * solution1.getPoint()[3];
142
double valC = 0.4 * solution1.getPoint()[4] + 0.6 * solution1.getPoint()[5];
144
f = new LinearObjectiveFunction(new double[] { 0.8, 0.2, 0.7, 0.3, 0.4, 0.6}, 0 );
145
constraints = new ArrayList<LinearConstraint>();
146
constraints.add(new LinearConstraint(new double[] { 1, 0, 1, 0, 1, 0 }, Relationship.EQ, 30.0));
147
constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 1, 0, 1 }, Relationship.EQ, 30.0));
148
constraints.add(new LinearConstraint(new double[] { 0.8, 0.2, 0.0, 0.0, 0.0, 0.0 }, Relationship.GEQ, valA));
149
constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.7, 0.3, 0.0, 0.0 }, Relationship.GEQ, valB));
150
constraints.add(new LinearConstraint(new double[] { 0.0, 0.0, 0.0, 0.0, 0.4, 0.6 }, Relationship.GEQ, valC));
152
RealPointValuePair solution2 = solver.optimize(f, constraints, GoalType.MAXIMIZE, true);
153
Assert.assertEquals(40.57143, solution2.getValue(), .0001);
52
157
public void testSimplexSolver() throws OptimizationException {