title: Constrained optimization in python where one variable depends on another variable
body: <p>I have a problem where I have 4 variables <code>x1, x2, x3 and x4</code>. I need to find the values for <code>x1, x2, x3, x4</code> with the following conditions:</p>
  
  <pre><code>1. 1995 &lt; 2*x1 + 4*x2 + 3*x3 + x4 &lt; 2000
  2. x1 &gt;= 1.2*x2
  3. x2 &gt;= 1.3*x3
  4. x3 &gt;= 1.1*x4
  5. x4 &gt; 0.0
  </code></pre>
  
  <p>I was able do this using python-constraint (<a href="https://labix.org/python-constraint" rel="nofollow noreferrer">https://labix.org/python-constraint</a>) but it takes ~30 mins to solve this on my system, which is too long.</p>
  
  <pre><code>from constraint import *
  
  problem = Problem()
  problem.addVariable("x1", range(100,500))
  problem.addVariable("x2", range(100,500))
  problem.addVariable("x3", range(100,500))
  problem.addVariable("x4", range(100,500))
  
  problem.addConstraint(lambda a, b, c, d: 2*a + 3*b + 4*c + 5*d &gt; 1995, ["x1", "x2", "x3", "x4"])
  problem.addConstraint(lambda a, b, c, d: 2*a + 3*b + 4*c + 5*d &lt; 2005, ["x1", "x2", "x3", "x4"])
  problem.addConstraint(lambda a, b: a &gt;= 1.2 * b, ["x1", "x2"])
  problem.addConstraint(lambda b, c: b &gt;= 1.3 * c, ["x2", "x3"])
  problem.addConstraint(lambda c, d: c &gt;= 1.1 * d, ["x3", "x4"])
  problem.addConstraint(lambda d: d &gt; 0, ["x4"])
  
  problem.getSolutions()
  </code></pre>
  
  <p>I also looked at <code>scipy.optimize.linprog</code> but I could not find a way to pass conditions 2, 3 and 4 because it is dependent on the value of another variable from the same problem. I can pass boundaries for each individual variables using the <code>bounds</code> parameter, like:</p>
  
  <pre><code>x1_bounds = (100, 200)
  x2_bounds = (200, 300)
  </code></pre>
  
  <p>But how do I pass values of other variables in bounds, like <code>x1_bounds &gt;= 1.2*x2</code>? Or is there any other way I can do this?</p>
  
  <p>This can be solved using GRG non-linear solver in excel but I'm not able to find an equivalent in python.</p>