Skip to content

Commit 54f5bb3

Browse files
committed
add tests for linear transportation problem
1 parent b0fa26d commit 54f5bb3

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

test/testsimplex.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,32 @@
113113

114114
end
115115

116+
@testset "Mini Transportation Problem - 2" begin
116117

118+
eps = 0.001
119+
# M1 M2 M3 Supply
120+
# F1 10 20 25 150
121+
# F2 12 15 7 100
122+
# Demand 190 40 20
123+
s = createsimplexproblem(
124+
Float64[10, 20, 25, 12, 15, 7],
125+
Float64[1 1 1 0 0 0; 0 0 0 1 1 1; 1 0 0 1 0 0; 0 1 0 0 1 0; 0 0 1 0 0 1],
126+
Float64[150, 100, 190, 40, 20],
127+
[EQ, EQ, EQ, EQ, EQ],
128+
Minimize)
129+
130+
iters = simplexiterations(s)
131+
132+
lastiter = iters[end]
133+
134+
@test lastiter.converged
135+
@test isapprox(lastiter.objective_value, 2720.0, atol=eps)
136+
@test sort(lastiter.basicvariableindex) == [1, 4, 5, 6, 10]
137+
@test sort(lastiter.artificialvariableindices) == [7, 8, 9, 10, 11]
138+
@test isapprox(lastiter.rhs, [150.0, 40.0, 40.0, 0.0, 20.0], atol=eps)
139+
end
117140

118-
@testset "Mini Transportation Problem" begin
141+
@testset "Mini Transportation Problem - 1" begin
119142

120143
eps = 0.001
121144
# Mini Transportation Problem

test/testtransportation.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@test balancedT.demand |> last == 200
4545
end
4646

47-
@testset "Solution" begin
47+
@testset "Solution - 1" begin
4848
#=
4949
| | D1 | D2 | D3 | D4 | Supply |
5050
| S1 | 1 | 5 (100) | 7 | 8 | 100 |
@@ -77,6 +77,18 @@
7777
]
7878
end
7979

80+
@testset "Solution - 2" begin
81+
t = TransportationProblem(
82+
Float64[10 20 25; 12 15 7],
83+
Float64[190, 40, 20],
84+
Float64[150, 100])
85+
86+
result = solve(t)
87+
88+
@test result.cost == 2720.0
89+
@test result.solution == [150.0 0.0 0.0; 40.0 40.0 20.0]
90+
end
91+
8092
@testset "North-West Corner" begin
8193
@testset "Example 1" begin
8294
t = TransportationProblem(

0 commit comments

Comments
 (0)