SCIP-backed formats (cpmpy.tools.io.scip_formats)
This file implements helper functions for converting CPMpy models to and from various data formats supported by the SCIP optimization suite.
Installation
The ‘pyscipopt’ optional dependency must be installed separately through pip:
$ pip install cpmpy[io.scip]
List of functions
Load a SCIP-compatible model from a file and return a CPMpy model. |
|
Write a CPMpy model to file using the SCIP solver. |
- cpmpy.tools.io.scip_formats.load_scip_format(instance: str | PathLike | TextIO, open: Callable = <built-in function open>, assume_integer: bool = False, type: str | None = None) Model[source]
Load a SCIP-compatible model from a file and return a CPMpy model.
- Parameters:
instance (str or os.PathLike or TextIO) – The path to the SCIP-compatible file to read, a string containing the model content directly, or a TextIO object already open for reading.
open (Callable) – The function to use to open the file. (SCIP does not require this argument, will be ignored)
assume_integer (bool) – Whether to assume that all variables are integer.
type (str, optional) – Type of the inline string or unnamed TextIO input. Required when
instanceis a raw string.
Warning
Setting assumes_integer to True will cause CPMpy to assume that all variables are integer, even if they are not explicitly declared as such in the problem file. Use with caution.
- Returns:
A CPMpy model.
- Return type:
cp.Model
- cpmpy.tools.io.scip_formats.write_scip_format(model: Model, path: str | PathLike | None = None, format: str = 'mps', header: str | None = None, verbose: bool = False, open: Callable = functools.partial(<built-in function open>, mode='w')) str[source]
Write a CPMpy model to file using the SCIP solver.
Supported formats include: - “mps” - “lp” - “cip” - “fzn” - “gms” - “pip”
More formats can be supported upon the installation of additional dependencies (like SIMPL). For more information, see the SCIP documentation: https://pyscipopt.readthedocs.io/en/latest/tutorials/readwrite.html
- Parameters:
model (cp.Model) – CPMpy model to write.
path (str or os.PathLike, optional) – The file path to write the SCIP output to. If None, the SCIP string is returned.
format (str) – Output format (e.g. “mps”, “lp”, “cip”, “fzn”, “gms”, “pip”).
header (Optional[str]) – Optional header text to prepend (format-dependent comment style). If None, a default CPMpy header is created only when writing to
path. Pass an empty string to skip adding a header.verbose (bool) – If True, allow SCIP to print progress.
open (Callable) – Callable to open the file for writing (default: builtin
open). Called asopen(path). Mirrors theopen=argument in loaders and allows custom compression or I/O (e.g.lambda p: lzma.open(p, 'wt')).
- Returns:
The file content as a string (whether written to
pathor not).- Return type:
str