Skip to main content

BilevelPy

CI Documentation Python License

BilevelPy

An extensible Python framework for building, solving, and evaluating Gurobi-based optimization models, with built-in support for hub-location problems.

Project status: BilevelPy is an alpha release. Its public API may change before version 1.0.0.

Overview

BilevelPy provides reusable abstractions for implementing optimization models with Gurobi. It separates data preparation, model construction, solver execution, and solution extraction into focused components.

The current release includes:

  • composable Variable and Constraint classes
  • dependency-aware model construction through BaseModel
  • structured datasets and preprocessing pipelines
  • configurable Gurobi execution and structured solutions
  • built-in hub-location components
  • CAB25 and CAB100 benchmark datasets

Installation

pip install bilevelpy

Requirements:

  • Python 3.11–3.14
  • Gurobi Optimizer 11.0 or newer
  • a valid Gurobi licence

BilevelPy is licensed separately from Gurobi. Installing BilevelPy does not provide a licence for Gurobi Optimizer.

See the installation guide for development setup and further details.

Typical workflow

from bilevelpy import Dataset, ModelSolver
from bilevelpy.data.builder import DatasetBuilder
from bilevelpy.data.loaders import HLPLoader
from bilevelpy.data.processor import HLPNodeSelector

dataset = (
    DatasetBuilder()
    .pipe(HLPLoader(Dataset.CAB100))
    .pipe(HLPNodeSelector(n_nodes=10))
    .build()
)

# Define a BaseModel subclass with the required variables,
# constraints, and objective.
model = MyModel(data=dataset)
solution = ModelSolver(model).solve()

print(solution)

The quickstart tutorial contains a complete single-allocation hub-location model.

Documentation

Research implementation

A complete research implementation built with BilevelPy is available in An Oracle-based Approach for Price-setting Problems in Logistics.

Citation

Citation metadata is available in CITATION.cff.

Changelog

See CHANGELOG.md for the release history.

Licence

BilevelPy is licensed under the Apache License 2.0.

Gurobi Optimizer and gurobipy are proprietary software distributed and licensed separately by Gurobi Optimization, LLC.

Metadata

Release files for bilevelpy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bilevelpy 0.1.0
File Size Uploaded
bilevelpy-0.1.0.tar.gz 93.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bilevelpy 0.1.0
File Interpreter ABI Platform
bilevelpy-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 193.1 kB

Release files / bilevelpy-0.1.0.tar.gz

Download URL bilevelpy-0.1.0.tar.gz
Size 93.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9544feee0648a16aa3ce1384a7ec99f57c1ff2798dc81429820eddaa6e8e4104
BLAKE2b-256 checksum
How to use checksums
7e044fdda08c969fe4da3eb6fde5f77d484167b8041d5fcbda6c89782da53da1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Windows/11

Release files / bilevelpy-0.1.0-py3-none-any.whl

Download URL bilevelpy-0.1.0-py3-none-any.whl
Size 99.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
26a962c2b5fb14dee2dd32cb641eb93cd85e2aa68f0cfc71d69bdbce03deee90
BLAKE2b-256 checksum
How to use checksums
7d6c1b51370582fd6daed65cb091feefcdfb1aa416826609de29792ca2b84aeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Windows/11

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page