python-mip icon indicating copy to clipboard operation
python-mip copied to clipboard

read() not returning status

Open mkurtzsd opened this issue 4 years ago • 0 comments

Describe the bug This is not a bug. It is an enhancement request to have the read() method return the status returned from the model's read of the problem file.

The status returned to the Mip library call from the Cbc_readMps() call is not being returned to the client Python script.

To Reproduce


m = Model(sense=LpMinimize)
m.verbose = 0
m.preprocess = 0
m.max_solutions = 1
m.threads = -1
m.read(file_name)  # This is a void function and does not return a status

Expected behavior Have the Model.read() method return the status from the underlying problem model reader. In this case, the Cbc_readMps() method is being called. The Cbc_readMps() method returns a status but it is ignored by the MIP Model object.

Library Code

Cbc_readMps(Cbc_Model *model, const char *filename)
{
  OsiClpSolverInterface *solver = model->solver_;
  int status = solver->readMps(filename, true, false);
  if ((status>0)&&(model->int_param[INT_PARAM_LOG_LEVEL] > 0)) {
    fflush(stdout); fflush(stderr);
    fprintf(stderr, "%d errors occurred while reading MPS.\n", status);
    fflush(stderr);
  }

  Cbc_deleteColBuffer(model);
  Cbc_deleteRowBuffer(model);
  Cbc_iniBuffer(model);

  fillAllNameIndexes(model);

  return status; // <<--- Status is returned here
}

Python Code:

        model_ext = [".lp", ".mps", ".mps.gz"]

        fn_low = path.lower()
        for ext in model_ext:
            if fn_low.endswith(ext):
                self.clear()
                self.solver.read(path) # <<-- status is not saved and returned to the client
                self.vars.update_vars(self.solver.num_cols())
                self.constrs.update_constrs(self.solver.num_rows())
                return

Desktop (please complete the following information):

  • Operating System, version: CenOS7
  • Python version: v3.7.9
  • Python-MIP version (we recommend you to test with the latest version): 1.13.0

Additional context

mkurtzsd avatar Jan 19 '21 22:01 mkurtzsd