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

Problem description. A Golomb ruler may be defined as a set of m integers 0 = a_1 < a_2 < ... < a_m such that the m(m-1)/2 differences a_j - a_i, 1 <= i < j <= m are distinct. Such a ruler is said to contain m marks and is of length a_m. The objective is to find optimal (minimum length) or near optimal rulers.

Model file. golomb.mzn.

Data files. m = 4, m = 6.

Solutions. m = 4, m = 6.

Job-Shop

Problem description. Example from the MiniZinc paper: (square) job shop scheduling in MiniZinc

Model file. jobshop_nxn.mzn.

Data files. n = 2, n = 4.

Solutions. n = 2, n = 4.

Langford

Problem description. 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. langford.mzn.

Data files. n = 9, k = 3, n = 10, k = 2.

Solutions. n = 9, k = 3, n = 10, k = 2.

Minimum Cost Flow

Problem description. 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. min_cost_flow.mzn.

Data files. n = 5, m = 10, n = 3, m = 6.

Solutions. n = 5, m = 10, n = 3, m = 6.

Multidimensional Knapsack Problem

Problem description. 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. multidimknapsack_simple.mzn.

Data files. n = 5, m = 3, n = 6, m = 4.

Solutions. n = 5, m = 3, n = 6, m = 4.

Open Shop Scheduling

Problem description. Rectangular Scheduling Problem. NJobs have to be performed using NMachines with the objective of minimising the total makespan.

Model file. oss.mzn.

Data files. NMachines = 3, NJobs = 3, NMachines = 4, NJobs = 3.

Solutions. NMachines = 3, NJobs = 3, NMachines = 4, NJobs = 3.

Perfect Squares

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

Model file. perfsq.mzn.

Data files. Z = 10, Z = 20.

Solutions. Z = 10, Z = 20.

Photo

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

Model file. photo.mzn.

Data files. n_names = 9, n_pref = 17, n_names = 11, n_pref = 20.

Solutions. n_names = 9, n_pref = 17, n_names = 11, n_pref = 20.

Production Planning

Problem description. Product example from the OPL book.

Model file. product.mzn.

Data files. NumProducts = 3, NumResources = 2, NumProducts = 4, NumResources = 3.

Solutions. NumProducts = 3, NumResources = 2, NumProducts = 4, NumResources = 3.

N-Queens

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

Model file. queen_cp2.mzn. This version uses constraint programming techniques.

Data files. N = 8, N = 64.

Solutions. N = 8, N = 64.

N-Queens IP Formulation

Problem description. Place N queens on a N x N chess board such that none of the queens can attack each other. Modelled using IP techniques.

Model file. queen_ip.mzn. This version uses IP techniques.

Data files. N = 8, N = 10.

Solutions. N = 8, N = 10.

Hoist Scheduling

Problem description. MiniZinc model of one-hoist scheduling from the following paper:
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. singHoist2.mzn.

Data files. NumTanks = 3, NumJobs = 3, NumTanks = 4, NumJobs = 4.

Solutions. NumTanks = 3, NumJobs = 3, NumTanks = 4, NumJobs = 4.

Sudoku

Problem description. Simple sudoku for squares of arbitrary size N = (S x S).

Model file. sudoku.mzn.

Data files. S = 3.

Solutions. S = 3.

Who owns the zebra?

Problem description. Also known as "Einstein's puzzle". For details see the comment at the top of the 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. zebra.mzn.

Solutions. zebra.soln.


Back to MiniZinc home page.