read_mps, read_freemps, read_MPS, read_freeMPS

Create an lprec structure and read an mps model from file.

lprec *read_mps(FILE *stream, int options);

lprec *read_freemps(FILE *stream, int options);

lprec *read_MPS(char *filename, int options);

lprec *read_freeMPS(char *filename, int options);

Return Value

Returns a pointer to a new lprec structure. This must be provided to almost all lp_solve functions.
A NULL return value indicates an error. Specifically file could not be opened or file has wrong structure or not enough memory available to setup an lprec structure.

Parameters

stream

Pointer to FILE structure.

filename

Filename to read the mps model from.

options

Specifies the verbose level and how to interprete the MPS layout.

The verbose level can be one of the following values:
CRITICAL (1), SEVERE (2), IMPORTANT (3), NORMAL (4), DETAILED (5), FULL (6)

See also set_verbose and get_verbose.

This can be ORed by any one of the following combinations:

MPS_FREE (8) The MPS format is free MPS format. If not specified, read_MPS and read_mps use by default the fixed MPS format. The option is not needed for read_freemps and read_freeMPS as these routine already interprete the file in free MPS format, but it is allowed to specify the option anyway. See also MPS file format
MPS_IBM (16) Interprete integer variables without bounds as binary variables. That is the original IBM standard. By default lp_solve interpretes variables without bounds as having no upperbound as for real variables. See also MPS file format (section G.)
MPS_NEGOBJCONST (32) Interprete the objective constant with an oposite sign. Some solvers interprete the objective constant as a value in the RHS and negate it when brought at the LHS. This option allows to let lp_solve do this also. See also MPS file format

Remarks

The read_mps, read_freemps, read_MPS, read_freeMPS functions construct a new lprec structure and read the model from filename. read_mps, read_freemps need a file pointer to an already opened file. read_MPS, read_freeMPS accepts the name of the file. The latter functions will generally be more convenient.

The model in the file must be in mps-format. The read_free* routines accept files only in free MPS format. The other routines by default accept files in fixed MPS format. However via the options parameter this can be set to free format also. That makes the read_free* routines obsolete, but they are kept for backward compatibility. The second argument of the routines was originally called verbose. This is extended from version 5.5.15 on to verbose with the possibility to add extra options.

It is advised not to read/write the lprec structure. Instead, use the function interface to communicate with the lp_solve library. This because the structure can change over time. The function interface will be more stable.

Example

#include <stdio.h>
#include <stdlib.h>
#include "lp_lib.h"
int main(void)
{
  lprec *lp;

  /* Read MPS model */
  lp = read_MPS("model.mps", NORMAL);
  if(lp == NULL) {
    fprintf(stderr, "Unable to read model\n");
    return(1);
  }

  /* Model read */

  /*
  .
  .
  .
  */

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also delete_lp, free_lp, make_lp, write_mps, write_freemps, write_MPS, write_freeMPS, MPS_writefileex, read_lp, read_LP, write_lp, write_LP, write_lpex