Skip to main content

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

Project description

s2mflow

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

pip install s2mflow

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.12.tar.gz (7.8 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.12-cp313-cp313-win_amd64.whl (199.4 kB view details)

Uploaded CPython 3.13Windows x86-64

s2mflow-0.1.12-cp313-cp313-manylinux_2_28_x86_64.whl (341.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

s2mflow-0.1.12-cp313-cp313-manylinux_2_28_aarch64.whl (335.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

s2mflow-0.1.12-cp313-cp313-macosx_11_0_arm64.whl (296.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

s2mflow-0.1.12-cp313-cp313-macosx_10_12_x86_64.whl (305.4 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: s2mflow-0.1.12.tar.gz
  • Upload date:
  • Size: 7.8 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.12.tar.gz
Algorithm Hash digest
SHA256 3bdfc457f66c29b92a3a42a3688bccf0c39d809229f73fbcfe46fc61147e57a6
MD5 9ce21724197e14a2e497fd3eacf6d979
BLAKE2b-256 cd84fe5b3f7acbb44dc5616a97df93d0390be543fd484cae5c93481c8a7c22aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12.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.12-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: s2mflow-0.1.12-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 199.4 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.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0691fb753dc188670a47a9771abc1208eb0c89a636e846f2f1bb30466ef7f725
MD5 916d4bc2536ae08b5a6962f847371708
BLAKE2b-256 c96e78ed900978a7559ae65a40b0d4851e7739328e4164c131eec6989d7da64b

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12-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.12-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.12-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4d0c7a426c5bc98c7533d3654f34cc87921834fac446a057a8d96db041e0d161
MD5 3e8bf11c86237b260219ae42f416f60e
BLAKE2b-256 19fbbf88abbd469c24a4b3661123f93f9b64ebeb527e47409360520ec43d5b9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12-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.12-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.12-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8b856dfe20383bce825653ae55928c9d98c0df8833e4e1257a72e9a3220a35ae
MD5 361e7cba6acfcc70bf1513fab3142f91
BLAKE2b-256 dafc6b53795bcbf0317e12d580e994ebabe9f5b4d51810010480cda2325cb8b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12-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.12-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16ca960d74e00506098be66a6deed3e7d0c69e7d751c1d124fd0d45b8c5d7c35
MD5 41e0b421e6d06f6d7f53cfe4559b56d9
BLAKE2b-256 1d44f92f404a5247105e557b9dbce687d0d46ec7be3c4c97fb380af3ba06f801

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12-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.12-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for s2mflow-0.1.12-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7b57af5e45ee023abd9da3b7096de86e8687ff33d872fcac69223a75217ca816
MD5 b1eff5ee82c8d447de51adacc4fc4f9e
BLAKE2b-256 211503206dc21d46555c1d4e2721834861d980264a49dc1262862d9c1a61b1d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for s2mflow-0.1.12-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