Transportation problem: Difference between revisions

Content added Content deleted
(→‎{{header|R}}: fix double output line)
(→‎{{header|Julia}}: swap optimizers: GLPK for Ipopt (produces integer solutions))
Line 2,496: Line 2,496:
=={{header|Julia}}==
=={{header|Julia}}==
Code taken from [https://github.com/dylanomics/transportation_problem here] using [https://jump.dev/JuMP.jl/stable/ JuMP].
Code taken from [https://github.com/dylanomics/transportation_problem here] using [https://jump.dev/JuMP.jl/stable/ JuMP].
<lang julia>using JuMP, Ipopt
<lang julia>using JuMP, GLPK


# cost vector
# cost vector
Line 2,512: Line 2,512:


# construct model
# construct model
model = Model(Ipopt.Optimizer)
model = Model(GLPK.Optimizer)
@variable(model, x[i=1:N] >= 0, base_name="traded quantities")
@variable(model, x[i=1:N] >= 0, base_name="traded quantities")
cost_fn = @expression(model, c'*x) # cost function
cost_fn = @expression(model, c'*x) # cost function
Line 2,531: Line 2,531:


{{out}}
{{out}}
<pre>solution vector of quantities = [20.000000008747048, 0.0, 4.9999996490783145, 0.0, 30.000000007494098, 5.0000003509216855]
<pre>solution vector of quantities = [20.0, 0.0, 5.0, 0.0, 30.0, 5.0]
minimum total cost = 179.99999927567436</pre>
minimum total cost = 180.0</pre>


=={{header|Kotlin}}==
=={{header|Kotlin}}==