get_nameindex

Gets the index of a given column or row name in the lp.

int get_nameindex(lprec *lp, char *name, unsigned char isrow);

Return Value

get_nameindex returns the index (column/row number) of the given column/row name. A return value of -1 indicates that the name does not exist. Note that the index is the original index number. So if presolve is active, it has no effect. It is the original column/row number that is returned.

Parameters

lp

Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI

name

The name of the column or row for which the index (column/row number) must be retrieved.

isrow

Set to FALSE (0) if column information is needed and TRUE (1) if row information is needed.

Remarks

The get_nameindex function returns the index (column/row number) of the given column/row name. Note that this index starts from 1. Some API routines expect zero-based indexes and thus this value must then be corrected with -1.
This routine is new from version 5.1.1.1.

Example

#include <stdio.h>
#include <stdlib.h>
#include "lp_lib.h"

int main(void)
{
  lprec *lp;
  int column;

  /* Create a new LP model */
  lp = make_lp(1, 0);
  if(lp == NULL) {
    fprintf(stderr, "Unable to create new LP model\n");
    return(1);
  }

  set_row_name(lp, 1, "col1");

  column = get_nameindex(lp, "col1", TRUE); /* will return 1 */
  column = get_nameindex(lp, "col", TRUE); /* will return -1 */

  delete_lp(lp);
  return(0);
}

lp_solve API reference

See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_row_name, get_row_name, get_origrow_name, set_col_name, get_col_name, get_origcol_name