4545- `cost::Real`: The optimal cost of the transportation problem.
4646
4747# Description
48+
4849The `TransportationResult` struct represents the result of solving a transportation problem.
4950It contains the original problem, the balanced problem, the solution matrix, and the optimal cost.
5051"""
@@ -120,17 +121,24 @@ end
120121
121122
122123"""
123- solve(t)
124+ solve(t, initial = NoInitial )
124125
125126# Arguments
126- `a::TransportationProblem`: The problem in type of TransportationProblem
127+
128+ - `a::TransportationProblem`: The problem in type of TransportationProblem
127129
128130# Output
129- `TransportationResult`: The custom data type that holds problem, solution, and optimum cost.
131+ - `TransportationResult`: The custom data type that holds problem, solution, and optimum cost.
132+ - `initial::TransportationResult`: The initial solution of the transportation problem (optional).
130133
131134# Description
135+
132136Solves a transportation problem given by an object of in type `TransportationProblem`.
133137
138+ initial is used to store the initial solution of the transportation problem. Any custom
139+ implementation should take a `TransportationProblem` and return a `TransportationResult` object.
140+ Currently, `northwestcorner` and `leastcost` are implemented as custom initial solutions.
141+
134142# Example
135143
136144```julia
@@ -168,7 +176,7 @@ Solution:
168176[-0.0 -0.0 -0.0 100.0; 100.0 -0.0 -0.0 -0.0; -0.0 -0.0 100.0 -0.0; -0.0 100.0 -0.0 -0.0]
169177```
170178"""
171- function solve (t:: TransportationProblem ):: TransportationResult
179+ function solve (t:: TransportationProblem ; initial :: Function = NoInitial ):: TransportationResult
172180 newt = balance (t)
173181
174182 model = JuMP. Model (HiGHS. Optimizer)
@@ -182,7 +190,7 @@ function solve(t::TransportationProblem)::TransportationResult
182190 @constraint (model, sum (x[1 : n, j] for j = 1 : p) .== newt. supply)
183191 @constraint (model, sum (x[i, 1 : p] for i = 1 : n) .== newt. demand)
184192
185- initial_solution = northwestcorner (newt). solution
193+ initial_solution = initial (newt). solution
186194 JuMP. set_start_value .(x, initial_solution)
187195
188196 optimize! (model)
@@ -194,6 +202,8 @@ function solve(t::TransportationProblem)::TransportationResult
194202 return result
195203end
196204
205+
206+
197207"""
198208 northwestcorner(a::TransportationProblem)::TransportationResult
199209
@@ -286,4 +296,9 @@ function leastcost(t::TransportationProblem)::TransportationResult
286296end
287297
288298
299+ function NoInitial (t:: TransportationProblem ):: TransportationResult
300+ TransportationResult (t, t, zeros (size (t. costs)), 0.0 )
301+ end
302+
303+
289304end # end of module
0 commit comments