You could divide the problem in z=0
and z>=0
. For the second subproblem, you could set up and solve the problem like this:
library(lpSolveAPI)
# create object
lprec <- make.lp(0,3)
invisible(lp.control(lprec, sense="max")) # sense defaults to "min"
# add objective and constraints
set.objfn(lprec, obj=c(150,92,41.1), indices=c(1,2,3))
add.constraint(lprec, 1, type="<=", rhs=600, indices=1)
add.constraint(lprec, 1, type=">=", rhs=200, indices=1)
add.constraint(lprec, 1, type="<=", rhs=600, indices=2)
add.constraint(lprec, 1, type=">=", rhs=200, indices=2)
add.constraint(lprec, c(1,1,1), type="<=", rhs=600, indices=c(1,2,3))
add.constraint(lprec, c(1,1), type=">=", rhs=200, indices=c(1,2))
# solve
print(lprec)
solve(lprec)
get.variables(lprec)
Note that I assumed that you meant 0<=y<=600
in your question. Note also that is not very useful (or possible) to set "<" constraints, it is much better to use "<=". At last, note that lpSolveAPI
assumes non-negativity of the decision variables by default, hence it is assumed z>=0
.
The first subproblem can be solved similarly. As you already know that in this case z=0
, the number of decision variables reduces to 2
.
The solution to the problem is then the best of both subsolutions. As @RHertel already commented, it is the solution where you put as much as you can onto x
, hence, y
and z
are 0.