[R] simplex

arun smartpink111 at yahoo.com
Wed Nov 13 14:19:00 CET 2013



Hi Sven,
May be this helps:

If you look into ?simplex.object 

"

solved This indicates whether the problem was solved.  A value of
          ‘-1’ indicates that no feasible solution could be found.  A
          value of ‘0’ that the maximum number of iterations was
          reached without termination of the second stage.  This may
          indicate an unbounded function or simply that more iterations
          are needed. A value of ‘1’ indicates that an optimal solution
          has been found.
"


 s1 <- simplex(a=price * -1, A1=A, b1=b, A2=A, b2=b2, maxi=T) # This cant find a solution
s1$solved
#[1] -1

A.K.




Dear All, 

I do have a problem with a linear optimisation I am trying to achieve: 

library(boot) 
price <- c(26.93, 26.23, 25.64, 25.97, 26.12, 26.18, 26.49, 27, 27.32, 27.93, 27.72, 27.23) 
A <- matrix(0, nrow=length(price)+1, ncol=length(price)) 
A[1,] <- 1 
for(i in 1:length(price)) A[i+1,i] <- 1 
b <- c(864000.01, 288000, 288000, 288000, 288000, 288000, 288000, 288000, 288000, 288000, 288000, 288000, 288000) 
b2 <- c(864000, 216000, 216000, 216000, 216000, 216000, 216000, 216000, 216000, 216000, 216000, 216000, 216000) 


simplex(a=price, A1=A, b1=b) # This works 
simplex(a=price, A1=A, b1=b, maxi=T) # This is the maxing function and works as well 
simplex(a=price * -1, A1=A, b1=b, A2=A, b2=b2, maxi=T) # This cant find a solution 


The result I would expect is that it picks the 4 
highest(note I multiplied "price" with -1) numbers and multiplies them 
with constraint in b2. 

For example this works: 


library(boot) 
price <- c(1, 2, 3 , 4) 
A <- matrix(0, nrow=length(price)+1, ncol=length(price)) 
A[1,] <- 1 
for(i in 1:length(price)) A[i+1,i] <- 1 
b <- c(8.01, 2.5, 2.5, 2.5, 2.5) 
b2 <- c(8, 2, 2, 2, 2) 

simplex(a=price, A1=A, b1=b) 
simplex(a=price, A1=A, b1=b, maxi=T) 
simplex(a=price * -1, A1=A, b1=b, A2=A, b2=b2, maxi=T) 


I cant see a logical difference between the two, why would it not find a solution for the first problem? 

Thank you. 


Sven



More information about the R-help mailing list