XCSP3 (cpmpy.tools.io.xcsp3)

Helper functions for loading CPMpy models from XCSP3-core formatted files.

XCSP3 is an XML-based format for constraint satisfaction and optimisation problems. More can be read about it here:

For additional XCSP3 utilities (benchmarking, analysis, CLI, …), see cpmpy.tools.xcsp3.

List of functions

load_xcsp3

Loads an XCSP3 instance (.xml or .xml.lzma) and returns its matching CPMpy model.

cpmpy.tools.io.xcsp3.load_xcsp3(xcsp3: str | PathLike | TextIO, open: Callable = <built-in function open>) Model[source]

Loads an XCSP3 instance (.xml or .xml.lzma) and returns its matching CPMpy model.

Parameters:
  • xcsp3 (str or os.PathLike or TextIO) –

    • A file path to an XML file (optionally LZMA-compressed with .lzma), or

    • A string containing the XML content directly, or

    • A TextIO object already open for reading

  • open – (callable): If xcsp3 is the path to a file, a callable to “open” that file (default=python standard library’s ‘open’).

Returns:

The XCSP3 instance loaded as a CPMpy model.