Reputation: 1535
Hello and thanks in advance. I'm using the package lpSolveAPI
to solve a linear programming problem. When I create my Linear Programming object then add my constraints, I'm iterating through all the rows in my constraint matrix mat
and adding constraints separately. The example here seems to do the same except by setting columns. Must I add each constraint separately? Or is there a way to just attach the entire constraint matrix, direction vector and right-hand-side vectors at once?
#Generate Linear Programming Object
lprec <- make.lp(nrow = nrow(mat) # Number of Constraints
, ncol = ncol(mat) # Number of Decision Variables
)
#Set Objective Function to Minimize
set.objfn(lprec, obj)
#Adding Constraints Separately
#Note Direction is included along with Constraint Value
for(i in 1:nrow(mat) ){
add.constraint(lprec,mat[i,], dir[i], rhs[i])
print(i)
}
Upvotes: 1
Views: 1093
Reputation: 108
lpSolveAPI doesn't allow this but you can use lpsove which is another package/interface to Lp_solve.
lprec <- lp(const.mat=mat, ...)
In the same way, direction and objective can be submitted as vectors using const.dir
and objective
parameters.
Upvotes: 0