Skip to main content

mdls

mdls is a small, decorator-based implementation of multi-directional local search (MDLS) for multi-objective optimisation. You supply an evaluate function and one move per objective; the library owns the non-dominated archive, selection, budgets and statistics.

The method follows Tricoire (2012). This package is a generalised, reusable version of the MDLS engine used in ORBITAL.

Install

pip install pymdls

The distribution is named pymdls; the import package is mdls, so the code below always uses from mdls import ....

Python 3.10 or newer is required. NumPy and Numba are installed automatically.

For the example's plotting command, install the extra:

pip install "pymdls[examples]"

Quick start

import numpy as np

from mdls import MDLS, move


def evaluate(x, inst):
    """MDLS minimises; g <= 0 means feasible."""
    return -(inst["obj"] @ x), [inst["weight"] @ x - inst["cap"]]


def _toggle(x, inst, rng, k, n_toggle):
    """One attempt: flip items, keep the copy if objective k improves."""
    y = x.copy()
    flip = rng.choice(x.size, size=n_toggle, replace=False)
    y[flip] = ~y[flip]
    if inst["weight"] @ y > inst["cap"]:
        return None
    return y if inst["obj"][k] @ y > inst["obj"][k] @ x else None


@move(improves=0, attempts=8)
def toggle_0(x, inst, rng, n_toggle=2):
    return _toggle(x, inst, rng, 0, n_toggle)


@move(improves=1, attempts=8)
def toggle_1(x, inst, rng, n_toggle=2):
    return _toggle(x, inst, rng, 1, n_toggle)


rng = np.random.default_rng(0)
n = 20
inst = {"obj": rng.random((2, n)), "weight": rng.random(n), "cap": 0.3 * n}
moves = [toggle_0(n_toggle=2), toggle_1(n_toggle=2)]
search = MDLS(evaluate, moves=moves, instance=inst)

res = search.run([np.zeros(n, dtype=bool)], max_eval=500, seed=0)
print(res.summary())
print(res.objectives)

What the library provides

  • Archive of feasible, non-dominated solutions with a relative tolerance, duplicate rejection and dominated-point eviction.
  • Move contract: a move is one improving attempt, optionally retried up to attempts times by the @move decorator.
  • Balanced search: every iteration applies one sampled move per objective from the same archived base solution.
  • Budgets: stop on iterations (max_iter), evaluations (max_eval, including initial solutions) or wall-clock time (time_limit).
  • Statistics: per-move counts of calls, no-moves, non-descents, infeasible results, dominated results, accepted results and time.
  • Extension points: is_feasible, selection, copy_solution, and the select, offer, copy and on_iteration hooks.

Moves are ordinary functions and stay readable; Numba is optional but is used inside the library's dominance scan and can be used inside your own moves.

Examples

The repository includes a bi-objective 0/1 knapsack:

python examples/knapsack.py run      # one search, writes front.csv
python examples/knapsack.py plot     # fronts for up to four seeds, writes front.png

The full tutorial, including the move contract and every option, is in user_guide.md.

Testing

pip install -e ".[dev,examples]"
pytest

License

MIT. See LICENSE.

Citation

If you use this package in academic work, cite the MDLS paper and optionally the software itself (see CITATION.cff):

Tricoire, F. (2012). Multi-directional local search. Computers & Operations Research, 39(12), 3089–3101. https://doi.org/10.1016/j.cor.2012.03.010

Metadata

Release files for pymdls 0.1.1

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

Source distribution (sdist)

Source distribution for pymdls 0.1.1
File Size Uploaded Provenance Actions
pymdls-0.1.1.tar.gz 23.2 kB With provenance Details for pymdls-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 33.5 kB

Release files / pymdls-0.1.1.tar.gz

Download URL pymdls-0.1.1.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2976ff3bc50d890acf397be4662e07e078757dd93b55ca0c5d19afbd3d657c99
BLAKE2b-256 checksum
How to use checksums
299254cd9e2124a3a8a2a6e4b30571061beec9794bc5c43bd111aacd1cca77f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / pymdls-0.1.1-py3-none-any.whl

Download URL pymdls-0.1.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a1d0361fee4e6af52a415df8c84969f294c30930a05cf9358bbdbee26aafc01
BLAKE2b-256 checksum
How to use checksums
1f248b2c92c20628754103f33025e33deb5daec1f9503c3ae55261b9027ad3ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for pymdls 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pymdls-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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