6#ifndef CoinPresolveMatrix_H
7#define CoinPresolveMatrix_H
36#define deleteAction(array, type) delete[]((type)array)
38#define deleteAction(array, type) delete[] array
45#if PRESOLVE_DEBUG > 0 || PRESOLVE_CONSISTENCY > 0
47#define PRESOLVE_STMT(s) s
49#define PRESOLVEASSERT(x) \
50 ((x) ? 1 : ((std::cerr << "FAILED ASSERTION at line " << __LINE__ << ": " #x "\n"), abort(), 0))
52inline void DIE(
const char *s)
68#define PRESENT_IN_REDUCED '\377'
72#define PRESOLVEASSERT(x) \
75#define PRESOLVE_STMT(s) \
79inline void DIE(
const char *) {}
86#ifndef PRESOLVE_DETAIL
87#define PRESOLVE_DETAIL_PRINT(s) \
91#define PRESOLVE_DETAIL_PRINT(s) s
106#define PRESOLVE_INF COIN_DBL_MAX
108#define PRESOLVE_SMALL_INF 1.0e20
110#define PRESOLVEFINITE(n) (-PRESOLVE_INF < (n) && (n) < PRESOLVE_INF)
173 throw CoinError(error, ps_routine,
"CoinPresolve");
201 virtual const char *
name()
const = 0;
217class OsiSolverInterface;
350 unsigned char &st_byte =
rowstat_[sequence];
351 st_byte =
static_cast< unsigned char >(st_byte & (~7));
352 st_byte =
static_cast< unsigned char >(st_byte | status);
368 unsigned char &st_byte =
colstat_[sequence];
369 st_byte =
static_cast< unsigned char >(st_byte & (~7));
370 st_byte =
static_cast< unsigned char >(st_byte | status);
376 std::cout <<
"Bad status: Var " << sequence
377 <<
" isFree, lb = " <<
clo_[sequence]
378 <<
", ub = " <<
cup_[sequence] << std::endl;
387 std::cout <<
"Bad status: Var " << sequence
388 <<
" atUpperBound, lb = " <<
clo_[sequence]
389 <<
", ub = " <<
cup_[sequence] << std::endl;
395 std::cout <<
"Bad status: Var " << sequence
396 <<
" atLowerBound, lb = " <<
clo_[sequence]
397 <<
", ub = " <<
cup_[sequence] << std::endl;
403 std::cout <<
"Bad status: Var " << sequence
404 <<
" superBasic, lb = " <<
clo_[sequence]
405 <<
", ub = " <<
cup_[sequence] << std::endl;
479 void setCost(
const double *cost,
int lenParam);
578 for (
int i = 0; i <
ncols_; i++)
816#define NO_LINK -66666666
825 int ipre = link[i].
pre;
826 int isuc = link[i].
suc;
828 link[ipre].
suc = isuc;
831 link[isuc].
pre = ipre;
843 int isuc = link[j].
suc;
865 int ipre = link[i].
pre;
866 int isuc = link[i].
suc;
932 double nonLinearVariable,
947 OsiSolverInterface *si,
952 double nonLinearVariable,
953 const char *prohibited,
986 for (
int i = 0; i <
nrows_; i++)
1001 integerType_[i] =
static_cast< unsigned char >(variableType);
1101#if PRESOLVE_DEBUG > 2
1102 assert(fabs(change_amount) < 1.0e50);
1581 unsigned char *colstat,
1582 unsigned char *rowstat);
1600 unsigned char *colstat,
1601 unsigned char *rowstat);
1679 int *minndxs,
int *majlens,
1688 int *hrow,
int *hincol,
1692 hrow, hincol, clink, ncols, colx);
1701 int *hcol,
int *hinrow,
1705 hcol, hinrow, rlink, nrows, rowx);
1721 for (k = ks; k < ke; k++)
1724 if (minndxs[k] == tgt)
1733 if (minndxs[k] == tgt)
1773 const int *minndxs);
1862 int *majlens,
int *minndxs,
double *els)
1869 minndxs[kmi] = minndxs[ke - 1];
1870 els[kmi] = els[ke - 1];
1884 int *majlens,
int *minndxs,
double *els)
1890 int iMinor = minndxs[k];
1891 if (!marked[iMinor]) {
1892 minndxs[put] = iMinor;
1893 els[put++] = els[k];
1898 majlens[majndx] =
static_cast< int >(put - ks);
1914 int *hincol,
int *hrow,
double *colels)
1931 int *hinrow,
int *hcol,
double *rowels)
1962 int *hincol,
int *hrow,
This file contains the enum for the standard set of Coin messages and a class definition whose sole p...
const double ZTOLDP2
Alternate zero tolerance.
const double ZTOLDP
Zero tolerance.
#define PRESOLVE_INF
The usual finite infinity.
void coin_init_random_vec(double *work, int n)
Initialize a vector with random numbers.
double * presolve_dupmajor(const double *elems, const int *indices, int length, CoinBigIndex offset, int tgt=-1)
Duplicate a major-dimension vector; optionally omit the entry with minor index tgt.
Error Class thrown by an exception.
Base class for message handling.
The standard set of Coin messages.
Class to hold and manipulate an array of massaged messages.
Sparse Matrix Base Class.
Augments CoinPrePostsolveMatrix with information about the problem that is only needed during postsol...
CoinBigIndex presolve_find_col(int col, CoinBigIndex krs, CoinBigIndex kre, const int *hcol)
Find position of a column in a row in a row-major matrix.
CoinPostsolveMatrix(ClpSimplex *si, int ncols0, int nrows0, CoinBigIndex nelems0, double maxmin_, double *sol, double *acts, unsigned char *colstat, unsigned char *rowstat)
Clp OSI constructor.
~CoinPostsolveMatrix()
Destructor.
CoinBigIndex presolve_find_minor2(int tgt, CoinBigIndex ks, int majlen, const int *minndxs, const CoinBigIndex *majlinks)
Find position of a minor index in a major vector in a threaded matrix.
CoinBigIndex * link_
Thread array.
CoinBigIndex presolve_find_row2(int row, CoinBigIndex kcs, int collen, const int *hrow, const CoinBigIndex *clinks)
Find position of a row in a column in a column-major threaded matrix.
CoinBigIndex free_list_
First entry in free entries thread.
void presolve_delete_from_major2(int majndx, int minndx, CoinBigIndex *majstrts, int *majlens, int *minndxs, CoinBigIndex *majlinks, CoinBigIndex *free_listp)
Delete the entry for a minor index from a major vector in a threaded matrix.
CoinBigIndex maxlink_
Allocated size of link_.
void presolve_delete_from_col2(int row, int col, CoinBigIndex *mcstrt, int *hincol, int *hrow, CoinBigIndex *clinks, CoinBigIndex *free_listp)
Delete the entry for row row from column col in a column-major threaded matrix.
void assignPresolveToPostsolve(CoinPresolveMatrix *&preObj)
Load an empty CoinPostsolveMatrix from a CoinPresolveMatrix.
CoinPostsolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
‘Native’ constructor
CoinPostsolveMatrix(OsiSolverInterface *si, int ncols0, int nrows0, CoinBigIndex nelems0, double maxmin_, double *sol, double *acts, unsigned char *colstat, unsigned char *rowstat)
Generic OSI constructor.
CoinBigIndex presolve_find_row3(int row, CoinBigIndex kcs, int collen, const int *hrow, const CoinBigIndex *clinks)
Find position of a row in a column in a column-major threaded matrix.
CoinBigIndex presolve_find_minor3(int tgt, CoinBigIndex ks, int majlen, const int *minndxs, const CoinBigIndex *majlinks)
Find position of a minor index in a major vector in a threaded matrix.
Collects all the information about the problem that is needed in both presolve and postsolve.
bool defaultHandler_
Indicates if the current handler_ is default (true) or not (false).
double * rlo_
Row (constraint) lower bounds.
int ncols_
current number of columns
double maxmin_
Maximization/minimization.
const int * getColLengths() const
Get column length vector for column-major packed matrix.
double * cup_
Column (primal variable) upper bounds.
int countEmptyCols()
Count empty columns.
const CoinBigIndex * getColStarts() const
Get column start vector for column-major packed matrix.
void setPrimalTolerance(double primTol)
Set the primal feasibility tolerance.
double * cost_
Objective coefficients.
void setRowUpper(const double *rowUpper, int lenParam)
Set row upper bounds.
double ztoldj_
Dual feasibility tolerance.
bool presolve_expand_col(CoinBigIndex *mcstrt, double *colels, int *hrow, int *hincol, presolvehlink *clink, int ncols, int colx)
Make sure a column (colx) in a column-major matrix has room for one more coefficient.
void setRowLower(const double *rowLower, int lenParam)
Set row lower bounds.
const double * getElementsByCol() const
Get vector of elements for column-major packed matrix.
CoinMessages messages() const
Return messages.
CoinBigIndex bulk0_
Allocated size of bulk storage for row indices and coefficients.
CoinBigIndex getNumElems() const
Get current number of non-zero coefficients.
CoinBigIndex nelems_
current number of coefficients
void setCost(const double *cost, int lenParam)
Set objective coefficients.
int nrows_
current number of rows
double * sol_
Vector of primal variable values.
const double * getCost() const
Get objective coefficients.
const double * getReducedCost() const
Get reduced costs.
CoinPrePostsolveMatrix(const OsiSolverInterface *si, int ncols_, int nrows_, CoinBigIndex nelems_)
Generic OSI constructor.
Status getRowStatus(int sequence) const
Get row status.
void setRowStatusUsingValue(int iRow)
Set status of row (artificial variable) to the correct nonbasic status given bounds and current value...
~CoinPrePostsolveMatrix()
Destructor.
int nrows0_
Allocated number of rows.
void setColLower(const double *colLower, int lenParam)
Set column lower bounds.
bool columnIsBasic(int sequence) const
Check if column (structural variable) is basic.
void presolve_make_memlists(int *lengths, presolvehlink *link, int n)
Initialise linked list for major vector order in bulk storage.
CoinPrePostsolveMatrix(const ClpSimplex *si, int ncols_, int nrows_, CoinBigIndex nelems_, double bulkRatio)
ClpOsi constructor.
void setObjOffset(double offset)
Set the objective function offset for the original system.
double ztolzb_
Primal feasibility tolerance.
CoinBigIndex presolve_find_row1(int row, CoinBigIndex kcs, CoinBigIndex kce, const int *hrow)
Find position of a row in a column in a column-major matrix.
double * clo_
Column (primal variable) lower bounds.
int getNumRows() const
Get current number of rows.
const double * getRowPrice() const
Get row solution (dual variables)
CoinBigIndex presolve_find_row(int row, CoinBigIndex kcs, CoinBigIndex kce, const int *hrow)
Find position of a row in a column in a column-major matrix.
CoinBigIndex nelems0_
Allocated number of coefficients.
int ncols0_
Allocated number of columns.
void presolve_delete_from_row(int row, int col, const CoinBigIndex *mrstrt, int *hinrow, int *hcol, double *rowels)
Delete the entry for column col from row row in a row-major matrix.
const char * columnStatusString(int j) const
Return a print string for status of a column (structural variable)
const double * getColLower() const
Get column lower bounds.
void setStatus(const CoinWarmStartBasis *basis)
Set the status of all variables from a basis.
int * originalRow_
Original row numbers.
bool rowIsBasic(int sequence) const
Check if artificial for this row is basic.
const double * getColUpper() const
Get column upper bounds.
CoinMessage messages_
Standard COIN messages.
CoinBigIndex presolve_find_col1(int col, CoinBigIndex krs, CoinBigIndex kre, const int *hcol)
Find position of a column in a row in a row-major matrix.
const int * getRowIndicesByCol() const
Get vector of row indices for column-major packed matrix.
void setStructuralStatus(const char *strucStatus, int lenParam)
Set column (structural variable) status vector.
const double * getColSolution() const
Get column solution (primal variable values)
bool presolve_expand_major(CoinBigIndex *majstrts, double *majels, int *minndxs, int *majlens, presolvehlink *majlinks, int nmaj, int k)
Make sure a major-dimension vector k has room for one more coefficient.
double bulkRatio_
Ratio of bulk0_ to nelems0_; default is 2.
void presolve_delete_from_col(int row, int col, const CoinBigIndex *mcstrt, int *hincol, int *hrow, double *colels)
Delete the entry for row row from column col in a column-major matrix.
CoinMessageHandler * messageHandler() const
Return message handler.
const double * getRowActivity() const
Get row activity (constraint lhs values)
void setObjSense(double objSense)
Set the objective sense (max/min)
void setColumnStatusUsingValue(int iColumn)
Set status of column (structural variable) to the correct nonbasic status given bounds and current va...
CoinWarmStartBasis * getStatus()
Get status in the form of a CoinWarmStartBasis.
Status
Enum for status of various sorts.
void setColumnStatus(int sequence, Status status)
Set column status (i.e., status of primal variable)
CoinBigIndex presolve_find_minor(int tgt, CoinBigIndex ks, CoinBigIndex ke, const int *minndxs)
Find position of a minor index in a major vector.
int * originalColumn_
Original column numbers.
const char * statusName(CoinPrePostsolveMatrix::Status status)
Generate a print string for a status code.
void presolve_delete_many_from_major(int majndx, char *marked, const CoinBigIndex *majstrts, int *majlens, int *minndxs, double *els)
Delete marked entries.
int getNumCols() const
Get current number of columns.
CoinMessageHandler * handler_
Message handler.
void setColUpper(const double *colUpper, int lenParam)
Set column upper bounds.
const char * rowStatusString(int i) const
Return a print string for status of a row (artificial variable)
double * rcosts_
Vector of reduced costs.
CoinBigIndex presolve_find_minor1(int tgt, CoinBigIndex ks, CoinBigIndex ke, const int *minndxs)
Find position of a minor index in a major vector.
CoinPrePostsolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
‘Native’ constructor
unsigned char * colstat_
Status of primal variables.
Status getColumnStatus(int sequence) const
Get column (structural variable) status.
double * colels_
Coefficients (positional correspondence with hrow_)
void setDualTolerance(double dualTol)
Set the dual feasibility tolerance.
bool presolve_expand_row(CoinBigIndex *mrstrt, double *rowels, int *hcol, int *hinrow, presolvehlink *rlink, int nrows, int rowx)
Make sure a row (rowx) in a row-major matrix has room for one more coefficient.
const double * getRowUpper() const
Get row upper bounds.
void presolve_delete_from_major(int majndx, int minndx, const CoinBigIndex *majstrts, int *majlens, int *minndxs, double *els)
Delete the entry for a minor index from a major vector.
double originalOffset_
Original objective offset.
int * hincol_
Vector of column lengths.
void setRowPrice(const double *rowSol, int lenParam)
Set row solution.
void setMessageHandler(CoinMessageHandler *handler)
Set message handler.
double * rowduals_
Vector of dual variable values.
void setRowActivity(const double *rowAct, int lenParam)
Set row activity.
double * acts_
Vector of constraint left-hand-side values (row activity)
const double * getRowLower() const
Get row lower bounds.
void setArtificialStatus(const char *artifStatus, int lenParam)
Set row (artificial variable) status vector.
CoinBigIndex * mcstrt_
Vector of column start positions in hrow_, colels_.
int * hrow_
Row indices (positional correspondence with colels_)
double * rup_
Row (constraint) upper bounds.
void setColSolution(const double *colSol, int lenParam)
Set column solution.
void setReducedCost(const double *redCost, int lenParam)
Set reduced costs.
void setRowStatus(int sequence, Status status)
Set row status (i.e., status of artificial for this row)
unsigned char * rowstat_
Status of constraints.
Abstract base class of all presolve routines.
virtual ~CoinPresolveAction()
Virtual destructor.
virtual const char * name() const =0
A name for debug printing.
virtual void postsolve(CoinPostsolveMatrix *prob) const =0
Apply the postsolve transformation for this particular presolve action.
void setNext(const CoinPresolveAction *nextAction)
modify next (when building rather than passing)
static void throwCoinError(const char *error, const char *ps_routine)
Stub routine to throw exceptions.
const CoinPresolveAction * next
The next presolve transformation.
CoinPresolveAction(const CoinPresolveAction *next)
Construct a postsolve object and add it to the transformation list.
Augments CoinPrePostsolveMatrix with information about the problem that is only needed during presolv...
void update_model(ClpSimplex *si, int nrows0, int ncols0, CoinBigIndex nelems0)
Update the model held by a Clp OSI.
friend void assignPresolveToPostsolve(CoinPresolveMatrix *&preObj)
Initialize a CoinPostsolveMatrix object, destroying the CoinPresolveMatrix object.
void setRowChanged(int i)
Mark row as changed.
void change_bias(double change_amount)
Adjust objective function constant offset.
double feasibilityTolerance_
Bounds can be moved by this to retain feasibility.
int stepRowsToDo()
Step row ToDo lists.
const double * getElementsByRow() const
Get vector of elements for row-major packed matrix.
void setMaximumSubstitutionLevel(int level)
Set Maximum substitution level (normally 3)
void unsetColInfinite(int i)
Mark column as not infinite ub (originally)
void unsetColChanged(int i)
Mark column as not changed.
double * usefulRowDouble_
Preallocated scratch work array, 2*nrows_.
int * hcol_
Column indices (positional correspondence with rowels_)
void addCol(int i)
Mark column as changed and add to list of columns to process next.
void setRowUsed(int i)
Mark row as used.
void setColUsed(int i)
Mark column as used.
~CoinPresolveMatrix()
Destructor.
double dobias_
Objective function offset introduced during presolve.
int recomputeSums(int whichRow)
Recompute row lhs bounds.
CoinPresolveMatrix(int ncols0, double maxmin, OsiSolverInterface *si, int nrows, CoinBigIndex nelems, bool doStatus, double nonLinearVariable, const char *prohibited, const char *rowProhibited=NULL)
Generic OSI constructor.
void setRowProhibited(int i)
Mark row as ineligible for preprocessing.
bool rowProhibited(int i) const
Test if row is eligible for preprocessing.
bool anyInteger_
Flag to say if any variables are integer.
bool colProhibited2(int i) const
Test if column is eligible for preprocessing.
int numberNextColsToDo_
Length of nextColsToDo_.
void unsetRowUsed(int i)
Mark row as unused.
void unsetColUsed(int i)
Mark column as unused.
void statistics()
Say we want statistics - also set time.
int * hinrow_
Vector of row lengths.
void setAnyProhibited(bool val=true)
Set a flag for presence of prohibited rows or columns.
void setVariableType(int i, int variableType)
Set variable type information for a single variable.
double startTime_
Start time of presolve.
void setStatus(int status)
Set problem status.
void update_model(OsiSolverInterface *si, int nrows0, int ncols0, CoinBigIndex nelems0)
Update the model held by a generic OSI.
int numberRowsToDo_
Length of rowsToDo_.
int numberColsToDo_
Length of colsToDo_.
bool colUsed(int i) const
Test if column is marked as used.
double * rowels_
Coefficients (positional correspondence with hcol_)
unsigned char * integerType_
Tracks integrality of columns (1 for integer, 0 for continuous)
void unsetRowChanged(int i)
Mark row as not changed.
void initializeStuff()
Allocate scratch arrays.
int * usefulColumnInt_
Preallocated scratch work array, 2*ncols_.
int numberColsToDo()
Return the number of columns on the colsToDo_ list.
CoinBigIndex * mrstrt_
Vector of row start positions in #hcol, rowels_.
presolvehlink * clink_
Linked list for the column-major representation.
unsigned char * rowChanged_
Row change status information.
bool isInteger(int i) const
Check for integrality of the specified variable.
bool colProhibited(int i) const
Test if column is eligible for preprocessing.
int stepColsToDo()
Step column ToDo lists.
void setMatrix(const CoinPackedMatrix *mtx)
Load the cofficient matrix.
bool rowUsed(int i) const
Test if row is marked as used.
void setColProhibited(int i)
Mark column as ineligible for preprocessing.
bool anyInteger() const
Check if there are any integer variables.
void setPass(int pass=0)
Set pass number.
int status_
Output status: 0 = feasible, 1 = infeasible, 2 = unbounded.
void initRowsToDo()
Initialise the row ToDo lists.
int pass_
Presolve pass number.
void setVariableType(bool allIntegers, int lenParam)
Set the type of all variables.
int * usefulRowInt_
Preallocated scratch work array, 3*nrows_.
int * infiniteUp_
Work array for count of infinite contributions to row lhs upper bound.
int status()
Returns problem status (0 = feasible, 1 = infeasible, 2 = unbounded)
void setColChanged(int i)
Mark column as changed.
int numberNextRowsToDo_
Length of nextRowsToDo_.
void addRow(int i)
Mark row as changed and add to list of rows to process next.
void setFeasibilityTolerance(double val)
Set feasibility tolerance.
void deleteStuff()
Free scratch arrays.
void setPresolveOptions(int value)
Sets any special options (see presolveOptions_)
CoinPresolveMatrix(int ncols0, double maxmin, ClpSimplex *si, int nrows, CoinBigIndex nelems, bool doStatus, double nonLinearVariable, double bulkRatio)
Clp OSI constructor.
bool colChanged(int i) const
Has column been changed?
int presolveOptions_
Fine control over presolve actions.
int numberRowsToDo()
Return the number of rows on the rowsToDo_ list.
double * sumDown_
Work array for sum of finite contributions to row lhs lower bound.
bool rowChanged(int i) const
Has row been changed?
bool tuning_
Print statistics for tuning.
int * nextRowsToDo_
Output list of rows to process next.
CoinPresolveMatrix(int ncols_alloc, int nrows_alloc, CoinBigIndex nelems_alloc)
‘Native’ constructor
double * randomNumber_
Array of random numbers (max row,column)
int presolveOptions() const
Picks up any special options.
int * infiniteDown_
Work array for count of infinite contributions to row lhs lower bound.
bool rowProhibited2(int i) const
Test if row is eligible for preprocessing.
void initColsToDo()
Initialise the column ToDo lists.
int * colsToDo_
Input list of columns to process.
void setColInfinite(int i)
Mark column as infinite ub (originally)
double feasibilityTolerance()
Return feasibility tolerance.
bool anyProhibited() const
Check if there are any prohibited rows or columns.
int maxSubstLevel_
Maximum substitution level.
int * rowsToDo_
Input list of rows to process.
int * nextColsToDo_
Output list of columns to process next.
double * sumUp_
Work array for sum of finite contributions to row lhs upper bound.
const int * getColIndicesByRow() const
Get vector of column indices for row-major packed matrix.
presolvehlink * rlink_
Linked list for the row-major representation.
bool anyProhibited_
Flag to say if any rows or columns are marked as prohibited.
double * usefulColumnDouble_
Preallocated scratch work array, ncols_.
unsigned char * colChanged_
Column change status information.
bool colInfinite(int i) const
Has column infinite ub (originally)
void setVariableType(const unsigned char *variableType, int lenParam)
Set variable type information for all variables.
int countEmptyRows()
Count number of empty rows.
const CoinBigIndex * getRowStarts() const
Get row start vector for row-major packed matrix.
void setAnyInteger(bool anyInteger=true)
Set a flag for presence (true) or absence (false) of integer variables.
The default COIN simplex (basis-oriented) warm start class.
Links to aid in packed matrix modification.
void PRESOLVE_MOVE_LINK(presolvehlink *link, int i, int j)
relink vector j in place of vector i
void PRESOLVE_INSERT_LINK(presolvehlink *link, int i, int j)
insert vector i after vector j
void PRESOLVE_REMOVE_LINK(presolvehlink *link, int i)
unlink vector i