Skip to main content

Access MiniZinc directly from Python

Project description


Logo

MiniZinc Python

The python package that allows you to access all of MiniZinc's functionalities directly from Python.
Explore the docs »

Report Bug · Request Feature

Table of Contents

About The Project

MiniZinc Python provides an interface from Python to the MiniZinc driver. The most important goal of this project are to allow easy access to MiniZinc using native Python structures. This will allow you to more easily make scripts to run MiniZinc, but will also allow the integration of MiniZinc models within bigger (Python) projects. This module also aims to expose an interface for meta-search. For problems that are hard to solve, meta-search can provide solutions to reach more or better solutions quickly.

Getting Started

To get a MiniZinc Python up and running follow these simple steps.

Installation

MiniZinc Python can be installed by running pip install minizinc. It requires MiniZinc 2.6+ and Python 3.8+ to be installed on the system. MiniZinc python expects the minizinc executable to be available on the executable path, the $PATH environmental variable, or in a default installation location.

For more information, please refer to the Documentation

Usage

Once all prerequisites and MiniZinc Python are installed, a minizinc module will be available in Python. The following Python code shows how to run a typical MiniZinc model.

import minizinc

# Create a MiniZinc model
model = minizinc.Model()
model.add_string("""
var -100..100: x;
int: a; int: b; int: c;
constraint a*(x*x) + b*x = c;
solve satisfy;
""")

# Transform Model into a instance
gecode = minizinc.Solver.lookup("gecode")
inst = minizinc.Instance(gecode, model)
inst["a"] = 1
inst["b"] = 4
inst["c"] = 0

# Solve the instance
result = inst.solve(all_solutions=True)
for i in range(len(result)):
    print("x = {}".format(result[i, "x"]))

For more examples, please refer to the Documentation

Testing

MiniZinc Python uses uv to manage its dependencies. To install the development dependencies run uv sync --dev.

Although continuous integration will test any code, it can be convenient to run the tests locally. The following commands can be used to test the MiniZinc Python package.

  • We use PyTest to run a suite of unit tests. You can run these tests by executing:
uv run pytest
  • We use Ruff to test against a range of Python style and performance guidelines. You can run the general linting using:
uv run ruff check

You can format the codebase to be compatible using:

uv run ruff format

(The continous integration will test that the code is correctly formatted using the --check flag.)

  • We use Mypy to check the type correctness of the codebase (for as far as possible). You can run the type checking using:
uv run mypy .

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the Mozilla Public License Version 2.0. See LICENSE for more information.

Contact

👤 Jip J. Dekker

🏛 MiniZinc

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

minizinc-0.10.0.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

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

minizinc-0.10.0-py3-none-any.whl (44.8 kB view details)

Uploaded Python 3

File details

Details for the file minizinc-0.10.0.tar.gz.

File metadata

  • Download URL: minizinc-0.10.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.30

File hashes

Hashes for minizinc-0.10.0.tar.gz
Algorithm Hash digest
SHA256 ce1d3501ce45068a5cf419a71e5aa507e3a62a3088638ae96a200ec329f90a3a
MD5 6b2fd47fb3f580eb04713969c80fcff0
BLAKE2b-256 dd3cf425820ca7d05f824563282998504719dfaef1022608808a6c36e44396f4

See more details on using hashes here.

File details

Details for the file minizinc-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: minizinc-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 44.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.30

File hashes

Hashes for minizinc-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bd951866f8b246c4210b801bfc926e6bf7bc59a17f002b4c5fc49d9d9ec17e3
MD5 71023667c248f5f9838539a7968f473d
BLAKE2b-256 d11dd1dc3d250643defde3d71cd9d64911b057ec38b88bc1555ed55b6260fc4f

See more details on using hashes here.

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