Skip to content

Instantly share code, notes, and snippets.

@Dekker1
Created May 13, 2022 00:26
Show Gist options
  • Save Dekker1/af2e0d65d398b1ce1c1f9c5627176eb1 to your computer and use it in GitHub Desktop.
Save Dekker1/af2e0d65d398b1ce1c1f9c5627176eb1 to your computer and use it in GitHub Desktop.
MiniZinc Python Example Docker
#!/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"])
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"]
@Dekker1
Copy link
Author

Dekker1 commented May 13, 2022

Note that the basic_example.py file should be executable

chmod +x basic_example.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment