Skip to content

Commit 2983891

Browse files
committed
pymzm project
1 parent 51c4de7 commit 2983891

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
layout: page
3+
title: Python MiniZinc Maker
4+
description: Generate MiniZinc models programmatically from Python
5+
img: assets/img/projects/python-minizinc-maker/banner.jpg
6+
importance: 1
7+
category: work
8+
related_publications: false
9+
---
10+
* GitHub Repository: [https://github.com/Arthod/python-minizinc-maker]()
11+
* PyPI Package: [https://pypi.org/project/pymzm/]()
12+
13+
Python MiniZinc Maker is an open-source library that allows developers to build pure [MiniZinc](https://www.minizinc.org/) models directly from Python code. Instead of manually writing `.mzn` files, users can define variables, constraints, objectives, and global constraints using a Python API and automatically generate valid MiniZinc models. The project bridges the gap between Python applications and constraint programming workflows powered by MiniZinc.
14+
15+
The library was designed to make optimization and constraint modeling more accessible for Python developers while preserving the flexibility and solver-independence offered by MiniZinc. MiniZinc itself is a high-level constraint modeling language that supports a wide range of optimization and satisfaction problems across multiple solver backends.
16+
17+
## Example Usage
18+
19+
A model can be created entirely from Python by defining variables, constraints, and optimization goals. The generated output is a standard MiniZinc model that can be solved using any MiniZinc-compatible solver.
20+
21+
We give below a
22+
23+
```python
24+
import pymzm
25+
model = pymzm.Model()
26+
27+
n = 8
28+
q = model.add_variables("q", range(n), val_min=0, val_max=n-1)
29+
30+
model.add_constraint(pymzm.Constraint.alldifferent(q))
31+
model.add_constraint(pymzm.Constraint.alldifferent([q[i] + i for i in range(n)]))
32+
model.add_constraint(pymzm.Constraint.alldifferent([q[i] - i for i in range(n)]))
33+
34+
model.set_solve_criteria("satisfy")
35+
model.generate()
36+
37+
import minizinc
38+
gecode = minizinc.Solver.lookup("gecode")
39+
result = minizinc.Instance(gecode, model).solve(all_solutions=False)
40+
# queen on column i is in row results[0, f"q_{j}"]
41+
```

0 commit comments

Comments
 (0)