Giter VIP home page Giter VIP logo

minizinc-python's Introduction


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 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 install test-suite dependencies, run poetry install --with dev (requires installation of Poetry)
  • To run all tests, simply execute poetry run tox in the repository directory.
  • Individual environments can be triggered using the -e flag.
    • To test the coding style of the repository run poetry run tox -e check
    • The py3x environments are used to test a specific Python version; for example, to test using Python version 3.7 run poetry run tox -e py37

Tox can also be used to generate the documentation, poetry run tox -e docs, and to typeset the Python code, poetry run 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.

  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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.