0

I am trying to optimize a transportation problem in R using lpSolve::lp.transport. My code is as follows:

library(lpSolve)

cost <- matrix(rep(100, 34968), nrow = 372)
row.signs <- rep("<=", 372)
row.RHS <- c(t(vehicleGVWR2[,2]))
col.signs <- rep(">=", 94)
col.RHS <- c(t(branchGVWR[, 2]))

lptrans <- lp.transport(cost, "min", row.signs, row.RHS, col.signs, col.RHS)

The cost matrix is "100" at every value because the cost of assignment is considered to be negligible/the same for each combination.

The cost matrix is 372x94. Is this too many variables for the function to handle? Or will the code eventually complete running?

Kim
  • 4,080
  • 2
  • 30
  • 51

1 Answers1

1

You should post the branchGVWR and branchGVWR2 vectors so we can test. However without those, since all of your cost coefficients are exactly equal, the problem solution is probably massively degenerate. So the solver is moving from solution to solution where the solutions are always equal. You could try adding a random epsilon value to each cost coefficient:

cost <- matrix(rep(100,34968),nrow = 372)
cost <- abs(rnorm(34968)) + cost

and see if that fixes the timeout problem.

SteveM
  • 2,226
  • 3
  • 12
  • 16