Changeset 800


Ignore:
Timestamp:
Jun 9, 2006 10:05:57 PM (13 years ago)
Author:
ladanyi
Message:

finishing conversion to svn

Location:
trunk/Clp
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/Clp/examples/makeDual.cpp

    r799 r800  
    5656  int numberExtraRows=0;
    5757  for (iRow=0;iRow<numberRows;iRow++) {
    58     if (rowLower[iRow]<-1.0e20) {
    59     } else if (rowUpper[iRow]>1.0e20) {
     58    if (rowLower[iRow]<=-1.0e20) {
     59    } else if (rowUpper[iRow]>=1.0e20) {
    6060    } else {
    6161      if (rowUpper[iRow]!=rowLower[iRow])
     
    7070  for (iColumn=0;iColumn<numberColumns;iColumn++) {
    7171    double offset=0.0;
    72     if (columnUpper[iColumn]>1.0e20) {
     72    if (columnUpper[iColumn]>=1.0e20) {
    7373      if (columnLower[iColumn]>-1.0e20)
    7474        offset=columnLower[iColumn];
    75     } else if (columnLower[iColumn]<-1.0e20) {
     75    } else if (columnLower[iColumn]<=-1.0e20) {
    7676      offset=columnUpper[iColumn];
    7777    } else {
     
    101101  for (iColumn=0;iColumn<numberColumns;iColumn++) {
    102102    // Offset is already in
    103     if (columnUpper[iColumn]>1.0e20) {
     103    if (columnUpper[iColumn]>=1.0e20) {
    104104      if (columnLower[iColumn]>-1.0e20) {
    105105        fromColumnsLower[iColumn]=-COIN_DBL_MAX;
     
    110110        fromColumnsUpper[iColumn]=objective[iColumn];
    111111      }
    112     } else if (columnLower[iColumn]<-1.0e20) {
     112    } else if (columnLower[iColumn]<=-1.0e20) {
    113113      fromColumnsLower[iColumn]=objective[iColumn];
    114114      fromColumnsUpper[iColumn]=COIN_DBL_MAX;
     
    119119  int kRow=0;
    120120  for (iRow=0;iRow<numberRows;iRow++) {
    121     if (rowLower[iRow]<-1.0e20) {
     121    if (rowLower[iRow]<=-1.0e20) {
    122122      assert (rowUpper[iRow]<1.0e20);
    123123      newObjective[kRow]=-rowUpper[iRow];
     
    126126      which[kRow]=iRow;
    127127      kRow++;
    128     } else if (rowUpper[iRow]>1.0e20) {
     128    } else if (rowUpper[iRow]>=1.0e20) {
    129129      newObjective[kRow]=-rowLower[iRow];
    130130      fromRowsLower[kRow]=0.0;
  • trunk/Clp/src/CbcOrClpParam.cpp

    r799 r800  
    352352  if (name_=="directory")
    353353    std::cout<<"Current working directory is "<<stringValue_<<std::endl;
    354   else if (name_=="printM!ask")
     354  else if (name_.substr(0,6)=="printM")
    355355    std::cout<<"Current value of printMask is "<<stringValue_<<std::endl;
    356356  else
     
    10941094    (
    10951095     "If the gap between best solution and best possible solution is less than this \
    1096 then the search will be terminated.  Also see gapRatio."
     1096then the search will be terminated.  Also see ratioGap."
    10971097     );
    10981098#endif
     
    12361236                  "off",COSTSTRATEGY);
    12371237  parameters[numberParameters-1].append("pri!orities");
    1238   parameters[numberParameters-1].append("pseudo!costs(not implemented yet)");
     1238  parameters[numberParameters-1].append("column!Order?");
    12391239  parameters[numberParameters-1].setLonghelp
    12401240    (
    12411241     "This orders the variables in order of their absolute costs - with largest cost ones being branched on \
    1242 first.  This primitive strategy can be surprsingly effective."
    1243      );
    1244 #endif
     1242first.  This primitive strategy can be surprsingly effective.  The column order\
     1243 option is obviously not on costs but easy to code here."
     1244     );
     1245#endif
     1246#if 0
     1247  parameters[numberParameters++]=
     1248    CbcOrClpParam("cpp!Generate","Generates C++ code",
     1249                  -1,50000,CPP);
     1250  parameters[numberParameters-1].setLonghelp
     1251    (
     1252     "Once you like what the stand-alone solver does then this allows \
     1253you to generate user_driver.cpp which approximates the code.  \
     12540 gives simplest driver, 1 generates saves and restores, 2 \
     1255generates saves and restores even for variables at default value. \
     12564 bit in cbc generates size dependent code rather than computed values."
     1257     );
     1258#endif
    12451259#ifdef COIN_HAS_CLP
    12461260  parameters[numberParameters++]=
     
    14811495See branchAndCut for information on options."
    14821496     );
     1497    parameters[numberParameters++]=
     1498      CbcOrClpParam("force!Solution","Whether to use given solution as crash for BAB",
     1499                    "off",USESOLUTION);
     1500    parameters[numberParameters-1].append("on");
     1501  parameters[numberParameters-1].setLonghelp
     1502    (
     1503     "If on then tries to branch to solution given by AMPL or priorities file."
     1504     );
    14831505#endif
    14841506  parameters[numberParameters++]=
     
    14941516#ifdef COIN_HAS_CBC
    14951517  parameters[numberParameters++]=
    1496     CbcOrClpParam("gap!Ratio","Stop when gap between best possible and \
    1497 best less than this fraction of larger of two",
    1498                   0.0,1.0e20,GAPRATIO);
    1499   parameters[numberParameters-1].setDoubleValue(0.0);
    1500   parameters[numberParameters-1].setLonghelp
    1501     (
    1502      "If the gap between best solution and best possible solution is less than this fraction \
    1503 of the objective value at the root node then the search will terminate.  See 'allowableGap' for a \
    1504 way of using absolute value rather than fraction."
    1505      );
    1506   parameters[numberParameters++]=
    15071518    CbcOrClpParam("gomory!Cuts","Whether to use Gomory cuts",
    15081519                  "off",GOMORYCUTS);
     
    18311842     );
    18321843  parameters[numberParameters-1].setDoubleValue(1.0);
     1844#endif
     1845#ifdef COIN_USE_CBC
     1846  parameters[numberParameters++]=
     1847    CbcOrClpParam("outDup!licates","takes duplicate rows etc out of integer model",
     1848                  OUTDUPROWS,7,false);
    18331849#endif
    18341850  parameters[numberParameters++]=
     
    19381954  parameters[numberParameters-1].append("sos");
    19391955  parameters[numberParameters-1].append("trysos");
     1956  parameters[numberParameters-1].append("strategy");
    19401957  parameters[numberParameters-1].setLonghelp
    19411958    (
     
    19441961 Save option saves on file presolved.mps.  equal will turn <= cliques into \
    19451962==.  sos will create sos sets if all 0-1 in sets (well one extra is allowed) \
    1946 and no overlaps.  trysos is same but allows any number extra."
     1963and no overlaps.  trysos is same but allows any number extra.  strategy is as \
     1964on but uses CbcStrategy."
    19471965     );
    19481966#endif
     
    20332051    (
    20342052     "If set then only those names which match mask are printed in a solution. \
    2035 '*' matches any character.  The default is '' i.e. unset so all variables are printed. \
     2053'?' matches any character and '*' matches any set of characters. \
     2054 The default is '' i.e. unset so all variables are printed. \
    20362055This is only active if model has names."
    20372056     );
     
    20452064 directory given by 'directory'.  A name of '$' will use the previous value for the name.  This\
    20462065 is initialized to '', i.e. it must be set.  This can not read from compressed files. \
    2047 File is in csv format with allowed headings - name, number, priority, direction.  Exactly one of\
     2066File is in csv format with allowed headings - name, number, priority, direction, up, down, solution.  Exactly one of\
    20482067 name and number must be given."
    20492068     );
     
    20672086     "This stops the execution of Clp, end, exit, quit and stop are synonyms"
    20682087     );
     2088#ifdef COIN_HAS_CBC
     2089  parameters[numberParameters++]=
     2090    CbcOrClpParam("ratio!Gap","Stop when gap between best possible and \
     2091best less than this fraction of larger of two",
     2092                  0.0,1.0e20,GAPRATIO);
     2093  parameters[numberParameters-1].setDoubleValue(0.0);
     2094  parameters[numberParameters-1].setLonghelp
     2095    (
     2096     "If the gap between best solution and best possible solution is less than this fraction \
     2097of the objective value at the root node then the search will terminate.  See 'allowableGap' for a \
     2098way of using absolute value rather than fraction."
     2099     );
     2100#endif
    20692101#ifdef COIN_HAS_CLP
    20702102  parameters[numberParameters++]=
     
    22222254     );
    22232255  parameters[numberParameters++]=
     2256    CbcOrClpParam("sos!Options","Whether to use SOS from AMPL",
     2257                  "off",SOS);
     2258  parameters[numberParameters-1].append("on");
     2259  parameters[numberParameters-1].setCurrentOption("on");
     2260  parameters[numberParameters-1].setLonghelp
     2261    (
     2262     "Normally if AMPL says there are SOS variables they should be used, but sometime sthey should\
     2263 be turned off - this does so."
     2264     );
     2265  parameters[numberParameters++]=
    22242266    CbcOrClpParam("slog!Level","Level of detail in Solver output",
    22252267                  -1,63,SOLVERLOGLEVEL);
     
    23072349  parameters[numberParameters++]=
    23082350    CbcOrClpParam("thread!s","Number of threads to try and use",
    2309                   -2,64,THREADS);
     2351                  -2,64,THREADS,false);
    23102352#endif
    23112353#ifdef COIN_HAS_CBC
     
    23552397     );
    23562398  parameters[numberParameters++]=
     2399    CbcOrClpParam("userClp","Hand coded Clp stuff",
     2400                  USERCLP);
     2401  parameters[numberParameters-1].setLonghelp
     2402    (
     2403     "There are times e.g. when using AMPL interface when you may wish to do something unusual.  \
     2404Look for USERCLP in main driver and modify sample code."
     2405     );
     2406#ifdef COIN_USE_CBC
     2407  parameters[numberParameters++]=
     2408    CbcOrClpParam("userCbc","Hand coded Cbc stuff",
     2409                  USERCBC);
     2410  parameters[numberParameters-1].setLonghelp
     2411    (
     2412     "There are times e.g. when using AMPL interface when you may wish to do something unusual.  \
     2413Look for USERCBC in main driver and modify sample code."
     2414     );
     2415#endif
     2416  parameters[numberParameters++]=
    23572417    CbcOrClpParam("verbose","Switches on longer help on single ?",
    2358                   0,7,VERBOSE,false);
     2418                  0,15,VERBOSE,false);
    23592419  parameters[numberParameters-1].setLonghelp
    23602420    (
  • trunk/Clp/src/CbcOrClpParam.hpp

    r799 r800  
    6060    MAXFACTOR,PERTVALUE,MAXITERATION,PRESOLVEPASS,IDIOT,SPRINT,
    6161    OUTPUTFORMAT,SLPVALUE,PRESOLVEOPTIONS,PRINTOPTIONS,SPECIALOPTIONS,
    62     SUBSTITUTION,DUALIZE,VERBOSE,THREADS,
     62    SUBSTITUTION,DUALIZE,VERBOSE,THREADS,CPP,
    6363
    6464    STRONGBRANCHING=151,CUTDEPTH, MAXNODES,NUMBERBEFORE,NUMBERANALYZE,
     
    7575    GOMORYCUTS,PROBINGCUTS,KNAPSACKCUTS,REDSPLITCUTS,
    7676    ROUNDING,SOLVER,CLIQUECUTS,COSTSTRATEGY,FLOWCUTS,MIXEDCUTS,
    77     TWOMIRCUTS,PREPROCESS,FPUMP,GREEDY,COMBINE,LOCALTREE,
     77    TWOMIRCUTS,PREPROCESS,FPUMP,GREEDY,COMBINE,LOCALTREE,USESOLUTION,SOS,
    7878   
    7979    DIRECTORY=301,IMPORT,EXPORT,RESTORE,SAVE,DUALSIMPLEX,PRIMALSIMPLEX,EITHERSIMPLEX,
     
    8181    TIGHTEN,FAKEBOUND,HELP,PLUSMINUS,NETWORK,ALLSLACK,REVERSE,BARRIER,NETLIB_BARRIER,NETLIB_TUNE,
    8282    REALLY_SCALE,BASISIN,BASISOUT,SOLVECONTINUOUS,CLEARCUTS,VERSION,STATISTICS,DEBUG,DUMMY,PRINTMASK,
    83 
    84     BAB=351,MIPLIB,STRENGTHEN,PRIORITYIN,
     83    OUTDUPROWS,USERCLP,
     84
     85    BAB=351,MIPLIB,STRENGTHEN,PRIORITYIN,USERCBC,
    8586
    8687    OSLSTUFF = 401,CBCSTUFF,
  • trunk/Clp/src/ClpCholeskyBase.cpp

    r799 r800  
    249249    CoinMemcpyN(region1,numberTotal,array);
    250250    CoinMemcpyN(region2,numberRowsModel,array+numberTotal);
     251    assert (numberRows_>=numberRowsModel+numberTotal);
    251252    solve(array);
    252253    int iRow;
     
    14101411    //std::sort(choleskyRow_+indexStart_[iRow]
    14111412    //      ,choleskyRow_+indexStart_[iRow]+nz);
    1412 #define CLP_DEBUG
     1413    //#define CLP_DEBUG
    14131414#ifdef CLP_DEBUG
    14141415    int last=-1;
  • trunk/Clp/src/ClpCholeskyDense.cpp

    r799 r800  
    7474#define BLOCKSHIFT 4
    7575
    76 #define BLOCKSQ BLOCK*BLOCK
    77 #define BLOCKSQSHIFT BLOCKSHIFT+BLOCKSHIFT
     76#define BLOCKSQ ( BLOCK*BLOCK )
     77#define BLOCKSQSHIFT ( BLOCKSHIFT+BLOCKSHIFT )
    7878#define number_blocks(x) (((x)+BLOCK-1)>>BLOCKSHIFT)
    7979#define number_rows(x) ((x)<<BLOCKSHIFT)
  • trunk/Clp/src/ClpCholeskyUfl.cpp

    r799 r800  
    4343ClpCholeskyUfl::~ClpCholeskyUfl ()
    4444{
     45#ifdef CLP_USE_CHOLMOD
    4546  cholmod_free_factor (&L_, &c_) ;
    4647  cholmod_finish (&c_) ;               
     48#endif
    4749}
    4850
     
    106108{
    107109  numberRows_ = model->numberRows();
     110  if (doKKT_) {
     111    numberRows_ += numberRows_ + model->numberColumns();
     112    printf("finish coding UFL KKT!\n");
     113    abort();
     114  }
    108115  rowsDropped_ = new char [numberRows_];
    109116  memset(rowsDropped_,0,numberRows_);
  • trunk/Clp/src/ClpDualRowSteepest.cpp

    r799 r800  
    163163  // we can't really trust infeasibilities if there is primal error
    164164  // this coding has to mimic coding in checkPrimalSolution
    165   double error = CoinMin(1.0e-3,model_->largestPrimalError());
     165  double error = CoinMin(1.0e-2,model_->largestPrimalError());
    166166  // allow tolerance at least slightly bigger than standard
    167167  tolerance = tolerance +  error;
     
    915915  // we can't really trust infeasibilities if there is primal error
    916916  // this coding has to mimic coding in checkPrimalSolution
    917   double error = CoinMin(1.0e-3,model_->largestPrimalError());
     917  double error = CoinMin(1.0e-2,model_->largestPrimalError());
    918918  // allow tolerance at least slightly bigger than standard
    919919  tolerance = tolerance +  error;
  • trunk/Clp/src/ClpDynamicMatrix.cpp

    r799 r800  
    931931      double relaxedTolerance=dualTolerance;
    932932      // we can't really trust infeasibilities if there is dual error
    933       double error = CoinMin(1.0e-3,model->largestDualError());
     933      double error = CoinMin(1.0e-2,model->largestDualError());
    934934      // allow tolerance at least slightly bigger than standard
    935935      relaxedTolerance = relaxedTolerance +  error;
  • trunk/Clp/src/ClpGubDynamicMatrix.cpp

    r799 r800  
    338338    }
    339339#endif
     340#ifdef CLP_DEBUG
     341 {
     342   for (int i=firstDynamic_;i<firstAvailable_;i++) {
     343     assert (getDynamicStatus(id_[i-firstDynamic_])==inSmall);
     344   }
     345 }
     346#endif
    340347    int minSet = minimumObjectsScan_<0 ? 5 : minimumObjectsScan_;
    341348    int minNeg = minimumGoodReducedCosts_<0 ? 5 : minimumGoodReducedCosts_;
     
    601608          firstAvailable_++;
    602609        } else {
     610          int jColumn = id_[iColumn-firstDynamic_];
     611          setDynamicStatus(jColumn,atLowerBound);
    603612          if (lowerColumn_||upperColumn_) {
    604             int jColumn = id_[iColumn-firstDynamic_];
    605613            if (model->getStatus(iColumn)==ClpSimplex::atUpperBound)
    606614              setDynamicStatus(jColumn,atUpperBound);
    607             else
    608               setDynamicStatus(jColumn,atLowerBound);
    609615            // treat solution as if exactly at a bound
    610616            double value = solution[iColumn];
     
    636642          lowerColumn[firstAvailable_]=lowerColumn[iColumn];
    637643          upperColumn[firstAvailable_]=upperColumn[iColumn];
    638           model->nonLinearCost()->setOne(firstAvailable_,solution[iColumn],0.0,COIN_DBL_MAX,
    639                                          cost_[jColumn]);
     644          double originalLower = lowerColumn_ ? lowerColumn_[jColumn] : 0.0;
     645          double originalUpper = upperColumn_ ? upperColumn_[jColumn] : COIN_DBL_MAX;
     646          if (originalUpper>1.0e30)
     647            originalUpper = COIN_DBL_MAX;
     648          model->nonLinearCost()->setOne(firstAvailable_,solution[iColumn],
     649                                         originalLower,originalUpper,
     650                                         cost_[jColumn]);
    640651          CoinBigIndex base = startColumn_[jColumn];
    641652          for (int j=0;j<numberThis;j++) {
     
    774785      // id will be sitting at firstAvailable
    775786      int sequence = id_[firstAvailable_-firstDynamic_];
     787      assert (!flagged(sequence));
    776788      setFlagged(sequence);
    777789      model->clearFlagged(firstAvailable_);
     
    817829                                         upperColumn[i],cost_[jColumn]);
    818830      }
     831      if (!model->numberIterations()&&rhsOffset_) {
     832        lastRefresh_ = - refreshFrequency_; // force refresh
     833      }
    819834    }
    820835    break;
     
    833848      double relaxedTolerance=dualTolerance;
    834849      // we can't really trust infeasibilities if there is dual error
    835       double error = CoinMin(1.0e-3,model->largestDualError());
     850      double error = CoinMin(1.0e-2,model->largestDualError());
    836851      // allow tolerance at least slightly bigger than standard
    837852      relaxedTolerance = relaxedTolerance +  error;
     
    917932    {
    918933      returnNumber = (lowerColumn_!=NULL||upperColumn_!=NULL) ? 1 : 0;
     934#if 0
     935      if (!returnNumber) {
     936        // may be gub slacks
     937        for (int i=0;i<numberSets_;i++) {
     938          if (upper_[i]>lower_[i]) {
     939            returnNumber=1;
     940            break;
     941          }
     942        }
     943      }
     944#endif
    919945    }
    920946    break;
     
    13621388            // already set startColumn[firstAvailable_]=numberElements;
    13631389            id_[firstAvailable_-firstDynamic_]=iBasic;
     1390            setDynamicStatus(iBasic,inSmall);
    13641391            backward_[firstAvailable_]=iSet;
    13651392            iBasic=firstAvailable_;
     
    17041731        // and now compute value to use for key
    17051732        ClpSimplex::Status iStatus;
    1706   int iSet;
     1733        int iSet;
    17071734        for ( iSet=0;iSet<numberSets_;iSet++) {
    17081735          iColumn = keyVariable_[iSet];
     
    18481875      int bigSequence = id_[sequenceOut-firstDynamic_];
    18491876      trueOut=bigSequence+firstDynamic_;
    1850       if (model->getStatus(sequenceOut)==ClpSimplex::atUpperBound)
    1851         setDynamicStatus(bigSequence,atUpperBound);
    1852       else
    1853         setDynamicStatus(bigSequence,atLowerBound);
     1877      if (getDynamicStatus(bigSequence)!=inSmall) {
     1878        if (model->getStatus(sequenceOut)==ClpSimplex::atUpperBound)
     1879          setDynamicStatus(bigSequence,atUpperBound);
     1880        else
     1881          setDynamicStatus(bigSequence,atLowerBound);
     1882      }
    18541883      if (doPrinting)
    18551884        printf(" ,outgoing set %d big seq %d,",iSet,bigSequence);
     
    20782107  return numberInfeasible;
    20792108}
     2109// Cleans data after setWarmStart
     2110void
     2111ClpGubDynamicMatrix::cleanData(ClpSimplex * model)
     2112{
     2113  // and redo chains
     2114  int numberColumns = model->numberColumns();
     2115  int iColumn;
     2116  // do backward
     2117  int * mark = new int [numberGubColumns_];
     2118  for (iColumn=0;iColumn<numberGubColumns_;iColumn++)
     2119    mark[iColumn]=-1;
     2120  int i;
     2121  for (i=0;i<firstDynamic_;i++) {
     2122    assert (backward_[i]==-1);
     2123    next_[i]=-1;
     2124  }
     2125  for (i=firstDynamic_;i<firstAvailable_;i++) {
     2126    iColumn = id_[i-firstDynamic_];
     2127    mark[iColumn]=i;
     2128  }
     2129  for (i=0;i<numberSets_;i++) {
     2130    int iKey=keyVariable_[i];
     2131    int lastNext = -1;
     2132    int firstNext = -1;
     2133    for (CoinBigIndex k= fullStart_[i];k<fullStart_[i+1];k++) {
     2134      iColumn = mark[k];
     2135      if (iColumn>=0) {
     2136        if (iColumn!=iKey) {
     2137          if (lastNext>=0)
     2138            next_[lastNext]=iColumn;
     2139          else
     2140            firstNext = iColumn;
     2141          lastNext=iColumn;
     2142        }
     2143        backward_[iColumn]=i;
     2144      }
     2145    }
     2146    setFeasible(i);
     2147    if (firstNext>=0) {
     2148      // others
     2149      next_[iKey]=firstNext;
     2150      next_[lastNext]=-(iKey+1);
     2151    } else if (iKey<numberColumns) {
     2152      next_[iKey]=-(iKey+1);
     2153    }
     2154  }
     2155  delete [] mark;
     2156  // fill matrix
     2157  double * element =  matrix_->getMutableElements();
     2158  int * row = matrix_->getMutableIndices();
     2159  CoinBigIndex * startColumn = matrix_->getMutableVectorStarts();
     2160  int * length = matrix_->getMutableVectorLengths();
     2161  CoinBigIndex numberElements = startColumn[firstDynamic_];
     2162  for (i=firstDynamic_;i<firstAvailable_;i++) {
     2163    int iColumn = id_[i-firstDynamic_];
     2164    int numberThis = startColumn_[iColumn+1]-startColumn_[iColumn];
     2165    length[i]=numberThis;
     2166    for (CoinBigIndex jBigIndex=startColumn_[iColumn];
     2167         jBigIndex<startColumn_[iColumn+1];jBigIndex++) {
     2168      row[numberElements] = row_[jBigIndex];
     2169      element[numberElements++] = element_[jBigIndex];
     2170    }
     2171    startColumn[i+1]=numberElements;
     2172  }
     2173}
  • trunk/Clp/src/ClpGubDynamicMatrix.hpp

    r799 r800  
    5656  */
    5757  virtual int checkFeasible(ClpSimplex * model,double & sum) const;
     58  /// Cleans data after setWarmStart
     59  void cleanData(ClpSimplex * model);
    5860  //@}
    5961
     
    153155  inline int firstAvailable() const
    154156  { return firstAvailable_;};
     157  /// set first free
     158  inline void setFirstAvailable(int value)
     159  { firstAvailable_ = value;};
    155160  /// first dynamic
    156161  inline int firstDynamic() const
  • trunk/Clp/src/ClpGubMatrix.cpp

    r799 r800  
    1515// at end to get min/max!
    1616#include "ClpGubMatrix.hpp"
     17//#include "ClpGubDynamicMatrix.hpp"
    1718#include "ClpMessage.hpp"
    1819//#define CLP_DEBUG
     
    912913  const int * row = matrix_->getIndices();
    913914  const double * elementByColumn = matrix_->getElements();
     915  //ClpGubDynamicMatrix* gubx =
     916  //dynamic_cast< ClpGubDynamicMatrix*>(this);
     917  //int * id = gubx->id();
    914918  // just count
    915919  for (i=0;i<numberColumnBasic;i++) {
     
    920924      numberElements += length;
    921925      numberBasic++;
     926      //printf("non gub - set %d id %d (column %d) nel %d\n",iSet,id[iColumn-20],iColumn,length);
    922927    } else {
    923928      // in gub set
     
    953958        }
    954959        numberElements+=extra;
     960        //printf("gub - set %d id %d (column %d) nel %d\n",iSet,id[iColumn-20],iColumn,extra);
    955961      }
    956962    }
     
    21202126      double relaxedTolerance=primalTolerance;
    21212127      // we can't really trust infeasibilities if there is primal error
    2122       double error = CoinMin(1.0e-3,model->largestPrimalError());
     2128      double error = CoinMin(1.0e-2,model->largestPrimalError());
    21232129      // allow tolerance at least slightly bigger than standard
    21242130      relaxedTolerance = relaxedTolerance +  error;
     
    23242330      double relaxedTolerance=dualTolerance;
    23252331      // we can't really trust infeasibilities if there is dual error
    2326       double error = CoinMin(1.0e-3,model->largestDualError());
     2332      double error = CoinMin(1.0e-2,model->largestDualError());
    23272333      // allow tolerance at least slightly bigger than standard
    23282334      relaxedTolerance = relaxedTolerance +  error;
  • trunk/Clp/src/ClpMain.cpp

    r799 r800  
    1414#include "CoinPragma.hpp"
    1515#include "CoinHelperFunctions.hpp"
     16#include "CoinSort.hpp"
    1617// History since 1.0 at end
    17 #define CLPVERSION "1.02.02"
     18#define CLPVERSION "1.03.01"
    1819
    1920#include "CoinMpsIO.hpp"
     
    4950
    5051static double totalTime=0.0;
    51 static bool maskMatches(std::string & mask, std::string & check);
     52static bool maskMatches(const int * starts, char ** masks,
     53                        std::string & check);
    5254
    5355//#############################################################################
     
    6062              ClpSimplex empty, bool doPresolve,int switchOff);
    6163static void statistics(ClpSimplex * originalModel, ClpSimplex * model);
     64static void generateCode(const char * fileName,int type);
    6265// Returns next valid field
    6366int CbcOrClpRead_mode=1;
     
    7881    int outputFormat=2;
    7982    int slpValue=-1;
     83    int cppValue=-1;
    8084    int printOptions=0;
    8185    int printMode=0;
     
    232236          std::cout<<"Commands are:"<<std::endl;
    233237          int maxAcross=5;
     238          bool evenHidden=false;
     239          if ((verbose&8)!=0) {
     240            // even hidden
     241            evenHidden = true;
     242            verbose &= ~8;
     243          }
    234244          if (verbose)
    235245            maxAcross=1;
     
    250260            for ( iParam=0; iParam<numberParameters; iParam++ ) {
    251261              int type = parameters[iParam].type();
    252               if (parameters[iParam].displayThis()&&type>=limits[iType]
     262              if ((parameters[iParam].displayThis()||evenHidden)&&
     263                  type>=limits[iType]
    253264                  &&type<limits[iType+1]) {
    254265                if (!across) {
     
    336347            else if (parameters[iParam].type()==SLPVALUE)
    337348              slpValue = value;
     349            else if (parameters[iParam].type()==CPP)
     350              cppValue = value;
    338351            else if (parameters[iParam].type()==PRESOLVEOPTIONS)
    339352              presolveOptions = value;
     
    628641              }
    629642              int status;
     643              if (cppValue>=0) {
     644                // generate code
     645                FILE * fp = fopen("user_driver.cpp","w");
     646                if (fp) {
     647                  // generate enough to do solveOptions
     648                  model2->generateCpp(fp);
     649                  solveOptions.generateCpp(fp);
     650                  fclose(fp);
     651                  // now call generate code
     652                  generateCode("user_driver.cpp",cppValue);
     653                } else {
     654                  std::cout<<"Unable to open file user_driver.cpp"<<std::endl;
     655                }
     656              }
    630657              try {
    631658                status=model2->initialSolve(solveOptions);
     
    14201447            }
    14211448            break;
     1449          case USERCLP:
     1450            // Replace the sample code by whatever you want
     1451            if (goodModels[iModel]) {
     1452              ClpSimplex * thisModel = &models[iModel];
     1453              printf("Dummy user code - model has %d rows and %d columns\n",
     1454                     thisModel->numberRows(),thisModel->numberColumns());
     1455            }
     1456            break;
    14221457          case HELP:
    14231458            std::cout<<"Coin LP version "<<CLPVERSION
     
    14971532                sprintf(format,"%%-%ds",CoinMax(lengthName,8));
    14981533                bool doMask = (printMask!=""&&lengthName);
     1534                int * maskStarts=NULL;
     1535                int maxMasks=0;
     1536                char ** masks =NULL;
     1537                if (doMask) {
     1538                  int nAst =0;
     1539                  const char * pMask2 = printMask.c_str();
     1540                  char pMask[100];
     1541                  int iChar;
     1542                  int lengthMask = strlen(pMask2);
     1543                  assert (lengthMask<100);
     1544                  if (*pMask2=='"') {
     1545                    if (pMask2[lengthMask-1]!='"') {
     1546                      printf("mismatched \" in mask %s\n",pMask2);
     1547                      break;
     1548                    } else {
     1549                      strcpy(pMask,pMask2+1);
     1550                      *strchr(pMask,'"')='\0';
     1551                    }
     1552                  } else if (*pMask2=='\'') {
     1553                    if (pMask2[lengthMask-1]!='\'') {
     1554                      printf("mismatched ' in mask %s\n",pMask2);
     1555                      break;
     1556                    } else {
     1557                      strcpy(pMask,pMask2+1);
     1558                      *strchr(pMask,'\'')='\0';
     1559                    }
     1560                  } else {
     1561                    strcpy(pMask,pMask2);
     1562                  }
     1563                  if (lengthMask>lengthName) {
     1564                    printf("mask %s too long - skipping\n",pMask);
     1565                    break;
     1566                  }
     1567                  maxMasks = 1;
     1568                  for (iChar=0;iChar<lengthMask;iChar++) {
     1569                    if (pMask[iChar]=='*') {
     1570                      nAst++;
     1571                      maxMasks *= (lengthName+1);
     1572                    }
     1573                  }
     1574                  int nEntries = 1;
     1575                  maskStarts = new int[lengthName+2];
     1576                  masks = new char * [maxMasks];
     1577                  char ** newMasks = new char * [maxMasks];
     1578                  int i;
     1579                  for (i=0;i<maxMasks;i++) {
     1580                    masks[i] = new char[lengthName+1];
     1581                    newMasks[i] = new char[lengthName+1];
     1582                  }
     1583                  strcpy(masks[0],pMask);
     1584                  for (int iAst=0;iAst<nAst;iAst++) {
     1585                    int nOldEntries = nEntries;
     1586                    nEntries=0;
     1587                    for (int iEntry = 0;iEntry<nOldEntries;iEntry++) {
     1588                      char * oldMask = masks[iEntry];
     1589                      char * ast = strchr(oldMask,'*');
     1590                      assert (ast);
     1591                      int length = strlen(oldMask)-1;
     1592                      int nBefore = ast-oldMask;
     1593                      int nAfter = length-nBefore;
     1594                      // and add null
     1595                      nAfter++;
     1596                      for (int i=0;i<=lengthName-length;i++) {
     1597                        char * maskOut = newMasks[nEntries];
     1598                        memcpy(maskOut,oldMask,nBefore);
     1599                        for (int k=0;k<i;k++)
     1600                          maskOut[k+nBefore]='?';
     1601                        memcpy(maskOut+nBefore+i,ast+1,nAfter);
     1602                        nEntries++;
     1603                        assert (nEntries<=maxMasks);
     1604                      }
     1605                    }
     1606                    char ** temp = masks;
     1607                    masks = newMasks;
     1608                    newMasks = temp;
     1609                  }
     1610                  // Now extend and sort
     1611                  int * sort = new int[nEntries];
     1612                  for (i=0;i<nEntries;i++) {
     1613                    char * maskThis = masks[i];
     1614                    int length = strlen(maskThis);
     1615                    while (maskThis[length-1]==' ')
     1616                      length--;
     1617                    maskThis[length]='\0';
     1618                    sort[i]=length;
     1619                  }
     1620                  CoinSort_2(sort,sort+nEntries,masks);
     1621                  int lastLength=-1;
     1622                  for (i=0;i<nEntries;i++) {
     1623                    int length = sort[i];
     1624                    while (length>lastLength)
     1625                      maskStarts[++lastLength] = i;
     1626                  }
     1627                  maskStarts[++lastLength]=nEntries;
     1628                  delete [] sort;
     1629                  for (i=0;i<maxMasks;i++)
     1630                    delete [] newMasks[i];
     1631                  delete [] newMasks;
     1632                }
    14991633                if (printMode>2) {
    15001634                  for (iRow=0;iRow<numberRows;iRow++) {
     
    15091643                      type=3;
    15101644                    }
    1511                     if (doMask&&!maskMatches(printMask,rowNames[iRow]))
     1645                    if (doMask&&!maskMatches(maskStarts,masks,rowNames[iRow]))
    15121646                      type=0;
    15131647                    if (type) {
     
    15231657                int numberColumns=models[iModel].numberColumns();
    15241658                double * dualColumnSolution =
    1525                   models[iModel].dualColumnSolution();
     1659  models[iModel].dualColumnSolution();
    15261660                double * primalColumnSolution =
    1527                   models[iModel].primalColumnSolution();
     1661  models[iModel].primalColumnSolution();
    15281662                double * columnLower = models[iModel].columnLower();
    15291663                double * columnUpper = models[iModel].columnUpper();
     
    15391673                    type=3;
    15401674                  }
    1541                   if (doMask&&!maskMatches(printMask,columnNames[iColumn]))
     1675                  if (doMask&&!maskMatches(maskStarts,masks,
     1676                                           columnNames[iColumn]))
    15421677                    type =0;
    15431678                  if (type) {
     
    15521687                if (fp!=stdout)
    15531688                  fclose(fp);
     1689                if (masks) {
     1690                  delete [] maskStarts;
     1691                  for (int i=0;i<maxMasks;i++)
     1692                    delete [] masks[i];
     1693                  delete [] masks;
     1694                }
    15541695              } else {
    15551696                std::cout<<"Unable to open file "<<fileName<<std::endl;
     
    15591700             
    15601701            }
     1702         
    15611703            break;
    15621704          case SAVESOL:
     
    19382080  breakdown("Objective",numberColumns,objective);
    19392081}
    1940 static bool maskMatches(std::string & mask, std::string & check)
     2082static bool maskMatches(const int * starts, char ** masks,
     2083                        std::string & check)
    19412084{
    19422085  // back to char as I am old fashioned
    1943   const char * maskC = mask.c_str();
    19442086  const char * checkC = check.c_str();
    1945   int length = strlen(maskC);
    1946   int lengthCheck;
    1947   for (lengthCheck=length-1;lengthCheck>=0;lengthCheck--) {
    1948     if (maskC[lengthCheck]!='*')
    1949       break;
     2087  int length = strlen(checkC);
     2088  while (checkC[length-1]==' ')
     2089    length--;
     2090  for (int i=starts[length];i<starts[length+1];i++) {
     2091    char * thisMask = masks[i];
     2092    int k;
     2093    for ( k=0;k<length;k++) {
     2094      if (thisMask[k]!='?'&&thisMask[k]!=checkC[k])
     2095        break;
     2096    }
     2097    if (k==length)
     2098      return true;
    19502099  }
    1951   lengthCheck++;
    1952   int lengthC = strlen(checkC);
    1953   if (lengthC>length)
    1954     return false; // can't be true
    1955   if (lengthC<lengthCheck) {
    1956     // last lot must be blank for match
    1957     for (int i=lengthC;i<lengthCheck;i++) {
    1958       if (maskC[i]!=' ')
    1959         return false;
     2100  return false;
     2101}
     2102static void clean(char * temp)
     2103{
     2104  char * put = temp;
     2105  while (*put>=' ')
     2106    put++;
     2107  *put='\0';
     2108}
     2109static void generateCode(const char * fileName,int type)
     2110{
     2111  FILE * fp = fopen(fileName,"r");
     2112  assert (fp);
     2113  int numberLines=0;
     2114#define MAXLINES 500
     2115#define MAXONELINE 200
     2116  char line[MAXLINES][MAXONELINE];
     2117  while (fgets(line[numberLines],MAXONELINE,fp)) {
     2118    assert (numberLines<MAXLINES);
     2119    clean(line[numberLines]);
     2120    numberLines++;
     2121  }
     2122  fclose(fp);
     2123  // add in actual solve
     2124  strcpy(line[numberLines],"5  clpModel->initialSolve(clpSolve);");
     2125  numberLines++;
     2126  fp = fopen(fileName,"w");
     2127  assert (fp);
     2128  char apo='"';   
     2129  char backslash = '\\';
     2130
     2131  fprintf(fp,"#include %cClpSimplex.hpp%c\n",apo,apo);
     2132  fprintf(fp,"#include %cClpSolve.hpp%c\n",apo,apo);
     2133
     2134  fprintf(fp,"\nint main (int argc, const char *argv[])\n{\n");
     2135  fprintf(fp,"  ClpSimplex  model;\n");
     2136  fprintf(fp,"  int status=1;\n");
     2137  fprintf(fp,"  if (argc<2)\n");
     2138  fprintf(fp,"    fprintf(stderr,%cPlease give file name%cn%c);\n",
     2139          apo,backslash,apo);
     2140  fprintf(fp,"  else\n");
     2141  fprintf(fp,"    status=model.readMps(argv[1],true);\n");
     2142  fprintf(fp,"  if (status) {\n");
     2143  fprintf(fp,"    fprintf(stderr,%cBad readMps %%s%cn%c,argv[1]);\n",
     2144                apo,backslash,apo);
     2145  fprintf(fp,"    exit(1);\n");
     2146  fprintf(fp,"  }\n\n");
     2147  fprintf(fp,"  // Now do requested saves and modifications\n");
     2148  fprintf(fp,"  ClpSimplex * clpModel = & model;\n");
     2149  int wanted[9];
     2150  memset(wanted,0,sizeof(wanted));
     2151  wanted[0]=wanted[3]=wanted[5]=wanted[8]=1;
     2152  if (type>0)
     2153    wanted[1]=wanted[6]=1;
     2154  if (type>1)
     2155    wanted[2]=wanted[4]=wanted[7]=1;
     2156  std::string header[9]=
     2157  { "","Save values","Redundant save of default values","Set changed values",
     2158    "Redundant set default values","Solve","Restore values","Redundant restore values","Add to model"};
     2159  for (int iType=0;iType<9;iType++) {
     2160    if (!wanted[iType])
     2161      continue;
     2162    int n=0;
     2163    int iLine;
     2164    for (iLine=0;iLine<numberLines;iLine++) {
     2165      if (line[iLine][0]=='0'+iType) {
     2166        if (!n)
     2167          fprintf(fp,"\n  // %s\n\n",header[iType].c_str());
     2168        n++;
     2169        fprintf(fp,"%s\n",line[iLine]+1);
     2170      }
    19602171    }
    19612172  }
    1962   // need only check this much
    1963   lengthC = CoinMin(lengthC,lengthCheck);
    1964   for (int i=0;i<lengthC;i++) {
    1965     if (maskC[i]!='*'&&maskC[i]!=checkC[i])
    1966       return false;
    1967   }
    1968   return true; // matches
     2173  fprintf(fp,"\n  // Now you would use solution etc etc\n\n");
     2174  fprintf(fp,"  return 0;\n}\n");
     2175  fclose(fp);
     2176  printf("C++ file written to %s\n",fileName);
    19692177}
    19702178/*
    19712179  Version 1.00.00 October 13 2004.
    1972   1.00.01 October 18.  Added basis handline helped/prodded by Thorsten Koch.
     2180  1.00.01 October 18.  Added basis handling helped/prodded by Thorsten Koch.
    19732181  Also modifications to make faster with sbb (I hope I haven't broken anything).
    19742182  1.00.02 March 21 2005.  Redid ClpNonLinearCost to save memory also redid
     
    19832191  branch and cut.
    19842192  1.02.02 May 19 2005.  Stuff for strong branching and some improvements to simplex
     2193  1.03.01 May 24 2006.  Lots done but I can't remember what!
    19852194 */
  • trunk/Clp/src/ClpMatrixBase.cpp

    r799 r800  
    191191  smallestPositive=0.0;
    192192  largestPositive=0.0;
     193}
     194/* The length of a major-dimension vector. */
     195int
     196ClpMatrixBase::getVectorLength(int index) const
     197{
     198  return getVectorLengths()[index];
    193199}
    194200// Says whether it can do partial pricing
     
    572578   is thrown. */
    573579void
    574 ClpMatrixBase::setDimensions(int numrows, int numcols) throw(CoinError)
    575 {
     580ClpMatrixBase::setDimensions(int numrows, int numcols){
    576581  // If odd matrix assume user knows what they are doing
    577582}
  • trunk/Clp/src/ClpMatrixBase.hpp

    r799 r800  
    5555  /** The lengths of the major-dimension vectors. */
    5656  virtual const int * getVectorLengths() const = 0 ;
     57  /** The length of a single major-dimension vector. */
     58  virtual int getVectorLength(int index) const ;
    5759  /** Delete the columns whose indices are listed in <code>indDel</code>. */
    5860  virtual void deleteCols(const int numDel, const int * indDel) = 0;
     
    103105  virtual void scaleRowCopy(ClpModel * model) const
    104106  { };
     107  /// Returns true if can create row copy
     108  virtual bool canGetRowCopy() const
     109  { return true;};
    105110  /** Realy really scales column copy
    106111      Only called if scales already exist.
     
    128133      MUST be at least as large as the current ones otherwise an exception
    129134      is thrown. */
    130   virtual void setDimensions(int numrows, int numcols) throw(CoinError);
     135  virtual void setDimensions(int numrows, int numcols);
    131136  /** Returns largest and smallest elements of both signs.
    132137      Largest refers to largest absolute value.
     
    140145                      int column) const =0;
    141146  /** Unpacks a column into an CoinIndexedvector
    142    ** in packed foramt
     147   ** in packed format
    143148   Note that model is NOT const.  Bounds and objective could
    144149   be modified if doing column generation (just for this variable) */
  • trunk/Clp/src/ClpModel.cpp

    r799 r800  
    1 // Copyright (C) 2002, International Business Machines
     1// copyright (C) 2002, International Business Machines
    22// Corporation and others.  All Rights Reserved.
    33
     
    34553455  return *this;
    34563456}
     3457// Create C++ lines to get to current state
     3458void
     3459ClpModel::generateCpp( FILE * fp)
     3460{
     3461  // Stuff that can't be done easily
     3462  if (!lengthNames_) {
     3463    // no names
     3464    fprintf(fp,"  clpModel->dropNames();\n");
     3465  }
     3466  ClpModel defaultModel;
     3467  ClpModel * other = &defaultModel;
     3468  int iValue1, iValue2;
     3469  double dValue1, dValue2;
     3470  iValue1 = this->maximumIterations();
     3471  iValue2 = other->maximumIterations();
     3472  fprintf(fp,"%d  int save_maximumIterations = clpModel->maximumIterations();\n",iValue1==iValue2 ? 2 : 1);
     3473  fprintf(fp,"%d  clpModel->setMaximumIterations(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     3474  fprintf(fp,"%d  clpModel->setMaximumIterations(save_maximumIterations);\n",iValue1==iValue2 ? 7 : 6);
     3475  dValue1 = this->primalTolerance();
     3476  dValue2 = other->primalTolerance();
     3477  fprintf(fp,"%d  double save_primalTolerance = clpModel->primalTolerance();\n",dValue1==dValue2 ? 2 : 1);
     3478  fprintf(fp,"%d  clpModel->setPrimalTolerance(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3479  fprintf(fp,"%d  clpModel->setPrimalTolerance(save_primalTolerance);\n",dValue1==dValue2 ? 7 : 6);
     3480  dValue1 = this->dualTolerance();
     3481  dValue2 = other->dualTolerance();
     3482  fprintf(fp,"%d  double save_dualTolerance = clpModel->dualTolerance();\n",dValue1==dValue2 ? 2 : 1);
     3483  fprintf(fp,"%d  clpModel->setDualTolerance(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3484  fprintf(fp,"%d  clpModel->setDualTolerance(save_dualTolerance);\n",dValue1==dValue2 ? 7 : 6);
     3485  iValue1 = this->numberIterations();
     3486  iValue2 = other->numberIterations();
     3487  fprintf(fp,"%d  int save_numberIterations = clpModel->numberIterations();\n",iValue1==iValue2 ? 2 : 1);
     3488  fprintf(fp,"%d  clpModel->setNumberIterations(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     3489  fprintf(fp,"%d  clpModel->setNumberIterations(save_numberIterations);\n",iValue1==iValue2 ? 7 : 6);
     3490  dValue1 = this->maximumSeconds();
     3491  dValue2 = other->maximumSeconds();
     3492  fprintf(fp,"%d  double save_maximumSeconds = clpModel->maximumSeconds();\n",dValue1==dValue2 ? 2 : 1);
     3493  fprintf(fp,"%d  clpModel->setMaximumSeconds(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3494  fprintf(fp,"%d  clpModel->setMaximumSeconds(save_maximumSeconds);\n",dValue1==dValue2 ? 7 : 6);
     3495  dValue1 = this->optimizationDirection();
     3496  dValue2 = other->optimizationDirection();
     3497  fprintf(fp,"%d  double save_optimizationDirection = clpModel->optimizationDirection();\n",dValue1==dValue2 ? 2 : 1);
     3498  fprintf(fp,"%d  clpModel->setOptimizationDirection(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3499  fprintf(fp,"%d  clpModel->setOptimizationDirection(save_optimizationDirection);\n",dValue1==dValue2 ? 7 : 6);
     3500  dValue1 = this->objectiveScale();
     3501  dValue2 = other->objectiveScale();
     3502  fprintf(fp,"%d  double save_objectiveScale = clpModel->objectiveScale();\n",dValue1==dValue2 ? 2 : 1);
     3503  fprintf(fp,"%d  clpModel->setObjectiveScale(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3504  fprintf(fp,"%d  clpModel->setObjectiveScale(save_objectiveScale);\n",dValue1==dValue2 ? 7 : 6);
     3505  dValue1 = this->rhsScale();
     3506  dValue2 = other->rhsScale();
     3507  fprintf(fp,"%d  double save_rhsScale = clpModel->rhsScale();\n",dValue1==dValue2 ? 2 : 1);
     3508  fprintf(fp,"%d  clpModel->setRhsScale(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3509  fprintf(fp,"%d  clpModel->setRhsScale(save_rhsScale);\n",dValue1==dValue2 ? 7 : 6);
     3510  iValue1 = this->scalingFlag();
     3511  iValue2 = other->scalingFlag();
     3512  fprintf(fp,"%d  int save_scalingFlag = clpModel->scalingFlag();\n",iValue1==iValue2 ? 2 : 1);
     3513  fprintf(fp,"%d  clpModel->scaling(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     3514  fprintf(fp,"%d  clpModel->scaling(save_scalingFlag);\n",iValue1==iValue2 ? 7 : 6);
     3515  dValue1 = this->getSmallElementValue();
     3516  dValue2 = other->getSmallElementValue();
     3517  fprintf(fp,"%d  double save_getSmallElementValue = clpModel->getSmallElementValue();\n",dValue1==dValue2 ? 2 : 1);
     3518  fprintf(fp,"%d  clpModel->setSmallElementValue(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     3519  fprintf(fp,"%d  clpModel->setSmallElementValue(save_getSmallElementValue);\n",dValue1==dValue2 ? 7 : 6);
     3520  iValue1 = this->logLevel();
     3521  iValue2 = other->logLevel();
     3522  fprintf(fp,"%d  int save_logLevel = clpModel->logLevel();\n",iValue1==iValue2 ? 2 : 1);
     3523  fprintf(fp,"%d  clpModel->setLogLevel(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     3524  fprintf(fp,"%d  clpModel->setLogLevel(save_logLevel);\n",iValue1==iValue2 ? 7 : 6);
     3525}
  • trunk/Clp/src/ClpModel.hpp

    r799 r800  
    1414//#define COIN_USE_CLP
    1515//#endif
    16 #include "ClpMatrixBase.hpp"
     16#include "ClpPackedMatrix.hpp"
    1717#include "CoinMessageHandler.hpp"
    1818#include "ClpParameters.hpp"
     
    571571      and new is used)
    572572      So up to user to delete current.  This was used where
    573       matrices were being rotated.
     573      matrices were being rotated. ClpModel takes ownership.
    574574  */
    575575   void replaceMatrix(ClpMatrixBase * matrix,bool deleteCurrent=false);
     576  /** Replace Clp Matrix (current is not deleted unless told to
     577      and new is used) So up to user to delete current.  This was used where
     578      matrices were being rotated.  This version changes CoinPackedMatrix
     579      to ClpPackedMatrix.  ClpModel takes ownership.
     580  */
     581   inline void replaceMatrix(CoinPackedMatrix * matrix,
     582                             bool deleteCurrent=false)
     583  { replaceMatrix(new ClpPackedMatrix(matrix),deleteCurrent);};
    576584   /// Objective value
    577585   inline double objectiveValue() const {
     
    764772    }
    765773#endif
     774    /// Create C++ lines to get to current state
     775    void generateCpp( FILE * fp);
    766776  //@}
    767777
  • trunk/Clp/src/ClpNonLinearCost.hpp

    r799 r800  
    5050{ status &= ~(15<<4);status |= (CLP_SAME<<4);}
    5151// Use second version to get more speed
    52 #define FAST_CLPNON
     52//#define FAST_CLPNON
    5353#ifndef FAST_CLPNON
    5454#define CLP_METHOD1 ((method_&1)!=0)
  • trunk/Clp/src/ClpPackedMatrix.cpp

    r799 r800  
    28382838   is thrown. */
    28392839void
    2840 ClpPackedMatrix::setDimensions(int numrows, int numcols) throw(CoinError)
     2840ClpPackedMatrix::setDimensions(int numrows, int numcols)
    28412841{
    28422842  matrix_->setDimensions(numrows,numcols);
  • trunk/Clp/src/ClpPackedMatrix.hpp

    r799 r800  
    5252   virtual const int * getVectorLengths() const
    5353  { return matrix_->getVectorLengths();} ;
     54  /** The length of a single major-dimension vector. */
     55  virtual int getVectorLength(int index) const
     56  { return matrix_->getVectorSize(index);};
    5457
    5558    /** Delete the columns whose indices are listed in <code>indDel</code>. */
     
    165168      MUST be at least as large as the current ones otherwise an exception
    166169      is thrown. */
    167   virtual void setDimensions(int numrows, int numcols) throw(CoinError);
     170  virtual void setDimensions(int numrows, int numcols);
    168171   //@}
    169172
  • trunk/Clp/src/ClpPlusMinusOneMatrix.cpp

    r799 r800  
    159159  } else {
    160160    numberRows_ ++; //  correct
     161    // but number should be same as rhs
     162    assert (numberRows_<=rhs.getNumRows());
     163    numberRows_ = rhs.getNumRows();
    161164    columnOrdered_ = true;
    162165  }
     
    18711874void
    18721875ClpPlusMinusOneMatrix::setDimensions(int newnumrows, int newnumcols)
    1873   throw(CoinError)
    18741876{
    18751877  if (newnumrows < 0)
  • trunk/Clp/src/ClpPlusMinusOneMatrix.hpp

    r799 r800  
    115115      MUST be at least as large as the current ones otherwise an exception
    116116      is thrown. */
    117   virtual void setDimensions(int numrows, int numcols) throw(CoinError);
     117  virtual void setDimensions(int numrows, int numcols);
    118118  /// Just checks matrix valid - will say if dimensions not quite right if detail
    119119  void checkValid(bool detail) const;
  • trunk/Clp/src/ClpPrimalColumnSteepest.cpp

    r799 r800  
    180180  // we can't really trust infeasibilities if there is dual error
    181181  // this coding has to mimic coding in checkDualSolution
    182   double error = CoinMin(1.0e-3,model_->largestDualError());
     182  double error = CoinMin(1.0e-2,model_->largestDualError());
    183183  // allow tolerance at least slightly bigger than standard
    184184  tolerance = tolerance +  error;
     
    273273      if (switchType==5) {
    274274        numberLook *= 5; // needs tuning for gub
    275         if (model_->numberIterations()%1000==0)
     275        if (model_->numberIterations()%1000==0&&model_->logLevel()>1) {
    276276          printf("numels %d ratio %g wanted %d look %d\n",
    277277                 sizeFactorization_,ratio,numberWanted,numberLook);
     278        }
    278279        // Update duals and row djs
    279280        // Do partial pricing
     
    486487    infeasible_->setNumElements(number);
    487488  }
    488   if(model_->numberIterations()<model_->lastBadIteration()+200) {
     489  if(model_->numberIterations()<model_->lastBadIteration()+200&&
     490     model_->factorization()->pivots()>10) {
    489491    // we can't really trust infeasibilities if there is dual error
    490492    double checkTolerance = 1.0e-8;
    491     if (!model_->factorization()->pivots())
    492       checkTolerance = 1.0e-6;
    493493    if (model_->largestDualError()>checkTolerance)
    494494      tolerance *= model_->largestDualError()/checkTolerance;
     
    606606  // we can't really trust infeasibilities if there is dual error
    607607  // this coding has to mimic coding in checkDualSolution
    608   double error = CoinMin(1.0e-3,model_->largestDualError());
     608  double error = CoinMin(1.0e-2,model_->largestDualError());
    609609  // allow tolerance at least slightly bigger than standard
    610610  tolerance = tolerance +  error;
     
    711711  // we can't really trust infeasibilities if there is dual error
    712712  // this coding has to mimic coding in checkDualSolution
    713   double error = CoinMin(1.0e-3,model_->largestDualError());
     713  double error = CoinMin(1.0e-2,model_->largestDualError());
    714714  // allow tolerance at least slightly bigger than standard
    715715  tolerance = tolerance +  error;
     
    951951  // we can't really trust infeasibilities if there is dual error
    952952  // this coding has to mimic coding in checkDualSolution
    953   double error = CoinMin(1.0e-3,model_->largestDualError());
     953  double error = CoinMin(1.0e-2,model_->largestDualError());
    954954  // allow tolerance at least slightly bigger than standard
    955955  tolerance = tolerance +  error;
     
    12211221  // we can't really trust infeasibilities if there is dual error
    12221222  // this coding has to mimic coding in checkDualSolution
    1223   double error = CoinMin(1.0e-3,model_->largestDualError());
     1223  double error = CoinMin(1.0e-2,model_->largestDualError());
    12241224  // allow tolerance at least slightly bigger than standard
    12251225  tolerance = tolerance +  error;
     
    14131413  // we can't really trust infeasibilities if there is dual error
    14141414  // this coding has to mimic coding in checkDualSolution
    1415   double error = CoinMin(1.0e-3,model_->largestDualError());
     1415  double error = CoinMin(1.0e-2,model_->largestDualError());
    14161416  // allow tolerance at least slightly bigger than standard
    14171417  tolerance = tolerance +  error;
     
    17351735  // we can't really trust infeasibilities if there is dual error
    17361736  // this coding has to mimic coding in checkDualSolution
    1737   double error = CoinMin(1.0e-3,model_->largestDualError());
     1737  double error = CoinMin(1.0e-2,model_->largestDualError());
    17381738  // allow tolerance at least slightly bigger than standard
    17391739  tolerance = tolerance +  error;
     
    18431843  // we can't really trust infeasibilities if there is dual error
    18441844  // this coding has to mimic coding in checkDualSolution
    1845   double error = CoinMin(1.0e-3,model_->largestDualError());
     1845  double error = CoinMin(1.0e-2,model_->largestDualError());
    18461846  // allow tolerance at least slightly bigger than standard
    18471847  tolerance = tolerance +  error;
     
    19921992  // we can't really trust infeasibilities if there is dual error
    19931993  // this coding has to mimic coding in checkDualSolution
    1994   double error = CoinMin(1.0e-3,model_->largestDualError());
     1994  double error = CoinMin(1.0e-2,model_->largestDualError());
    19951995  // allow tolerance at least slightly bigger than standard
    19961996  tolerance = tolerance +  error;
     
    33743374  // we can't really trust infeasibilities if there is dual error
    33753375  // this coding has to mimic coding in checkDualSolution
    3376   double error = CoinMin(1.0e-3,model_->largestDualError());
     3376  double error = CoinMin(1.0e-2,model_->largestDualError());
    33773377  // allow tolerance at least slightly bigger than standard
    33783378  tolerance = tolerance +  error;
     
    35023502  // we can't really trust infeasibilities if there is dual error
    35033503  // this coding has to mimic coding in checkDualSolution
    3504   double error = CoinMin(1.0e-3,model_->largestDualError());
     3504  double error = CoinMin(1.0e-2,model_->largestDualError());
    35053505  // allow tolerance at least slightly bigger than standard
    35063506  tolerance = tolerance +  error;
     
    36133613  double * duals2 = duals-numberColumns;
    36143614  int chunk = CoinMin(1024,(numberColumns+nSlacks)/32);
    3615   if (model_->numberIterations()%1000==0) {
     3615  if (model_->numberIterations()%1000==0&&model_->logLevel()>1) {
    36163616    printf("%d wanted, nSlacks %d, chunk %d\n",numberWanted,nSlacks,chunk);
    36173617    int i;
  • trunk/Clp/src/ClpQuadraticObjective.cpp

    r799 r800  
    692692
    693693  // Btran basic costs
     694  model->factorization()->updateColumnTranspose(workSpace,&arrayVector);
    694695  double * work = workSpace->denseVector();
    695   model->factorization()->updateColumnTranspose(workSpace,&arrayVector);
    696696  ClpFillN(work,numberRows,0.0);
    697697  // now look at dual solution
  • trunk/Clp/src/ClpSimplex.cpp

    r799 r800  
    554554  double lastError=COIN_DBL_MAX;
    555555  int iRefine;
    556   double * work = workSpace->denseVector();
    557556  CoinIndexedVector * thisVector = arrayVector;
    558557  CoinIndexedVector * lastVector = previousVector;
    559558  factorization_->updateColumn(workSpace,thisVector);
     559  double * work = workSpace->denseVector();
    560560#ifdef CLP_DEBUG
    561561  if (numberIterations_==-3840) {
     
    15321532      // need to reject something
    15331533      int iSequence;
    1534       if (algorithm_<0)
     1534      if (algorithm_>0)
    15351535        iSequence = sequenceIn_;
    15361536      else
     
    20512051  double relaxedTolerance=primalTolerance_;
    20522052  // we can't really trust infeasibilities if there is primal error
    2053   double error = CoinMin(1.0e-3,largestPrimalError_);
     2053  double error = CoinMin(1.0e-2,largestPrimalError_);
    20542054  // allow tolerance at least slightly bigger than standard
    20552055  relaxedTolerance = relaxedTolerance +  error;
     
    21642164  double relaxedTolerance=dualTolerance_;
    21652165  // we can't really trust infeasibilities if there is dual error
    2166   double error = CoinMin(1.0e-3,largestDualError_);
     2166  double error = CoinMin(1.0e-2,largestDualError_);
    21672167  // allow tolerance at least slightly bigger than standard
    21682168  relaxedTolerance = relaxedTolerance +  error;
     
    23452345  double relaxedToleranceP=primalTolerance_;
    23462346  // we can't really trust infeasibilities if there is primal error
    2347   double error = CoinMin(1.0e-3,largestPrimalError_);
     2347  double error = CoinMin(1.0e-2,largestPrimalError_);
    23482348  // allow tolerance at least slightly bigger than standard
    23492349  relaxedToleranceP = relaxedToleranceP +  error;
     
    23542354  double relaxedToleranceD=dualTolerance;
    23552355  // we can't really trust infeasibilities if there is dual error
    2356   error = CoinMin(1.0e-3,largestDualError_);
     2356  error = CoinMin(1.0e-2,largestDualError_);
    23572357  // allow tolerance at least slightly bigger than standard
    23582358  relaxedToleranceD = relaxedToleranceD +  error;
     
    25242524{
    25252525  bool goodMatrix=true;
     2526  spareIntArray_[0]=0;
     2527  if (!matrix_->canGetRowCopy())
     2528    makeRowCopy=false; // switch off row copy if can't produce
    25262529  int saveLevel=handler_->logLevel();
    25272530  // Arrays will be there and correct size unless what is 63
     
    47434746   barrier.setCholesky(cholesky);
    47444747 } else {
    4745    ClpCholeskyUfl * cholesky = new ClpCholeskyUfl();
     4748   ClpCholeskyBase * cholesky = new ClpCholeskyBase();
     4749   // not yetClpCholeskyUfl * cholesky = new ClpCholeskyUfl();
    47464750   cholesky->setKKT(true);
    47474751   barrier.setCholesky(cholesky);
     
    50075011  primalTolerance_ = otherModel.primalTolerance_;
    50085012  delete dualRowPivot_;
    5009   dualRowPivot_ = otherModel.dualRowPivot_->clone(false);
     5013  dualRowPivot_ = otherModel.dualRowPivot_->clone(true);
    50105014  delete primalColumnPivot_;
    5011   primalColumnPivot_ = otherModel.primalColumnPivot_->clone(false);
     5015  primalColumnPivot_ = otherModel.primalColumnPivot_->clone(true);
    50125016  perturbation_ = otherModel.perturbation_;
    50135017  specialOptions_ = otherModel.specialOptions_;
     
    73217325              <<x<<model_->sequenceWithin(iSequence)
    73227326              <<CoinMessageEol;
     7327          // if Gub then needs to be sequenceIn_
     7328          int save=model_->sequenceIn();
     7329          model_->setSequenceIn(iSequence);
    73237330          model_->setFlagged(iSequence);
     7331          model_->setSequenceIn(save);
    73247332          //printf("flagging %d from loop\n",iSequence);
    73257333          startCheck();
     
    87898797  }
    87908798}
     8799// Create C++ lines to get to current state
     8800void
     8801ClpSimplex::generateCpp( FILE * fp, bool defaultFactor)
     8802{
     8803  ClpModel::generateCpp(fp);
     8804  ClpSimplex defaultModel;
     8805  ClpSimplex * other = &defaultModel;
     8806  int iValue1, iValue2;
     8807  double dValue1, dValue2;
     8808  // Stuff that can't be done easily
     8809  if (factorizationFrequency()==other->factorizationFrequency()) {
     8810    if (defaultFactor) {
     8811      fprintf(fp,"3  // For branchAndBound this may help\n");
     8812      fprintf(fp,"3  clpModel->defaultFactorizationFrequency();\n");
     8813    } else {
     8814      // tell user about default
     8815      fprintf(fp,"3  // For initialSolve you don't need below but ...\n");
     8816      fprintf(fp,"3  // clpModel->defaultFactorizationFrequency();\n");
     8817    }
     8818  }
     8819  iValue1 = this->factorizationFrequency();
     8820  iValue2 = other->factorizationFrequency();
     8821  fprintf(fp,"%d  int save_factorizationFrequency = clpModel->factorizationFrequency();\n",iValue1==iValue2 ? 2 : 1);
     8822  fprintf(fp,"%d  clpModel->setFactorizationFrequency(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     8823  fprintf(fp,"%d  clpModel->setFactorizationFrequency(save_factorizationFrequency);\n",iValue1==iValue2 ? 7 : 6);
     8824  dValue1 = this->dualBound();
     8825  dValue2 = other->dualBound();
     8826  fprintf(fp,"%d  double save_dualBound = clpModel->dualBound();\n",dValue1==dValue2 ? 2 : 1);
     8827  fprintf(fp,"%d  clpModel->setDualBound(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     8828  fprintf(fp,"%d  clpModel->setDualBound(save_dualBound);\n",dValue1==dValue2 ? 7 : 6);
     8829  dValue1 = this->infeasibilityCost();
     8830  dValue2 = other->infeasibilityCost();
     8831  fprintf(fp,"%d  double save_infeasibilityCost = clpModel->infeasibilityCost();\n",dValue1==dValue2 ? 2 : 1);
     8832  fprintf(fp,"%d  clpModel->setInfeasibilityCost(%g);\n",dValue1==dValue2 ? 4 : 3,dValue1);
     8833  fprintf(fp,"%d  clpModel->setInfeasibilityCost(save_infeasibilityCost);\n",dValue1==dValue2 ? 7 : 6);
     8834  iValue1 = this->perturbation();
     8835  iValue2 = other->perturbation();
     8836  fprintf(fp,"%d  int save_perturbation = clpModel->perturbation();\n",iValue1==iValue2 ? 2 : 1);
     8837  fprintf(fp,"%d  clpModel->setPerturbation(%d);\n",iValue1==iValue2 ? 4 : 3,iValue1);
     8838  fprintf(fp,"%d  clpModel->setPerturbation(save_perturbation);\n",iValue1==iValue2 ? 7 : 6);
     8839}
  • trunk/Clp/src/ClpSimplex.hpp

    r799 r800  
    932932  inline int maximumBasic() const
    933933  { return maximumBasic_;};
     934  /// Create C++ lines to get to current state
     935  void generateCpp( FILE * fp,bool defaultFactor=false);
    934936  /** For advanced options
    935937      1 - Don't keep changing infeasibility weight
  • trunk/Clp/src/ClpSimplexDual.cpp

    r799 r800  
    16981698  double tolerance = dualTolerance_;
    16991699  // we can't really trust infeasibilities if there is dual error
    1700   double error = CoinMin(1.0e-3,largestDualError_);
     1700  double error = CoinMin(1.0e-2,largestDualError_);
    17011701  // allow tolerance at least slightly bigger than standard
    17021702  tolerance = tolerance +  error;
     
    36143614            cleanDuals=1;
    36153615            // make sure fake bounds are back
     3616            //computeObjectiveValue();
    36163617            changeBounds(true,NULL,changeCost);
     3618            //computeObjectiveValue();
    36173619            createRim(4);
    36183620            // make sure duals are current
    3619             //computeDuals(givenDuals);
    3620             //checkDualSolution();
     3621            computeDuals(givenDuals);
     3622            checkDualSolution();
    36213623            //if (numberDualInfeasibilities_)
    36223624              numberChanged_=1; // force something to happen
    3623               //else
    3624               computeObjectiveValue();
     3625            //else
     3626            //computeObjectiveValue();
    36253627          }
    36263628          if (lastCleaned<numberIterations_&&numberTimesOptimal_<4&&
     
    39763978           limit&&
    39773979           !numberAtFakeBound()&&!numberDualInfeasibilities_) {
     3980    //printf("lim %g obj %g %g\n",limit,objectiveValue_,objectiveValue());
    39783981    problemStatus_=1;
    39793982    secondaryStatus_ = 1; // and say was on cutoff
     
    41864189  double maximumFraction = 1.0e-5;
    41874190  double constantPerturbation = 100.0*dualTolerance_;
    4188   const int * lengths = matrix_->getVectorLengths();
    41894191  int maxLength=0;
    41904192  int minLength=numberRows_;
     
    42464248  for (iColumn=0;iColumn<numberColumns_;iColumn++) {
    42474249    if (columnLowerWork_[iColumn]<columnUpperWork_[iColumn]) {
    4248       int length = lengths[iColumn];
     4250      int length = matrix_->getVectorLength(iColumn);
    42494251      if (length>2) {
    42504252        maxLength = CoinMax(maxLength,length);
     
    44524454      }
    44534455      if (value) {
    4454         int length = lengths[iColumn];
     4456        int length = matrix_->getVectorLength(iColumn);
    44554457        if (length>3) {
    44564458          length = (int) ((double) length * factor);
  • trunk/Clp/src/ClpSimplexNonlinear.cpp

    r799 r800  
    774774  normUnflagged=1.0;
    775775  double dualTolerance2 = CoinMin(1.0e-8,1.0e-2*dualTolerance_);
    776   double dualTolerance3 = CoinMin(1.0e-3,1.0e3*dualTolerance_);
     776  double dualTolerance3 = CoinMin(1.0e-2,1.0e3*dualTolerance_);
    777777  if (!numberNonBasic) {
    778778    //if (nonLinearCost_->sumInfeasibilities()>1.0e-4)
     
    23322332  if (saveObj-currentObj<1.0e-5&&nTotalPasses>2000) {
    23332333    normUnflagged=0.0;
    2334     double dualTolerance3 = CoinMin(1.0e-3,1.0e3*dualTolerance_);
     2334    double dualTolerance3 = CoinMin(1.0e-2,1.0e3*dualTolerance_);
    23352335    for (int iSequence=0;iSequence<numberColumns_+numberRows_;iSequence++) {
    23362336      switch(getStatus(iSequence)) {
  • trunk/Clp/src/ClpSimplexPrimal.cpp

    r799 r800  
    638638{
    639639  int dummy; // for use in generalExpanded
     640  int saveFirstFree=firstFree_;
    640641  // number of pivots done
    641642  int numberPivots = factorization_->pivots();
     
    11551156  if (goToDual)
    11561157    problemStatus_=10; // try dual
     1158  // make sure first free monotonic
     1159  if (firstFree_>=0&&saveFirstFree>=0) {
     1160    firstFree_=saveFirstFree;
     1161    nextSuperBasic(1,NULL);
     1162  }
    11571163#if 0
    11581164  double thisObj = progress->lastObjective(0);
     
    23732379    if (largestDualError_>1.0e-5)
    23742380      checkValue=1.0e-1;
    2375     if (solveType_==1&&((saveDj*dualIn_<1.0e-20&&!ifValuesPass)||
    2376         fabs(saveDj-dualIn_)>checkValue*(1.0+fabs(saveDj)))) {
     2381    if (!ifValuesPass&&solveType_==1&&(saveDj*dualIn_<1.0e-20||
     2382        fabs(saveDj-dualIn_)>checkValue*(1.0+fabs(saveDj))||
     2383                        fabs(dualIn_)<dualTolerance_)) {
    23772384      char x = isColumn(sequenceIn_) ? 'C' :'R';
    23782385      handler_->message(CLP_PRIMAL_DJ,messages_)
     
    23942401        // take on more relaxed criterion
    23952402        if (saveDj*dualIn_<1.0e-20||
    2396             fabs(saveDj-dualIn_)>2.0e-1*(1.0+fabs(dualIn_))) {
     2403            fabs(saveDj-dualIn_)>2.0e-1*(1.0+fabs(dualIn_))||
     2404            fabs(dualIn_)<dualTolerance_) {
    23972405          // need to reject something
    23982406          char x = isColumn(sequenceIn_) ? 'C' :'R';
     
    24372445          int ii = index[i];
    24382446          dj_[ii] += element[ii];
     2447          reducedCost_[ii] = dj_[ii];
    24392448          element[ii]=0.0;
    24402449        }
  • trunk/Clp/src/ClpSolve.cpp

    r799 r800  
    2222#include "ClpNetworkMatrix.hpp"
    2323#endif
     24#include "ClpLinearObjective.hpp"
    2425#include "ClpSolve.hpp"
    2526#include "ClpPackedMatrix.hpp"
     
    373374  double time2;
    374375  ClpMatrixBase * saveMatrix=NULL;
     376  ClpObjective * savedObjective=NULL;
     377  if (objective_->type()>=2&&optimizationDirection_==0) {
     378    // pretend linear
     379    savedObjective=objective_;
     380    // make up objective
     381    double * obj = new double[numberColumns_];
     382    for (int i=0;i<numberColumns_;i++) {
     383      double l = fabs(columnLower_[i]);
     384      double u = fabs(columnUpper_[i]);
     385      obj[i]=0.0;
     386      if (CoinMin(l,u)<1.0e20) {
     387        if (l<u)
     388          obj[i]=1.0+CoinDrand48()*1.0e-2;
     389        else
     390          obj[i]=-1.0-CoinDrand48()*1.0e-2;
     391      }
     392    }
     393    objective_= new ClpLinearObjective(obj,numberColumns_);
     394    delete [] obj;
     395  }
    375396  ClpSimplex * model2 = this;
    376397  bool interrupt = (options.getSpecialOption(2)==0);
     
    619640  int numberColumns = model2->numberColumns();
    620641  int numberRows = model2->numberRows();
    621   // If not all slack basis - switch off all
     642  // If not all slack basis - switch off all except sprint
    622643  int number=0;
    623644  int iRow;
     
    628649    doIdiot=0;
    629650    doCrash=0;
    630     doSprint=0;
     651    //doSprint=0;
    631652  }
    632653  if (options.getSpecialOption(3)==0) {
     
    12551276   
    12561277    // We will need arrays to choose variables.  These are too big but ..
    1257     double * weight = new double [numberRows+originalNumberColumns];
     1278    float * weight = new float [numberRows+originalNumberColumns];
    12581279    int * sort = new int [numberRows+originalNumberColumns];
    12591280    int numberSort=0;
    12601281    // We are going to add slacks to get feasible.
    12611282    // initial list will just be artificials
    1262     // first we will set all variables as close to zero as possible
    12631283    int iColumn;
    12641284    const double * columnLower = model2->columnLower();
    12651285    const double * columnUpper = model2->columnUpper();
    12661286    double * columnSolution = model2->primalColumnSolution();
    1267    
     1287
     1288    // See if we have costed slacks
     1289    int * negSlack = new int[numberRows];
     1290    int * posSlack = new int[numberRows];
     1291    int iRow;
     1292    for (iRow=0;iRow<numberRows;iRow++) {
     1293      negSlack[iRow]=-1;
     1294      posSlack[iRow]=-1;
     1295    }
     1296    const double * element = model2->matrix()->getElements();
     1297    const int * row = model2->matrix()->getIndices();
     1298    const CoinBigIndex * columnStart = model2->matrix()->getVectorStarts();
     1299    const int * columnLength = model2->matrix()->getVectorLengths();
    12681300    for (iColumn=0;iColumn<originalNumberColumns;iColumn++) {
    1269       double value =0.0;
    1270       if (columnLower[iColumn]>0.0)
    1271         value = columnLower[iColumn];
    1272       else if (columnUpper[iColumn]<0.0)
    1273         value = columnUpper[iColumn];
    1274       columnSolution[iColumn]=value;
     1301      if (!columnSolution[iColumn]||fabs(columnSolution[iColumn])>1.0e20) {
     1302        double value =0.0;
     1303        if (columnLower[iColumn]>0.0)
     1304          value = columnLower[iColumn];
     1305        else if (columnUpper[iColumn]<0.0)
     1306          value = columnUpper[iColumn];
     1307        columnSolution[iColumn]=value;
     1308      }
     1309      if (columnLength[iColumn]==1) {
     1310        int jRow=row[columnStart[iColumn]];
     1311        if (!columnLower[iColumn]) {
     1312          if (element[columnStart[iColumn]]>0.0&&posSlack[jRow]<0)
     1313            posSlack[jRow]=iColumn;
     1314          else if (element[columnStart[iColumn]]<0.0&&negSlack[jRow]<0)
     1315            negSlack[jRow]=iColumn;
     1316        } else if (!columnUpper[iColumn]) {
     1317          if (element[columnStart[iColumn]]<0.0&&posSlack[jRow]<0)
     1318            posSlack[jRow]=iColumn;
     1319          else if (element[columnStart[iColumn]]>0.0&&negSlack[jRow]<0)
     1320            negSlack[jRow]=iColumn;
     1321        }
     1322      }
    12751323    }
    12761324    // now see what that does to row solution
     
    12781326    CoinZeroN (rowSolution,numberRows);
    12791327    model2->times(1.0,columnSolution,rowSolution);
    1280    
     1328    // See if we can adjust using costed slacks
     1329    double penalty=infeasibilityCost_*optimizationDirection_;
     1330    const double * lower = model2->rowLower();
     1331    const double * upper = model2->rowUpper();
     1332    for (iRow=0;iRow<numberRows;iRow++) {
     1333      if (lower[iRow]>rowSolution[iRow]+1.0e-8) {
     1334        int jColumn = posSlack[iRow];
     1335        if (jColumn>=0) {
     1336          if (columnSolution[jColumn])
     1337            continue;
     1338          double difference = lower[iRow]-rowSolution[iRow];
     1339          double elementValue = element[columnStart[jColumn]];
     1340          if (elementValue>0.0) {
     1341            double movement = CoinMin(difference/elementValue,columnUpper[jColumn]);
     1342            columnSolution[jColumn] = movement;
     1343            rowSolution[iRow] += movement*elementValue;
     1344          } else {
     1345            double movement = CoinMax(difference/elementValue,columnLower[jColumn]);
     1346            columnSolution[jColumn] = movement;
     1347            rowSolution[iRow] += movement*elementValue;
     1348          }
     1349        }
     1350      } else if (upper[iRow]<rowSolution[iRow]-1.0e-8) {
     1351        int jColumn = negSlack[iRow];
     1352        if (jColumn>=0) {
     1353          if (columnSolution[jColumn])
     1354            continue;
     1355          double difference = upper[iRow]-rowSolution[iRow];
     1356          double elementValue = element[columnStart[jColumn]];
     1357          if (elementValue<0.0) {
     1358            double movement = CoinMin(difference/elementValue,columnUpper[jColumn]);
     1359            columnSolution[jColumn] = movement;
     1360            rowSolution[iRow] += movement*elementValue;
     1361          } else {
     1362            double movement = CoinMax(difference/elementValue,columnLower[jColumn]);
     1363            columnSolution[jColumn] = movement;
     1364            rowSolution[iRow] += movement*elementValue;
     1365          }
     1366        }
     1367      }
     1368    }
     1369    delete [] negSlack;
     1370    delete [] posSlack;
    12811371    int * addStarts = new int [numberRows+1];
    12821372    int * addRow = new int[numberRows];
    12831373    double * addElement = new double[numberRows];
    1284     const double * lower = model2->rowLower();
    1285     const double * upper = model2->rowUpper();
    12861374    addStarts[0]=0;
    12871375    int numberArtificials=0;
    12881376    double * addCost = new double [numberRows];
    1289     const double penalty=1.0e8*optimizationDirection_;
    1290     int iRow;
    12911377    for (iRow=0;iRow<numberRows;iRow++) {
    1292       if (lower[iRow]>rowSolution[iRow]) {
     1378      if (lower[iRow]>rowSolution[iRow]+1.0e-8) {
    12931379        addRow[numberArtificials]=iRow;
    12941380        addElement[numberArtificials]=1.0;
     
    12961382        numberArtificials++;
    12971383        addStarts[numberArtificials]=numberArtificials;
    1298       } else if (upper[iRow]<rowSolution[iRow]) {
     1384      } else if (upper[iRow]<rowSolution[iRow]-1.0e-8) {
    12991385        addRow[numberArtificials]=iRow;
    13001386        addElement[numberArtificials]=-1.0;
     
    13581444    }
    13591445    int i;
     1446    // Just do this number of passes in Sprint
     1447    if (doSprint>0)
     1448      maxSprintPass=options.getExtraInfo(1);
     1449    // but if big use to get ratio
     1450    int ratio=3;
     1451    if (maxSprintPass>1000) {
     1452      ratio = CoinMax(maxSprintPass/1000,3);
     1453      maxSprintPass= maxSprintPass %1000;
     1454      printf("%d passes wanted with ratio of %d\n",maxSprintPass,ratio);
     1455    }
     1456    // Just take this number of columns in small problem
     1457    int smallNumberColumns = CoinMin(ratio*numberRows,numberColumns);
     1458    smallNumberColumns = CoinMax(smallNumberColumns,3000);
     1459    smallNumberColumns = CoinMin(smallNumberColumns,numberColumns);
     1460    //int smallNumberColumns = CoinMin(12*numberRows/10,numberColumns);
     1461    //smallNumberColumns = CoinMax(smallNumberColumns,3000);
     1462    //smallNumberColumns = CoinMax(smallNumberColumns,numberRows+1000);
     1463    // redo as may have changed
     1464    columnLower = model2->columnLower();
     1465    columnUpper = model2->columnUpper();
     1466    columnSolution = model2->primalColumnSolution();
    13601467    // Set up initial list
     1468    numberSort=0;
    13611469    if (numberArtificials) {
    13621470      numberSort=numberArtificials;
    13631471      for (i=0;i<numberSort;i++)
    13641472        sort[i] = i+originalNumberColumns;
    1365     } else {
    1366       numberSort = CoinMin(numberRows_,numberColumns_);
    1367       for (i=0;i<numberSort;i++)
    1368         sort[i] = i;
    1369     }
     1473    }
     1474    // maybe a solution there already
     1475    for (iColumn=0;iColumn<originalNumberColumns;iColumn++) {
     1476      if (model2->getColumnStatus(iColumn)==basic)
     1477        sort[numberSort++]=iColumn;
     1478    }
     1479    for (iColumn=0;iColumn<originalNumberColumns;iColumn++) {
     1480      if (model2->getColumnStatus(iColumn)!=basic) {
     1481        if (columnSolution[iColumn]>columnLower[iColumn]&&
     1482            columnSolution[iColumn]<columnUpper[iColumn])
     1483          sort[numberSort++]=iColumn;
     1484      }
     1485    }
     1486    numberSort = CoinMin(numberSort,smallNumberColumns);
    13701487   
    1371     // redo as will have changed
    1372     columnLower = model2->columnLower();
    1373     columnUpper = model2->columnUpper();
    13741488    int numberColumns = model2->numberColumns();
    13751489    double * fullSolution = model2->primalColumnSolution();
    13761490   
    1377     // Just do this number of passes in Sprint
    1378     if (doSprint>0)
    1379       maxSprintPass=options.getExtraInfo(1);
     1491   
    13801492    int iPass;
    13811493    double lastObjective=1.0e31;
     
    13831495    model2->setInitialDenseFactorization(true);
    13841496   
    1385     // Just take this number of columns in small problem
    1386     int smallNumberColumns = CoinMin(3*numberRows,numberColumns);
    1387     smallNumberColumns = CoinMax(smallNumberColumns,3000);
    1388     smallNumberColumns = CoinMin(smallNumberColumns,numberColumns);
    1389     //int smallNumberColumns = CoinMin(12*numberRows/10,numberColumns);
    1390     //smallNumberColumns = CoinMax(smallNumberColumns,3000);
    1391     //smallNumberColumns = CoinMax(smallNumberColumns,numberRows+1000);
    13921497    // We will be using all rows
    13931498    int * whichRows = new int [numberRows];
     
    14031508      ClpSimplex small(model2,numberRows,whichRows,numberSort,sort);
    14041509      small.setPerturbation(model2->perturbation());
     1510      small.setInfeasibilityCost(model2->infeasibilityCost());
     1511      if (model2->factorizationFrequency()==200) {
     1512        // User did not touch preset
     1513        small.defaultFactorizationFrequency();
     1514      }
    14051515      // now see what variables left out do to row solution
    14061516      double * rowSolution = model2->primalRowSolution();
     
    14481558             numberRows,model2->primalRowSolution());
    14491559      // get reduced cost for large problem
    1450       CoinMemcpyN(model2->objective(),numberColumns,weight);
    1451       model2->transposeTimes(-1.0,small.dualRowSolution(),weight);
     1560      double * djs = model2->dualColumnSolution();
     1561      CoinMemcpyN(model2->objective(),numberColumns,djs);
     1562      model2->transposeTimes(-1.0,small.dualRowSolution(),djs);
    14521563      int numberNegative=0;
    14531564      double sumNegative = 0.0;
    14541565      // now massage weight so all basic in plus good djs
     1566      // first count and do basic
     1567      numberSort=0;
    14551568      for (iColumn=0;iColumn<numberColumns;iColumn++) {
    1456         double dj = weight[iColumn]*optimizationDirection_;
     1569        double dj = djs[iColumn]*optimizationDirection_;
    14571570        double value = fullSolution[iColumn];
    1458         if (model2->getColumnStatus(iColumn)==ClpSimplex::basic)
    1459           dj = -1.0e50;
    1460         else if (dj<0.0&&value<columnUpper[iColumn])
    1461           dj = dj;
    1462         else if (dj>0.0&&value>columnLower[iColumn])
    1463           dj = -dj;
    1464         else if (columnUpper[iColumn]>columnLower[iColumn])
    1465           dj = fabs(dj);
    1466         else
    1467           dj = 1.0e50;
    1468         weight[iColumn] = dj;
    1469         if (dj<-dualTolerance_&&dj>-1.0e50) {
     1571        if (model2->getColumnStatus(iColumn)==ClpSimplex::basic) {
     1572          sort[numberSort++] = iColumn;
     1573        } else if (dj<-dualTolerance_&&value<columnUpper[iColumn]) {
    14701574          numberNegative++;
    14711575          sumNegative -= dj;
     1576        } else if (dj>dualTolerance_&&value>columnLower[iColumn]) {
     1577          numberNegative++;
     1578          sumNegative += dj;
    14721579        }
    1473         sort[iColumn] = iColumn;
    14741580      }
    14751581      handler_->message(CLP_SPRINT,messages_)
     
    14781584        <<CoinMessageEol;
    14791585      if ((small.objectiveValue()*optimizationDirection_>lastObjective-1.0e-7&&iPass>5)||
    1480           !small.numberIterations()||
     1586          (!small.numberIterations()&&iPass)||
    14811587          iPass==maxSprintPass-1||small.status()==3) {
    14821588       
     
    14841590      } else {
    14851591        lastObjective = small.objectiveValue()*optimizationDirection_;
     1592        double tolerance;
     1593        double averageNegDj = sumNegative/((double) (numberNegative+1));
     1594        if (numberNegative+numberSort>smallNumberColumns)
     1595          tolerance = -dualTolerance_;
     1596        else
     1597          tolerance = 10.0*averageNegDj;
     1598        int saveN = numberSort;
     1599        for (iColumn=0;iColumn<numberColumns;iColumn++) {
     1600          double dj = djs[iColumn]*optimizationDirection_;
     1601          double value = fullSolution[iColumn];
     1602          if (model2->getColumnStatus(iColumn)!=ClpSimplex::basic) {
     1603            if (dj<-dualTolerance_&&value<columnUpper[iColumn])
     1604              dj = dj;
     1605            else if (dj>dualTolerance_&&value>columnLower[iColumn])
     1606              dj = -dj;
     1607            else if (columnUpper[iColumn]>columnLower[iColumn])
     1608              dj = fabs(dj);
     1609            else
     1610              dj = 1.0e50;
     1611            if (dj<tolerance) {
     1612              weight[numberSort] = dj;
     1613              sort[numberSort++] = iColumn;
     1614            }
     1615          }
     1616        }
    14861617        // sort
    1487         CoinSort_2(weight,weight+numberColumns,sort);
    1488         numberSort = smallNumberColumns;
     1618        CoinSort_2(weight+saveN,weight+numberSort,sort+saveN);
     1619        numberSort = CoinMin(smallNumberColumns,numberSort);
    14891620      }
    14901621    }
     
    15251656#ifndef SLIM_CLP
    15261657    //printf("***** experimental pretty crude barrier\n");
    1527     //#define SAVEIT 1
     1658    //#define SAVEIT 2
    15281659#ifndef SAVEIT
    15291660#define BORROW
     
    17781909        // solve
    17791910        model2->setPerturbation(100);
     1911        if (model2->factorizationFrequency()==200) {
     1912          // User did not touch preset
     1913          model2->defaultFactorizationFrequency();
     1914        }
    17801915#if 1
    17811916        // throw some into basis
     
    18221957          delete [] dsort;
    18231958        }
     1959        // model2->allSlackBasis();
    18241960        if (gap<1.0e-3*((double) (numberRows+numberColumns))) {
    18251961          if (saveUpper) {
     
    20352171  perturbation_=savePerturbation;
    20362172  scalingFlag_=saveScaling;
     2173  // If faking objective - put back correct one
     2174  if (savedObjective) {
     2175    delete objective_;
     2176    objective_=savedObjective;
     2177  }
    20372178  return finalStatus;
    20382179}
     
    20822223 
    20832224}
     2225// Constructor when you really know what you are doing
     2226ClpSolve::ClpSolve ( SolveType method, PresolveType presolveType,
     2227             int numberPasses, int options[6],
     2228             int extraInfo[6], int independentOptions[3])
     2229{
     2230  method_ = method;
     2231  presolveType_=presolveType;
     2232  numberPasses_=numberPasses;
     2233  int i;
     2234  for (i=0;i<6;i++)
     2235    options_[i]=options[i];
     2236  for (i=0;i<6;i++)
     2237    extraInfo_[i]=extraInfo[i];
     2238  for (i=0;i<3;i++)
     2239    independentOptions_[i]=independentOptions[i];
     2240}
    20842241
    20852242// Copy constructor.
     
    21762333  independentOptions_[0]= trueFalse ? 1 : 0;
    21772334}
     2335#include <string>
     2336// Generates code for above constructor
     2337void
     2338ClpSolve::generateCpp(FILE * fp)
     2339{
     2340  std::string solveType[] = {
     2341    "ClpSolve::useDual",
     2342    "ClpSolve::usePrimal",
     2343    "ClpSolve::usePrimalorSprint",
     2344    "ClpSolve::useBarrier",
     2345    "ClpSolve::useBarrierNoCross",
     2346    "ClpSolve::automatic",
     2347    "ClpSolve::notImplemented"
     2348  };
     2349  std::string presolveType[] =  {
     2350    "ClpSolve::presolveOn",
     2351    "ClpSolve::presolveOff",
     2352    "ClpSolve::presolveNumber",
     2353    "ClpSolve::presolveNumberCost"
     2354  };
     2355  fprintf(fp,"3  ClpSolve::SolveType method = %s;\n",solveType[method_].c_str());
     2356  fprintf(fp,"3  ClpSolve::PresolveType presolveType = %s;\n",
     2357    presolveType[presolveType_].c_str());
     2358  fprintf(fp,"3  int numberPasses = %d;\n",numberPasses_);
     2359  fprintf(fp,"3  int options[] = {%d,%d,%d,%d,%d,%d};\n",
     2360    options_[0],options_[1],options_[2],
     2361    options_[3],options_[4],options_[5]);
     2362  fprintf(fp,"3  int extraInfo[] = {%d,%d,%d,%d,%d,%d};\n",
     2363    extraInfo_[0],extraInfo_[1],extraInfo_[2],
     2364    extraInfo_[3],extraInfo_[4],extraInfo_[5]);
     2365  fprintf(fp,"3  int independentOptions[] = {%d,%d,%d};\n",
     2366    independentOptions_[0],independentOptions_[1],independentOptions_[2]);
     2367  fprintf(fp,"3  ClpSolve clpSolve(method,presolveType,numberPasses,\n");
     2368  fprintf(fp,"3                    options,extraInfo,independentOptions);\n");
     2369}
  • trunk/Clp/src/ClpSolve.hpp

    r799 r800  
    4141  //@{
    4242  /// Default constructor
    43     ClpSolve (  );
    44 
     43  ClpSolve (  );
     44  /// Constructor when you really know what you are doing
     45  ClpSolve ( SolveType method, PresolveType presolveType,
     46             int numberPasses, int options[6],
     47             int extraInfo[6], int independentOptions[3]);
     48  /// Generates code for above constructor
     49  void generateCpp(FILE * fp);
    4550  /// Copy constructor.
    4651  ClpSolve(const ClpSolve &);
Note: See TracChangeset for help on using the changeset viewer.