title: R: Error in is.nloptr(ret) : inequality constraints in x0 returns NA
body: <p>I was trying to solve a nonlinear optimization problem using <code>nloptr</code> package in R, <a href="https://cran.r-project.org/web/packages/nloptr/index.html" rel="nofollow noreferrer">CRAN page</a>. </p>
  
  <pre><code>library('nloptr')
  
  #parameters 
  N_h &lt;- c(39552, 38347, 43969, 36942, 41760)
  
  s_h1 &lt;- c(4.6, 3.4, 3.3, 2.8, 3.7)
  
  s_h2 &lt;- c(11.7, 9.8, 7.0, 6.5, 9.8)
  
  s_h3 &lt;- c(332, 357, 246, 173, 279)
  
  Cost &lt;- c(3,4,5,6,7)
  
  C_cap &lt;- c(1.5, 1.5, 1.5, 1.5, 1.5)
  
  c&lt;- Cost+C_cap
  N &lt;- sum(N_h)
  d_h &lt;- c(N_h/N)
  d1 &lt;-(d_h)^2*s_h1
  d2 &lt;-(d_h)^2*s_h2
  d3 &lt;-(d_h)^2*s_h3
  
  
  
  #Objective
  f0&lt;-function(x, d1, d2, d3, c, Gamma){
   return(x[1])
  }
  
  
  #Constraints
  g0&lt;- function(x, d1, d2, d3, c, Gamma){
     return(c((c[1]*x[2]+c[2]*x[3]+c[3]*x[4]+c[4]*x[5]+c[5]*x[6]+x[7]*Gamma+sum(x[8:12])-x[1]),
  
         (-x[7]-x[8]+c[1]*x[2]),
         (-x[7]-x[9]+c[2]*x[3]),
         (-x[7]-x[10]+c[3]*x[4]),
         (-x[7]-x[11]+c[4]*x[5]),
         (-x[7]-x[12]+c[5]*x[6]),
         (d1[1]/x[2]+d1[2]/x[3]+d1[3]/x[4]+d1[4]/x[5]+d1[5]/x[6]-0.5037),
         (d2[1]/x[2]+d2[2]/x[3]+d2[3]/x[4]+d2[4]/x[5]+d2[5]/x[6]-0.50868),
         (d3[1]/x[2]+d3[2]/x[3]+d3[3]/x[4]+d3[4]/x[5]+d3[5]/x[6]-0.55),
         (x[2]+x[3]+x[4]+x[5]+x[6]-1081)
     ))
      }
  
    #Initialization and algo
  x0&lt;-c(100, 10,10,10,10,10,  2,  2,2,2,2)
  
  
  
  Rob2 &lt;- nloptr(x0=x0,
                  eval_f = f0,
                  lb=c(-Inf, 2,2,2,2,2,  0,  0,0,0,0),
                  ub=c(Inf, 1000,1000,1000,1000,1000,  Inf,  Inf,Inf,Inf,Inf),
                  eval_g_ineq=g0,
                  opts=list("algorithm"="NLOPT_GN_MLSL",
                            maxeval=100000,
                            "xtol_rel"=1.0e-8,
                            "print_level" = 2),
                  d1=d1, d2=d2,d3=d3, c=c, Gamma=Gamma)
  </code></pre>
  
  <p>On running this algorithm the Error is as follows:</p>
  
  <pre><code>   Error in is.nloptr(ret) : inequality constraints in x0 returns NA
  </code></pre>
  
  <p>Any suggestion or help would be highly appreciable.!!</p>
  
  <p>#Edit</p>
  
  <p>The original problem is like follows</p>
  
  <pre><code>Min x[1]
  subject to
  -x[7]-x[8]+c[1]*x[2]&lt;=0
  -x[7]-x[9]+c[2]*x[3]&lt;=0
  ..
  ..
  x[2]+x[3]+x[4]+x[5]+x[6]-1081&lt;=0
  </code></pre>