0

I have an equation with three variables to different ranges for the variables

f(x)= 150*x + 92*y + 41,1*z -> max

subject to

x > 0 & x < 600
x > 0 & x < 600
x+y+z <600
if x<200 or y<200 or x+y <200 -> z=0

I would like to find the maximum value for the variable. My knowledge of R is too small to be able to solve it by myself.

Krantz
  • 1,424
  • 1
  • 12
  • 31
Mariusz
  • 3
  • 3

1 Answers1

1

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.

Karsten W.
  • 17,826
  • 11
  • 69
  • 103