Transportation problem: Difference between revisions

Undo revision 317421 by Dylanomics (talk)
(Undo revision 317422 by Dylanomics (talk))
(Undo revision 317421 by Dylanomics (talk))
Line 2,495:
 
=={{header|Julia}}==
Code taken fromUsing [https://github.com/dylanomicsJuliaOpt/transportation_problemMathProgBase.jl here] using [https://jump.dev/JuMPMathProgBase.jl/stable/ JuMP].
<lang julia>using JuMPMathProgBase, IpoptClp
 
c = [3, 5, 7, 3, 2, 5];
# cost vector
c = [3, 5, 7, 3, 2, 5];
N = size(c,1);
 
# constraints Ax (<,>,=) b
A = [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];
b = [ 25, 35, 20, 30, 10];
s = ['<', '<', '=', '=', '='];
 
b = [ 25, 35, 20, 30, 10];
# construct model
s = ['<', '<', '=', '=', '='];
model = Model(Ipopt.Optimizer)
@variable(model, x[i=1:N] >= 0, base_name="traded quantities")
cost_fn = @expression(model, c'*x) # cost function
@constraint(model, C1, A[1:2,:]*x .<= b[1:2]) # inequality constraints
@constraint(model, C2, A[3:5,:]*x .== b[3:5]) # equality constraints
@objective(model, Min, cost_fn) # objective function
 
sol = linprog(c, A, b, s, ClpSolver())
# solve model
@show sol.status
status = JuMP.optimize!(model);
@show sol.sol
xstar = value.(x);
@show sol.objval</lang>
println("solution vector of quantities = ", xstar)
println("minimum total cost = ", JuMP.objective_value(model))
 
# recover Lagrange multipliers for post-optimality
λ = [JuMP.dual(C1[1]),JuMP.dual(C1[2])]
μ = [JuMP.dual(C2[1]),JuMP.dual(C2[2]),JuMP.dual(C2[3])]
{{out}}
<pre>sol.status = :Optimal
<pre>
solution vector of quantitiessol.sol = [20.0000000087470480, 0.0, 45.99999964907831450, 0.0, 30.0000000074940980, 5.00000035092168550]
minimum total costsol.objval = 179180.999999275674360</pre>
 
=={{header|Kotlin}}==