Gurobi OptiMods

Painless Optimization Templates

Matthias Miltenberger

EURO 2024, Copenhagen

Why OptiMods?

Diving head-first into Optimization can be daunting!


You should be proficient in:

  • maths
  • modeling
  • programming
  • data science


enter Gurobi OptiMods!

What are OptiMods?

Each OptiMod solves a single, specific problem

What are OptiMods?

Take input data in natural form, return solutions in natural form

What are OptiMods?

Using gurobipy and common Python packages (pandas, scipy, networkx, …)

What are OptiMods?

Solves an optimization problem using Gurobi without explicit modeling

What are OptiMods?

Each OptiMod is comprehensively documented

Drawbacks

Are OptiMods the solution to all your problems?



… unfortunately not



Simplicity comes at the price of flexibility!

Quick installation and usage instructions




  1. Installation via PyPI:

    pip install gurobi-optimods
  2. Documentation on your selected Mod:
    https://gurobi-optimods.readthedocs.io

  3. Bring your data into the required format and run the Mod


Documentation is a major part of the project

Demo: Min-Cost-Flow

Input data

from gurobi_optimods import datasets

edge_data, node_data = datasets.simple_graph_pandas()
edge_data
node_data
capacity cost
source target
0 1 2 9
2 2 7
1 3 1 1
2 3 1 10
4 2 6
3 5 2 1
4 5 2 1
demand
0 -2
1 0
2 -1
3 1
4 0
5 2

Demo: Min-Cost-Flow

Solution

from gurobi_optimods import datasets
from gurobi_optimods.min_cost_flow import min_cost_flow_pandas
edge_data, node_data = datasets.simple_graph_pandas()
obj, sol = min_cost_flow_pandas(edge_data, node_data, verbose=False)
obj
sol
31.0
source  target
0       1         1.0
        2         1.0
1       3         1.0
2       3         0.0
        4         2.0
3       5         0.0
4       5         2.0
Name: flow, dtype: float64

Demo: Line Optimization

Input data

from gurobi_optimods import datasets

node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]


node_data.head(4)
number posx posy
0 1 50000.0 510000.0
1 2 320000.0 510000.0
2 3 50000.0 440000.0
3 4 130000.0 440000.0

Demo: Line Optimization

Input data

from gurobi_optimods import datasets

node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]


edge_data.head(4)
source target length time
0 1 2 0.010 360
1 2 1 0.010 360
2 1 3 0.006 240
3 3 1 0.006 240

Demo: Line Optimization

Input data

from gurobi_optimods import datasets

node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]


line_data.head(4)
linename capacity fix_cost operating_cost
0 new7_B 600 15 3
1 new15_B 600 15 2
2 new23_B 600 15 6
3 new31_B 600 15 6

Demo: Line Optimization

Input data

from gurobi_optimods import datasets

node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]


linepath_data.head(4)
linename edge_source edge_target
0 new7_B 1 2
1 new7_B 2 6
2 new7_B 6 8
3 new7_B 8 6

Demo: Line Optimization

Input data

from gurobi_optimods import datasets

node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]


demand_data.head(4)
source target demand
0 1 2 5
1 1 3 5
2 1 4 25
3 1 5 10

Demo: Line Optimization

Solution

from gurobi_optimods import datasets
from gurobi_optimods.line_optimization import line_optimization
node_data, edge_data, line_data, linepath_data, demand_data = (
     datasets.load_siouxfalls_network_data()
)
frequencies = [1,3]
obj_cost, final_lines = line_optimization(
    node_data,
    edge_data,
    line_data,
    linepath_data,
    demand_data,
    frequencies,
    verbose=False,
)
obj_cost
211.0

Demo: Line Optimization

Visualization

from gurobi_optimods.line_optimization import plot_lineplan
plot_lineplan(node_data, edge_data, linepath_data, final_lines)

Coming soon: Metro Map OptiMod

Computing an Octilinear Graph Representation

Summary and Conclusion

https://github.com/Gurobi/gurobi-optimods

  • OptiMods provide data-driven APIs to solve common optimization problems
  • Great way to make optimization more accessible
  • Many optimization topics are still waiting to be turned into a new OptiMod

Get involved and share your feedback and ideas!

Thank You!