Skip to main content

Meta-generator: generating multicommodity flow instances from single-commodity flow instances.

Project description

s2mflow

CI Documentation License: MIT Python Version

A high-performance meta-generation framework for lifting single-commodity flow instances into the multicommodity space.

s2mflow is a Python library PyPI with a high-speed Rust core (via PyO3) designed to transform single-commodity minimum-cost flow (MCF) instances into minimum-cost multicommodity flow (MCMCF) instances. It is built for researchers in Operations Research, Mathematical Optimization, and Network Optimization who need to generate reproducible, scalable test data.

s2mflow implements and extends the meta-generation framework introduced in:

Felix P. Broesamle and Stefan Nickel. 2026. "On the Single-Multi-Commodity Gap: Lifting Single- to Multicommodity Flow Instances". Optimization Online. Preprint. Available at https://optimization-online.org/?p=34287.

Key Features

  • High Performance: Core logic implemented in Rust for zero-overhead data handling.
  • DIMACS Compatible: Load standard .min single-commodity files.
  • Custom MCMCF Format: Introduces the .mcfmin format for standardized multicommodity data storage.
  • Supply Partitioning Methods:
    • uniform: Equal distribution of supply and demand across commodities.
    • spread: Randomized, heterogeneous distribution of supply and demand across commodities.
  • Randomizing Capacities and Costs: Functionality for generating randomized commodity-specific capacities and costs for each arc.
  • Network Utilities: Support for identifying incoming and outgoing edges.

The Extended .mcfmin Format

The library uses a natural extension of the DIMACS .min format to support multiple commodities:

  • Problem Line: p min <num_nodes> <num_edges> <num_commodities> <randomize_caps> <randomize_costs> <is_uniform> <seed = 0>.
    • seed: relevant if is_uniform = 0 (Spread method) or if randomization of commodity-specific capacities or costs is enabled (randomize_caps = 1 or randomize_costs = 1).
  • Node Line: n <node_id> <total_demand> <demand_com_1> <demand_com_2> ... <demand_com_K>.
  • Arc Line: Depending on the randomization flags (randomize_caps, randomize_costs):
    • Default (0, 0): a <from> <to> <low> <cap_total> <cap_total> <cost>.
    • Commodity-specific capacities (1, 0): a <from> <to> <low> <cap_total> <cap_1> ... <cap_K> <cost>.
    • Commodity-specific costs (0, 1): a <from> <to> <low> <cap_total> <cap_total> <cost_1> ... <cost_K>.
    • Commodity-specific capacities and costs (1, 1): a <from> <to> <low> <cap_total> <cap_1> ... <cap_K> <cost_1> ... <cost_K>.

Installation

Standard Installation

pip install s2mflow
# or via poetry
poetry add s2mflow

Building from Source

git clone https://github.com/FelixBroesamle/s2mflow.git
cd s2mflow
poetry install -vvv
poetry run maturin develop --release

Quick Start

# .min example data:
# c  *** Minimum cost flow ***
# c
# p min 5 10
# n 1 10
# n 5 -10
# a 1 2 0 10 9
# a 1 4 0 16 2
# a 2 4 0 10 10
# a 2 3 0 10 1
# a 3 5 0 10 10
# a 3 2 0 20 2
# a 3 4 0 17 9
# a 4 3 0 10 9
# a 4 1 0 10 3
# a 4 2 0 19 2

import s2mflow

# 1. Load a single-commodity network
network = s2mflow.load_min_instance("input.min")

# 2. Generate multicommodity data for 3 commodities
mc_data = s2mflow.generate_multi_commodity_data(
    instance=network,
    num_commodities=3,
    is_uniform=False,
    seed=42,
)

# 3. Save as a multi-commodity instance
s2mflow.save_multi_commodity_instance("output.mcfmin", network, mc_data)

# c Multicommodity flow generated by s2mflow
# p min 5 10 3 0 0 0 42
# n 1 10 2 3 5
# n 5 -10 -2 -3 -5
# a 1 2 0 10 10 9
# a 1 4 0 16 16 2
# a 2 4 0 10 10 10
# a 2 3 0 10 10 1
# a 3 5 0 10 10 10
# a 3 2 0 20 20 2
# a 3 4 0 17 17 9
# a 4 3 0 10 10 9
# a 4 1 0 10 10 3
# a 4 2 0 19 19 2

