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) This class requires CPLEX runtime, otherwise an exception is raised.
Example
Use class method
readto read a model file.>>> m = ModelReader.read('mymodel.lp', ignore_names=True)
reads a model while ignoring all names.
Global function
read_modelis a synonym forModelReader.read, and is the preferred way to read model files.-
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 class is
docplex.mp.model.Model. - kwargs – A dict of keyword-based arguments that are used when creating the modelpassed to the model constructor.
Example
m = read_model(“c:/temp/foo.mps”, model_name=”docplex_foo”, ignore_names=True)
reads a ,odel from file “c:/temp/foo.mps”, sets its name to “docplex_foo”, and discard all names.
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
-
docplex.mp.model_reader.read_model(filename, model_name=None, verbose=False, **kwargs)[source]¶ Reads a model from a CPLEX export file.
Accepts all formats exported by CPLEX: LP, SAV, SAV.gz, MPS.
If an error occurs while reading the file, the message of the exception is printed and the function returns None.
Parameters: - filename – The model 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.
- kwargs – A dict of keyword-based arguments that are passed to the model contructor.
Note
This function requires CPLEX runtime, otherwise an exceotion is raised.
Example
m = read_model(“c:/temp/foo.mps”, model_name=”docplex_foo”, solver_agent=”local”, output_level=100)
Returns: An instance of Model, or None if an exception is raised. See also