docplex.mp.model_reader module¶
-
class
docplex.mp.model_reader.ModelReader[source]¶ Bases:
objectThis class is used to read models from CPLEX files (e.g. SAV, LP, MPS)
Note
This class requires CPLEX to be installed and present in
PYTHONPATH. The following file formats are accepted: LP, SAV, MPS.Example
Use the class method
readto read a model file.Reads the contents of file
mymodel.savinto an AdvModel instance, built with the context my_ctx, with the parameterignore_namesset to True:m = ModelReader.read(path='mymodel.lp', model_class=AdvModel, context=my_ctx, ignore_names=True)
-
classmethod
read(filename, model_name=None, verbose=False, model_class=None, **kwargs)[source]¶ Reads a model from a CPLEX export file.
Accepts all formats exported by CPLEX: LP, SAV, MPS.
If an error occurs while reading the file, the message of the exception is printed and the function returns None.
Parameters: - filename – The file to read.
- model_name – An optional name for the newly created model. If None, the model name will be the path basename.
- verbose – An optional flag to print informative messages, default is False.
- model_class – An optional class type; must be a subclass of Model. The returned model is built using this model_class and the keyword arguments kwargs, if any. By default, the model is class is Model (see
- kwargs – A dict of keyword-based arguments that are used when creating the model instance.
Example
m = read_model(“c:/temp/foo.mps”, model_name=”docplex_foo”, solver_agent=”docloud”, output_level=100)
Returns: An instance of Model, or None if an exception is raised. See also
-
classmethod
read_model(filename, model_name=None, verbose=False, model_class=None, **kwargs)[source]¶ This method is a synonym of read for compatibility.
-
classmethod
read_prm(filename)[source]¶ Reads a CPLEX PRM file.
Reads a CPLEX parameters file and returns a DOcplex parameter group instance. This parameter object can be used in a solve().
Parameters: filename – a path string Returns: A RootParameterGroup object, if the read operation succeeds, else None.
-
classmethod
-
exception
docplex.mp.model_reader.ModelReaderError(msg, *args)[source]¶ Bases:
docplex.mp.utils.DOcplexException