Changeset 2033 for trunk/Cbc/src


Ignore:
Timestamp:
May 8, 2014 1:41:51 PM (5 years ago)
Author:
mlubin
Message:

SOS updates and test (not yet working)

Location:
trunk/Cbc/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/Cbc_C_Interface.cpp

    r2032 r2033  
    823823    return model;
    824824}
    825 /* Add an SOS constraint to the model */
    826 COINLIBAPI void  COINLINKAGE
    827 Cbc_addSOS_Dense(Cbc_Model * model, int numObjects, const int * len,
    828                  const int * const* which, const double * weights, const int type)
    829 {
    830     const char prefix[] = "Cbc_C_Interface::Cbc_addSOS_Dense(): ";
    831 //  const int  VERBOSE = 2;
    832     if (VERBOSE > 0) printf("%sbegin\n", prefix);
    833 
    834     assert(1 > 0);// this is probably broken
    835     int i, j;
    836     // I think this is a different model due to overriding = operator
    837     CbcModel m = *(model->model_);
    838 
    839     CbcObject ** objects = new CbcObject * [numObjects];
    840 
    841     if (VERBOSE > 1) printf("%s numObjects = %i\n", prefix, numObjects);
    842     for (i = 0; i < numObjects; i++) {
    843         if (VERBOSE > 1) {
    844             printf("%s len[%i] = %i, identifier = %i, type = %i\n",
    845                    prefix, i, len[i], i, type);
    846             fflush(stdout);
    847             for (j = 0; j < len[i]; j++) {
    848                 if (VERBOSE > 2 || j == 0 || j == (len[i] - 1)) {
    849                     printf("%s which[%i][%i] = %d, weights[%i] = %g\n",
    850                            prefix, i, j, which[i][j], j, weights[j]);
    851                     fflush(stdout);
    852                 }
    853             }
    854         }
    855 
    856         // Make a CbcSOS and assign it to objects
    857         if (VERBOSE > 1) printf("%s len[%i] = %i\n", prefix, i, len[i]);
    858         if (VERBOSE > 1) printf("%s new CbcSOS()\n", prefix);
    859         // ***
    860         objects[i] = new CbcSOS(model->model_, (int)(len[i]),
    861                                 (const int*)which[i], (const double*)weights, (int)i, (int)type);
    862         // ***
    863         if (objects[i] == NULL) {
    864             printf("%s ERROR: objects[%i] == NULL\n", prefix, i);
    865             fflush(stdout);
    866             assert(objects[i] != NULL);
    867         }
    868     }
    869     if (VERBOSE > 1) printf("%s calling addObjects()\n", prefix);
    870     fflush(stdout);
    871     model->model_->addObjects(numObjects, objects);
    872     if (VERBOSE > 1) printf("%s finished addObjects()\n", prefix);
    873 
    874     for (i = 0; i < numObjects; i++) delete objects[i];
    875     delete [] objects;
    876 
    877     if (VERBOSE > 0) printf("%sreturn\n", prefix);
    878     return;
    879 }
    880825/** Add SOS constraints to the model using row-order matrix */
    881826COINLIBAPI void  COINLINKAGE
    882 Cbc_addSOS_Sparse(Cbc_Model * model, const int * rowStarts,
    883                   const int * rowIndices, const double * weights, const int type)
    884 {
    885     const char prefix[] = "Cbc_C_Interface::Cbc_addSOS_Sparse(): ";
    886 //  const int  VERBOSE = 1;
     827Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts,
     828           const int * colIndices, const double * weights, const int type)
     829{
     830    const char prefix[] = "Cbc_C_Interface::Cbc_addSOS(): ";
     831  //const int  VERBOSE = 4;
    887832    if (VERBOSE > 0) printf("%sbegin\n", prefix);
    888833
    889     int numRows = Cbc_getNumRows(model);
    890834    if (VERBOSE > 0) printf("%s numRows = %i\n", prefix, numRows);
    891 
    892     // The passed sparse matrix must have the same number of rows as the model
    893     assert(numRows == Cbc_getNumRows(model));
    894835
    895836    int row, i;
     
    925866        const int numWeights = rowStarts[row+1] - rowStarts[row];
    926867        if (VERBOSE > 2) printf("%s  numWeights = %i\n", prefix, numWeights);
    927         colIndex    = rowIndices + rowStarts[row];
     868        colIndex    = colIndices + rowStarts[row];
    928869        colWeight   = weights + rowStarts[row];
    929870        if (numWeights > 0) {
  • trunk/Cbc/src/Cbc_C_Interface.h

    r2032 r2033  
    201201    Cbc_setInteger(Cbc_Model * model, int iColumn)
    202202    ;
    203     /** Add SOS constraints to the model using dense matrix */
    204     COINLIBAPI void  COINLINKAGE
    205     Cbc_addSOS_Dense(Cbc_Model * model, int numObjects, const int * len,
    206                      const int * const * which, const double * weights, const int type)
    207     ;
    208203    /** Add SOS constraints to the model using row-order matrix */
    209204    COINLIBAPI void  COINLINKAGE
    210     Cbc_addSOS_Sparse(Cbc_Model * model, const int * rowStarts,
    211                       const int * rowIndices, const double * weights, const int type)
     205    Cbc_addSOS(Cbc_Model * model, int numRows, const int * rowStarts,
     206               const int * colIndices, const double * weights, const int type)
    212207    ;
    213208    /** Print the model */
Note: See TracChangeset for help on using the changeset viewer.