title: Optimization Solvers with Linear Constraints in R
body: <p>Does anyone know of any R packages that allow you to maximize a function according to a linear constraint? I have been recommended ipoptr but I cannot figure out how to install it so that I can use the R interface.</p>
  <p>For some background, I am trying to allocate 80M of investment (x) between 114 products in a way that maximizes revenue (y). Predicted revenue for each product and investment level is based off a two-part model i.e. it is the result of multiplying the predicted probability of any revenue being generated, by the predicted level of revenue, conditional on revenue being generated. Each line of the objective function represents the fitted model for each product.</p>
  <p>I have tried using nloptr but it seems to be unable to find global maximums - it always gives me the same values as my starting values.</p>
  <p>I am including the functions I am using below.</p>
  <pre><code># Objective function
  function(x){
    return(-((plogis(-0.17283 + 0.0000471*x[1])*exp(9.53643)*(x[1])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[2])*exp(9.53643)*(x[2])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[3])*exp(9.53643)*(x[3])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[4])*exp(9.53643)*(x[4])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[5])*exp(9.53643)*(x[5])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[6])*exp(9.53643)*(x[6])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[7])*exp(9.53643)*(x[7])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[8])*exp(9.53643)*(x[8])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[9])*exp(9.53643)*(x[9])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[10])*exp(9.53643)*(x[10])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[11])*exp(9.53643)*(x[11])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[12])*exp(9.53643)*(x[12])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[13])*exp(9.53643)*(x[13])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[14])*exp(9.53643)*(x[14])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[15])*exp(9.53643)*(x[15])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[16])*exp(9.53643)*(x[16])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[17])*exp(9.53643)*(x[17])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[18])*exp(9.53643)*(x[18])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[19])*exp(9.53643)*(x[19])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[20])*exp(9.53643)*(x[20])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[21])*exp(9.53643)*(x[21])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[22])*exp(9.53643)*(x[22])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[23])*exp(9.53643)*(x[23])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[24])*exp(9.53643)*(x[24])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[25])*exp(9.53643)*(x[25])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[26])*exp(9.53643)*(x[26])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[27])*exp(9.53643)*(x[27])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[28])*exp(9.53643)*(x[28])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[29])*exp(9.53643)*(x[29])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[30])*exp(9.53643)*(x[30])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[31])*exp(9.53643)*(x[31])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[32])*exp(9.53643)*(x[32])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[33])*exp(9.53643)*(x[33])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[34])*exp(9.53643)*(x[34])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[35])*exp(9.53643)*(x[35])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[36])*exp(9.53643)*(x[36])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[37])*exp(9.53643)*(x[37])^0.468)+
               (plogis(-0.17283 + 0.0000471*x[38])*exp(9.53643)*(x[38])^0.468)+
               (plogis(0.11617 + 0.0000471*x[39])*exp(8.70643)*(x[39])^0.468)+
               (plogis(0.11617 + 0.0000471*x[40])*exp(8.70643)*(x[40])^0.468)+
               (plogis(0.11617 + 0.0000471*x[41])*exp(8.70643)*(x[41])^0.468)+
               (plogis(0.11617 + 0.0000471*x[42])*exp(8.70643)*(x[42])^0.468)+
               (plogis(0.11617 + 0.0000471*x[43])*exp(8.70643)*(x[43])^0.468)+
               (plogis(0.11617 + 0.0000471*x[44])*exp(8.70643)*(x[44])^0.468)+
               (plogis(0.11617 + 0.0000471*x[45])*exp(8.70643)*(x[45])^0.468)+
               (plogis(0.11617 + 0.0000471*x[46])*exp(8.70643)*(x[46])^0.468)+
               (plogis(0.11617 + 0.0000471*x[47])*exp(8.70643)*(x[47])^0.468)+
               (plogis(0.11617 + 0.0000471*x[48])*exp(8.70643)*(x[48])^0.468)+
               (plogis(0.11617 + 0.0000471*x[49])*exp(8.70643)*(x[49])^0.468)+
               (plogis(0.11617 + 0.0000471*x[50])*exp(8.70643)*(x[50])^0.468)+
               (plogis(0.11617 + 0.0000471*x[51])*exp(8.70643)*(x[51])^0.468)+
               (plogis(0.11617 + 0.0000471*x[52])*exp(8.70643)*(x[52])^0.468)+
               (plogis(0.11617 + 0.0000471*x[53])*exp(8.70643)*(x[53])^0.468)+
               (plogis(0.11617 + 0.0000471*x[54])*exp(8.70643)*(x[54])^0.468)+
               (plogis(0.11617 + 0.0000471*x[55])*exp(8.70643)*(x[55])^0.468)+
               (plogis(0.11617 + 0.0000471*x[56])*exp(8.70643)*(x[56])^0.468)+
               (plogis(0.11617 + 0.0000471*x[57])*exp(8.70643)*(x[57])^0.468)+
               (plogis(0.11617 + 0.0000471*x[58])*exp(8.70643)*(x[58])^0.468)+
               (plogis(0.11617 + 0.0000471*x[59])*exp(8.70643)*(x[59])^0.468)+
               (plogis(0.11617 + 0.0000471*x[60])*exp(8.70643)*(x[60])^0.468)+
               (plogis(0.11617 + 0.0000471*x[61])*exp(8.70643)*(x[61])^0.468)+
               (plogis(0.11617 + 0.0000471*x[62])*exp(8.70643)*(x[62])^0.468)+
               (plogis(0.11617 + 0.0000471*x[63])*exp(8.70643)*(x[63])^0.468)+
               (plogis(0.11617 + 0.0000471*x[64])*exp(8.70643)*(x[64])^0.468)+
               (plogis(0.11617 + 0.0000471*x[65])*exp(8.70643)*(x[65])^0.468)+
               (plogis(0.11617 + 0.0000471*x[66])*exp(8.70643)*(x[66])^0.468)+
               (plogis(0.11617 + 0.0000471*x[67])*exp(8.70643)*(x[67])^0.468)+
               (plogis(0.11617 + 0.0000471*x[68])*exp(8.70643)*(x[68])^0.468)+
               (plogis(0.11617 + 0.0000471*x[69])*exp(8.70643)*(x[69])^0.468)+
               (plogis(0.11617 + 0.0000471*x[70])*exp(8.70643)*(x[70])^0.468)+
               (plogis(0.11617 + 0.0000471*x[71])*exp(8.70643)*(x[71])^0.468)+
               (plogis(0.11617 + 0.0000471*x[72])*exp(8.70643)*(x[72])^0.468)+
               (plogis(0.90817 + 0.0000471*x[73])*exp(8.89943)*(x[73])^0.468)+
               (plogis(0.90817 + 0.0000471*x[74])*exp(8.89943)*(x[74])^0.468)+
               (plogis(0.90817 + 0.0000471*x[75])*exp(8.89943)*(x[75])^0.468)+
               (plogis(0.90817 + 0.0000471*x[76])*exp(8.89943)*(x[76])^0.468)+
               (plogis(0.90817 + 0.0000471*x[77])*exp(8.89943)*(x[77])^0.468)+
               (plogis(0.90817 + 0.0000471*x[78])*exp(8.89943)*(x[78])^0.468)+
               (plogis(0.90817 + 0.0000471*x[79])*exp(8.89943)*(x[79])^0.468)+
               (plogis(0.90817 + 0.0000471*x[80])*exp(8.89943)*(x[80])^0.468)+
               (plogis(0.90817 + 0.0000471*x[81])*exp(8.89943)*(x[81])^0.468)+
               (plogis(0.90817 + 0.0000471*x[82])*exp(8.89943)*(x[82])^0.468)+
               (plogis(0.90817 + 0.0000471*x[83])*exp(8.89943)*(x[83])^0.468)+
               (plogis(0.90817 + 0.0000471*x[84])*exp(8.89943)*(x[84])^0.468)+
               (plogis(0.90817 + 0.0000471*x[85])*exp(8.89943)*(x[85])^0.468)+
               (plogis(0.90817 + 0.0000471*x[86])*exp(8.89943)*(x[86])^0.468)+
               (plogis(0.90817 + 0.0000471*x[87])*exp(8.89943)*(x[87])^0.468)+
               (plogis(0.90817 + 0.0000471*x[88])*exp(8.89943)*(x[88])^0.468)+
               (plogis(0.90817 + 0.0000471*x[89])*exp(8.89943)*(x[89])^0.468)+
               (plogis(0.90817 + 0.0000471*x[90])*exp(8.89943)*(x[90])^0.468)+
               (plogis(0.90817 + 0.0000471*x[91])*exp(8.89943)*(x[91])^0.468)+
               (plogis(0.90817 + 0.0000471*x[92])*exp(8.89943)*(x[92])^0.468)+
               (plogis(0.90817 + 0.0000471*x[93])*exp(8.89943)*(x[93])^0.468)+
               (plogis(0.90817 + 0.0000471*x[94])*exp(8.89943)*(x[94])^0.468)+
               (plogis(0.90817 + 0.0000471*x[95])*exp(8.89943)*(x[95])^0.468)+
               (plogis(0.90817 + 0.0000471*x[96])*exp(8.89943)*(x[96])^0.468)+
               (plogis(0.90817 + 0.0000471*x[97])*exp(8.89943)*(x[97])^0.468)+
               (plogis(0.90817 + 0.0000471*x[98])*exp(8.89943)*(x[98])^0.468)+
               (plogis(0.90817 + 0.0000471*x[99])*exp(8.89943)*(x[99])^0.468)+
               (plogis(0.90817 + 0.0000471*x[100])*exp(8.89943)*(x[100])^0.468)+
               (plogis(0.90817 + 0.0000471*x[101])*exp(8.89943)*(x[101])^0.468)+
               (plogis(0.90817 + 0.0000471*x[102])*exp(8.89943)*(x[102])^0.468)+
               (plogis(0.90817 + 0.0000471*x[103])*exp(8.89943)*(x[103])^0.468)+
               (plogis(0.90817 + 0.0000471*x[104])*exp(8.89943)*(x[104])^0.468)+
               (plogis(0.90817 + 0.0000471*x[105])*exp(8.89943)*(x[105])^0.468)+
               (plogis(0.90817 + 0.0000471*x[106])*exp(8.89943)*(x[106])^0.468)+
               (plogis(0.90817 + 0.0000471*x[107])*exp(8.89943)*(x[107])^0.468)+
               (plogis(0.90817 + 0.0000471*x[108])*exp(8.89943)*(x[108])^0.468)+
               (plogis(0.90817 + 0.0000471*x[109])*exp(8.89943)*(x[109])^0.468)+
               (plogis(0.90817 + 0.0000471*x[110])*exp(8.89943)*(x[110])^0.468)+
               (plogis(-2.15083 + 0.0000471*x[111])*exp(9.87243)*(x[111])^0.468)+
               (plogis(-2.15083 + 0.0000471*x[112])*exp(9.87243)*(x[112])^0.468)+
               (plogis(-2.15083 + 0.0000471*x[113])*exp(9.87243)*(x[113])^0.468)+
               (plogis(-2.15083 + 0.0000471*x[114])*exp(9.87243)*(x[114])^0.468)+
               (plogis(-1.86183 + 0.0000471*x[115])*exp(9.04243)*(x[115])^0.468)+
               (plogis(-1.86183 + 0.0000471*x[116])*exp(9.04243)*(x[116])^0.468)+
               (plogis(-1.86183 + 0.0000471*x[117])*exp(9.04243)*(x[117])^0.468)+
               (plogis(-1.86183 + 0.0000471*x[118])*exp(9.04243)*(x[118])^0.468)+
               (plogis(-1.06983 + 0.0000471*x[119])*exp(9.23543)*(x[119])^0.468)+
               (plogis(-1.06983 + 0.0000471*x[120])*exp(9.23543)*(x[120])^0.468)+
               (plogis(-1.06983 + 0.0000471*x[121])*exp(9.23543)*(x[121])^0.468)+
               (plogis(-1.06983 + 0.0000471*x[122])*exp(9.23543)*(x[122])^0.468)))
  }
  
  # Inequality constraint function
  eval_g0_ineq &lt;- function(x)
  {
    return(x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]+x[8]+x[9]+x[10]+x[11]+x[12]+x[13]+x[14]+x[15]+x[16]+x[17]+x[18]+x[19]+x[20]+x[21]+x[22]+x[23]+x[24]+x[25]+x[26]+x[27]+x[28]+x[29]+x[30]+x[31]+x[32]+x[33]+x[34]+x[35]+x[36]+x[37]+x[38]+x[39]+x[40]+x[41]+x[42]+x[43]+x[44]+x[45]+x[46]+x[47]+x[48]+x[49]+x[50]+x[51]+x[52]+x[53]+x[54]+x[55]+x[56]+x[57]+x[58]+x[59]+x[60]+x[61]+x[62]+x[63]+x[64]+x[65]+x[66]+x[67]+x[68]+x[69]+x[70]+x[71]+x[72]+x[73]+x[74]+x[75]+x[76]+x[77]+x[78]+x[79]+x[80]+x[81]+x[82]+x[83]+x[84]+x[85]+x[86]+x[87]+x[88]+x[89]+x[90]+x[91]+x[92]+x[93]+x[94]+x[95]+x[96]+x[97]+x[98]+x[99]+x[100]+x[101]+x[102]+x[103]+x[104]+x[105]+x[106]+x[107]+x[108]+x[109]+x[110]+x[111]+x[112]+x[113]+x[114]+x[115]+x[116]+x[117]+x[118]+x[119]+x[120]+x[121]+x[122]-80000)
  }
  
  # Lower bounds
  lb = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
  
  # Upper bounds
  ub = c(30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000),
  
  
  </code></pre>