Skip to content
Prev 319280 / 398503 Next

Optimization in R similar to MS Excel Solver

Pavel_K <kuk064 <at> vsb.cz> writes:
(1) The solution you say the Excel Solver returns does not appear to be 
    correct: The column sum in columns 3 to 5 is not (greater or) equal
    to 1 as you request.

(2) lpSolve does not return an error, but says "no feasible solution found",
    which seems to be correct: The equality constraints are too strict.

(3) If you relieve these constraints to inequalities, lpSolves does find
    a solution:

    costs <- matrix(c(
    30, 20, 60, 40, 66, 90,
    20, 30, 60, 40, 66, 90,
    25, 31, 60, 40, 66, 90,
    27, 26, 60, 40, 66, 90), 4, 6, byrow = TRUE)

    firms <- c(15, 10, 5, 30)

    row.signs <- rep (">=", 4)
    row.rhs   <- firms
    col.signs <- rep (">=", 6)
    col.rhs   <- c(1,1,1,1,1,1)

    require("lpSolve")
    T <- lp.transport (costs, "min", row.signs, row.rhs, col.signs, col.rhs,
                       presolve = 0, compute.sens = 0)
    T$solution
    sum(T$solution * costs)     # 1557

Of course, I don't know which constraints you really want to impose.
Hans Werner