minizinc(mzn, *dzn_files, data=None, keep=False, include=None, solver=<pymzn.mzn.solvers.Gecode object>, output_mode='dict', output_vars=None, all_solutions=False, timeout=None, force_flatten=False, **solver_args)¶
Implements the workflow to solve a CSP problem encoded with MiniZinc.
- 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. The latter two formats are only available if the solver supports them.
- 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’.
- 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.
- 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.
- 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.
- **solver_args – Additional arguments to pass to the solver, provided as additional keyword arguments to this function. Check the solver documentation for the available arguments.
Returns a list of solutions as a SolnStream instance. The actual content of the stream depends on the output_mode chosen.