Access MiniZinc directly from Python
Project description
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.5.0+ and
Python 3.6.0+ 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 Tox environments to test its coding style and functionality. The code style tests are executed using Black, Flake8, and isort. The functionality tests are constructed using the PyTest unit testing framework.
- To run all tests, simply execute
tox
in the repository directory. - Individual environments can be triggered using the
-e
flag.- To test the coding style of the repository run
tox -e check
- The
py3x
environments are used to test a specific Python version; for example, to test using Python version 3.7 runtox -e py37
- To test the coding style of the repository run
Tox can also be used to generate the documentation, tox -e docs
, and to
typeset the Python code, tox -e format
.
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the Mozilla Public License Version 2.0. See LICENSE
for more information.
Contact
👤 Jip J. Dekker
- Twitter: @DekkerOne
- Github: Dekker1
🏛 MiniZinc
- Website: https://www.minizinc.org/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file minizinc-0.9.0.tar.gz
.
File metadata
- Download URL: minizinc-0.9.0.tar.gz
- Upload date:
- Size: 37.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a85d4183bc3451ed48a1f8b7589755e13f557e8701cca32ab3f33c03c9f5c5b |
|
MD5 | 25f7725fa9991ff4fe537329a2a36a05 |
|
BLAKE2b-256 | 858f91efc03090c536797fb2c023ed3418217d1804cdfd2744c27a71e8fad8e8 |
File details
Details for the file minizinc-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: minizinc-0.9.0-py3-none-any.whl
- Upload date:
- Size: 39.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.11.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf50f0de07a93eca141d4a984dd623c0794898558ca9d22771bdf67817ae86fd |
|
MD5 | 5346f94b05be1a5f0de652c618a22516 |
|
BLAKE2b-256 | 8c9e8e27a8346ee9620f35fe740329c612357279eabc3733f84c90b08b2b937f |