Skip to content

Commit 5239486

Browse files
committed
export JuMP model from Transportation problems
1 parent a434933 commit 5239486

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/transportation.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,22 @@ end
4343
- `balancedProblem::TransportationProblem`: The balanced transportation problem.
4444
- `solution::Matrix`: The solution matrix of the transportation problem.
4545
- `cost::Real`: The optimal cost of the transportation problem.
46+
- `model::Union{JuMP.Model, Nothing}`: The JuMP model used to solve the transportation problem. Methods that
47+
do not use JuMP will set this field to `nothing`.
48+
4649
4750
# Description
4851
4952
The `TransportationResult` struct represents the result of solving a transportation problem.
5053
It contains the original problem, the balanced problem, the solution matrix, and the optimal cost.
54+
5155
"""
5256
struct TransportationResult
5357
originalProblem::TransportationProblem
5458
balancedProblem::TransportationProblem
5559
solution::Matrix
5660
cost::Real
61+
model::Union{JuMP.Model, Nothing}
5762
end
5863

5964
function Base.show(io::IO, t::TransportationProblem)
@@ -202,7 +207,7 @@ function solve(
202207
solution = value.(x)
203208
cost = JuMP.objective_value(model)
204209

205-
result = TransportationResult(t, newt, solution, cost)
210+
result = TransportationResult(t, newt, solution, cost, model)
206211
return result
207212
end
208213

@@ -253,7 +258,7 @@ function northwestcorner(t::TransportationProblem)::TransportationResult
253258
end
254259

255260
cost = problem.costs .* asgnmatrix |> sum
256-
result = TransportationResult(t, problem, asgnmatrix, cost)
261+
result = TransportationResult(t, problem, asgnmatrix, cost, nothing)
257262
return result
258263
end
259264

@@ -295,13 +300,13 @@ function leastcost(t::TransportationProblem)::TransportationResult
295300
end
296301
cost += amount * mincost
297302
end
298-
result = TransportationResult(t, problem, asgnmatrix, cost)
303+
result = TransportationResult(t, problem, asgnmatrix, cost, nothing)
299304
return result
300305
end
301306

302307

303308
function NoInitial(t::TransportationProblem)::TransportationResult
304-
TransportationResult(t, t, zeros(size(t.costs)), 0.0)
309+
TransportationResult(t, t, zeros(size(t.costs)), 0.0, nothing)
305310
end
306311

307312

0 commit comments

Comments
 (0)