read_lp, read_lp_file, read_LP

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

lprec *read_lp(FILE *stream, short verbose, char *lp_name);

lprec *read_lp_file(FILE *stream, short verbose, char *lp_name);

lprec *read_LP(char *filename, short verbose, char *lp_name);

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 lp model from.

verbose

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.

lp_name

Initial name of the model. See also set_lp_name and get_lp_name. May be NULL if the model has no name.

Remarks

The read_lp, read_lp_file (which are identical, read_lp_file is there for backwards compatibility) and read_LP functions construct a new lprec structure and read the model from filename. read_lp, read_lp_file need a file pointer to an already opened file. read_LP accepts the name of the file. The latter function will generally be more convenient.

The model in the file must be in lp-format.

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 "lpkit.h" 
int main(void)
{ 
  lprec *lp;

  /* Read LP model */
  lp = read_LP("model.lp", NORMAL, "test model");
  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, copy_lp, make_lp, write_lp, write_LP, read_mps, read_MPS, write_mps, write_MPS