{"id":2174,"library":"ortools","title":"Google OR-Tools","description":"Google OR-Tools is an open-source, fast, and portable software suite for solving combinatorial optimization problems. It provides a comprehensive collection of solvers for linear programming, mixed-integer programming, constraint programming (CP-SAT), vehicle routing, and network flow problems. Written primarily in C++, it offers official wrappers for Python, C#, and Java. As of version 9.15.6755, the library is actively developed with frequent releases delivering new features, performance enhancements, and bug fixes across its various solvers.","status":"active","version":"9.15.6755","language":"en","source_language":"en","source_url":"https://github.com/google/or-tools","tags":["optimization","solver","operations-research","linear-programming","constraint-programming","vehicle-routing","graph-algorithms","mathematics"],"install":[{"cmd":"pip install ortools","lang":"bash","label":"Install ortools"}],"dependencies":[{"reason":"Minimum required Python version for ortools 9.x.","package":"python","optional":false}],"imports":[{"note":"For Linear Programming (LP) and Mixed-Integer Programming (MIP).","symbol":"pywraplp","correct":"from ortools.linear_solver import pywraplp"},{"note":"For Constraint Programming (CP-SAT solver).","symbol":"cp_model","correct":"from ortools.sat.python import cp_model"},{"note":"For Vehicle Routing Problems (using the legacy CP solver).","symbol":"routing_enums_pb2, pywrapcp","correct":"from ortools.constraint_solver import routing_enums_pb2, pywrapcp"},{"note":"Required for initializing OR-Tools internals in some environments or older versions, though often implicitly handled now.","symbol":"init","correct":"from ortools.init.python import init"}],"quickstart":{"code":"from ortools.linear_solver import pywraplp\n\ndef main():\n    # Create the linear solver with the GLOP backend.\n    solver = pywraplp.Solver.CreateSolver('GLOP')\n    if not solver:\n        return\n\n    # Create the variables x and y.\n    x = solver.NumVar(0, 1, 'x')\n    y = solver.NumVar(0, 2, 'y')\n\n    print('Number of variables =', solver.NumVariables())\n\n    # Define the constraints: x + y <= 2\n    solver.Add(x + y <= 2.0)\n\n    print('Number of constraints =', solver.NumConstraints())\n\n    # Define the objective function: Maximize 3 * x + y.\n    solver.Maximize(3 * x + y)\n\n    # Invoke the solver and display the results.\n    status = solver.Solve()\n\n    if status == pywraplp.Solver.OPTIMAL:\n        print('Solution:')\n        print('Objective value =', solver.Objective().Value())\n        print('x =', x.solution_value())\n        print('y =', y.solution_value())\n    else:\n        print('The problem does not have an optimal solution.')\n\n    print('\\nAdvanced statistics:')\n    print('Problem solved in %f milliseconds' % solver.wall_time())\n    print('Problem solved in %d iterations' % solver.iterations())\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates how to solve a simple linear programming problem using the GLOP solver via the `pywraplp` wrapper. It sets up variables, defines constraints, an objective function, and then solves and prints the results."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or newer. Ensure your `pip` is updated and use `pip install ortools`.","message":"OR-Tools 9.x and later require Python 3.9 or higher. Support for Python 3.8 was dropped.","severity":"breaking","affected_versions":"9.0.xxxx and later"},{"fix":"Rewrite linear/MIP models using `ortools.linear_solver.model_builder` or `ortools.math_opt.python.mathopt` APIs. Refer to the official documentation for migration guides.","message":"The `MPSolver` for linear and mixed-integer programming is deprecated. Users should migrate to `ModelBuilder` or the newer `MathOpt` API for future compatibility and improved features. `MathOpt` is being actively developed and will eventually replace `ModelBuilder`.","severity":"deprecated","affected_versions":"9.9.xxxx and later (MPSolver deprecated, ModelBuilder available), 10.0.x (MPSolver removed, MathOpt for Python/C++)"},{"fix":"Update method calls in your CP-SAT models to use snake_case (e.g., `solver.parameters.max_time_in_seconds = 10` instead of `solver.parameters.maxTimeInSeconds = 10`).","message":"After OR-Tools 9.8, the CP-SAT Python API methods were refactored to use PEP8-compliant snake_case naming conventions (e.g., `solver.parameters.set_max_time_in_seconds`). While older CamelCase methods are currently still supported, it is best practice to update your code to use the snake_case equivalents to avoid potential future breakage or deprecation.","severity":"gotcha","affected_versions":"9.8.xxxx and later"},{"fix":"Minimize complex operations within callbacks or avoid them if performance is critical. Always wrap callback logic in `try-except` blocks to gracefully handle and log exceptions.","message":"Using callbacks (e.g., `on_solution_callback` in CP-SAT) can significantly degrade search performance, especially if not implemented efficiently. Additionally, unhandled exceptions within these callbacks can lead to a Fatal Python error and program termination without a stack trace.","severity":"gotcha","affected_versions":"All versions with CP-SAT callbacks"},{"fix":"Explicitly specify the correct solver type when creating a solver instance (e.g., `solver = pywraplp.Solver.CreateSolver('CBC_MIXED_INTEGER_PROGRAMMING')`).","message":"It's a common mistake to confuse Mixed-Integer Programming (MIP) solvers with Linear Programming (LP) solvers. Ensure you select the correct solver backend (e.g., `pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING` for MIP or `pywraplp.Solver.GLOP_LINEAR_PROGRAMMING` for LP) appropriate for your problem type, otherwise results may be incorrect (e.g., always returning 0 for integer variables if an LP solver is used for an MIP problem).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor OR-Tools release notes for v10.0. Be prepared for potential code adjustments, especially for routing and constraint programming APIs, and test thoroughly when upgrading. Consider holding off on Python 3.14 adoption until official support is confirmed.","message":"OR-Tools v10.0 is slated to migrate Python wrappers for routing and constraint_solver from SWIG to pybind11, which may introduce breaking changes in API structure or behavior. Additionally, Python 3.14 support has been identified as broken in some pre-release testing.","severity":"breaking","affected_versions":"v10.0.x (expected late 2026/early 2027)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}