22 *
33 * This file is part of the COIN-OR CBC MIP Solver
44 *
5- * CoinConflictGraph implementation which supports modifications.
5+ * CoinConflictGraph implementation which supports modifications.
66 * For a static conflict graph implemenation with faster queries
77 * check CoinStaticConflictGraph.
88 *
99 * @file CoinDynamicConflictGraph.cpp
10- * @brief CoinConflictGraph implementation which supports modifications.
10+ * @brief CoinConflictGraph implementation which supports modifications.
1111 * @author Samuel Souza Brito and Haroldo Gambini Santos
12121313 * @date 03/27/2020
2929#include " CoinStaticConflictGraph.hpp"
3030#include " CoinPackedMatrix.hpp"
3131#include " CoinCliqueList.hpp"
32+ #include " CoinColumnType.hpp"
3233
3334#define EPS 1e-6
3435
@@ -105,11 +106,11 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph ( size_t _size )
105106{
106107}
107108
108- /* first pass: process all
109+ /* first pass: process all
109110 * cliques that will be stored directly
110111 *
111112 * second pass: process constraints where only a part
112- * of the constraint may be a clique
113+ * of the constraint may be a clique
113114 **/
114115CoinDynamicConflictGraph::CoinDynamicConflictGraph (
115116 const int numCols,
@@ -131,7 +132,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
131132 this ->tRowRHS = std::vector<double >();
132133 tRowRHS.reserve (tnRowCap);
133134
134- // temporary area
135+ // temporary area
135136 std::vector<size_t > clqIdxs (numCols*2 );
136137
137138 // maximum number of nonzeros in constraints that
@@ -143,6 +144,8 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
143144 const double *coefs = matrixByRow->getElements ();
144145 const CoinBigIndex *start = matrixByRow->getVectorStarts ();
145146 const int *length = matrixByRow->getVectorLengths ();
147+
148+ // temporary area to store columns of a row (idx, coef), will be sorted later
146149 std::vector<std::pair<size_t , double > > columns (numCols);
147150
148151 smallCliques = new CoinCliqueList ( 4096 , 3276 );
@@ -151,7 +154,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
151154 for (size_t idxRow = 0 ; idxRow < (size_t )matrixByRow->getNumRows (); idxRow++) {
152155 const char rowSense = sense[idxRow];
153156
154- if (length[idxRow] < 2 || rowSense == ' N' )
157+ if (length[idxRow] < 2 || rowSense == ' N' )
155158 continue ;
156159
157160 const double mult = (rowSense == ' G' ) ? -1.0 : 1.0 ;
@@ -164,10 +167,8 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
164167 for (size_t j = start[idxRow]; j < (size_t )start[idxRow] + length[idxRow]; j++) {
165168 const size_t idxCol = idxs[j];
166169 const double coefCol = coefs[j] * mult;
167- const bool isBinary = ((colType[idxCol] != 0 ) && (colLB[idxCol] == 0.0 )
168- && (colUB[idxCol] == 0.0 || colUB[idxCol] == 1.0 ));
169170
170- if (!isBinary ) {
171+ if (colType[idxCol] != CoinColumnType::Binary ) {
171172 onlyBinaryVars = false ;
172173 break ;
173174 }
@@ -205,7 +206,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
205206 assert (nz == length[idxRow]);
206207 // assert(rhs >= 0.0);
207208#endif
208-
209+
209210 // explicit clique
210211 if ((twoLargest[0 ] <= rhs) && ((twoSmallest[0 ] + twoSmallest[1 ]) >= (rhs + EPS)) && (nz > 2 )) {
211212 if (nz >= CoinConflictGraph::minClqRow_) {
@@ -230,8 +231,10 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
230231 }
231232
232233 if (columns[j].first < (size_t ) numCols) {
234+ // original variable
233235 newBounds_.push_back (std::make_pair (columns[j].first , std::make_pair ( 0.0 , 0.0 )));
234236 } else {
237+ // complement variable
235238 newBounds_.push_back (std::make_pair (columns[j].first - numCols, std::make_pair ( 1.0 , 1.0 )));
236239 }
237240 }
@@ -241,7 +244,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
241244#endif
242245
243246 maxNzOC = std::max (maxNzOC, nz);
244-
247+
245248 this ->addTmpRow ( nz, columns, rhs );
246249
247250 if (rowSense == ' E' || rowSense == ' R' ) {
@@ -264,7 +267,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
264267#endif
265268
266269 this ->addTmpRow ( nz, columns, rhs );
267-
270+
268271 } // equality constraints
269272 } // not explicit clique
270273 } // all rows
@@ -274,9 +277,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
274277
275278 /* inserting trivial conflicts: variable-complement */
276279 for (size_t i = 0 ; i < (size_t )numCols; i++) {
277- const bool isBinary = ((colType[i] != 0 ) && (colLB[i] == 1.0 || colLB[i] == 0.0 )
278- && (colUB[i] == 0.0 || colUB[i] == 1.0 ));
279- if (isBinary) { // consider only binary variables
280+ if (colType[i] == CoinColumnType::Binary) { // consider only binary variables
280281 conflicts->addNeighbor ( i, i+numCols );
281282 conflicts->addNeighbor ( numCols+i, i );
282283 }
@@ -290,7 +291,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (
290291 // at this point large cliques will already be include
291292 this ->largeClqs ->computeNodeOccurrences ( size_ );
292293
293- // processing small cliques
294+ // processing small cliques
294295 if (smallCliques->nCliques ())
295296 {
296297 smallCliques->computeNodeOccurrences ( size_ );
@@ -483,12 +484,12 @@ void CoinDynamicConflictGraph::printInfo() const
483484
484485 size_t minClq = INT_MAX;
485486 size_t maxClq = 0 ;
486-
487+
487488 for ( size_t i=0 ; (i<this ->nCliques ()) ; ++i ) {
488489 minClq = std::min ( minClq, cliqueSize (i) );
489490 maxClq = std::max ( maxClq, cliqueSize (i) );
490491 }
491-
492+
492493 double totalDegree = 0.0 ;
493494 size_t minD = INT_MAX;
494495 size_t maxD = 0 ;
@@ -499,7 +500,7 @@ void CoinDynamicConflictGraph::printInfo() const
499500 maxD = std::max ( maxD, conflicts->rowSize (i) );
500501 }
501502 double avd = totalDegree / ((double )size_);
502-
503+
503504 printf (" Conflict graph info:\n " );
504505 printf (" \t nodes: %zu\n " , this ->size ());
505506 printf (" \t density: %.4f\n " , this ->density () );
@@ -563,7 +564,7 @@ void CoinDynamicConflictGraph::processSmallCliquesNode(
563564 size_t newConf = 0 ;
564565 size_t prevConf = conflicts->rowSize (node);
565566 const size_t *oldConfs = conflicts->getRow (node);
566- for ( size_t j=0 ; (j<prevConf) ; ++j )
567+ for ( size_t j=0 ; (j<prevConf) ; ++j )
567568 iv[oldConfs[j]] = true ;
568569 iv[node] = true ;
569570
0 commit comments