Module docplex.cp.fzn.fzn_parser

Parser converting a FZN file to internal model representation.

This parser does not support the complete set of predicates described in the specifications of FlatZinc that can be found here: http://www.minizinc.org/downloads/doc-1.6/flatzinc-spec.pdf

Basically, it supports essentially integer expressions, some floating point expressions and custom predicates related to scheduling.

The predicates that are supported are:

  • array predicates

    array_bool_and, array_bool_element, array_bool_or, array_bool_xor, array_float_element, array_int_element, array_set_element, array_var_bool_element, array_var_float_element, array_var_int_element, array_var_set_element.

  • boolean predicates

    bool2int, bool_and, bool_clause, bool_eq, bool_eq_reif, bool_le, bool_le_reif, bool_lin_eq, bool_lin_le, bool_lt, bool_lt_reif, bool_not, bool_or, bool_xor.

  • integer predicates

    int_abs, int_div, int_eq, int_eq_reif, int_le, int_le_reif, int_lin_eq, int_lin_eq_reif, int_lin_le, int_lin_le_reif, int_lin_ne, int_lin_ne_reif, int_lt, int_lt_reif, int_max, int_min, int_mod, int_ne, int_ne_reif, int_plus, int_times, int2float.

  • float predicates

    float_abs, float_exp, float_ln, float_log10, float_log2, float_sqrt, float_eq, float_eq_reif, float_le, float_le_reif, float_lin_eq, float_lin_eq_reif, float_lin_le, float_lin_le_reif, float_lin_lt, float_lin_lt_reif, float_lin_ne, float_lin_ne_reif, float_lt, float_lt_reif, float_max, float_min, float_ne, float_ne_reif, float_plus.

  • set predicates

    set_in, set_in_reif.

  • custom predicates

    all_different_int, subcircuit, count_eq_const, table_int, inverse, lex_lesseq_bool, lex_less_bool, lex_lesseq_int, lex_less_int, int_pow, cumulative

Detailed description

class docplex.cp.fzn.fzn_parser.FznConstraint(predicate, args, annotations)[source]

Bases: docplex.cp.fzn.fzn_parser.FznObject

Descriptor of a FZN constraint

Create a new FZN constraint :param predicate: Name of the predicate :param args: List or arguments :param annotations: Declaration annotations

class docplex.cp.fzn.fzn_parser.FznObject[source]

Bases: object

Descriptor of a FZN object

class docplex.cp.fzn.fzn_parser.FznObjective(operation, expr, annotations)[source]

Bases: docplex.cp.fzn.fzn_parser.FznObject

Descriptor of a FZN objective

Create a new FZN constraint :param operation: Objective operation in ‘satisfy’, ‘minimize’, ‘maximize’ :param expr: Target expression :param annotations: Annotations

class docplex.cp.fzn.fzn_parser.FznParameter(name, type, size, value)[source]

Bases: docplex.cp.fzn.fzn_parser.FznObject

Descriptor of a FZN parameter

Create a new FZN parameter :param name: Name of the parameter :param type: Type of the parameter :param size: Array size, None if not array :param value: Parameter value

class docplex.cp.fzn.fzn_parser.FznParser(mdl=None)[source]

Bases: object

Reader of FZN file format

Create a new FZN format parser

Parameters:mdl – Model to fill, None (default) to create a new one.
get_model()[source]

Get the model that have been parsed

Returns:CpoModel result of the parsing
get_output_variables()[source]

Get the list of model output variables

Returns:List of output variables, in declaration order.
parse(cfile)[source]

Parse a FZN file

Parameters:cfile – FZN file to read
Raises:FznParserException – Parsing exception
parse_string(str)[source]

Parse a string

Result of the parsing is added to the current result model.

Parameters:str – String to parse
exception docplex.cp.fzn.fzn_parser.FznParserException(msg)[source]

Bases: docplex.cp.utils.CpoException

The base class for exceptions raised by the CPO parser

Create a new exception :param msg: Error message

class docplex.cp.fzn.fzn_parser.FznReader(mdl=None)[source]

Bases: object

Reader of FZN file format

Create a new FZN reader

parse(cfile)[source]

Parse a FZN file

Parameters:cfile – FZN file to read
Raises:FznParserException – Parsing exception
parse_string(str)[source]

Parse a string

Result of the parsing is added to the current result model.

Parameters:str – String to parse
write(out=None)[source]

Write the model.

If the given output is a string, it is considered as a file name that is opened by this method using ‘utf-8’ encoding.

Parameters:out (Optional) – Target output stream or file name. If not given, default value is sys.stdout.
class docplex.cp.fzn.fzn_parser.FznVariable(name, type, domain, annotations, size, value)[source]

Bases: docplex.cp.fzn.fzn_parser.FznObject

Descriptor of a FZN variable

Create a new FZN variable :param name: Name of the variable :param type: Variable type :param domain: Variable domain :param annotations: Declaration annotations (dictionary) :param size: Array size, None if not array :param value: Initial value, None if none

is_defined()[source]

Check if the variable is introduced :returns: True if variable is introduced, False otherwise

is_introduced()[source]

Check if the variable is introduced :returns: True if variable is introduced, False otherwise

is_output()[source]

Check if the variable is introduced :returns: True if variable is introduced, False otherwise