CoinLpIO

Class to read and write Lp files.

Class to read and write Lp files.

Description

Lp file format: / this is a comment \ this too Min obj: x0 + x1 + 3 x2 - 4.5 xyr + 1 s.t. cons1: x0 - x2 - 2.3 x4 <= 4.2 / this is another comment c2: x1 + x2 >= 1 cc: x1 + x2 + xyr = 2 Bounds 0 <= x1 <= 3 1 >= x2 x3 = 1 -2 <= x4 <= Inf xyr free Integers x0 Generals x1 xyr Binaries x2 End Notes: Keywords are: Min, Max, Minimize, Maximize, s.t., Subject To, Bounds, Integers, Generals, Binaries, Semis, End, Free, Inf. Keywords are not case sensitive and may be in plural or singular form. They should not be used as objective, row or column names. Bounds, Integers, Generals, Binaries sections are optional. Generals and Integers are synonymous. Bounds section (if any) must come before Integers, Generals, and Binaries sections. Row names must be followed by ':' without blank space. Row names are optional. If row names are present, they must be distinct (if the k-th constraint has no given name, its name is set automatically to "consk" for k=0,...,). For valid row names, see the method is_invalid_name(). Column names must be followed by a blank space. They must be distinct. For valid column names, see the method is_invalid_name(). Multiple objectives may be specified, but when there are multiple objectives, they must have names (to indicate where each one starts). The objective function names must be followed by ':' without blank space. If there is a single objective, the objective function name is optional. If no name is given, the name is set to "obj" by default. For valid objective function names, see the method is_invalid_name(). Ranged constraints are written as two constraints. If a name is given for a ranged constraint, the upper bound constraint has that name and the lower bound constraint has that name with "_low" as suffix. This should be kept in mind when assigning names to ranged constraint, as the resulting name must be distinct from all the other names and be considered valid by the method is_invalid_name(). At most one term related to any single variable may appear in the objective function; if more than one term are present, only the last one is taken into account. At most one constant term may appear in the objective function; if present, it must appear last. Default bounds are 0 for lower bound and +infinity for upper bound. Free variables get default lower bound -infinity and default upper bound +infinity. Writing "x0 Free" in an LP file means "set lower bound on x0 to -infinity". If more than one upper (resp. lower) bound on a variable appears in the Bounds section, the last one is the one taken into account. The bounds for a binary variable are set to 0/1 only if this bound is stronger than the bound obtained from the Bounds section. Numbers larger than DBL_MAX (or larger than 1e+400) in the input file might crash the code. A comment must start with '' or '/'. That symbol must either be the first character of a line or be preceded by a blank space. The comment ends at the end of the line. Comments are skipped while reading an Lp file and they may be inserted anywhere.

Public Methods

passInMessageHandler

Pass in Message handler.

void passInMessageHandler(CoinMessageHandler * handler)

Parameters:

newLanguage

Set the language for messages.

void newLanguage(CoinMessages::Language language)

Parameters:

setLanguage

Set the language for messages.

void setLanguage(CoinMessages::Language language)

Parameters:

messageHandler

Return the message handler.

CoinMessageHandler * messageHandler()

messages

Return the messages.

CoinMessages messages()

messagesPointer

Return the messages pointer.

CoinMessages * messagesPointer()

CoinLpIO

Default Constructor.

 CoinLpIO()

gutsOfDestructor

Does the heavy lifting for destruct and assignment.

void gutsOfDestructor()

gutsOfCopy

Does the heavy lifting for copy and assignment.

void gutsOfCopy(const CoinLpIO & )

Parameters:

operator=

assignment operator

CoinLpIO & operator=(const CoinLpIO & rhs)

Parameters:

CoinLpIO

Copy constructor.

 CoinLpIO(const CoinLpIO & )

Parameters:

~CoinLpIO

Destructor.

 ~CoinLpIO()

freePreviousNames

Free the vector previous_names_[section] and set card_previous_names_[section] to 0.

