r - how to write code for a given mathematical model using lpSolve -


i have following mathematical model:

enter image description here

and following r code above model:

library(utils); library(xlsx) library(lpsolve) datadea<- structure(list(dmus = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,  13, 14, 15, 16, 17, 18, 19, 20, 21, 22), input1cash = c(5, 6,  4, 8, 5, 8, 4.4, 2.6, 3.4, 3.6, 2, 3, 3, 2.6, 4, 5, 6, 4, 7,  6, 8, 9), input2lev = c(4, 5, 5, 5, 6, 3, 4.4, 8, 8, 4.4, 7,  7, 5.6, 5, 4, 3.2, 4, 3.5, 3, 2.5, 2, 2), output1eps = c(1, 1,  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),   output2roa = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0, 0, 0), members = c(1, 1, 1, 1, 1, 1, 1,    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), .names = c("dmus",  "input1cash", "input2lev", "output1eps", "output2roa", "members" ), row.names = c(na, 22l), class = "data.frame") effcrs<- structure(c(0.846153846153846, 0.6875, 0.838461538461538,  0.611111111111111,  0.685534591194969, 0.8, 0.85423197492163, 0.82, 0.706896551724138,  0.942906574394464, 1, 0.803921568627451, 0.883306320907618, 1,  0.939655172413793, 0.964912280701755, 0.785714285714286, 1,  0.846153846153846, 1, 1, 1), .dim = c(22l, 1l), .dimnames = list(c("effcrs", "efficiency",  "efficiency", "efficiency", "efficiency", "efficiency", "efficiency",  "efficiency", "efficiency", "efficiency", "efficiency", "efficiency",  "efficiency", "efficiency", "efficiency", "efficiency", "efficiency",  "efficiency", "efficiency", "efficiency", "efficiency", "efficiency" ), null)) n <- 22 # number of dmu s = 2 # number of inputs m = 1 # number of outputs inputs = datadea[,c(2,3)] outputs = datadea[,4] #code minimum cross efficiencies crosseffmin <- matrix(0,nrow=n,ncol=n)  #code minimum cross efficiencies crosseffmin <- matrix(0,nrow=n,ncol=n) (i in 1:n) { f.obj <- c(rep(0,s),(datadea[i,4])) # objective function coefficients aux1 <- cbind(outputs,-1*inputs) #constraint 3 row.names(aux1) <- 1:nrow(aux1)#new line aux1<- rbind(aux1,c(0*rep(1,m),as.numeric(inputs[i,]))) # constraint 1 aux1<- rbind(aux1,c(as.numeric(outputs[i]),effcrs[i]*as.numeric(-inputs [i,]))) #constraint 2 f.con <- aux1 #all lhs constraints f.rhs = rep(0,(n+1)) # rhs constraint 3 f.rhs[n+1] = 1 #rhs constraint 2 f.rhs[n+2] = 0 #rhs constraint 1 f.dir <- rep("<=",n+1) #direction constraint 3 f.dir[n+1] = "=" #direction constraint 2 f.dir[n+2] = "=" #direction constraint 1 constraints<- rbind(f.con,f.dir,f.rhs) #all defined constraint matrix  result <- lp("min", f.obj, f.con, f.dir, f.rhs,scale=0, compute.sens=true) weights0 <- result$solution  (j in 1:n) { crosseffmin[i,j] <- (weights0[1:m]%*%t(outputs[j]))/(weights0[(m+1): (m+s)]%*%t(inputs[j,])) } }  print(crosseffmin) 

in crosseffmin matrix values bottom 3 lines incorrect, objective function , constraints defined correct lp function?

the correct output sample first few columns following (where can see values last 3 row #19,20 , 21:

desired output


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -