4.2.1.9. Assertions and debugging functions

These functions help debug models and check that input data conforms to the expectations.

In this section: debug_mode, abort, assert, assert_dbg, default, expression_name_dbg, logstream_to_string, mzn_internal_check_debug_mode, trace, trace_dbg, trace_exp, trace_logstream, trace_stdout, trace_to_json_section, trace_to_section, mzn_break_here.

Constants

debug_mode

bool: debug_mode

Set to true iff --debug flag is set.

Functions and Predicates

abort

test abort(string: msg)

Abort evaluation and print message msg.

assert

1.  function any $T: assert(bool: b, string: msg, any $T: x)

2.  function array [$U] of any $T: assert(bool: b,
                                          string: msg,
                                          array [$U] of any $T: x)

3.  test assert(bool: b, string: msg)
1, 2.

If b is true, return x, otherwise abort with message msg.

  1. If b is true, return true, otherwise abort with message msg.

assert_dbg

test assert_dbg(bool: b, string: msg)

Return true, when the --debug flag is set, check if b is true, otherwise abort with message msg.

default

 1.  function $T: 'default'(opt $T: x, $T: y)

 2.  function opt $T: 'default'(opt $T: x, opt $T: y)

 3.  function var $T: 'default'(var opt $T: x, var $T: y)

 4.  function var opt $T: 'default'(var opt $T: x, var opt $T: y)

 5.  function array [$U] of $T: 'default'(array [$U] of $T: x,
                                          array [$U] of $T: y)

 6.  function array [$U] of opt $T: 'default'(array [$U] of opt $T: x,
                                              array [$U] of opt $T: y)

 7.  function array [$U] of var $T: 'default'(array [$U] of var $T: x,
                                              array [$U] of var $T: y)

 8.  function array [$U] of var opt $T: 'default'(array [$U] of var opt $T: x,
                                                  array [$U] of var opt $T: y)

 9.  function set of $$E: 'default'(set of $$E: x, set of $$E: y)

10.  function var set of $$E: 'default'(var set of $$E: x,
                                        var set of $$E: y)

11.  function set of $T: 'default'(opt set of $T: x, set of $T: y)

12.  function opt set of $T: 'default'(opt set of $T: x, opt set of $T: y)
1-4.

If x is defined and not absent, return x, otherwise return y.

5-10.

If x is defined, return x, otherwise return y.

11, 12.

If x is define amd mpt absent, return x, otherwise return y.

expression_name_dbg

annotation expression_name_dbg(string: s)

Used to attach a expression_name annotation with name s to an expression when –debug is enabled.

logstream_to_string

function string: logstream_to_string()

Return logging stream as string

mzn_internal_check_debug_mode

test mzn_internal_check_debug_mode()

Returns true iff --debug flag is set.

trace

1.  function any $T: trace(string: msg, any $T: x)

2.  function array [$U] of any $T: trace(string: msg,
                                         array [$U] of any $T: x)

3.  test trace(string: msg)
1, 2.

Return x, and print message msg.

  1. Return true, and print message msg.

trace_dbg

test trace_dbg(string: msg)

Return true, and when --debug flag is set print message msg.

trace_exp

function any $T: trace_exp(any $T: x)
function array [$U] of any $T: trace_exp(array [$U] of any $T: x)

Return x, and print a string representation of it.

trace_logstream

1.  function any $T: trace_logstream(string: msg, any $T: x)

2.  function array [$U] of any $T: trace_logstream(string: msg,
                                                   array [$U] of any $T: x)

3.  test trace_logstream(string: msg)
1, 2.

Return x, and print message msg to logging stream.

  1. Return true, and print message msg to logging stream.

trace_stdout

1.  function any $T: trace_stdout(string: msg, any $T: x)

2.  function array [$U] of any $T: trace_stdout(string: msg,
                                                array [$U] of any $T: x)

3.  test trace_stdout(string: msg)
1, 2.

Return x, and print message msg.

  1. Return true, and print message msg.

trace_to_json_section

test trace_to_json_section(string: section, opt $T: x)
test trace_to_json_section(string: section, array [$U] of opt $T: x)

Return true, and print x to the JSON section section.

trace_to_section

1.  function any $T: trace_to_section(string: section,
                                      string: msg,
                                      any $T: x)

2.  function array [$U] of any $T: trace_to_section(string: section,
                                                    string: msg,
                                                    array [$U] of any $T: x)

3.  test trace_to_section(string: section, string: msg)
1, 2.

Return x, and print message msg to section section.

  1. Return true, and print message msg to section section.

Annotations

mzn_break_here

annotation mzn_break_here

With debug build of the MiniZinc compiler, call MiniZinc::mzn_break_here when flattening this expression to make debugging easier. This annotation is ignored by the release build.