CoinModel

This is a simple minded model which is stored in a format which makes it easier to construct and modify but not efficient for algorithms.

This is a simple minded model which is stored in a format which makes it easier to construct and modify but not efficient for algorithms.

Inheritance

Inherits from: CoinBaseModel

Description

It has to be passed across to ClpModel or OsiSolverInterface by addRows, addCol(umn)s or loadProblem. It may have up to four parts - 1) A matrix of doubles (or strings - see note A) 2) Column information including integer information and names 3) Row information including names 4) Quadratic objective (not implemented - but see A) This class is meant to make it more efficient to build a model. It is at its most efficient when all additions are done as addRow or as addCol but not mixed. If only 1 and 2 exist then solver.addColumns may be used to pass to solver, if only 1 and 3 exist then solver.addRows may be used. Otherwise solver.loadProblem must be used. If addRows and addColumns are mixed or if individual elements are set then the speed will drop to some extent and more memory will be used. It is also possible to iterate over existing elements and to access columns and rows by name. Again each of these use memory and cpu time. However memory is unlikely to be critical as most algorithms will use much more. Notes: A) Although this could be used to pass nonlinear information around the only use at present is to have named values e.g. value1 which can then be set to a value after model is created. I have no idea whether that could be useful but I thought it might be fun. Quadratic terms are allowed in strings! A solver could try and use this if so - the convention is that 0.5* quadratic is stored B) This class could be useful for modeling.

Public Methods

addRow

add a row - numberInRow may be zero

void addRow(int numberInRow, const int * columns, const double * elements, double rowLower = -, double rowUpper, const char * name = NULL)

Parameters:

addColumn

add a column - numberInColumn may be zero */

void addColumn(int numberInColumn, const int * rows, const double * elements, double columnLower = 0.0, double columnUpper, double objectiveValue = 0.0, const char * name = NULL, bool isInteger = false)

Parameters:

addCol

add a column - numberInColumn may be zero */

void addCol(int numberInColumn, const int * rows, const double * elements, double columnLower = 0.0, double columnUpper, double objectiveValue = 0.0, const char * name = NULL, bool isInteger = false)

Parameters:

operator()

Sets value for row i and column j.

void operator()(int i, int j, double value)

Parameters:

setElement

Sets value for row i and column j.

void setElement(int i, int j, double value)

Parameters:

getRow

Gets sorted row - user must provide enough space (easiest is allocate number of columns).

int getRow(int whichRow, int * column, double * element)

Parameters:

getColumn

Gets sorted column - user must provide enough space (easiest is allocate number of rows).

int getColumn(int whichColumn, int * column, double * element)

Parameters:

setQuadraticElement

Sets quadratic value for column i and j.

void setQuadraticElement(int i, int j, double value)

Parameters:

operator()

Sets value for row i and column j as string.

void operator()(int i, int j, const char * value)

Parameters:

setElement

Sets value for row i and column j as string.

void setElement(int i, int j, const char * value)

Parameters:

associateElement

Associates a string with a value. Returns string id (or -1 if does not exist)

int associateElement(const char * stringValue, double value)

Parameters:

setRowLower

