Ignore:
Timestamp:
Jun 7, 2010 8:27:42 AM (9 years ago)
Author:
stefan
Message:

merge split branch into trunk; fix some examples

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:externals
      •  

        old new  
        1 BuildTools        https://projects.coin-or.org/svn/BuildTools/stable/0.5
        2 ThirdParty/ASL    https://projects.coin-or.org/svn/BuildTools/ThirdParty/ASL/stable/1.0
        3 ThirdParty/Blas   https://projects.coin-or.org/svn/BuildTools/ThirdParty/Blas/stable/1.0
        4 ThirdParty/Lapack https://projects.coin-or.org/svn/BuildTools/ThirdParty/Lapack/stable/1.0
        5 ThirdParty/Glpk   https://projects.coin-or.org/svn/BuildTools/ThirdParty/Glpk/stable/1.5
        6 Data/Sample       https://projects.coin-or.org/svn/Data/stable/1.0/Sample
        7 CoinUtils         https://projects.coin-or.org/svn/CoinUtils/stable/2.6/CoinUtils
        8 Cgl               https://projects.coin-or.org/svn/Cgl/stable/0.55/Cgl
        9 Clp               https://projects.coin-or.org/svn/Clp/stable/1.12/Clp
        10 Osi               https://projects.coin-or.org/svn/Osi/stable/0.103/Osi
        11 Vol               https://projects.coin-or.org/svn/Vol/stable/1.1/Vol
         1BuildTools        https://projects.coin-or.org/svn/BuildTools/trunk
         2ThirdParty/ASL    https://projects.coin-or.org/svn/BuildTools/ThirdParty/ASL/trunk
         3ThirdParty/Blas   https://projects.coin-or.org/svn/BuildTools/ThirdParty/Blas/trunk
         4ThirdParty/Lapack https://projects.coin-or.org/svn/BuildTools/ThirdParty/Lapack/trunk
         5ThirdParty/Glpk   https://projects.coin-or.org/svn/BuildTools/ThirdParty/Glpk/trunk
         6Data/Sample       https://projects.coin-or.org/svn/Data/trunk/Sample
         7#Data/miplib3      https://projects.coin-or.org/svn/Data/trunk/miplib3
         8CoinUtils         https://projects.coin-or.org/svn/CoinUtils/trunk/CoinUtils
         9Cgl               https://projects.coin-or.org/svn/Cgl/trunk/Cgl
         10Clp               https://projects.coin-or.org/svn/Clp/trunk/Clp
         11Osi               https://projects.coin-or.org/svn/Osi/trunk/Osi
         12#Vol               https://projects.coin-or.org/svn/Vol/trunk/Vol
    • Property svn:mergeinfo changed
      /branches/split (added)merged: 1437-1439,​1444-1448,​1463
  • trunk/Cbc

  • trunk/Cbc/examples/cbc_driverC_sos.c

    r713 r1464  
    44/* This example shows the use of the "C" interface for CBC. */
    55
     6#include "CbcConfig.h"
    67#include "Cbc_C_Interface.h"
    78#include <stdio.h>
     
    1011#include <assert.h>
    1112
    12 // prototypes
     13/* prototypes */
    1314void printSolution(Cbc_Model *cbc_model);
    1415Cbc_Model * getDefaultModel(int argc, const char *argv[]);
     
    1617
    1718/* Call back function - just says whenever it gets Clp0005 or Coin0002 */
    18 // TODO: It seems that Cbc gives callbacks but not Coin
     19/* TODO: It seems that Cbc gives callbacks but not Coin */
    1920static void callBack(Cbc_Model * model, int messageNumber,
    2021                     int nDouble, const double * vDouble,
     
    6667  Cbc_setLogLevel(model, 1);
    6768  if (VERBOSE>0) printf("%s Log Level %i\n", prefix, Cbc_logLevel(model));
    68   // register callback
     69  /* register callback */
    6970  Cbc_registerCallBack(model,callBack);
    70   // Keep names when reading an mps file
    71   if (argc<2)
    72     // status=Cbc_readMps(model,"../../../../../Data/Sample/ltw.mps");
    73     status=Cbc_readMps(model,"../../../../../Data/Sample/p0033.mps");
     71  /* Keep names when reading an mps file */
     72  if (argc<2) {
     73#if defined(COIN_HAS_SAMPLE) && defined(SAMPLEDIR)
     74    status=Cbc_readMps(model, SAMPLEDIR "/p0033.mps");
     75#else
     76    fprintf(stderr, "Do not know where to find sample MPS files.\n");
     77    exit(1);
     78#endif
     79  }
    7480  else
    7581    status=Cbc_readMps(model,argv[1]);
     
    8389  if (1) Cbc_setIntegerTolerance(model,  1.0e-5);
    8490
    85   /// Solve initial LP relaxation
     91  /* Solve initial LP relaxation */
    8692  Cbc_initialSolve(model);
    8793
    8894  if (VERBOSE>0) printf("%s return\n",prefix);
    8995  return model;
    90 } //  getDefaultModel()
     96} /* getDefaultModel() */
    9197
    9298void printSolution(Cbc_Model *cbc_model) {
    93   //
    94   //  Now to print out solution.  The methods used return modifiable
    95   //  arrays while the alternative names return const pointers -
    96   //  which is of course much more virtuous.
    97   // 
    98   //  This version just does non-zero column and row values.
    99   //
    100   //
    101 
    102   // If we have not kept names (parameter to readMps) this will be 0
    103   //   assert(Cbc_lengthNames(cbc_model));
     99 
     100  /*  Now to print out solution.  The methods used return modifiable
     101      arrays while the alternative names return const pointers -
     102      which is of course much more virtuous.
     103    
     104      This version just does non-zero column and row values.
     105  */
     106
     107  /* If we have not kept names (parameter to readMps) this will be 0
     108      assert(Cbc_lengthNames(cbc_model));
     109  */
    104110  {
    105111    int  name_length = 256;
     
    118124  printf("Is Dual Objective Limit Reached = %i\n",Cbc_isDualObjectiveLimitReached(cbc_model));
    119125  printf("Is Iteration Limit Reached = %i\n",Cbc_isIterationLimitReached(cbc_model));
    120   printf("Objective Sense = %g\n",Cbc_getObjSense(cbc_model));  // (1 - minimize, -1 - maximize, 0 - ignore)
     126  printf("Objective Sense = %g\n",Cbc_getObjSense(cbc_model));  /* (1 - minimize, -1 - maximize, 0 - ignore) */
    121127  printf("Primal Feasible = %i\n",Cbc_primalFeasible(cbc_model));
    122128  printf("Dual Feasible = %i\n",Cbc_dualFeasible(cbc_model));
     
    132138  printf("--------------------------------------\n");
    133139
    134   //  Rows
     140  /*  Rows */
    135141  {
    136142    int numberRows = Cbc_numberRows(cbc_model);
     
    164170  }
    165171  printf("--------------------------------------\n");
    166   // Columns
     172  /* Columns */
    167173  {
    168174    int numberColumns = Cbc_numberColumns(cbc_model);
     
    188194        char name[20];
    189195        sprintf(name," Col%-4i",iColumn);
    190         //      Cbc_columnName(cbc_model,iColumn,name);
     196        /*      Cbc_columnName(cbc_model,iColumn,name); */
    191197        printf("%6d %8s",iColumn,name);
    192198        printf(" %13g",columnPrimal[iColumn]);
     
    200206  }
    201207  printf("--------------------------------------\n");
    202 } //  printSolution()
     208} /*  printSolution() */
    203209
    204210int main (int argc, const char *argv[])
     
    215221  if (VERBOSE>0) printf("%s Version %g\n",prefix,Cbc_getVersion());
    216222
    217   // set model using the local routine for reading an MPS file
     223  /* set model using the local routine for reading an MPS file */
    218224  model = getDefaultModel(argc, argv);
    219   model2 = NULL;  // used to keep model around
    220 
    221   // This clause ought to set the initial basis, but does not yet work.
     225  model2 = NULL;  /* used to keep model around */
     226
     227  /* This clause ought to set the initial basis, but does not yet work. */
    222228  {
    223229    int i;
     
    227233    int elem_length = Cbc_getNumElements(model);
    228234
    229     int * cbc_rowStatus    = NULL; //(int *) malloc(row_length*sizeof(int));
    230     int * cbc_columnStatus = NULL; //(int *) malloc(col_length*sizeof(int));
    231     //    Cbc_getBasisStatus(model, cbc_columnStatus, cbc_rowStatus);
     235    int * cbc_rowStatus    = NULL;
     236    int * cbc_columnStatus = NULL;
    232237
    233238    if (0) {
     
    238243      fflush(stdout);
    239244    }
    240     // print solution status variables
     245    /* print solution status variables */
    241246    if (0) {
    242247      if (cbc_rowStatus) {
     
    246251        }
    247252      } else {
    248         fprintf(stdout,"%s cbc_rowStatus = %p\n", prefix, cbc_rowStatus);
     253        fprintf(stdout,"%s cbc_rowStatus = %p\n", prefix, (void*)cbc_rowStatus);
    249254        fflush(stdout);
    250255      }
     
    255260        }
    256261      } else {
    257         fprintf(stdout,"%s cbc_columnStatus = %p\n", prefix, cbc_columnStatus);
     262        fprintf(stdout,"%s cbc_columnStatus = %p\n", prefix, (void*)cbc_columnStatus);
    258263        fflush(stdout);
    259264      }
    260265    }
    261     //    free( cbc_rowStatus );
    262     //    free( cbc_columnStatus );
    263   }
    264 
    265   // Save model as a clone (does not work as of 2004).
     266  }
     267
     268  /* Save model as a clone (does not work as of 2004). */
    266269  model2 = Cbc_clone(model);
    267270
    268   // Store which variables are integer as defined in the MPS file.
    269   // They will be set to Continuous before adding the SOS constraints.
     271  /* Store which variables are integer as defined in the MPS file.
     272     They will be set to Continuous before adding the SOS constraints. */
    270273
    271274  {
     
    284287  Cbc_problemName(model,80,modelName);
    285288
    286   // Solve the MPS version of the problem
     289  /* Solve the MPS version of the problem */
    287290  if (1) { 
    288291    if (VERBOSE>1) {
     
    291294        prefix, Cbc_optimizationDirection(model));
    292295    }
    293     //    Cbc_setLogLevel(model, VERBOSE); // 4 is verbose
     296    /*    Cbc_setLogLevel(model, VERBOSE); // 4 is verbose */
    294297    time1 = Cbc_cpuTime(model) ;
    295298    Cbc_branchAndBound(model);
     
    304307  }
    305308  {
    306     //
    307     // SOS specification data
    308     // specify numberSets, numPoints, and whichRanges explicitly
    309     // NOTE: These need to be commented according to the MPS file.
    310     //   Example_1_1: Cbc0004I MPS reads 1081 only columns out of 1085
    311     //                Then the 4th range goes out of bounds
    312     //   Example_2: Cbc0006I The LP relaxation is infeasible or too expensive
    313     //   Mod_RT_1: Cbc0006I The LP relaxation is infeasible or too expensive
    314     //
     309   
     310    /* SOS specification data
     311      specify numberSets, numPoints, and whichRanges explicitly
     312      NOTE: These need to be commented according to the MPS file.
     313         Example_1_1: Cbc0004I MPS reads 1081 only columns out of 1085
     314                      Then the 4th range goes out of bounds
     315         Example_2: Cbc0006I The LP relaxation is infeasible or too expensive
     316         Mod_RT_1: Cbc0006I The LP relaxation is infeasible or too expensive
     317    */
    315318    const int numberSets =
    316       1; // dummy
     319      1; /* dummy
    317320    //    4; // Example_1_1
    318321    //    2;  // Example_2
    319322    //    2;  // Mod_RT_1
    320     //    2;  // SITH
     323    //    2;  // SITH */
    321324    const int numPoints =
    322       1; // dummy
     325      1; /* dummy
    323326    //    257; // Example_1_1
    324327    //    256;  // Example_2
    325328    //    257;  // Mod_RT_1
    326     //    257;  // SITH
    327 
    328     //const int whichRanges[numberSets][2]
    329     const int whichRanges[1][2] = { // counting from zero?
    330       {0,0} // dummy
    331       //    {56,312}, {313, 569}, {572, 828}, {829, 1085} // Example_1_1
    332       //    {48, 303}, {304, 559} // Example_2
    333       //    {45, 301}, {302, 558} // Mod_RT_1
    334       //    {45, 301}, {302, 558} // SITH
     329    //    257;  // SITH */
     330
     331    const int whichRanges[1][2] = { /* counting from zero? */
     332      {0,0} /* dummy */
     333      /*   {56,312}, {313, 569}, {572, 828}, {829, 1085} // Example_1_1
     334           {48, 303}, {304, 559} // Example_2
     335           {45, 301}, {302, 558} // Mod_RT_1
     336           {45, 301}, {302, 558} // SITH
     337      */
    335338    };
    336     // the rest is determined parametrically
     339    /* the rest is determined parametrically */
    337340    int *len = malloc(numberSets* sizeof(int[1]));
    338     //int **which = new int * [numberSets];
    339341    int **which = malloc(numberSets* sizeof(int[1]));
    340342    int setNum, pointNum;
     
    350352      which[setNum] = malloc(numPoints*sizeof(int[1]));
    351353      for (j = 0; j < len[setNum]; j++)
    352         //      which[setNum][j] = whichRanges[setNum][0] + j - 6; // hack for missing columns in example 1_1
    353         which[setNum][j] = whichRanges[setNum][0] + j; // Example_2
     354        which[setNum][j] = whichRanges[setNum][0] + j; /* Example_2 */
    354355    }
    355356    weights = malloc(numPoints*sizeof(double[1])); 
    356357    for (pointNum = 0; pointNum < numPoints; pointNum++) weights[pointNum] = pointNum+1;
    357358
    358     // Now use SOS2
    359     // NOTE: Only enable this if known good SOS Specification (above)
     359    /* Now use SOS2
     360       NOTE: Only enable this if known good SOS Specification (above)
     361    */
    360362    if (1) { 
    361363      if (VERBOSE>1) printf("%s Use SOS2\n",prefix);
    362364
    363       // Restore model
     365      /* Restore model */
    364366      Cbc_deleteModel(model);
    365367      if (0) {
     
    368370        model = getDefaultModel(argc, argv);
    369371      }
    370       //    Cbc_setLogLevel(model, 4); // 4 is verbose
     372      /*    Cbc_setLogLevel(model, 4); // 4 is verbose */
    371373      if (VERBOSE>1) printf("%s Model %s has %d rows and %d columns\n",
    372374        prefix, modelName,Cbc_numberRows(model),Cbc_numberColumns(model));
    373375
    374       // make SOS cuts
     376      /* make SOS cuts */
    375377      for (i=0;i<numberIntegers;i++) {
    376378        int iColumn = integerVariable[i];
    377         // Stop being integer
     379        /* Stop being integer */
    378380        Cbc_setContinuous(model, iColumn);
    379381      }
    380       // add cut (0 - use dense, 1 - use sparse (TODO: test this))
     382      /* add cut (0 - use dense, 1 - use sparse (TODO: test this)) */
    381383      if (0) for (i=0;i<numberSets;i++) {
    382384        printf(
    383385          "%s calling Cbc_addSOS(), len[%i] = %i, which[%i][0] = %i, which[%i][%i] = %i,\n  weights[0] = %g, weights[%i] = %g\n",
    384386          prefix, i, len[i], i, which[i][0], i, len[i]-1, which[i][len[i]-1], weights[0], len[i]-1, weights[len[i]-1]);
    385         //      Cbc_addSOS_Sparse(model,len[i],which[i],weights,i,2);
     387        /*      Cbc_addSOS_Sparse(model,len[i],which[i],weights,i,2); */
    386388      } else {
    387         int numObjects = numberSets; // cannot pass const int
     389        int numObjects = numberSets; /* cannot pass const int */
    388390        Cbc_addSOS_Dense(model, numObjects, len, (const int**)which, (const double*)weights, 2);
    389391      }
    390392    }
    391393
    392     Cbc_setOptimizationDirection(model, 1); // 1 minimize
     394    Cbc_setOptimizationDirection(model, 1); /* 1 minimize */
    393395    if (VERBOSE>1) {
    394396      printf("%s Solve MPS version of the problem\n",prefix);
     
    414416  if (VERBOSE>0) printf("%s return 0\n",prefix);
    415417  return 0;
    416 } //  main()
     418} /*  main() */
Note: See TracChangeset for help on using the changeset viewer.