r - get.basis() in lpSolveAPI -
i confused return of function get.basis(). example,
lprec <- make.lp(0, 4) set.objfn(lprec, c(1, 3, 6.24, 0.1)) add.constraint(lprec, c(0, 78.26, 0, 2.9), ">=", 92.3) add.constraint(lprec, c(0.24, 0, 11.31, 0), "<=", 14.8) add.constraint(lprec, c(12.68, 0, 0.08, 0.9), ">=", 4) set.bounds(lprec, lower = c(28.6, 18), columns = c(1, 4)) set.bounds(lprec, upper = 48.98, columns = 4) rownames <- c("thisrow", "thatrow", "lastrow") colnames <- c("colone", "coltwo", "colthree", "colfour") dimnames(lprec) <- list(rownames, colnames) solve(lprec)
then basic variables are
> get.basis(lprec) [1] -7 -2 -3
however, solution is
> get.variables(lprec) [1] 28.60000 0.00000 0.00000 31.82759
from solution, seems variable 1 , variable 4 basis. hence how vector (-7, -2, -3) come from?
i guessing 3 constraints , 4 decision variables.
after reviewed simplex method bounded variables, understood how happens. these 2 links helpful. example; video
come problem, structure
lpsolveapi (r interface lp_solve) rewrite constraint structure following format after adding appropriate slack variables. first 3 columns slack variables. hence, return of get.basis()
, -7,-2,-3, column 7, 2, 3 represent variable 4, slack variable 2 , 3.
with respect kind of lp bounded variables, variable nonbasic @ either lower bound or upper bound. return of get.basis(lp, nonbasic=true)
-1,-4,-5,-6. minus means these variables @ lower bound. means slack variable 1 = 0, variable 4 = 28.6, variable 5 = 0, variable 6 = 0.
thus, optimal solution 28.6(nonbasic), 0(nonbasic), 0(nonbasic), 31.82(basic)
Comments
Post a Comment