All Projects → paolodragone → pymzn

paolodragone / pymzn

Licence: MIT license
A Python wrapper for the MiniZinc tool pipeline.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pymzn

minizinc-python
Access to all MiniZinc functionality directly from Python
Stars: ✭ 92 (+70.37%)
Mutual labels:  constraint-programming, minizinc
Flask movie project
🎬 Flask构建的小花椒视频网站(重新配置 ing……)
Stars: ✭ 15 (-72.22%)
Mutual labels:  jinja2
Index.py
An easy-to-use high-performance asynchronous web framework.
Stars: ✭ 158 (+192.59%)
Mutual labels:  jinja2
pycsp3
A Python Library for modeling combinatorial constrained problems
Stars: ✭ 39 (-27.78%)
Mutual labels:  constraint-programming
Aiohttp Jinja2
jinja2 template renderer for aiohttp.web
Stars: ✭ 180 (+233.33%)
Mutual labels:  jinja2
cplex-scala
A scala library for IBM ILOG CPLEX
Stars: ✭ 20 (-62.96%)
Mutual labels:  constraint-programming
Td4a
Template designer for automation
Stars: ✭ 139 (+157.41%)
Mutual labels:  jinja2
ordered
Entropy-controlled contexts in Python
Stars: ✭ 36 (-33.33%)
Mutual labels:  constraint-programming
simsttab
Simple timetabling engine for schools
Stars: ✭ 21 (-61.11%)
Mutual labels:  constraint-programming
Statik
Multi-purpose static web site generator aimed at developers.
Stars: ✭ 249 (+361.11%)
Mutual labels:  jinja2
Staticjinja
Minimalist Python library for building static websites with Jinja
Stars: ✭ 218 (+303.7%)
Mutual labels:  jinja2
Yasha
A command-line tool to render Jinja templates for great good
Stars: ✭ 189 (+250%)
Mutual labels:  jinja2
jinja.dart
Jinja2 template engine port for Dart.
Stars: ✭ 38 (-29.63%)
Mutual labels:  jinja2
Dnsmasqweb
基于DNSmasq的DNS解析、以及DHCP地址分配系统
Stars: ✭ 166 (+207.41%)
Mutual labels:  jinja2
conjure
Conjure: The Automated Constraint Modelling Tool
Stars: ✭ 84 (+55.56%)
Mutual labels:  constraint-programming
Ops Cli
Ops - cli wrapper for Terraform, Ansible, Helmfile and SSH for cloud automation
Stars: ✭ 152 (+181.48%)
Mutual labels:  jinja2
Django Webpush
Web Push Notification Package for Django
Stars: ✭ 217 (+301.85%)
Mutual labels:  jinja2
CNApy
An integrated visual environment for metabolic modeling with common methods such as FBA, FVA and Elementary Flux Modes, and advanced features such as thermodynamic methods, extended Minimal Cut Sets, OptKnock, RobustKnock, OptCouple and more!
Stars: ✭ 27 (-50%)
Mutual labels:  constraint-programming
pylodon
Flask-based ActivityPub server
Stars: ✭ 86 (+59.26%)
Mutual labels:  jinja2
HyperGraphLib
C++ Hypergraph modelling Library using Boost and OpenMP with some algorithms, including isomorphism using Gecode.
Stars: ✭ 19 (-64.81%)
Mutual labels:  constraint-programming

PyMzn

PyMzn is a Python library that wraps and enhances the MiniZinc tools for constraint programming. PyMzn is built on top of the minizinc toolkit and provides a number of off-the-shelf functions to readily solve problems encoded with the MiniZinc language and return solutions as Python dictionaries.

Usage

First, we need to define a constraint program via MiniZinc. Here is a simple 0-1 knapsack problem encoded with MiniZinc:

    %% knapsack01.mzn %%
    int: n;                     % number of objects
    set of int: OBJ = 1..n;
    int: capacity;              % the capacity of the knapsack
    array[OBJ] of int: profit;  % the profit of each object
    array[OBJ] of int: size;    % the size of each object

    var set of OBJ: x;
    constraint sum(i in x)(size[i]) <= capacity;
    var int: obj = sum(i in x)(profit[i]);
    solve maximize obj;


    %% knapsack01.dzn %%
    n = 5;
    profit = [10, 3, 9, 4, 8];
    size = [14, 4, 10, 6, 9];

You can solve the above problem using the pymzn.minizinc function:

    import pymzn
    solns = pymzn.minizinc('knapsack01.mzn', 'knapsack01.dzn', data={'capacity': 20})
    print(solns)

The result will be:

    [{'x': {3, 5}}]

The returned object is a lazy solution stream, which can either be iterated or directly indexed as a list. The pymzn.minizinc function takes care of all the preprocessing, the communication with the minizinc executable, and the parsing of the solutions stream into Python dictionaries.

PyMzn is also able to:

  • Convert Python dictionaries to dzn format and back (e.g. when passing data to the pymzn.minizinc function);
  • Interface with many different solvers;
  • Preprocess MiniZinc models by embedding code from the Jinja2 templating language;
  • Perform concurrent MiniZinc execution using Python coroutines.

For a follow-up of the previous example, read the PyMzn tutorial.

For more information on the PyMzn classes and functions refer to the reference manual.

Install

PyMzn can be installed via Pip:

    pip install pymzn

or from the source code available on GitHub:

    python setup.py install

Requirements

PyMzn is developed and maintained in Python 3.5. Starting from version 0.18.0, support for Python 2 and versions previous to 3.5 has been dropped (its just too much work mainintaining them). Using the package pymzn.aio for concurrent execution requires Python 3.6 (though it is optional).

PyMzn requires the MiniZinc toolkit to be installed on your machine. Starting from PyMzn 0.18.0, the minimum MiniZinc version required is the 2.2.0. If you need to work with previous versions of MiniZinc, PyMzn 0.17.1 should work fine.

The easiest way to install MiniZinc is to download the MiniZincIDE package, which contains both the MiniZinc binaries and several solvers. After downloading the package, make sure the executables are visible to PyMzn either by setting the PATH environment variable or by configuring it using the pymzn.config module.

For more details take a look at the Install section in the documentation.

Optional dependencies include:

  • Jinja2, for preprocessing through Jinja templating language;
  • PyYAML and appdirs, for loading and saving configuration files.

Author

Paolo Dragone, PhD student at the University of Trento (Italy).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].