Initializing help system before first use

XPRSgetnamelist

XPRSgetnamelist


Purpose
Returns the names for the rows, columns, sets, piecewise linear of general constraints in a given range. The names will be returned in a character buffer, with no trailing whitespace and with each name being separated by a NULL character.
Synopsis
int XPRS_CC XPRSgetnamelist(XPRSprob prob, int type, char names[], int names_len, int * names_len_reqd, int first, int last);
Arguments
prob 
The current problem.
type 
if row names are required;
if column names are required.
if set names are required.
if piecewise linear constraint names are required.
if general constraint names are required.
names 
A buffer into which the names will be returned as a sequence of null-terminated strings. The buffer should be of length names_len bytes. May be NULL if names_len is 0.
names_len 
The maximum number of bytes that may be written to the buffer names.
names_len_reqd 
A pointer to a variable into which will be written the number of bytes required to contain the names in the specified range. May be NULL if not required.
first 
First row, column, set, piecewise linear or general constraint in the range.
last 
Last row, column, set, piecewise linear or general constraint in the range.
Example
The following example retrieves and outputs the row and column names for the current problem.
int i, o, cols, rows, cnames_len, rnames_len;
char *cnames, *rnames;
...
/* Get problem size */
XPRSgetintattrib(prob,XPRS_COLS,&cols);
XPRSgetintattrib(prob,XPRS_ROWS,&rows);
/* Request number of bytes required to retrieve the names */
XPRSgetnamelist(prob,1,NULL,0,&rnames_len,0,rows-1);
XPRSgetnamelist(prob,2,NULL,0,&cnames_len,0,cols-1);

/* Now allocate buffers big enough then fetch the names */
cnames = (char *) malloc(sizeof(char)*cnames_len);
rnames = (char *) malloc(sizeof(char)*rnames_len);
XPRSgetnamelist(prob,1,rnames,rnames_len,NULL,0,rows-1);
XPRSgetnamelist(prob,2,cnames,cnames_len,NULL,0,cols-1);

/* Output row names */
o=0;
for (i=0;i<rows;i++) {
  printf("Row #%d: %s\n", i, rnames+o);
  o += strlen(rnames+o)+1;
}
/* Output column names */
o=0;
for (i=0;i<cols;i++) {
  printf("Col #%d: %s\n", i, cnames+o);
  o += strlen(cnames+o)+1;
} 
Related topics