Skip to content

Commit

Permalink
CoinBuild: Replace magic number for build type
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andre committed Jul 31, 2024
1 parent c53f0d7 commit 720900f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
34 changes: 16 additions & 18 deletions src/CoinBuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ CoinBuild::CoinBuild()
, currentItem_(NULL)
, firstItem_(NULL)
, lastItem_(NULL)
, type_(-1)
, type_(Type::Unset)
{
}
//-------------------------------------------------------------------
// Constructor with type
//-------------------------------------------------------------------
CoinBuild::CoinBuild(int type)
CoinBuild::CoinBuild(Type type)
: numberItems_(0)
, numberOther_(0)
, numberElements_(0)
Expand All @@ -62,8 +62,6 @@ CoinBuild::CoinBuild(int type)
, lastItem_(NULL)
, type_(type)
{
if (type < 0 || type > 1)
type_ = -1; // unset
}

//-------------------------------------------------------------------
Expand Down Expand Up @@ -171,9 +169,9 @@ void CoinBuild::addRow(int numberInRow, const int *columns,
const double *elements, double rowLower,
double rowUpper)
{
if (type_ < 0) {
type_ = 0;
} else if (type_ == 1) {
if (type_ == Type::Unset) {
type_ = Type::Row;
} else if (type_ == Type::Column) {
printf("CoinBuild:: unable to add a row in column mode\n");
abort();
}
Expand All @@ -189,7 +187,7 @@ void CoinBuild::addRow(int numberInRow, const int *columns,
int CoinBuild::row(int whichRow, double &rowLower, double &rowUpper,
const int *&indices, const double *&elements) const
{
assert(type_ == 0);
assert(type_ == Type::Row);
setMutableCurrent(whichRow);
double dummyObjective;
return currentItem(rowLower, rowUpper, dummyObjective, indices, elements);
Expand All @@ -200,20 +198,20 @@ int CoinBuild::row(int whichRow, double &rowLower, double &rowUpper,
int CoinBuild::currentRow(double &rowLower, double &rowUpper,
const int *&indices, const double *&elements) const
{
assert(type_ == 0);
assert(type_ == Type::Row);
double dummyObjective;
return currentItem(rowLower, rowUpper, dummyObjective, indices, elements);
}
// Set current row
void CoinBuild::setCurrentRow(int whichRow)
{
assert(type_ == 0);
assert(type_ == Type::Row);
setMutableCurrent(whichRow);
}
// Returns current row number
int CoinBuild::currentRow() const
{
assert(type_ == 0);
assert(type_ == Type::Row);
return currentItem();
}
// add a column
Expand All @@ -222,9 +220,9 @@ void CoinBuild::addColumn(int numberInColumn, const int *rows,
double columnLower,
double columnUpper, double objectiveValue)
{
if (type_ < 0) {
type_ = 1;
} else if (type_ == 0) {
if (type_ == Type::Unset) {
type_ = Type::Column;
} else if (type_ == Type::Row) {
printf("CoinBuild:: unable to add a column in row mode\n");
abort();
}
Expand All @@ -237,7 +235,7 @@ int CoinBuild::column(int whichColumn,
double &columnLower, double &columnUpper, double &objectiveValue,
const int *&indices, const double *&elements) const
{
assert(type_ == 1);
assert(type_ == Type::Column);
setMutableCurrent(whichColumn);
return currentItem(columnLower, columnUpper, objectiveValue, indices, elements);
}
Expand All @@ -247,19 +245,19 @@ int CoinBuild::column(int whichColumn,
int CoinBuild::currentColumn(double &columnLower, double &columnUpper, double &objectiveValue,
const int *&indices, const double *&elements) const
{
assert(type_ == 1);
assert(type_ == Type::Column);
return currentItem(columnLower, columnUpper, objectiveValue, indices, elements);
}
// Set current column
void CoinBuild::setCurrentColumn(int whichColumn)
{
assert(type_ == 1);
assert(type_ == Type::Column);
setMutableCurrent(whichColumn);
}
// Returns current column number
int CoinBuild::currentColumn() const
{
assert(type_ == 1);
assert(type_ == Type::Column);
return currentItem();
}
// add a item
Expand Down
20 changes: 13 additions & 7 deletions src/CoinBuild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
class COINUTILSLIB_EXPORT CoinBuild {

public:
enum Type {
Unset = -1,
Row = 0,
Column = 1,
};

/**@name Useful methods */
//@{
/// add a row
Expand All @@ -46,12 +52,12 @@ class COINUTILSLIB_EXPORT CoinBuild {
/// Return number of rows or maximum found so far
inline int numberRows() const
{
return (type_ == 0) ? numberItems_ : numberOther_;
return (type_ == Type::Row) ? numberItems_ : numberOther_;
}
/// Return number of columns or maximum found so far
inline int numberColumns() const
{
return (type_ == 1) ? numberItems_ : numberOther_;
return (type_ == Type::Column) ? numberItems_ : numberOther_;
}
/// Return number of elements
inline CoinBigIndex numberElements() const
Expand Down Expand Up @@ -86,7 +92,7 @@ class COINUTILSLIB_EXPORT CoinBuild {
/// Returns current column number
int currentColumn() const;
/// Returns type
inline int type() const
inline Type type() const
{
return type_;
}
Expand All @@ -96,8 +102,8 @@ class COINUTILSLIB_EXPORT CoinBuild {
//@{
/** Default constructor. */
CoinBuild();
/** Constructor with type 0==for addRow, 1== for addColumn. */
CoinBuild(int type);
/** Constructor with type Type::Row == for addRow, Type::Column == for addColumn. */
CoinBuild(Type type);
/** Destructor */
~CoinBuild();
//@}
Expand Down Expand Up @@ -147,8 +153,8 @@ class COINUTILSLIB_EXPORT CoinBuild {
double *firstItem_;
/// Last item pointer
double *lastItem_;
/// Type of build - 0 for row, 1 for column, -1 unset
int type_;
/// Type of build
Type type_;
//@}
};

Expand Down

0 comments on commit 720900f

Please sign in to comment.