Skip to content

Commit

Permalink
rm some binarySearch in analyzeStructure
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxies committed Nov 10, 2023
1 parent 34a2797 commit 32330ff
Showing 1 changed file with 96 additions and 91 deletions.
187 changes: 96 additions & 91 deletions src/MibSModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3511,16 +3511,26 @@ MibSModel::setVarTypes()
void
MibSModel::analyzeStructure()
{
int i(0),j(0),index(0), mult(0);
bool lowerRow;
double rhs(0.0);
int i(0), j(0), index(0), mult(0);
int numCols(numVars_);
int numRows(numCons_);
int uCols(upperDim_);
int lCols(lowerDim_);
int lRows(lowerRowNum_);
int counterStart, counterEnd, rowIndex;
double * lObjCoeffs = getLowerObjCoeffs();
int * uColIndices = getUpperColInd();
int * lColIndices = getLowerColInd();
int * uRowIndices = getUpperRowInd();
int * lRowIndices = getLowerRowInd();
double * lObjCoeffs = getLowerObjCoeffs();
const double * matElements = colMatrix_->getElements();
const int * matIndices = colMatrix_->getIndices();
const int * matStarts = colMatrix_->getVectorStarts();

colSignsG2_ = new int[numCols];
colSignsA2_ = new int[numCols];

for(i = 0; i < uCols; i++){
index = uColIndices[i];
Expand Down Expand Up @@ -3549,34 +3559,27 @@ MibSModel::analyzeStructure()
}
}

