title: Convert string representation of a comparison formula back to formula
body: <p>Python newbie here.</p>
  <p>I have a library function that is expecting a formula object;
  <code>solver.Add(x + y &lt; 5)</code></p>
  <p>However my formula is dynamic and being provided from another system as a string <code>&quot;x + y &lt; 5&quot;</code></p>
  <p>The library function doesn't not accept a string, my question is there a way to create a function that can evaluate my string and return the formula as an object? eg
  <code>solver.Add(evaluateFormula(&quot;x + y &lt; 5&quot;))</code>
  or
  <code>solver.Add(evaluateFormula(&quot;x + y&quot;) &lt; 5)</code></p>
  <p>Using the built in <code>eval()</code> does not work for this type of formula since that tries to execute the formula which is not what I want to do.</p>
  <p>Here's some full sample code;</p>
  <pre><code>from ortools.linear_solver import pywraplp
  
  def main():
      # Create the MIP solver BOP/SAT/CBC
      solver = pywraplp.Solver.CreateSolver('BOP')
  
      # Sample Input Data
      req_json = {
          &quot;Variables&quot;: [
              {
                  &quot;Name&quot;: &quot;x&quot;,
                  &quot;Max&quot;: 10
              },
              {
                  &quot;Name&quot;: &quot;y&quot;,
                  &quot;Max&quot;: 5
              }
          ],
          &quot;Constraints&quot;: [
              {
                  &quot;Name&quot;: &quot;c&quot;,
                  &quot;Formula&quot;: &quot;x + y &lt; 5&quot;
              }
          ]
      }
  
      # Create the variables
      v = {}
      for i in range(len(req_json['Variables'])):
          v[i] = solver.IntVar(0, req_json['Variables'][i]['Max'], req_json['Variables'][i]['Name'])
  
      # Create the constraints
      solver.Add(v[0] + v[1] &lt; 5)
      # solver.Add(evaluateFormula(req_json['Constraints'][0]['Formula']))
  
      # Maximize
      solver.Maximize(v[0] + v[1])
  
      # Solve
      status = solver.Solve()
  
      if status == pywraplp.Solver.OPTIMAL:
          print('Solution:')
          print('Objective value =', solver.Objective().Value())
          print('x =', v[0].solution_value())
          print('y =', v[1].solution_value())
  </code></pre>