fuzzy_logic_77
fuzzy_logic_77

Reputation: 373

Minizinc - How can I constrain each column of an array to contain only one of a given integer?

I'm trying to populate a 10 row array such that each column contains a "1", a "2", a "3" and seven "0" s. Does anyone have any idea how to do this? I tried constraining the column total to equal 6 but that returned columns with six ones, two threes etc. Is there a 'count' function that I am unaware of? Thanks!

Upvotes: 2

Views: 784

Answers (1)

hakank
hakank

Reputation: 6854

There are at least three constraints that can be used for this:

  • global_cardinality
  • count
  • and perhaps all_different_except_0

See https://www.minizinc.org/2.0/doc-lib/doc-globals.html for a list of the global constraints supported in MiniZinc 2. The counting constraints are here: https://www.minizinc.org/2.0/doc-lib/doc-globals-counting.html

An example of how to use global_cardinality is here: http://hakank.org/minizinc/sudoku_pi.mzn

Upvotes: 3

Related Questions