Citing

If you use s2mflow in your research, please use the following preferred citation for the framework:

@misc{BroesamleNickel:SMCG,
    author = {Broesamle, Felix P. and Nickel, Stefan},
    title = {On the Single-Multi-Commodity Gap: Lifting Single- to Multicommodity Flow Instances},
    year = {2026},
    howpublished = {Optimization Online},
    note = {Preprint. Available at \url{https://optimization-online.org/?p=34287}},
    url = {https://optimization-online.org/?p=34287},
}

To cite s2mflow specifically in your research, please cite the software:

@software{s2mflow2026,
  author = {Broesamle, Felix P. and Nickel, Stefan},
  title = {s2mflow: A Meta-generator for Multicommodity Flow Instances},
  year = {2026},
  url = {https://github.com/FelixBroesamle/s2mflow}
}

Resources

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s2mflow-0.1.17.tar.gz (8.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

s2mflow-0.1.17-cp313-cp313-win_amd64.whl (193.2 kB view details)

Uploaded CPython 3.13Windows x86-64

s2mflow-0.1.17-cp313-cp313-manylinux_2_28_x86_64.whl (336.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

s2mflow-0.1.17-cp313-cp313-manylinux_2_28_aarch64.whl (331.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

s2mflow-0.1.17-cp313-cp313-macosx_11_0_arm64.whl (293.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

s2mflow-0.1.17-cp313-cp313-macosx_10_12_x86_64.whl (301.3 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file s2mflow-0.1.17.tar.gz.

File metadata

  • Download URL: s2mflow-0.1.17.tar.gz
  • Upload date:
  • Size: 8.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for s2mflow-0.1.17.tar.gz
Algorithm Hash digest
SHA256 3a17be96f53ea15df14eeca0f289a34ee01ea1ceab2b8027befc9a148b99e3ef
MD5 3230a7f83fbc9e10c9b552719b4e4f1e
BLAKE2b-256 091c3a40f1a0707ad1acd1284f3a6ec3b5124dae0c27bc676dbb68c8bb4b3834

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17.tar.gz:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file s2mflow-0.1.17-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: s2mflow-0.1.17-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 193.2 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for s2mflow-0.1.17-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3032b0391be6dd31cbcadf928a0f42fc78159a55feee62e073ba94685d3dcfdb
MD5 ebbd24f76982cec353f909fb5de4dade
BLAKE2b-256 ffb5a059fb65276c4ae52303a97d7f35a3c07c31cc7a834a31c44de16088c1c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17-cp313-cp313-win_amd64.whl:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file s2mflow-0.1.17-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.17-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5725fabf07b813c5aacf477a59411ff1ed44d56c08c0529d58a4529f89645534
MD5 ed7cb4147455385cb6500ae10e8cb177
BLAKE2b-256 843b9383f46d432bf628079b84d0ae2b04343a8d6a7854d1ebfa28335547cfa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file s2mflow-0.1.17-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.17-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 25a439b262d277fd472a01d445da99156c2848b6550731724302075ce88b7e22
MD5 76613f2ef5fe259baccc4010ada49621
BLAKE2b-256 4fd285b25792ff2cc0f92cb56988134534cfe8752017e3092f733f97210725af

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file s2mflow-0.1.17-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.17-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 811c69744093f8824f4562892fd4dbe9600204311d2327921c85d8b5abca5737
MD5 f986fcda3885ff4d23b6eb09a1cb2d1c
BLAKE2b-256 31d9bd85bbe9e157be79f8f6d8124ea265d94a6d18888d1f5cf6a2e10e4a6d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file s2mflow-0.1.17-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.17-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0331b3adca8417519a3372be1188333c2f562494bc123123859ddc996cb7d81b
MD5 441f2f6100842807478a0bc7ffda0340
BLAKE2b-256 68894c8ac0341a40fff42ad19cae3cf333136ad9ea6a61c36c08598b713e9fac

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.17-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release.yml on FelixBroesamle/s2mflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page