for (i = 0; i < numCols; i++){
if (colType_[i] != 'B'){
if (binarySearch(0, lCols - 1, i, lColIndices) < 0){
if(varType_[i] == MibSVarLinking){
allLinkingBin_ = false;
}
allUpperBin_ = false;
}
else{
allLowerBin_ = false;
}
if ((!allUpperBin_) && (!allLowerBin_) && (!allLinkingBin_)){
break;
for(i = 0; i < uCols; i++){
index = uColIndices[i];
if(colType_[index] != 'B'){
if(varType_[index] == MibSVarLinking){
allLinkingBin_ = false;
}
allUpperBin_ = false;
}
if((!allUpperBin_) && (!allLinkingBin_)){
break;
}
}

for (i = 0; i < lCols; i++){
index = lColIndices[i];
if(colType_[index] != 'B'){
allLowerBin_ = false;
break;
}
}
}

int counterStart, counterEnd;
int rowIndex;
bool lowerRow, lowerCol;
double rhs(0.0);

const double * matElements = colMatrix_->getElements();
const int * matIndices = colMatrix_->getIndices();
const int * matStarts = colMatrix_->getVectorStarts();
colSignsG2_ = new int[numCols];
colSignsA2_ = new int[numCols];

for (i = 0; i < lCols; i++){
if ((fabs(lObjCoeffs[i] - floor(lObjCoeffs[i])) > etol_) &&
Expand All @@ -3586,28 +3589,60 @@ MibSModel::analyzeStructure()
}
}

for(i = 0; i < numRows; i++){
index = (i >= lRows)? uRowIndices[i-lRows]:lRowIndices[i];
switch(origRowSense_[index]){
case 'L':
rhs = conUB_[index];
break;
case 'G':
rhs = conLB_[index];
break;
case 'E':
std::cout << "Something went wrong in equality constraints conversion.";
std::cout << std::endl;
abort(); // YX: handled in loadProblemData()
break;
case 'R':
std::cout << "Something went wrong in range constraints conversion.";
std::cout << std::endl;
abort(); // YX: handled in loadProblemData()
break;
}

if((isUpperCoeffInt_ || isLowerCoeffInt_) &&
((fabs(rhs - floor(rhs)) > etol_) && (fabs(rhs - ceil(rhs)) > etol_))){
if(i - lRows >= 0){
isUpperCoeffInt_ = false;
}else{
isLowerCoeffInt_ = false;
}
}
}

//Signs of matrices A1, A2, G1 and G2 are determined
//based on converting the row senses to 'G' in order to match the
//MibS cuts paper.
for (i = 0; i < numCols; i++){
counterStart = matStarts[i];
counterEnd = matStarts[i+1];
colSignsG2_[i] = MibSModel::colSignUnknown;
colSignsA2_[i] = MibSModel::colSignUnknown;
index = (i >= lCols)? uColIndices[i-lCols]:lColIndices[i];
counterStart = matStarts[index];
counterEnd = matStarts[index + 1];
colSignsG2_[index] = MibSModel::colSignUnknown;
colSignsA2_[index] = MibSModel::colSignUnknown;
for (j = counterStart; j < counterEnd; j++){
rowIndex = matIndices[j];
if (binarySearch(0, structRowNum_-1, rowIndex, structRowInd_) < 0){
continue;
}
if(origRowSense_[rowIndex] == 'L'){
mult = -1;
}
else{
}else{
mult = 1;
}
lowerRow = binarySearch(0, lRows - 1,
rowIndex, lRowIndices) < 0 ? false:true;
if ((fabs(matElements[j] - floor(matElements[j])) > etol_) &&
if ((isLowerCoeffInt_ || isUpperCoeffInt_) &&
(fabs(matElements[j] - floor(matElements[j])) > etol_) &&
(fabs(matElements[j] - ceil(matElements[j])) > etol_)){
if (lowerRow){
isLowerCoeffInt_ = false;
Expand All @@ -3616,82 +3651,52 @@ MibSModel::analyzeStructure()
}
}
if (mult * matElements[j] < -etol_){
if (lowerRow){
if (lowerCol){
if((lowerRow) &&
((colSignsG2_[index] != MibSModel::colSignInconsistent) ||
(colSignsA2_[index] != MibSModel::colSignInconsistent))){
if(i < lCols){
positiveG2_ = false;
if (colSignsG2_[i] == MibSModel::colSignUnknown){
colSignsG2_[i] = MibSModel::colSignNegative;
}else if (colSignsG2_[i] == MibSModel::colSignPositive){
colSignsG2_[i] = MibSModel::colSignInconsistent;
if (colSignsG2_[index] == MibSModel::colSignUnknown){
colSignsG2_[index] = MibSModel::colSignNegative;
}else if (colSignsG2_[index] == MibSModel::colSignPositive){
colSignsG2_[index] = MibSModel::colSignInconsistent;
}
}else{
positiveA2_ = false;
if (colSignsA2_[i] == MibSModel::colSignUnknown){
colSignsA2_[i] = MibSModel::colSignNegative;
}else if (colSignsA2_[i] == MibSModel::colSignPositive){
colSignsA2_[i] = MibSModel::colSignInconsistent;
if (colSignsA2_[index] == MibSModel::colSignUnknown){
colSignsA2_[index] = MibSModel::colSignNegative;
}else if (colSignsA2_[index] == MibSModel::colSignPositive){
colSignsA2_[index] = MibSModel::colSignInconsistent;
}
}
} else {
if (lowerCol){
}else if(!lowerRow){
if(i < lCols){
positiveG1_ = false;
} else {
}else{
positiveA1_ = false;
}
}
} else {
if (lowerRow) {
if (lowerCol) {
if (colSignsG2_[i] == MibSModel::colSignUnknown){
colSignsG2_[i] = MibSModel::colSignPositive;
}else if (colSignsG2_[i] == MibSModel::colSignNegative){
colSignsG2_[i] = MibSModel::colSignInconsistent;
if((lowerRow) &&
((colSignsG2_[index] != MibSModel::colSignInconsistent) ||
(colSignsA2_[index] != MibSModel::colSignInconsistent))) {
if (i < lCols) {
if (colSignsG2_[index] == MibSModel::colSignUnknown){
colSignsG2_[index] = MibSModel::colSignPositive;
}else if (colSignsG2_[index] == MibSModel::colSignNegative){
colSignsG2_[index] = MibSModel::colSignInconsistent;
}
}else{
if (colSignsA2_[i] == MibSModel::colSignUnknown){
colSignsA2_[i] = MibSModel::colSignPositive;
}else if (colSignsA2_[i] == MibSModel::colSignNegative){
colSignsA2_[i] = MibSModel::colSignInconsistent;
if (colSignsA2_[index] == MibSModel::colSignUnknown){
colSignsA2_[index] = MibSModel::colSignPositive;
}else if (colSignsA2_[index] == MibSModel::colSignNegative){
colSignsA2_[index] = MibSModel::colSignInconsistent;
}
}
}
}
}
}

if ((isUpperCoeffInt_ == true) || (isLowerCoeffInt_ == true)){
for (i = 0; i < numRows; i++){
switch(origRowSense_[i]){
case 'L':
rhs = conUB_[i];
break;
case 'G':
rhs = conLB_[i];
break;
case 'E':
std::cout << "Something went wrong in equality constraints conversion.";
std::cout << std::endl;
abort(); // YX: handled in loadProblemData()
break;
case 'R':
std::cout << "Something went wrong in range constraints conversion.";
std::cout << std::endl;
abort(); // YX: handled in loadProblemData()
break;
}
if ((fabs(rhs - floor(rhs)) > etol_) &&
(fabs(rhs - ceil(rhs)) > etol_)){
lowerRow = binarySearch(0, lRows - 1,
i, lRowIndices) < 0 ? false:true;
if (lowerRow){
isLowerCoeffInt_ = false;
} else {
isUpperCoeffInt_ = false;
}
}
}
}

}
}

//#############################################################################
Expand Down

0 comments on commit 32330ff

Please sign in to comment.