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