1

I am new to optimization so please bear with me. Here is my problem:

A, B, C, D and E are percentages (18%,2%,1%,78%,1%)

Maximize sum (A(x) + B(x) + C(x) +D(x) + E(x)) ie maximize x ( x<=499572)

such that

  1. A(x) <= 20076
  2. B(x) <= 8619
  3. C(x) <= 145
  4. D(x) <= 465527
  5. E(x) <= 5205

How do I frame this problem in R?

I was using LPsolve package but I am ok with any suggestions.

2
  • Forget R, you just need a simple calculator. The optimal x is the smallest x in the range which violates one of the 5 constraints (or, 499572 if none of the constraints are violated). You don't really need linear programming with just 1 decision variable. This blog post shows how to use LPsolve in R. Commented Sep 20, 2018 at 11:25
  • It is your third constraint which is binding, leading to an optimal solution of x = 14500. Commented Sep 20, 2018 at 11:38

1 Answer 1

4

We restate the problem, omitting positivity constraints on the single scalar variable x, as:

maximize 1 * x
such that
 0.18 * x <= 20076 
 0.02 * x <= 8619 
 0.01 * x <= 145 
 0.78 * x <= 465527 
 0.01 * x <= 5205 

so as a linear program we have the following optimum value of x:

library(lpSolve)

constr.mat <- c(.18, .02, .01, .78, .01)
RHS <- c(20076, 8619, 145, 465527, 5205)
soln <- lp("max", 1, constr.mat, "<=", RHS)
soln$solution
## [1] 14500

Of course, as pointed out in the comments below the question this problem can be solved trivially without linear programming by taking the least upper bound of x:

min(RHS / constr.mat)
## [1] 14500

Note

If what you really meant was not the problem stated in the question but rather this 5 variable problem:

max 0.18 * x1 + 0.02 * x2 + 0.01 * x3 + 0.78 * x4 + 0.01 * x5
such that
 0.18 * x1 <= 20076 
 0.02 * x2 <= 8619 
 0.01 * x3 <= 145 
 0.78 * x4 <= 465527 
 0.01 * x5 <= 5205 

then we have

soln2 <- lp("max", constr.mat, diag(constr.mat), "<=", RHS)
soln2$solution
## [1] 111533.3 430950.0  14500.0 596829.5 520500.0

Again this is trivial to compute without linear programming:

RHS / constr.mat
## [1] 111533.3 430950.0  14500.0 596829.5 520500.0
Sign up to request clarification or add additional context in comments.

1 Comment

this works..thank you so much... i understand some of it. I will get back if I have more doubts :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.