May 13, 2018

Mixed Integer Linear Programming , on Python using Google Optimisation Tools


  1. Install Python 64 bits ( https://www.python.org/downloads/), append the Path windows environmental value by adding the location of python.
    you can also install an IDE like Visual Studio Community, previous known as Visual Studio Express.
    You need the VS Community if you want to compile C++, or C# codes with Google OR tools
  2. Install Google Optimisation Tools using python PIP: (https://developers.google.com/optimization/introduction/installing/binary#installing-on-windows)
    • python -m pip install --user --upgrade ortools
    • But before check that you have the proper version ( python 64 bit and version >3.6 and PIP is higher than 9.01
      • python --version
      • python -c "import platform; print(platform.architecture()[0])"
      • python -m pip --version
  3. Run your first MIP 
    • Or Run the sample Linear Problem:
    from __future__ import print_function
    from ortools.linear_solver import pywraplp

    def main():
      solver = pywraplp.Solver('SolveSimpleSystem',
                               pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
      x = solver.NumVar(0, 1, 'x')
      y = solver.NumVar(0, 2, 'y')
      objective = solver.Objective()
      objective.SetCoefficient(x, 1)
      objective.SetCoefficient(y, 1)
      objective.SetMaximization()
      solver.Solve()
      print('Solution:')
      print('x = ', x.solution_value())
      print('y = ', y.solution_value())

    if __name__ == '__main__':
      main()