docplex.mp.model_reader module¶
-
class
docplex.mp.model_reader.
ModelReader
(**kwargs)[source]¶ Bases:
object
This class is used to read models from CPLEX files.
All keyword arguments understood by the Model class can be passed to the ModelReader constructor in which case, these arguments will be used to create the initial empty model.
Parameters: model_class – A subclass of Model (the default). This class type is used to build the empty model and fill it with the contents of the file. For example, to build an instance of AdvModel, pass model_class=AdvModel to the constructor of ModelReader. Returns: An instance of doc.mp.model.Model
if the file was successfully read, or None.Note
This class requires CPLEX to be installed and present in
PYTHONPATH
. The following file formats are accepted: LP, SAV, MPS.Example
Reads the contents of file
mymodel.sav
into an AdvModel instance, built with the context my_ctx:mr = ModelReader(model_class=AdvModel) mr.read_model('mymodel.sav', context=my_ctx)
-
read_model
(filename, model_name=None, verbose=True, **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 – Flag.
- 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.
-