[R] Optimization in R similar to MS Excel Solver

Berend Hasselman bhh at xs4all.nl
Tue Mar 12 10:26:56 CET 2013


On 12-03-2013, at 08:45, Pavel_K <kuk064 at vsb.cz> wrote:

> Dear Mr Hasselman,
> for a better understanding I have attached an example solved in excel by
> using the tool Solver.
> 
> I want to assign for each municipality one of the centres and apply it for
> calculating the minimum cost as you can see in an example.
> I used package lpsolve, but it does not work. I am not sure how to treat
> with this part of statement, I think I made mistake in it:
> row.rhs <- c(15,10,5,30) and
> col.rhs <- c(1,1,1,1,1,1)
> 
> The example in R:
> 
> library(lpSolve)
> costs <- as.matrix(read.table("C:/R/OPTIMIZATION/DATA.TXT", dec = ",",
> sep=";",header=TRUE)) 
> row.signs <- rep ("=", 4) 
> row.rhs <- c(15,10,5,30) 
> col.signs <- rep ("=", 6) 
> col.rhs <- c(1,1,1,1,1,1) 
> lp.transport (costs, "min", row.signs, row.rhs, col.signs, col.rhs,
> presolve=0, compute.sens=0) 
> lp.transport (costs, "min", row.signs, row.rhs, col.signs, col.rhs,
> presolve=0, compute.sens=0)$solution 
> 
> Outcome: 
> Error in lp.transport(costs, "min", row.signs, row.rhs, col.signs, col.rhs, 
> : 
> Error: We have 6 signs, but 7 columns 
> Hope the example solved in excel will help you to understand my problem.
> 

You post is not available on Nabble.
The excel file is inaccessible because it doesn't exist.

Apart from that: show the contents of costs.
Use

dput(costs)

and put the result in the message to R-help. That is the only way one can find out why lp.transport gives an error.
And please read the posting guide (link is at the bottom of each posting to this list).

Berend

> Thank you
> Pavel
> example.xls <http://r.789695.n4.nabble.com/file/n4661019/example.xls>  
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Optimization-in-R-similar-to-MS-Excel-Solver-tp4660997p4661019.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list