Find out how ICT can support biomedical and clinical researchFind out more. From Clever cars to clever farms... Embedded Systems
MiniZinc Examples

MiniZinc Examples

Here we give several MiniZinc examples. For each one, we provide a problem description, a model, one or more data files, and one or more solutions provided by our implementation.


Golomb

A Golomb ruler may be defined as a set of m integers 0 = a1 < a2 < … < am such that the m(m-1)/2 differences aj - ai, 1 ≤ i < jm are distinct. Such a ruler is said to contain m marks and is of length am. The objective is to find optimal (minimum length) or near optimal rulers. 

Model file Data files Solutions
golomb.mzn

m = 4

m = 6

m = 4

m = 6


Job-Shop

Example from the MiniZinc paper: n×n job shop scheduling in MiniZinc.

Model file Data files Solutions
jobshop_nxn.mzn

n = 2

n = 4

n = 2

n = 4


Langford

Langford's Problem (CSPlib problem 24). Instance L(k,n): Arrange k sets of numbers 1 to n so that each appearance of the number m is m numbers on from the last. For example, the L(3,9) problem is to arrange 3 sets of the numbers 1 to 9 so that the first two 1's and the second two 1's appear one number apart, the first two 2's and the second two 2's appear two numbers apart, etc.

Model file Data files Solutions
langford.mzn

n = 9, k = 3

n = 10, k = 2

n = 9, k = 3

n = 10, k = 2


Minimum Cost Flow

Classic OR problem: Find the minimum cost flow in a network, while satisfying the demands in the nodes, and not violating the capacities of the arcs.

Model file Data files Solutions
min_cost_flow.mzn

n = 5, m = 10

n = 4, m = 6

n = 5, m = 10

n = 4, m = 6


Multidimensional Knapsack Problem

The classical 0/1 multidimensional knapsack problem. There is a knapsack with m different capacity constraints. There are n items with profits and weights. The goal is to maximise the total profit of the items in the knapsack while not violating any of the capacity constraints.

Model file Data files Solutions
multidimknapsack_simple.mzn

n = 5, m = 3

n = 6, m = 4

n = 5, m = 3

n = 6, m = 4


Open Shop Scheduling

Rectangular Scheduling Problem. J jobs have to be performed using M machines with the objective of minimising the total makespan.

Model file Data files Solutions
oss.mzn

M = 3, J = 3

M = 4, J = 3

M = 3, J = 3

M = 4, J = 3


Perfect Squares

Perfect squares: find a set of integers the sum of whose squares is itself a square.

Model file Data files Solutions
perfsq.mzn

z = 10

z = 20

z = 10

z = 20


Photo

A group of N people wants to take a group photo. Each person can give P preferences next to whom he or she wants to be placed in the photo. The problem to be solved is to find a placement that satisfies as many preferences as possible.

Model file Data files Solutions
photo.mzn

N = 9, P = 17

N = 11, P = 20

N = 9, P = 17

N = 11, P = 20


Production Planning

Product example from the OPL book.

Model file Data files Solutions
product.mzn

NumProducts = 3, NumResources = 2

NumProducts = 4, NumResources = 3

NumProducts = 3, NumResources = 2

NumProducts = 4, NumResources = 3


N-Queens

Place N queens on a N x N chess board such that none of the queens can attack each other.

Model file Data files Solutions

queen_cp2.mzn (CP version)

N = 8

N = 64

N = 8

N = 64

queen_ip.mzn (IP version)

N = 8

N = 10

N = 8

N = 10


Hoist Scheduling

MiniZinc model of one-hoist scheduling. Robert Rodosek and Mark Wallace. A Generic Model and Hybrid Algorithm for Hoist Scheduling Problems. In Michael J. Maher and Jean-Francois Puget eds. Principles and Practice of Constraint Programming - CP98, Springer, Lecture Notes in Computer Science, volume 1520, 1998.

Model file Data files Solutions
singHoist2.mzn

NumTanks = 3, NumJobs = 3

NumTanks = 4, NumJobs = 4

NumTanks = 3, NumJobs = 3

NumTanks = 4, NumJobs = 4


Sudoku

Simple sudoku for squares of arbitrary size N = S2.

Model file Data files Solutions
sudoku.mzn S = 3 S = 3


Who owns the zebra?

Also known as "Einstein's puzzle". For details see the comment at the top of the model file. There is no separate data file for this problem because it is formulated in such a way that the model and data cannot be easily separated.

Model file Data files Solutions
zebra.mzn N/A
zebra.soln