Sets rowLower (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowLower(int whichRow, double rowLower)

Parameters:

setRowUpper

Sets rowUpper (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowUpper(int whichRow, double rowUpper)

Parameters:

setRowBounds

Sets rowLower and rowUpper (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowBounds(int whichRow, double rowLower, double rowUpper)

Parameters:

setRowName

Sets name (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowName(int whichRow, const char * rowName)

Parameters:

setColumnLower

Sets columnLower (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnLower(int whichColumn, double columnLower)

Parameters:

setColumnUpper

Sets columnUpper (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnUpper(int whichColumn, double columnUpper)

Parameters:

setColumnBounds

Sets columnLower and columnUpper (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnBounds(int whichColumn, double columnLower, double columnUpper)

Parameters:

setColumnObjective

Sets columnObjective (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnObjective(int whichColumn, double columnObjective)

Parameters:

setColumnName

Sets name (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnName(int whichColumn, const char * columnName)

Parameters:

setColumnIsInteger

Sets integer state (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnIsInteger(int whichColumn, bool columnIsInteger)

Parameters:

setObjective

Sets columnObjective (if column does not exist then all columns up to this are defined with default values and no elements)

void setObjective(int whichColumn, double columnObjective)

Parameters:

setIsInteger

Sets integer state (if column does not exist then all columns up to this are defined with default values and no elements)

void setIsInteger(int whichColumn, bool columnIsInteger)

Parameters:

setInteger

Sets integer (if column does not exist then all columns up to this are defined with default values and no elements)

void setInteger(int whichColumn)

Parameters:

setContinuous

Sets continuous (if column does not exist then all columns up to this are defined with default values and no elements)

void setContinuous(int whichColumn)

Parameters:

setColLower

Sets columnLower (if column does not exist then all columns up to this are defined with default values and no elements)

void setColLower(int whichColumn, double columnLower)

Parameters:

setColUpper

Sets columnUpper (if column does not exist then all columns up to this are defined with default values and no elements)

void setColUpper(int whichColumn, double columnUpper)

Parameters:

setColBounds

Sets columnLower and columnUpper (if column does not exist then all columns up to this are defined with default values and no elements)

void setColBounds(int whichColumn, double columnLower, double columnUpper)

Parameters:

setColObjective

Sets columnObjective (if column does not exist then all columns up to this are defined with default values and no elements)

void setColObjective(int whichColumn, double columnObjective)

Parameters:

setColName

Sets name (if column does not exist then all columns up to this are defined with default values and no elements)

void setColName(int whichColumn, const char * columnName)

Parameters:

Coin8CharacterName

Create a name in field given a sequence number - allows >10000000.

void Coin8CharacterName(char rowColumn, int number, char * field)

Parameters:

setColIsInteger

Sets integer (if column does not exist then all columns up to this are defined with default values and no elements)

void setColIsInteger(int whichColumn, bool columnIsInteger)

Parameters:

setRowLower

Sets rowLower (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowLower(int whichRow, const char * rowLower)

Parameters:

setRowUpper

Sets rowUpper (if row does not exist then all rows up to this are defined with default values and no elements)

void setRowUpper(int whichRow, const char * rowUpper)

Parameters:

setColumnLower

Sets columnLower (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnLower(int whichColumn, const char * columnLower)

Parameters:

setColumnUpper

Sets columnUpper (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnUpper(int whichColumn, const char * columnUpper)

Parameters:

setColumnObjective

Sets columnObjective (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnObjective(int whichColumn, const char * columnObjective)

Parameters:

setColumnIsInteger

Sets integer (if column does not exist then all columns up to this are defined with default values and no elements)

void setColumnIsInteger(int whichColumn, const char * columnIsInteger)

Parameters:

setObjective

Sets columnObjective (if column does not exist then all columns up to this are defined with default values and no elements)

void setObjective(int whichColumn, const char * columnObjective)

Parameters:

setIsInteger

Sets integer (if column does not exist then all columns up to this are defined with default values and no elements)

void setIsInteger(int whichColumn, const char * columnIsInteger)

Parameters:

deleteRow

Deletes all entries in row and bounds.

void deleteRow(int whichRow)

Parameters:

deleteColumn

Deletes all entries in column and bounds and objective.

void deleteColumn(int whichColumn)

Parameters:

deleteCol

Deletes all entries in column and bounds.

void deleteCol(int whichColumn)

Parameters:

deleteElement

Takes element out of matrix - returning position (<0 if not there);.

CoinBigIndex deleteElement(int row, int column)

Parameters:

deleteThisElement

Takes element out of matrix when position known.

void deleteThisElement(int row, int column, CoinBigIndex position)

Parameters:

packRows

Packs down all rows i.e.

int packRows()

packColumns

Packs down all columns i.e.

int packColumns()

packCols

Packs down all columns i.e.

int packCols()

pack

Packs down all rows and columns.

int pack()

setObjective

Sets columnObjective array.

void setObjective(int numberColumns, const double * objective)

Parameters:

setColumnLower

Sets columnLower array.

void setColumnLower(int numberColumns, const double * columnLower)

Parameters:

setColLower

Sets columnLower array.

void setColLower(int numberColumns, const double * columnLower)

Parameters:

setColumnUpper

Sets columnUpper array.

void setColumnUpper(int numberColumns, const double * columnUpper)

Parameters:

setColUpper

Sets columnUpper array.

void setColUpper(int numberColumns, const double * columnUpper)

Parameters:

setRowLower

Sets rowLower array.

void setRowLower(int numberRows, const double * rowLower)

Parameters:

setRowUpper

Sets rowUpper array.

void setRowUpper(int numberRows, const double * rowUpper)

Parameters:

writeMps

Write the problem in MPS format to a file with the given filename.

int writeMps(const char * filename, int compression = 0, int formatType = 0, int numberAcross = 2, bool keepStrings = false)

Parameters:

differentModel

Check two models against each other.

int differentModel(CoinModel & other, bool ignoreNames)

Parameters:

passInMatrix

Pass in CoinPackedMatrix (and switch off element updates)

void passInMatrix(const CoinPackedMatrix & matrix)

Parameters:

convertMatrix

Convert elements to CoinPackedMatrix (and switch off element updates).

int convertMatrix()

packedMatrix

Return a pointer to CoinPackedMatrix (or NULL)

const CoinPackedMatrix * packedMatrix()

originalRows

Return pointers to original rows (for decomposition)

const int * originalRows()

originalColumns

Return pointers to original columns (for decomposition)

const int * originalColumns()

numberElements

Return number of elements.

CoinBigIndex numberElements()

elements

Return elements as triples.

const CoinModelTriple * elements()

operator()

Returns value for row i and column j.

double operator()(int i, int j)

Parameters:

getElement

Returns value for row i and column j.

double getElement(int i, int j)

Parameters:

operator()

Returns value for row rowName and column columnName.

double operator()(const char * rowName, const char * columnName)

Parameters:

getElement

Returns value for row rowName and column columnName.

double getElement(const char * rowName, const char * columnName)

Parameters:

getQuadraticElement

Returns quadratic value for columns i and j.

double getQuadraticElement(int i, int j)

Parameters:

getElementAsString

Returns value for row i and column j as string.

const char * getElementAsString(int i, int j)

Parameters:

pointer

Returns pointer to element for row i column j.

double * pointer(int i, int j)

Parameters:

position

Returns position in elements for row i column j.

CoinBigIndex position(int i, int j)

Parameters:

firstInRow

Returns first element in given row - index is -1 if none.

CoinModelLink firstInRow(int whichRow)

Parameters:

lastInRow

Returns last element in given row - index is -1 if none.

CoinModelLink lastInRow(int whichRow)

Parameters:

firstInColumn

Returns first element in given column - index is -1 if none.

CoinModelLink firstInColumn(int whichColumn)

Parameters:

lastInColumn

Returns last element in given column - index is -1 if none.

CoinModelLink lastInColumn(int whichColumn)

Parameters:

next

Returns next element in current row or column - index is -1 if none.

CoinModelLink next(CoinModelLink & current)

Parameters:

previous

Returns previous element in current row or column - index is -1 if none.

CoinModelLink previous(CoinModelLink & current)

Parameters:

firstInQuadraticColumn

Returns first element in given quadratic column - index is -1 if none.

CoinModelLink firstInQuadraticColumn(int whichColumn)

Parameters:

lastInQuadraticColumn

Returns last element in given quadratic column - index is -1 if none.

CoinModelLink lastInQuadraticColumn(int whichColumn)

Parameters:

getRowLower

Gets rowLower (if row does not exist then -COIN_DBL_MAX)

double getRowLower(int whichRow)

Parameters:

getRowUpper

Gets rowUpper (if row does not exist then +COIN_DBL_MAX)

double getRowUpper(int whichRow)

Parameters:

getRowName

Gets name (if row does not exist then NULL)

const char * getRowName(int whichRow)

Parameters:

rowLower

double rowLower(int whichRow)

Parameters:

rowUpper

Gets rowUpper (if row does not exist then COIN_DBL_MAX)

double rowUpper(int whichRow)

Parameters:

rowName

Gets name (if row does not exist then NULL)

const char * rowName(int whichRow)

Parameters:

getColumnLower

Gets columnLower (if column does not exist then 0.0)

double getColumnLower(int whichColumn)

Parameters:

getColumnUpper

Gets columnUpper (if column does not exist then COIN_DBL_MAX)

double getColumnUpper(int whichColumn)

Parameters:

getColumnObjective

Gets columnObjective (if column does not exist then 0.0)

double getColumnObjective(int whichColumn)

Parameters:

getColumnName

Gets name (if column does not exist then NULL)

const char * getColumnName(int whichColumn)

Parameters:

getColumnIsInteger

Gets if integer (if column does not exist then false)

bool getColumnIsInteger(int whichColumn)

Parameters:

columnLower

Gets columnLower (if column does not exist then 0.0)

double columnLower(int whichColumn)

Parameters:

columnUpper

Gets columnUpper (if column does not exist then COIN_DBL_MAX)

double columnUpper(int whichColumn)

Parameters:

columnObjective

Gets columnObjective (if column does not exist then 0.0)

double columnObjective(int whichColumn)

Parameters:

objective

Gets columnObjective (if column does not exist then 0.0)

double objective(int whichColumn)

Parameters:

columnName

Gets name (if column does not exist then NULL)

const char * columnName(int whichColumn)

Parameters:

columnIsInteger

Gets if integer (if column does not exist then false)

bool columnIsInteger(int whichColumn)

Parameters:

isInteger

Gets if integer (if column does not exist then false)

bool isInteger(int whichColumn)

Parameters:

getColLower

Gets columnLower (if column does not exist then 0.0)

double getColLower(int whichColumn)

Parameters:

getColUpper

Gets columnUpper (if column does not exist then COIN_DBL_MAX)

double getColUpper(int whichColumn)

Parameters:

getColObjective

Gets columnObjective (if column does not exist then 0.0)

double getColObjective(int whichColumn)

Parameters:

getColName

Gets name (if column does not exist then NULL)

const char * getColName(int whichColumn)

Parameters:

getColIsInteger

Gets if integer (if column does not exist then false)

bool getColIsInteger(int whichColumn)

Parameters:

getRowLowerAsString

Gets rowLower (if row does not exist then -COIN_DBL_MAX)

const char * getRowLowerAsString(int whichRow)

Parameters:

getRowUpperAsString

Gets rowUpper (if row does not exist then +COIN_DBL_MAX)

const char * getRowUpperAsString(int whichRow)

Parameters:

rowLowerAsString

const char * rowLowerAsString(int whichRow)

Parameters:

rowUpperAsString

Gets rowUpper (if row does not exist then COIN_DBL_MAX)

const char * rowUpperAsString(int whichRow)

Parameters:

getColumnLowerAsString

Gets columnLower (if column does not exist then 0.0)

const char * getColumnLowerAsString(int whichColumn)

Parameters:

getColumnUpperAsString

Gets columnUpper (if column does not exist then COIN_DBL_MAX)

const char * getColumnUpperAsString(int whichColumn)

Parameters:

getColumnObjectiveAsString

Gets columnObjective (if column does not exist then 0.0)

const char * getColumnObjectiveAsString(int whichColumn)

Parameters:

getColumnIsIntegerAsString

Gets if integer (if column does not exist then false)

const char * getColumnIsIntegerAsString(int whichColumn)

Parameters:

columnLowerAsString

Gets columnLower (if column does not exist then 0.0)

const char * columnLowerAsString(int whichColumn)

Parameters:

columnUpperAsString

Gets columnUpper (if column does not exist then COIN_DBL_MAX)

const char * columnUpperAsString(int whichColumn)

Parameters:

columnObjectiveAsString

Gets columnObjective (if column does not exist then 0.0)

const char * columnObjectiveAsString(int whichColumn)

Parameters:

objectiveAsString

Gets columnObjective (if column does not exist then 0.0)

const char * objectiveAsString(int whichColumn)

Parameters:

columnIsIntegerAsString

Gets if integer (if column does not exist then false)

const char * columnIsIntegerAsString(int whichColumn)

Parameters:

isIntegerAsString

Gets if integer (if column does not exist then false)

const char * isIntegerAsString(int whichColumn)

Parameters:

row

Row index from row name (-1 if no names or no match)

int row(const char * rowName)

Parameters:

column

Column index from column name (-1 if no names or no match)

int column(const char * columnName)

Parameters:

type

Returns type.

int type()

unsetValue

returns unset value

double unsetValue()

createPackedMatrix

Creates a packed matrix - return number of errors.

int createPackedMatrix(CoinPackedMatrix & matrix, const double * associated)

Parameters:

countPlusMinusOne

Fills in startPositive and startNegative with counts for +-1 matrix.

int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative, const double * associated)

Parameters:

createPlusMinusOne

Creates +-1 matrix given startPositive and startNegative counts for +-1 matrix.

void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative, int * indices, const double * associated)

Parameters:

createArrays

Creates copies of various arrays - return number of errors.

int createArrays(double *& rowLower, double *& rowUpper, double *& columnLower, double *& columnUpper, double *& objective, int *& integerType, double *& associated)

Parameters:

stringsExist

Says if strings exist.

bool stringsExist()

stringArray

Return string array.

const CoinModelHash * stringArray()

associatedArray

Returns associated array.

double * associatedArray()

rowLowerArray

Return rowLower array.

double * rowLowerArray()

rowUpperArray

Return rowUpper array.

double * rowUpperArray()

columnLowerArray

Return columnLower array.

double * columnLowerArray()

columnUpperArray

Return columnUpper array.

double * columnUpperArray()

objectiveArray

Return objective array.

double * objectiveArray()

integerTypeArray

Return integerType array.

int * integerTypeArray()

rowNames

Return row names array.

const CoinModelHash * rowNames()

columnNames

Return column names array.

const CoinModelHash * columnNames()

zapRowNames

Reset row names.

void zapRowNames()

zapColumnNames

Reset column names.

void zapColumnNames()

cutMarker

Returns array of 0 or nonzero if can be a cut (or returns NULL)

const int * cutMarker()

optimizationDirection

Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.

double optimizationDirection()

setOptimizationDirection

Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.

void setOptimizationDirection(double value)

Parameters:

moreInfo

Return pointer to more information.

void * moreInfo()

setMoreInfo

Set pointer to more information.

void setMoreInfo(void * info)

Parameters:

whatIsSet

Returns which parts of model are set 1 - matrix 2 - rhs 4 - row names 8 - column bounds and/or objective 16 - column names 32 - integer types.

int whatIsSet()

loadBlock

Load in a problem by copying the arguments. The constraints on the rows are given by lower and upper bounds.

void loadBlock(const CoinPackedMatrix & matrix, const double * collb, const double * colub, const double * obj, const double * rowlb, const double * rowub)

Parameters:

loadBlock

Load in a problem by copying the arguments. The constraints on the rows are given by sense/rhs/range triplets.

void loadBlock(const CoinPackedMatrix & matrix, const double * collb, const double * colub, const double * obj, const char * rowsen, const double * rowrhs, const double * rowrng)

Parameters:

loadBlock

Load in a problem by copying the arguments. The constraint matrix is is specified with standard column-major column starts / row indices / coefficients vectors. The constraints on the rows are given by lower and upper bounds.

void loadBlock(const int numcols, const int numrows, const CoinBigIndex * start, const int * index, const double * value, const double * collb, const double * colub, const double * obj, const double * rowlb, const double * rowub)

Parameters:

loadBlock

Load in a problem by copying the arguments. The constraint matrix is is specified with standard column-major column starts / row indices / coefficients vectors. The constraints on the rows are given by sense/rhs/range triplets.

void loadBlock(const int numcols, const int numrows, const CoinBigIndex * start, const int * index, const double * value, const double * collb, const double * colub, const double * obj, const char * rowsen, const double * rowrhs, const double * rowrng)

Parameters:

CoinModel

Default constructor.

 CoinModel()

CoinModel

Constructor with sizes.

 CoinModel(int firstRows, int firstColumns, CoinBigIndex firstElements, bool noNames = false)

Parameters:

CoinModel

Read a problem in MPS or GAMS format from the given filename.

 CoinModel(const char * fileName, int allowStrings = 0)

Parameters:

CoinModel

Read a problem from AMPL nl file, if linked against ASL.

 CoinModel(int nonLinear, const char * fileName, const void * info)

Parameters:

CoinModel

From arrays.

 CoinModel(int numberRows, int numberColumns, const CoinPackedMatrix * matrix, const double * rowLower, const double * rowUpper, const double * columnLower, const double * columnUpper, const double * objective)

Parameters:

clone

Clone.

CoinBaseModel * clone()

~CoinModel

Destructor.

 ~CoinModel()

CoinModel

The copy constructor.

 CoinModel(const CoinModel & )

Parameters:

operator=

=

CoinModel & operator=(const CoinModel & )

Parameters:

Checks that links are consistent.

void validateLinks()

computeAssociated

Fills in all associated - returning number of errors.

int computeAssociated(double * associated)

Parameters:

quadraticRow

Gets correct form for a quadratic row - user to delete If row is not quadratic then returns which other variables are involved with tiny (1.0e-100) elements and count of total number of variables which could not be put in quadratic form.

CoinPackedMatrix * quadraticRow(int rowNumber, double * linear, int & numberBad)

Parameters:

replaceQuadraticRow

Replaces a quadratic row.

void replaceQuadraticRow(int rowNumber, const double * linear, const CoinPackedMatrix * quadraticPart)

Parameters:

reorder

If possible return a model where if all variables marked nonzero are fixed the problem will be linear.

CoinModel * reorder(const char * mark)

Parameters:

setCutMarker

Sets cut marker array.

void setCutMarker(int size, const int * marker)

Parameters:

setPriorities

Sets priority array.

void setPriorities(int size, const int * priorities)

Parameters:

priorities

priorities (given for all columns (-1 if not integer)

const int * priorities()

setOriginalIndices

For decomposition set original row and column indices.

void setOriginalIndices(const int * row, const int * column)

Parameters:

Source

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