title: Implementing a Python Solver with Customised Constraints
body: <p>I have two variables who are related to each other and I want to find an optimal solution, which in this case is the minimum of their sum. For now, let's call them <code>X</code> and <code>Y</code>, and along with pre-defined constants, they add up to a set of "variables" <code>s1</code> and <code>s2</code> (that later feed the constraints):</p>
  
  <pre><code>105896649.59 + X = s1
      -6738.82 + Y = s2
  </code></pre>
  
  <p>While searching the SciPy docs, I have come across the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html" rel="nofollow noreferrer">linear programming</a> solution, where I have the minimizing function (in this case, <code>X + Y</code>) and a set of inequality and equality constraints to which my variables are bound. In my case, they are as follow:</p>
  
  <ul>
  <li><code>X &gt;= 0, Y &gt;= 0</code></li>
  <li><code>s1 &gt;= 1, s2 &gt;= 1</code></li>
  <li><code>s2 / (s1 + s2) = 0.0001%</code></li>
  </ul>
  
  <p>For this specific case, the code was easily implementable:</p>
  
  <pre class="lang-py prettyprint-override"><code>from scipy.optimize import linprog
  
  lstConst = [105896649.59, -6738.82]
  
  # function to minimise: X + Y
  c= [1, 1]
  
  # left-hand side of the equation for s2 / (s1 + s2) = 0.0001%
  # i.e., -0.000001 * X + 0.999999 * Y
  Aeq = [[-0.000001, 0.999999]]
  
  # right-hand side of the equation
  beq = [0.000001 * (lstConst[0] + lstConst[1]) - lstConst[1]]
  
  # ensures minimum can't be a negative number
  minX = max(1, max(1 -lstConst[0], 0))
  minY = max(1, max(1 -lstConst[1], 0))
  
  X_bounds = (minX, None)
  
  Y_bounds = (minY, None)
  
  res = linprog(c, A_eq=Aeq, b_eq=beq, bounds=[X_bounds, Y_bounds])
  </code></pre>
  
  <p>So we have the values for <code>X</code> and <code>Y</code> to minimize the function on the <code>x</code> parameter:</p>
  
  <pre><code>In [1]: res.x
  Out[1]: array([1.00000000e+00, 6.84471676e+03])
  </code></pre>
  
  <hr>
  
  <p>I would like to build upon this approach:</p>
  
  <ol>
  <li>In fact, there is another set of restrictions: <code>s1</code> and <code>s2</code> must also be integers (note that <code>X</code> and <code>Y</code> have no problem with being floats).</li>
  <li>Instead of defining a single value for the ratio between <code>s1</code> and <code>s2</code>, I would supply a list of different possible ratios.</li>
  </ol>
  
  <p>In essence, I would like to find the minimum values for the <code>X + Y</code> function given several different ratios between <code>s1</code> and <code>s2</code>. This could be achievable by either iterating over a list to define <code>Aeq</code> and <code>beq</code> on each iteration or defining additional restrictions (if possible).</p>
  
  <p>However, I'm clueless as to the integer restriction and how to make the linear programming algorithm take it into account.</p>
  
  <p>If anyone has an alternative suggestion that uses a library/optimizer other than SciPy and <code>linprog</code>, that's also welcome.</p>