void freePreviousNames(const int section)

Parameters:

freeAll

Free all memory (except memory related to hash tables and objName_).

void freeAll()

convertBoundToSense

A quick inlined function to convert from lb/ub style constraint definition to sense/rhs/range style.

void convertBoundToSense(const double lower, const double upper, char & sense, double & right, double & range)

Parameters:

getProblemName

Get the problem name.

const char * getProblemName()

setProblemName

Set problem name.

void setProblemName(const char * name)

Parameters:

getNumCols

Get number of columns.

int getNumCols()

getNumRows

Get number of rows.

int getNumRows()

getNumElements

Get number of nonzero elements.

CoinBigIndex getNumElements()

getColLower

Get pointer to array[getNumCols()] of column lower bounds.

const double * getColLower()

getColUpper

Get pointer to array[getNumCols()] of column upper bounds.

const double * getColUpper()

getRowLower

Get pointer to array[getNumRows()] of row lower bounds.

const double * getRowLower()

getRowUpper

Get pointer to array[getNumRows()] of row upper bounds.

const double * getRowUpper()

getRowSense

Get pointer to array[getNumRows()] of constraint senses.

const char * getRowSense()

getRightHandSide

Get pointer to array[getNumRows()] of constraint right-hand sides.

const double * getRightHandSide()

getRowRange

Get pointer to array[getNumRows()] of row ranges.

const double * getRowRange()

getNumObjectives

Get pointer to array[getNumCols()] of objective function coefficients.

const int getNumObjectives()

getObjCoefficients

Get pointer to array[getNumCols()] of objective function coefficients.

const double * getObjCoefficients()

getObjCoefficients

Get pointer to array[getNumCols()] of objective function coefficients for objective j.

const double * getObjCoefficients(int j)

Parameters:

getMatrixByRow

Get pointer to row-wise copy of the coefficient matrix.

const CoinPackedMatrix * getMatrixByRow()

getMatrixByCol

Get pointer to column-wise copy of the coefficient matrix.

const CoinPackedMatrix * getMatrixByCol()

getQuadraticObjective

Get pointer to quadratic objective (or NULL)

CoinPackedMatrix * getQuadraticObjective()

setQuadraticObjective

copy in quadratic objective

void setQuadraticObjective(CoinPackedMatrix * matrix)

Parameters:

getObjName

Get objective function name.

const char * getObjName()

getObjName

Get objective function name for objective j.

const char * getObjName(int j)

Parameters:

getPreviousRowNames

Get pointer to array[*card_prev] of previous row names.

void getPreviousRowNames(char const *const * prev, int * card_prev)

Parameters:

getPreviousColNames

Get pointer to array[*card_prev] of previous column names.

void getPreviousColNames(char const *const * prev, int * card_prev)

Parameters:

getRowNames

Get pointer to array[getNumRows()+1] of row names, including objective function name as last entry.

char const *const * getRowNames()

getColNames

Get pointer to array[getNumCols()] of column names.

char const *const * getColNames()

rowName

Return the row name for the specified index.

const char * rowName(int index)

Parameters:

columnName

Return the column name for the specified index.

const char * columnName(int index)

Parameters:

rowIndex

Return the index for the specified row name.

int rowIndex(const char * name)

Parameters:

columnIndex

Return the index for the specified column name.

int columnIndex(const char * name)

Parameters:

objectiveOffset

Returns the (constant) objective offset.

double objectiveOffset()

objectiveOffset

Returns the (constant) objective offset for objective j.

double objectiveOffset(int j)

Parameters:

setObjectiveOffset

Set objective offset.

void setObjectiveOffset(double value)

Parameters:

wasMaximization

Return true if maximization problem reformulated as minimization.

bool wasMaximization()

setObjectiveOffset

Set objective offset.

void setObjectiveOffset(double value, int j)

Parameters:

isInteger

Return true if a column is an integer (binary or general integer) variable.

bool isInteger(int columnNumber)

Parameters:

