Thanks to Peter and Mark for your replies - I am obviously not setting up the inputs correctly.
On Thu, Oct 23, 2008 at 3:02 AM, <[EMAIL PROTECTED]> wrote: > Hi Selwyn: To follow up on Peter's reply, you're either not setting up the > problem to do what you want it to do or you're not understand > what it is doing. I explain your first two cases below. > > CASE 1) > > proportions = c( 0.46, 0.28, 0.26) > constraints = c( 352, 75, 171) > > temp <- lp(objective.in = proportions, > const.mat = diag(c(1,1,1)), > const.rhs=constraints, > const.dir=rep('<=',3), > direction='max' > ) > > print(temp$solution) > > ## > Success: the objective function is 227.38 > > 227.38*proportions > > 227.38 * proportions #[1] 104.5948 63.6664 59.1188 (OK all less than > constraints, however...) > > > > #================================================================================== > MY COMMENT > > the problem you just set up above is > > max( .46*x1 + 0.28*x2 + 0.26*x3 ) > subject to > > x1 <= 352 > x2 <= 75 > x3 <= 171 > > x_i >= 0 for all i ( that's an implied constraint in lpSolve becaue all > decision variables are restericted to be positive implicitly ) > > and if you type > > print(temp$solution) > > you will see that the answer is x1=352, x2 = 75 and x3 = 171. > > Now, in below you said 267 is a better answer but there are 2 problems > with this statement. > > 1) how did you achieve the objective function of 267 ? the objective > function is 0.46*x1 + 0.28*x2 + 0.26*x3 > > 2) multiplying the objective function VALUE by the propotions has no > meaning. the solution, which is the INDIVIDUAL VALUES OF > THE SOLUTUON, multiplies the proportions and this is the optimal value of > objective function You can't get any better objective function value > than 227.38 in your model formulation above. It basically just sets the > values of the x1, x32 and x3 so that the constraints are binding. > this way the maximum objective function is achieved because all the > coefficients of the objective function ( what you > call proportions ) are positive. > > > #========================================================================= > > CASE2 : this problem set up is similar to the rpevious one just with > different values. it's > > max( .47*x1 + 0.28*x2 + 0.25*x3 ) > subject to > > x1 <= 12 > x2 <= 7 > x3 <= 99 > > essentially my commet here is the as the previous comment. the budget > constraints are not violated. if you type print(temp$solution) you will > see that the solution is x1=12, x2 = 7 and x3 = 99. again, 32.35* > proprtions2 has no meaning in this problem. you > need to multiply the coefficients , x1, x2 and x3 by their correspoding > proportions and you will see that this > equals the value of the objective function. and again, the constraints are > not violated because the constraints > are in fact binding. x1 goes to its maximum value, x2 takes on its maximum > value and x3 takes on its maximum value. > > so, maybe these are not the problems you're trying to solve but lpSolve is > doing the correct thing, given the problems you are sending it. > I hope this helped. Good luck. > > ## This example goes over the budget constraints > > proportions2 = c( 0.47, 0.28, 0.25) > constraints2 = c(12, 7, 99) > > temp <- lp(objective.in = proportions2, > const.mat = diag(c(1,1,1)), > const.rhs=constraints2, > const.dir=rep('<=',3), > direction='max' > ) > > print(temp$solution) > > ## > Success: the objective function is 32.35 > 32.35 * proportions2 ##[1] 15.2045 9.0580 8.0875 1st and second values > are > higher than the constraints allow!!! > > > > > # your original email is below. > > > #==================================================================================== > > On Wed, Oct 22, 2008 at 10:33 AM, Selwyn McCracken wrote: > > Hi list, >> >> I want to find the total maximum resources I can spend given a set >> allocation proportion and some simple budget constraints. >> >> However, I get suboptimal results via lp and friends (i.e. lpSolve and >> simplex in the linprog and boot) . >> >> For example: >> >> library(lpSolve) >> >> proportions = c( 0.46, 0.28, 0.26) >> constraints = c( 352, 75, 171) >> >> lp(objective.in = proportions, >> const.mat = diag(c(1,1,1)), >> const.rhs=constraints, >> const.dir=rep('<=',3), >> direction='max' >> ) >> >> ## > Success: the objective function is 227.38 >> 227.38 * proportions #[1] 104.5948 63.6664 59.1188 (OK all less than >> constraints, however...) >> >> 267 * proportions ## [1] 122.82 74.76 69.42 (... a better result is >> possible) >> >> ## This example goes over the budget constraints >> >> proportions2 = c( 0.47, 0.28, 0.25) >> constraints2 = c(12, 7, 99) >> >> lp(objective.in = proportions2, >> const.mat = diag(c(1,1,1)), >> const.rhs=constraints2, >> const.dir=rep('<=',3), >> direction='max' >> ) >> >> ## > Success: the objective function is 32.35 >> 32.35 * proportions2 ##[1] 15.2045 9.0580 8.0875 1st and second values >> are >> higher than the constraints allow!!! >> >> Any help gratefully received. >> >> Best regards, >> Selwyn >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.