Skip to content

Commit 14fd222

Browse files
yuxiestkralphs
authored andcommitted
check matrix orientation - convert to col-ordered
1 parent ebb82f1 commit 14fd222

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/MibSModel.cpp

+17-4
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@ MibSModel::loadProblemData(const CoinPackedMatrix& matrix,
11041104
int problemType(MibSPar_->entry(MibSParams::bilevelProblemType));
11051105

11061106
int i(0), j(0), k(0), start(0), end(0), beg(0);
1107-
1107+
1108+
bool matType = matrix.isColOrdered(); // YX: check input matrix orientation
11081109
int inputNumRows = matrix.getNumRows(); // YX: to diff from #eqConstrs
11091110
int numCols = matrix.getNumCols();
11101111

@@ -1118,6 +1119,13 @@ MibSModel::loadProblemData(const CoinPackedMatrix& matrix,
11181119
CoinPackedMatrix rowMatrix;
11191120
CoinPackedMatrix *newMatrix = NULL;
11201121
CoinPackedMatrix *matrix1 = NULL; // YX: w/ appended equality constrs
1122+
1123+
// YX: need col mat to start; cp to matrix1 if row-ordered
1124+
if(!matType){
1125+
matrix1 = new CoinPackedMatrix();
1126+
matrix1->copyOf(matrix);
1127+
matrix1->reverseOrdering();
1128+
}
11211129

11221130
// --- prepare for equality constraints (if any) ---
11231131

@@ -1176,12 +1184,17 @@ MibSModel::loadProblemData(const CoinPackedMatrix& matrix,
11761184

11771185
// YX: add rows to the problem matrix and link pointers to vectors
11781186
if(numRows > inputNumRows){
1179-
matrix1 = new CoinPackedMatrix();
1180-
matrix1->copyOf(matrix);
1187+
if(!matrix1){
1188+
matrix1 = new CoinPackedMatrix();
1189+
matrix1->copyOf(matrix);
1190+
}
11811191
matrix1->reverseOrdering();
11821192

11831193
rowMatrix = matrix;
1184-
rowMatrix.reverseOrdering();
1194+
// YX: switch if matrix was col ordered
1195+
if(matType){
1196+
rowMatrix.reverseOrdering();
1197+
}
11851198
const double * matElements = rowMatrix.getElements();
11861199
const int * matIndices = rowMatrix.getIndices();
11871200
const int * matStarts = rowMatrix.getVectorStarts();

0 commit comments

Comments
 (0)