pymzn.minizinc

pymzn.minizinc(mzn, *dzn_files, data=None, keep=False, include=None, solver=None, output_mode='dict', output_vars=None, output_dir=None, timeout=None, all_solutions=False, num_solutions=None, force_flatten=False, args=None, wait=True, statistics=False, no_output_annotations=True, **kwargs)

Implements the workflow to solve a CSP problem encoded with MiniZinc.

Parameters:
  • mzn (str or MiniZincModel) – The minizinc problem to be solved. It can be either a string or an instance of MiniZincModel. If it is a string, it can be either the path to the mzn file or the content of the model.
  • *dzn_files – A list of paths to dzn files to attach to the mzn2fzn execution, provided as positional arguments; by default no data file is attached. Data files are meant to be used when there is data that is static across several minizinc executions.
  • data (dict) – Additional data as a dictionary of variables assignments to supply to the mzn2fnz function. The dictionary is then automatically converted to dzn format by the pymzn.dzn function. This property is meant to include data that dynamically changes across several minizinc executions.
  • keep (bool) – Whether to keep the generated mzn, dzn, fzn and ozn files or not. If False, the generated files are created as temporary files which will be deleted right after the problem is solved. Though pymzn generated files are not originally intended to be kept, this property can be used for debugging purpose. Notice that in case of error the files are not deleted even if this parameter is False. Default is False.
  • include (str or list) – One or more additional paths to search for included mzn files.
  • solver (Solver) – An instance of Solver to use to solve the minizinc problem. The default is pymzn.gecode.
  • output_mode ('dzn', 'json', 'item', 'dict') – The desired output format. The default is ‘dict’ which returns a stream of solutions decoded as python dictionaries. The ‘item’ format outputs a stream of strings as returned by the solns2out tool, formatted according to the output statement of the MiniZinc model. The ‘dzn’ and ‘json’ formats output a stream of strings formatted in dzn of json respectively.
  • output_vars ([str]) – A list of output variables. These variables will be the ones included in the output dictionary. Only available if ouptut_mode=’dict’.
  • output_dir (str) – Output directory for files generated by PyMzn. The default (None) is the temporary directory of your OS (if keep=False) or the current working directory (if keep=True).
  • timeout (int) – Number of seconds after which the solver should stop the computation and return the best solution found. This is only available if the solver has support for a timeout.
  • all_solutions (bool) – Whether all the solutions must be returned. Notice that this can only be used if the solver supports returning all solutions. Default is False.
  • num_solutions (int) – The upper bound on the number of solutions to be returned. Can only be used if the solver supports returning a fixed number of solutions. Default is 1.
  • force_flatten (bool) – Wheter the function should be forced to produce a flat model. Whenever possible, this function feeds the mzn file to the solver without passing through the flattener, force_flatten=True prevents this behavior and always produces a fzn file which is in turn passed to the solver.
  • args (dict) – Arguments for the template engine.
  • wait (bool) – Whether to wait for the solving process to finish before returning the solution stream.
  • statistics (bool) – Whether to save the statistics of the solver (if supported).
  • no_output_annotations (bool) – Whether to avoid using output annotation when handling output variables.
  • **kwargs – Additional arguments to pass to the solver, provided as additional keyword arguments to this function. Check the solver documentation for the available arguments.
Returns:

Returns a list of solutions as a Solutions instance. The actual content of the stream depends on the output_mode chosen.

Return type:

Solutions