Skip to content

Commit ff3b7c2

Browse files
committed
add new tests for Simplex
1 parent cb3bae9 commit ff3b7c2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 0.2.9 (Upcoming Release)
22

33
- Fix documentation of simplex
4+
- Add tests for Simplex
45

56

67
### 0.2.8

test/testsimplex.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,49 @@
5858

5959
end
6060

61+
@testset "Capacity planning example" begin
62+
63+
eps = 0.00001
64+
# Maximize z = 3x + 4y
65+
# subject to
66+
# x + 2y <= 300
67+
# 2x + y <= 300
68+
# x, y >= 0
69+
problem1 = createsimplexproblem(
70+
[3.0, 4.0],
71+
[1.0 2.0; 2.0 1.0],
72+
[300.0, 300.0],
73+
[LE, LE],
74+
Maximize,
75+
)
76+
iters = simplexiterations(problem1)
77+
lastiter = iters[end]
78+
@test lastiter.converged
79+
@test isapprox(lastiter.objective_value, 700.0, atol = eps)
80+
@test isapprox(lastiter.rhs, [100.0, 100.0], atol = eps)
81+
82+
# Maximize z = 3x + 4y
83+
# subject to
84+
# x + 2y <= Cap1
85+
# 2x + y <= Cap2
86+
# Cap1 + Cap2 = 600
87+
# x, y, Cap1, Cap2 >= 0
88+
problem2 = createsimplexproblem(
89+
[3.0, 4.0, 0.0, 0.0],
90+
[1.0 2.0 -1.0 0.0; 2.0 1.0 0.0 -1.0; 0.0 0.0 1.0 1.0],
91+
[eps, eps, 600.0],
92+
[LE, LE, EQ],
93+
Maximize,
94+
)
95+
iters = simplexiterations(problem2)
96+
lastiter = iters[end]
97+
@test lastiter.converged
98+
# Problem has epsilons in rhs, so objective value is slightly off
99+
# due to numerical issues. Allowing a bit more tolerance here.
100+
@test isapprox(lastiter.objective_value, 800.0, atol = 10 * eps)
101+
@test isapprox(lastiter.rhs, [200.0, 200.0, 400.0], atol = 10 * eps)
102+
end
103+
61104

62105

63106
@testset "Minimization Problem" begin

0 commit comments

Comments
 (0)