integerColumns

Get characteristic vector of integer variables.

const char * integerColumns()

getInfinity

Get infinity.

double getInfinity()

setInfinity

Set infinity.

void setInfinity(const double )

Parameters:

getEpsilon

Get epsilon.

double getEpsilon()

setEpsilon

Set epsilon.

void setEpsilon(const double )

Parameters:

getNumberAcross

Get numberAcross, the number of monomials to be printed per line.

int getNumberAcross()

setNumberAcross

Set numberAcross.

void setNumberAcross(const int )

Parameters:

getDecimals

Get decimals, the number of digits to write after the decimal point.

int getDecimals()

setDecimals

Set decimals.

void setDecimals(const int )

Parameters:

setLpDataWithoutRowAndColNames

Set the data of the object.

void setLpDataWithoutRowAndColNames(const CoinPackedMatrix & m, const double * collb, const double * colub, const double * obj_coeff, const char * integrality, const double * rowlb, const double * rowub)

Parameters:

setLpDataWithoutRowAndColNames

void setLpDataWithoutRowAndColNames(const CoinPackedMatrix & m, const double * collb, const double * colub, const double * obj_coeff, int num_objectives, const char * integrality, const double * rowlb, const double * rowub)

Parameters:

is_invalid_name

Return 0 if buff is a valid name for a row, a column or objective function, return a positive number otherwise.

int is_invalid_name(const char * buff, const bool ranged)

Parameters:

are_invalid_names

Return 0 if each of the card_vnames entries of vnames is a valid name, return a positive number otherwise.

int are_invalid_names(char const *const * vnames, const int card_vnames, const bool check_ranged)

Parameters:

setDefaultRowNames

Set objective function name to the default "obj" and row names to the default "cons0", "cons1", ...

void setDefaultRowNames()

setDefaultColNames

Set column names to the default "x0", "x1", ...

void setDefaultColNames()

setLpDataRowAndColNames

Set the row and column names.

void setLpDataRowAndColNames(char const *const *const rownames, char const *const *const colnames)

Parameters:

writeLp

Write the data in Lp format in the file with name filename.

int writeLp(const char * filename, const double epsilon, const int numberAcross, const int decimals, const bool useRowNames = true)

Parameters:

writeLp

Write the data in Lp format in the file pointed to by the paramater fp.

int writeLp(FILE * fp, const double epsilon, const int numberAcross, const int decimals, const bool useRowNames = true)

Parameters:

writeLp

Write the data in Lp format in the file with name filename.

int writeLp(const char * filename, const bool useRowNames = true)

Parameters:

writeLp

Write the data in Lp format in the file pointed to by the parameter fp.

int writeLp(FILE * fp, const bool useRowNames = true)

Parameters:

readLp

Read the data in Lp format from the file with name filename, using the given value for epsilon.

void readLp(const char * filename, const double epsilon)

Parameters:

readLp

Read the data in Lp format from the file with name filename.

void readLp(const char * filename)

Parameters:

readLp

Read the data in Lp format from the file stream, using the given value for epsilon.

void readLp(FILE * fp, const double epsilon)

Parameters:

readLp

Read the data in Lp format from the file stream.

void readLp(FILE * fp)

Parameters:

readLp

Does work of readLp.

void readLp()

print

Dump the data. Low level method for debugging.

void print()

throwError

Throw an error after printing message.

void throwError(const char * str, const char * methodName, const char * className, const char * fileName, int line)

Parameters:

warnError

void warnError(const char * printBuffer, int line = 1)

Parameters:

loadSOS

Load in SOS stuff.

void loadSOS(int numberSets, const CoinSet * sets)

Parameters:

loadSOS

Load in SOS stuff.

void loadSOS(int numberSets, const CoinSet ** sets)

Parameters:

numberSets

Number of SOS sets.

int numberSets()

setInformation

Set information.

CoinSet ** setInformation()

Source

Header: layer-0/CoinUtils/src/CoinLpIO.hpp