pymzm
Create pure Minizinc .mzn files from Python using python-minizinc-maker library.
Science Score: 31.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.4%) to scientific vocabulary
Keywords
Repository
Create pure Minizinc .mzn files from Python using python-minizinc-maker library.
Basic Info
Statistics
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
python-minizinc-maker
Create pure Minizinc .mzn files from Python using python-minizinc-maker.
Install
Installed with pip from pypi
pip3 install pymzm
Model
Model: model = pymzm.Model() \
Variable: x = model.add_variable(name, vtype, val_min, val_max) \
Variables: xs = model.add_variables(name, indicies, vtype, val_min, val_max) \
Constraint: model.add_constraint(expr)\
Solve: model.set_solve_criteria(solve_criteria, expr)
Global constraints
alldifferent, among, all_equal, count, increasing, decreasing, ..(more to be added later)..
Solve
- model.setsolvecriteria(pymzm.SOLVE_MAXIMIZE, pymzm.Expression.sum(xs))
- model.setsolvecriteria(pymzm.SOLVE_SATISFY)
Examples
intfact.py - Integer Factorization example
intfact.py ```python import pymzm model = pymzm.Model()
x = model.addvariable("x", valmin=1, valmax=99999999) y = model.addvariable("y", valmin=1, valmax=99999999)
model.addconstraint(x * y == 7829 * 6907) model.addconstraint(y > 1) model.add_constraint(x > y)
model.setsolvecriteria(pymzm.SOLVE_SATISFY) model.generate() model.write("model.mzn") ... ```
model.mzn
mzn
var 1..99999999: x;
var 1..99999999: y;
constraint x * y = 54074903;
constraint y > 1;
constraint x > y;
solve satisfy;
Now you can use the minizinc library to solve the model directly.
intfact.py
python
...
import minizinc
gecode = minizinc.Solver.lookup("gecode")
result = minizinc.Instance(gecode, model).solve(all_solutions=True)
print(f"x = {result[0].x}") # x = 7829
print(f"y = {result[0].y}") # y = 6907
bibd.py - Balanced Incomplete Block Design
https://www.csplib.org/Problems/prob028/ ```python v = 7; b = 7; r = 3; k = 3; l = 1
model = pymzm.Model()
indicies = [(i, j) for i in range(v) for j in range(b)]
bool if object v is in block b
xs = model.addvariables("x", indices=indicies, vtype=pymzm.Variable.VTYPEBOOL)
for i in range(b): model.addconstraint(pymzm.Expression.sum(xs[i, j] for j in range(v)) == r) for i in range(v): model.addconstraint(pymzm.Expression.sum(xs[j, i] for j in range(b)) == k)
for i in range(b): for j in range(i): model.add_constraint(pymzm.Expression.sum(xs[i, k] * xs[j, k] for k in range(v)) == l)
model.setsolvecriteria(pymzm.SOLVE_SATISFY) model.generate()
gecode = minizinc.Solver.lookup("gecode") result = minizinc.Instance(gecode, model).solve(all_solutions=False)
for i in range(v):
print(" ".join([str(int(result[f"x{i}{j}"])) for j in range(b)]))
outputs
0 0 1 0 0 1 1
0 1 0 0 1 1 0
1 0 0 1 0 1 0
0 0 1 1 1 0 0
0 1 0 1 0 0 1
1 1 1 0 0 0 0
1 0 0 0 1 0 1
```
sat.py - Satisfiability
```python model = pymzm.Model()
xs = model.addvariables("x", indices=range(4), vtype=pymzm.Variable.VTYPEBOOL) model.addconstraint(pymzm.Expression.AND([ xs[0] | xs[1] | ~xs[2], xs[1] | xs[2] | ~xs[3], xs[0] | ~xs[1] | xs[3], ])) model.setsolvecriteria(pymzm.SOLVESATISFY) model.generate()
gecode = minizinc.Solver.lookup("gecode") result = minizinc.Instance(gecode, model).solve(all_solutions=False)
for i in range(4): print(f"x{i} = {result[f'x{i}']}") ```
Owner
- Name: Ahmad Othman
- Login: Arthod
- Kind: user
- Website: https://lichess.org/@/AhmadMSOthman
- Twitter: AhmadMSOthman
- Repositories: 17
- Profile: https://github.com/Arthod
Computer Science student at the University of Southern Denmark
Citation (CITATION.cff)
cff-version: 1.2.0 message: "If you use this software, please cite it as below." type: software authors: - family-names: "Othman" given-names: "Ahmad M." orcid: "https://orcid.org/0009-0008-9458-5973" title: "Python MiniZinc Maker" version: 1.0.0 doi: 10.5281/zenodo.15126980 date-released: 2017-09-07 url: "https://github.com/Arthod/python-minizinc-maker"
GitHub Events
Total
- Issues event: 1
- Issue comment event: 1
- Push event: 2
Last Year
- Issues event: 1
- Issue comment event: 1
- Push event: 2
Packages
- Total packages: 1
-
Total downloads:
- pypi 10 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
pypi.org: pymzm
Create pure Minizinc .mzn files from Python using python-minizinc-maker library.
- Homepage: https://github.com/Arthod/python-minizinc-maker
- Documentation: https://pymzm.readthedocs.io/
- License: MIT License
-
Latest release: 0.0.1
published about 2 years ago