OR-Tools

repository·stable·Indexed 11 days ago

https://github.com/google/or-tools

Google's open-source suite for combinatorial optimization, providing solvers for constraint programming, linear programming, and routing problems. It supports C++, Python, Java, and .NET, and includes solvers such as CP-SAT, GLOP, GLPK, PDLP, and SCIP.

Tokens
273.1K
Snippets
423
Records
519
Agent score
94%

What's inside OR-Tools

  1. What is GLOP (Google's Linear Optimization Package)

    stable
    GLOP is a production-ready implementation of the revised simplex method designed for solving linear programming (LP) problems. It focuses on high performance and numerical stability. While written in C++, it is accessible through the OR-Tools linear solver wrapper in Java, Python, and C#.
  2. Overview of OR-Tools Julia wrappers

    stable

    The OR-Tools Julia wrappers are intended for the open-source community and are currently considered highly experimental. The wrapper is divided into three distinct packages:

    • ORTools_jll: Contains the precompiled OR-Tools binaries.
    • ORToolsGenerated.jl: Contains the generated parts of the wrapper, currently corresponding to Protocol Buffers files.
    • ORTools.jl: The high-level wrapper intended to provide MathOptInterface code for use through JuMP. Note: This package is not yet written.

    Currently, only MathOpt is accessible through its C API.

  3. Overview of the Primal-Dual Hybrid Gradient Solver (PDLP)

    stable
    PDLP is a library designed for solving Linear Programming (LP) and Quadratic Programming (QP) problems using first-order methods. It is based on the Primal-Dual Hybrid Gradient (PDHG) algorithm, which incorporates preprocessing with scaling and optional presolving to enhance performance and numerical stability.
  4. What is Google OR-Tools?

    stable

    Google OR-Tools is an open-source, fast, and portable software suite designed to solve combinatorial optimization problems. It uses state-of-the-art algorithms to find optimal or near-optimal solutions from vast sets of possible solutions. The .NET wrapper allows developers to integrate these optimization capabilities into .NET applications.

    Key problem domains include:

    • Vehicle Routing: Finding optimal routes for fleets subject to constraints like capacity or time windows.
    • Scheduling: Optimizing task sequences on machines or resources with precedence constraints.
    • Bin Packing: Maximizing the number of objects packed into bins with fixed capacities.
    • Constraint Programming: Finding feasible solutions based on complex constraints (e.g., resource exclusivity or distance limits).
    • Linear and Mixed-Integer Programming: Using solvers like Glop (linear optimizer) or SCIP (mixed-integer programming) to optimize objective functions subject to linear inequalities.
    • Graph Algorithms: Solving shortest path, min-cost flow, max flow, and linear sum assignment problems.
  5. What is OR-Tools and what does it include?

    stable

    Google Optimization Tools (OR-Tools) is an open-source software suite designed for solving combinatorial optimization problems. It is written in C++ but provides high-level wrappers for Python, C#, and Java.

    The suite includes several specialized solvers and algorithms:

    • Constraint Programming Solvers: CP* and CP-SAT.
    • Linear Programming Solvers: Glop (Simplex-based) and PDLP (First-order).
    • Mixed Integer Solvers: Wrappers around commercial and other open-source solvers.
    • Routing & Packing: Bin packing, knapsack algorithms, Traveling Salesman Problem (TSP), and Vehicle Routing Problem (VRP).
    • Graph Algorithms: Shortest paths, min cost flow, max flow, and linear sum assignment.
  6. Overview of the Vehicle Routing solver

    stable

    The Vehicle Routing library is an extension built on top of the CP (Constraint Programming) solver library. It is designed to model and solve a wide range of generic vehicle routing problems, including:

    • Traveling Salesman Problem (TSP)
    • Capacitated Vehicle Routing Problem (CVRP)
    • Vehicle Routing Problem with Time Windows (VRPTW)

    Users can define complex constraints and objectives to optimize routes for fleets of vehicles.

  7. Overview of OR-Tools solvers and capabilities

    stable

    OR-Tools is an open-source suite of operations research tools developed by Google. It provides specialized solvers for several mathematical optimization domains:

    • Constraint Programming
      • CP-SAT solver: A constraint programming solver utilizing SAT (satisfiability) methods.
      • Original CP solver: A standard constraint programming solver.
    • Linear and Mixed-Integer Programming
      • Glop: A linear optimizer designed to find the optimal value of a linear objective function subject to linear inequality constraints.
      • MPSolver and ModelBuilder: High-level wrappers that interface with various commercial and open-source solvers, such as CBC, CLP, GLPK, Gurobi, or SCIP.
    • Vehicle Routing
      • A specialized library for solving routing problems to identify optimal vehicle paths under specific constraints.
    • Graph Algorithms
      • Implementations for finding shortest paths, min-cost flows, max flows, and linear sum assignments.
  8. Use the Vehicle Routing solver

    stable

    The Vehicle Routing solver is an extension built on top of the CP solver library. It is designed to model and solve generic vehicle routing problems, including:

    • Traveling Salesman Problem (TSP)
    • Capacitated Vehicle Routing Problem (CVRP)
    • Vehicle Routing Problem with Time Windows (VRPTW)

    Core API entry point:

    • routing.h: The primary header for modeling and solving routing problems.
  9. Explore C++ OR-Tools example categories

    stable

    OR-Tools provides a variety of C++ examples categorized by the underlying solver or problem type. Use these as templates for your own modeling:

    Constraint Solver Examples

    Focus on modeling objects like integer variables, arithmetic constraints, and search strategies:

    • cryptarithm.cc: Basic modeling (variables, arithmetic constraints, simple search).
    • golomb.cc: Handling objective functions and collecting multiple solutions.
    • magic_square.cc: Using automatic search.
    • costas_array.cc: Feasibility (hard constraints) vs. Optimization (soft constraints/violation costs).
    • jobshop.cc: Job scheduling on machines.
    • nqueens.cc: Solving N-Queens and breaking symmetries during search.
    • network_routing_sat.cc: Multicommodity mono-routing with capacity constraints.
    • sports_scheduling_sat.cc: Soccer championship scheduling using global constraints.
    • dobble_ls.cc: Writing custom Local Search operators, filters, and simple constraints.

    Routing Examples

    Specific implementations for vehicle and delivery logistics:

    • cvrptw.cc: Capacitated Vehicle Routing Problem with Time Windows.
    • pdptw.cc: Pickup and Delivery Problem with Time Windows.

    Graph Examples

    Using graph-based APIs:

    • flow_api.cc: Min-Cost Flow and Max-Flow APIs.
    • linear_assignment_api.cc: Linear Sum Assignment solver.
    • dimacs_assignment.cc: Solving DIMACS assignment challenges.

    Linear and Integer Programming Examples

    Using the linear solver wrapper API:

    • linear_programming.cc: Solving Linear Programming (LP) problems.
    • integer_programming.cc: Solving Integer Programming (IP) problems.
    • linear_solver_protocol_buffers.cc: Using Protocol Buffers for LP/IP input and output.
    • strawberry_fields_with_column_generation.cc: Dynamic column generation for 2D covering problems.
  10. Solve Linear and Integer Programming problems with OR-Tools

    stable

    OR-Tools provides a unified way to model and solve Linear Programming (LP) and Integer Programming (IP) problems. The modern workflow involves modeling your problem using the MPModelRequest Protocol Buffer API and then passing that request to a solver using the SolveMPModel() function.

    Core Components

    • MPModelRequest (Proto API): Defined in linear_solver.proto, this is the primary way to describe your optimization model (objective function, constraints, and variable types).
    • SolveMPModel(): The main entry point for execution, found in solve_mp_model.h. It takes an MPModelRequest and runs it through a specified solver engine.
    • ModelBuilder: Available in Python and Java, these classes provide a high-level abstraction to help you construct complex MPModelRequest objects, particularly when dealing with linear expressions.
    • MPSolver (Legacy): An older API that is no longer in active development. While it is largely interoperable with the MPModelRequest API, it may not support all modern features.

    Problem Mathematical Form

    Models typically follow this structure: $$\begin{array}{lll} (P) & \max & cx\ & s.t. & L\leq Ax\leq U\ & & l\leq x\leq u\ & &x_i\in\mathbb{Z}\quad\forall i\in I\ \end{array}$$

  11. Use MathOpt for mathematical optimization

    stable

    MathOpt is a generic API provided by OR-Tools to access various mathematical optimization solvers (e.g., GLOP, CP-SAT, SCIP, and Gurobi) through a single, interoperable interface.

    Key Recommendations:

    • Prefer MathOpt over MPSolver: For new development, use the MathOpt API instead of the legacy MPSolver (defined in linear_solver.h) whenever possible.
    • Use Client Libraries: Most users should build and solve models using the official client libraries for C++, Python, or Java.
    • Avoid Proto API: While a proto-based API is available, it is not recommended for general use.
  12. Use the Constraint Programming (CP) solver

    stable

    The CP solver is used for solving combinatorial optimization problems using Constraint Programming. To implement a CP model, you should interact with the core objects defined in the library.

    Key entry points for developers:

    • constraint_solver.h: Contains the declaration of the core objects required to build and solve CP models.
    • constraint_solveri.h: Contains the collection of objects used to extend the Constraint Solver library functionality.