Convert Figma logo to code with AI

google logoor-tools

Google's Operations Research tools:

11,147
2,115
11,147
63

Top Related Projects

2,230

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)

5,370

A Python-embedded modeling language for convex optimization problems.

12,986

SciPy library main repository

Quick Overview

Google OR-Tools is an open-source software suite for optimization, specializing in solving combinatorial optimization problems. It provides a set of tools and libraries for various optimization techniques, including linear programming, constraint programming, and vehicle routing.

Pros

  • Comprehensive suite of optimization algorithms and tools
  • Supports multiple programming languages (C++, Python, Java, and .NET)
  • Actively maintained by Google with regular updates and improvements
  • Extensive documentation and examples available

Cons

  • Steep learning curve for beginners in optimization
  • Can be complex to set up and integrate into existing projects
  • Some advanced features may require in-depth knowledge of optimization techniques
  • Performance may vary depending on the specific problem and chosen algorithm

Code Examples

  1. Solving a simple linear programming problem:
from ortools.linear_solver import pywraplp

def main():
    solver = pywraplp.Solver.CreateSolver('GLOP')
    x = solver.NumVar(0, 1, 'x')
    y = solver.NumVar(0, 2, 'y')
    
    solver.Add(x + y <= 2)
    solver.Add(3 * x + y <= 3)
    
    solver.Maximize(x + 10 * y)
    status = solver.Solve()
    
    if status == pywraplp.Solver.OPTIMAL:
        print('Solution:')
        print('x =', x.solution_value())
        print('y =', y.solution_value())
    else:
        print('The problem does not have an optimal solution.')

if __name__ == '__main__':
    main()
  1. Solving a constraint programming problem:
from ortools.sat.python import cp_model

def main():
    model = cp_model.CpModel()
    x = model.NewIntVar(0, 10, 'x')
    y = model.NewIntVar(0, 10, 'y')
    
    model.Add(x + 2 * y >= 7)
    model.Add(x - y <= 2)
    
    solver = cp_model.CpSolver()
    status = solver.Solve(model)
    
    if status == cp_model.OPTIMAL:
        print('x =', solver.Value(x))
        print('y =', solver.Value(y))
    else:
        print('No solution found.')

if __name__ == '__main__':
    main()
  1. Solving a vehicle routing problem:
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp

def create_data_model():
    data = {}
    data['distance_matrix'] = [
        [0, 2, 9, 10],
        [1, 0, 6, 4],
        [15, 7, 0, 8],
        [6, 3, 12, 0],
    ]
    data['num_vehicles'] = 1
    data['depot'] = 0
    return data

