Logo
The MiniZinc Handbook
  • 1. Overview
  • 2. A MiniZinc Tutorial
  • 3. User Manual
  • 4. Reference Manual
    • 4.1. Specification of MiniZinc
    • 4.2. The MiniZinc library
      • 4.2.1. Standard Library
      • 4.2.2. Global constraints
        • 4.2.2.1. All-Different and related constraints
        • 4.2.2.2. Lexicographic constraints
        • 4.2.2.3. Sorting constraints
        • 4.2.2.4. Channeling constraints
        • 4.2.2.5. Counting constraints
        • 4.2.2.6. Array-related constraints
        • 4.2.2.7. Set-related constraints
        • 4.2.2.8. Mathematical constraints
        • 4.2.2.9. Packing constraints
        • 4.2.2.10. Scheduling constraints
        • 4.2.2.11. Graph constraints
        • 4.2.2.12. Extensional constraints (table, regular etc.)
        • 4.2.2.13. Machine learning constraints
        • 4.2.2.14. Deprecated constraints
      • 4.2.3. FlatZinc builtins
      • 4.2.4. Additional declarations for Gecode
      • 4.2.5. Additional declarations for Chuffed
      • 4.2.6. MiniZincIDE tools
      • 4.2.7. MiniZinc definitions for the MiniZinc diversity extension.
      • 4.2.8. Experimental Features
    • 4.3. Interfacing Solvers to Flatzinc
    • 4.4. Machine-readable JSON output format
The MiniZinc Handbook
  • 4. Reference Manual
  • 4.2. The MiniZinc library
  • 4.2.2. Global constraints
  • 4.2.2.6. Array-related constraints

4.2.2.6. Array-related constraints

In this section: element, member, write, writes, writes_seq.

element

predicate element(var $$E: i, array [$$E] of var bool: x, var bool: y)
predicate element(var $$E: i,
                  array [$$E] of var float: x,
                  var float: y)
predicate element(var $$E: i, array [$$E] of var $$T: x, var $$T: y)
predicate element(var $$E: i,
                  array [$$E] of var set of $$T: x,
                  var set of $$T: y)

Constrains i to be the index of the element y in the array x.

member

1.  predicate member(array [$X] of var bool: x, var bool: y)

2.  predicate member(array [$X] of var float: x, var float: y)

3.  predicate member(array [$X] of var $$E: x, var $$E: y)

4.  predicate member(array [$X] of var set of $$E: x, var set of $$E: y)

5.  predicate member(var set of $$E: x, var $$E: y)
1-4.

Requires that y occurs in the array x.

  1. Requires that y occurs in the set x.

write

1.  predicate write(array [$$E] of var $$T: I,
                    var $$E: i,
                    var $$T: v,
                    array [$$E] of var $$T: O)

2.  function array [$$E] of var $$T: write(array [$$E] of var $$T: I,
                                           var $$E: i,
                                           var $$T: v)
  1. Creates a new array O from an input array I with a change at position i to take value v

    I is an array of values O is an array of values with same index set as I i is an index for I v is the value to write

  2. Return the input array I with a change at position i to take value v

    I is an array of values i is an index for I v is the value to write

writes

1.  predicate writes(array [$$X] of var $$T: I,
                     array [$$Y] of var $$X: P,
                     array [$$Y] of var $$T: V,
                     array [$$X] of var $$T: O)

2.  function array [$$X] of var $$T: writes(array [$$X] of var $$T: I,
                                            array [$$Y] of var $$X: P,
                                            array [$$Y] of var $$T: V)
  1. Creates a new array O from an input array I with a simultaneous change at positions P to values V

    I is an array of input values O is an array of integers with same index set as I P is an array of index values in I V is an array of values to write

  2. Returns a new array from an input array I with a simultaneous change at positions P to values V

    I is an array of input values P is an array of index values in I V is an array of values to write

writes_seq

1.  predicate writes_seq(array [$$X] of var $$T: I,
                         array [$$Y] of var $$X: P,
                         array [$$Y] of var $$T: V,
                         array [$$X] of var $$T: O)

2.  function array [$$X] of var $$T: writes_seq(array [$$X] of var $$T: I,
                                                array [$$Y] of var $$X: P,
                                                array [$$Y] of var $$T: V)
  1. Creates a new array O from an input array I with a sequence of changes at positions P to take values V

    I is an array of input values O is an array of output values with same index set as I P is an array of indices in I V is an array of values to write

  2. Return the input array I with a sequence of changes at positions P to take values V

    I is an array of input values P is an array of index values in I V is an array of values to write

Previous Next

© Copyright 2016, 2017, 2018, 2019, 2020 Peter J. Stuckey, Kim Marriott, Guido Tack.

Creative Commons License