Anonymous user
Transportation problem: Difference between revisions
add R to list of languages
(small change to </lang> to break up Kotlin from Julia (oof that took a while to find)) |
(add R to list of languages) |
||
Line 3,551:
</pre>
Note that [[Vogel%27s_approximation_method#Phix]] gets a few of the others wrong and loops on #2, then again that is unbalanced (needs a dummy customer), and I'm not sure whether throwing such at VAM is fair or not.
=={{header|R}}==
Using <code>lpSolve::lptransport</code>.
<lang R>library(lpSolve)
# cost matrix
costs <- matrix(c(3, 5, 7,
3, 2, 5), nrow = 2, byrow = TRUE)
# constraints for suppliers
row.signs <- rep("<=", 2)
row.rhs <- c(25, 35)
# constraints for customers
col.signs <- rep("=", 3)
col.rhs <- c(20, 30, 10)
# minimum cost (objective value)
lp.transport(costs, "min", row.signs, row.rhs, col.signs, col.rhs)
# solution matrix
sol = lp.transport(costs, "min", row.signs, row.rhs, col.signs, col.rhs)$solution
rownames(sol) <- c("Supplier 1", "Supplier 2")
colnames(sol) <- c("Customer 1", "Customer 2", "Customer 3")
sol </lang>
{{out}}
Output:
<pre>Success: the objective function is 180
Customer 1 Customer 2 Customer 3
Supplier 1 20 0 5
Supplier 2 0 30 5
</pre>
=={{header|Racket}}==
|