def main():
    data = create_data_model()
    manager = pywrapcp.RoutingIndexManager(len(data['distance_matrix']), data['num_vehicles'], data['depot'])
    routing = pywrapcp.RoutingModel(manager)
    
    def distance_callback(from_index, to_index):
        from_node = manager.IndexToNode(from_index)
        to_node = manager.IndexToNode(to_index)
        return data['distance_matrix'][from_node][to_node]
    
    transit_callback_index = routing.RegisterTransitCallback(distance_callback)
    routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
    
    search_parameters = pywrapcp.DefaultRoutingSearchParameters()
    search_parameters.first_solution_strategy = (
        routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
    
    solution = routing.SolveWithParameters(search_parameters)

Competitor Comparisons

2,230

Modeling language for Mathematical Optimization (linear, mixed-integer, conic, semidefinite, nonlinear)

Pros of JuMP

  • Written in Julia, offering high performance and ease of use for scientific computing
  • Provides a more flexible and extensible modeling framework
  • Supports a wider range of solvers through MathOptInterface

Cons of JuMP

  • Smaller community and ecosystem compared to OR-Tools
  • Less comprehensive documentation and fewer examples
  • Limited support for specialized constraint types (e.g., routing constraints)

Code Comparison

OR-Tools (Python):

from ortools.linear_solver import pywraplp

solver = pywraplp.Solver.CreateSolver('GLOP')
x = solver.NumVar(0, 1, 'x')
y = solver.NumVar(0, 2, 'y')
solver.Add(x + y <= 2)
solver.Maximize(x + 2 * y)

JuMP (Julia):

using JuMP, GLPK

model = Model(GLPK.Optimizer)
@variable(model, 0 <= x <= 1)
@variable(model, 0 <= y <= 2)
@constraint(model, x + y <= 2)
@objective(model, Max, x + 2y)

Both OR-Tools and JuMP are powerful optimization libraries, but they cater to different audiences. OR-Tools offers a more comprehensive suite of tools for various optimization problems, while JuMP provides a flexible modeling framework with excellent performance in the Julia ecosystem.

5,370

A Python-embedded modeling language for convex optimization problems.

Pros of CVXPY

  • Easier to use and more intuitive for Python developers
  • Focuses specifically on convex optimization problems
  • Automatic problem transformation and solver selection

Cons of CVXPY

  • More limited scope compared to OR-Tools' broader optimization capabilities
  • May be slower for large-scale problems due to its high-level abstraction

Code Comparison

CVXPY:

import cvxpy as cp

x = cp.Variable()
objective = cp.Minimize((x - 2)**2)
constraints = [0 <= x, x <= 1]
prob = cp.Problem(objective, constraints)
prob.solve()

OR-Tools:

from ortools.linear_solver import pywraplp

solver = pywraplp.Solver.CreateSolver('GLOP')
x = solver.NumVar(0, 1, 'x')
solver.Minimize((x - 2) * (x - 2))
solver.Solve()

Both repositories provide powerful optimization tools, but CVXPY is more focused on convex optimization and offers a more Pythonic interface. OR-Tools, on the other hand, provides a broader range of optimization techniques and may be more suitable for large-scale industrial applications.

12,986

SciPy library main repository

Pros of SciPy

  • Broader scope covering various scientific computing domains
  • Larger community and ecosystem with extensive documentation
  • More mature project with a longer history of development

Cons of SciPy

  • Less specialized for optimization problems compared to OR-Tools
  • May have slower performance for certain optimization tasks
  • Steeper learning curve for beginners due to its extensive functionality

Code Comparison

SciPy (Optimization example):

from scipy.optimize import minimize

def objective(x):
    return x[0]**2 + x[1]**2

result = minimize(objective, [1, 1])
print(result.x)

OR-Tools (Optimization example):

from ortools.linear_solver import pywraplp

solver = pywraplp.Solver.CreateSolver('GLOP')
x = solver.NumVar(0, 10, 'x')
y = solver.NumVar(0, 10, 'y')
solver.Minimize(x**2 + y**2)
solver.Solve()
print(x.solution_value(), y.solution_value())

Both libraries offer optimization capabilities, but OR-Tools provides a more specialized and potentially more efficient approach for certain types of optimization problems, while SciPy offers a broader range of scientific computing tools beyond just optimization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OR-Tools - Google Optimization Tools

PyPI version PyPI download Binder
NuGet version NuGet download
Maven Central
Discord

Google's software suite for combinatorial optimization.

Table of Contents

About OR-Tools

Google Optimization Tools (a.k.a., OR-Tools) is an open-source, fast and portable software suite for solving combinatorial optimization problems.

The suite contains:

  • Two constraint programming solver (CP* and CP-SAT);
  • Two linear programming solvers (Glop and PDLP);
  • Wrappers around commercial and other open source solvers, including mixed integer solvers;
  • Bin packing and knapsack algorithms;
  • Algorithms for the Traveling Salesman Problem and Vehicle Routing Problem;
  • Graph algorithms (shortest paths, min cost flow, max flow, linear sum assignment).

We wrote OR-Tools in C++, but provide wrappers in Python, C# and Java.

Codemap

This software suite is composed of the following components:

  • Makefile Top-level for GNU Make based build.
  • makefiles Subsidiary Make files, CI and build system documentation.
  • CMakeLists.txt Top-level for CMake based build.
  • cmake Subsidiary CMake files, CI and build system documentation.
  • WORKSPACE Top-level for Bazel based build.
  • bazel Subsidiary Bazel files, CI and build system documentation.
  • ortools Root directory for source code.
    • base Basic utilities.
    • algorithms Basic algorithms.
      • samples Carefully crafted samples.
    • graph Graph algorithms.
      • samples Carefully crafted samples.
    • linear_solver Linear solver wrapper.
      • samples Carefully crafted samples.
    • glop Simplex-based linear programming solver.
      • samples Carefully crafted samples.
    • pdlp First-order linear programming solver.
      • samples Carefully crafted samples.
    • lp_data Data structures for linear models.
    • constraint_solver Constraint and Routing solver.
      • docs Documentation of the component.
      • samples Carefully crafted samples.
    • sat SAT solver.
      • docs Documentation of the component.
      • samples Carefully crafted samples.
    • bop Boolean solver based on SAT.
    • util Utilities needed by the constraint solver
  • examples Root directory for all examples.
  • tools Delivery Tools (e.g. Windows GNU binaries, scripts, release dockers)

Installation

This software suite has been tested under:

  • Ubuntu 18.04 LTS and up (64-bit);
  • Apple macOS Mojave with Xcode 9.x (64-bit);
  • Microsoft Windows with Visual Studio 2022 (64-bit).

OR-Tools currently builds with a Makefile, but also provides Bazel and CMake support.

For installation instructions (both source and binary), please visit https://developers.google.com/optimization/introduction/installing.

Build from source using Make (legacy)

We provide a Make based build.
Please check the Make build instructions.

Build from source using CMake

We provide a CMake based build.
Please check the CMake build instructions.

Build from source using Bazel

We provide a Bazel based build.
Please check the Bazel build instructions.

Quick Start

The best way to learn how to use OR-Tools is to follow the tutorials in our developer guide:

https://developers.google.com/optimization/introduction/get_started

If you want to learn from code examples, take a look at the examples in the examples directory.

Documentation

The complete documentation for OR-Tools is available at: https://developers.google.com/optimization/

Contributing

The CONTRIBUTING.md file contains instructions on how to submit the Contributor License Agreement before sending any pull requests (PRs). Of course, if you're new to the project, it's usually best to discuss any proposals and reach consensus before sending your first PR.

License

The OR-Tools software suite is licensed under the terms of the Apache License 2.0.
See LICENSE for more information.