OR-Tools Examples

  • This page provides a variety of code examples and tutorials for different optimization problems, including linear optimization, integer optimization, constraint optimization, and routing.

  • The examples cover various use cases like the Traveling Salesperson Problem (TSP), Vehicle Routing Problem (VRP), and more, with variations like capacity constraints, pickup and delivery, and time windows.

  • Users can access code in C++, Python, .Net, and Java, along with accompanying tutorials to understand the implementation.

  • Interactive Colabs are available, allowing users to run the code demos directly in their browser for immediate experimentation.

  • The table organizes these resources by problem type and interface, providing easy navigation to relevant materials for specific optimization needs.

The following table provides links to:

  • Code examples in the supported languages: C++ Image Python Image DotNet Image Java Image
  • Tutorials that explain the examples. Image
  • Colabs — code demos that you can run directly in your browser. Image
Problem Type Interface Description Tutorials Colabs Code examples
Linear Optimization MPSolver (GLOP) Simple linear programming example Image Image Image Image Image Image
Integer Optimization MPSolver (SCIP) Simple mixed-integer programming example Image Image Image Image Image Image
Constraint Optimization CP-SAT Solver Simple constraint programming example Image Image Image Image Image Image
Constraint Optimization CP-SAT Solver Simple CP program Image Image Image Image Image
Routing Routing solver Simple TSP example Image Image Image Image Image
Routing Routing solver TSP with distance matrix Image Image Image Image Image Image
Routing Routing solver TSP with 2D locations Image Image Image Image Image Image
Routing Routing solver Simple Vehicle Routing Problem example Image Image Image Image Image Image
Routing Routing solver Vehicle Routing Problem with capacity constraints Image Image Image Image Image Image
Routing Routing solver Vehicle Routing Problem with pickup and delivery constraints Image Image Image Image Image Image
Routing Routing solver Vehicle Routing Problem with time window constraints Image Image Image Image Image Image
Routing Routing solver Vehicle Routing Problem with start and end locations Image Image Image Image Image Image