setting variables to a value using linear programming in r -
i have developed linear programming model in r , know command set variable value, here code , results:
install.packages("lpsolveapi") library(lpsolveapi) #want solve 6 variables, these correspond number of bins lprec <- make.lp(0, 6) lp.control(lprec, sense="max") #model 1 set.objfn(lprec, c(13.8, 70.52,122.31,174.73,223.49,260.65)) add.constraint(lprec, c(13.8, 70.52, 122.31, 174.73, 223.49, 260.65), "=", 204600) add.constraint(lprec, c(1,1,1,1,1,1), "=", 5000)
here results:
> solve(lprec) [1] 0 > get.objective(lprec) [1] 204600 > get.variables(lprec) [1] 2609.309 2390.691 0.000 0.000 0.000 0.000
i set first result (2609) 3200,and last result 48, , optimize on other variables, appreciated.
ideally expectation constrained optimization should add more constraints per requirement. not familiar lpsolveapi , not able correct coding need like:
add.constraint(lprec, c(1, 0, 0, 0, 0, 0), "=", 3200) add.constraint(lprec, c(0, 0, 0, 0, 0, 1), "=", 48)
along existing constraints.
Comments
Post a Comment