Created
May 13, 2022 00:26
-
-
Save Dekker1/af2e0d65d398b1ce1c1f9c5627176eb1 to your computer and use it in GitHub Desktop.
MiniZinc Python Example Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from minizinc import Instance, Model, Solver | |
gecode = Solver.lookup("gecode") | |
trivial = Model() | |
trivial.add_string( | |
""" | |
var 1..10: x; | |
constraint (x mod 2) = 1; | |
solve ::int_search([x], input_order, indomain_min) maximize x; | |
""" | |
) | |
instance = Instance(gecode, trivial) | |
# Find and print all intermediate solutions | |
result = instance.solve(intermediate_solutions=True) | |
for i in range(len(result)): | |
print(result[i, "x"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM minizinc/minizinc:latest-alpine | |
RUN apk add --update --no-cache python3 py3-pip | |
RUN pip3 install --no-cache-dir minizinc | |
COPY basic_example.py /usr/local/bin/basic_example.py | |
ENTRYPOINT ["/usr/local/bin/basic_example.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the
basic_example.py
file should be executable