Changeset 344


Ignore:
Timestamp:
Apr 6, 2004 1:19:33 PM (16 years ago)
Author:
forrest
Message:

event handling

Location:
trunk
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpDynamicMatrix.cpp

    r341 r344  
    248248  originalMatrix->getMutableVectorStarts()[numberColumns]=originalMatrix->getNumElements();
    249249  originalMatrix->setDimensions(newRowSize,-1);
     250  numberActiveColumns_=firstDynamic_;
    250251  // redo number of columns
    251252  numberColumns = matrix_->getNumCols();
     
    843844    else
    844845      setStatus(iSet,ClpSimplex::atUpperBound);
     846    if (lowerSet_[iSet]==upperSet_[iSet])
     847      setStatus(iSet,ClpSimplex::isFixed);
    845848    if (getStatus(iSet)!=model->getStatus(sequenceOut))
    846849      printf("** set %d status %d, var status %d\n",iSet,
     
    875878    //printf("rhs for set %d (%d) is %g %g - cost %g\n",iSet,i,model->lowerRegion(0)[i+numberStaticRows_],
    876879    //     model->upperRegion(0)[i+numberStaticRows_],model->costRegion(0)[i+numberStaticRows_]);
    877     }
     880    //}
    878881  }
    879882#endif
     
    15101513  for (i=0;i<numberSets_;i++) {
    15111514    if (toIndex_[i]<0) {
    1512       assert(keyValue(i)>=lowerSet_[i]&&keyValue(i)<=upperSet_[i]);
     1515      //assert(keyValue(i)>=lowerSet_[i]&&keyValue(i)<=upperSet_[i]);
    15131516      n++;
    15141517    }
     
    19111914        upper[numberInSet]=COIN_DBL_MAX;
    19121915      else
    1913         lower[numberInSet]= columnUpper_[j];
     1916        upper[numberInSet]= columnUpper_[j];
    19141917      back[numberInSet++]=j;
    19151918      j = next_[j];
  • trunk/ClpModel.cpp

    r342 r344  
    1515#include "CoinTime.hpp"
    1616#include "ClpModel.hpp"
     17#include "ClpEventHandler.hpp"
    1718#include "ClpPackedMatrix.hpp"
    1819#include "CoinPackedVector.hpp"
     
    7071  handler_ = new CoinMessageHandler();
    7172  handler_->setLogLevel(1);
     73  eventHandler_ = new ClpEventHandler();
    7274  messages_ = ClpMessage();
    7375  CoinSeedRandom(1234567);
     
    116118  delete [] status_;
    117119  status_=NULL;
     120  delete eventHandler_;
     121  eventHandler_=NULL;
    118122}
    119123//#############################################################################
     
    139143                                const double * rowObjective)
    140144{
     145  // save event handler in case already set
     146  ClpEventHandler * handler = eventHandler_->clone();
    141147  gutsOfDelete();
     148  eventHandler_ = handler;
    142149  numberRows_=numberRows;
    143150  numberColumns_=numberColumns;
     
    304311   else
    305312    handler_ = rhs.handler_;
     313  eventHandler_ = rhs.eventHandler_->clone();
    306314  messages_ = rhs.messages_;
    307315  intParam_[ClpMaxNumIteration] = rhs.intParam_[ClpMaxNumIteration];
     
    13221330                     bool dropNames, bool dropIntegers)
    13231331{
    1324 #if 0
    1325   // Could be recoded to be faster and take less memory
    1326   // and to allow re-ordering and duplicates etc
    1327   gutsOfCopy(*rhs,true);
    1328   int numberRowsWhole = rhs->numberRows();
    1329   int * delRow = new int[numberRowsWhole];
    1330   memset(delRow,0,numberRowsWhole*sizeof(int));
    1331   int i;
    1332   for (i=0;i<numberRows;i++) {
    1333     int iRow=whichRow[i];
    1334     assert (iRow>=0&&iRow<numberRowsWhole);
    1335     delRow[iRow]=1;
    1336   }
    1337   numberRows=0;
    1338   for (i=0;i<numberRowsWhole;i++) {
    1339     if (delRow[i]==0)
    1340       delRow[numberRows++]=i;
    1341   }
    1342   deleteRows(numberRows,delRow);
    1343   delete [] delRow;
    1344   int numberColumnsWhole = rhs->numberColumns();
    1345   int * delColumn = new int[numberColumnsWhole];
    1346   memset(delColumn,0,numberColumnsWhole*sizeof(int));
    1347   for (i=0;i<numberColumns;i++) {
    1348     int iColumn=whichColumn[i];
    1349     assert (iColumn>=0&&iColumn<numberColumnsWhole);
    1350     delColumn[iColumn]=1;
    1351   }
    1352   numberColumns=0;
    1353   for (i=0;i<numberColumnsWhole;i++) {
    1354     if (delColumn[i]==0)
    1355       delColumn[numberColumns++]=i;
    1356   }
    1357   deleteColumns(numberColumns,delColumn);
    1358   delete [] delColumn;
    1359 #else
    13601332  defaultHandler_ = rhs->defaultHandler_;
    13611333  if (defaultHandler_)
     
    13631335   else
    13641336    handler_ = rhs->handler_;
     1337  eventHandler_ = rhs->eventHandler_->clone();
    13651338  messages_ = rhs->messages_;
    13661339  intParam_[ClpMaxNumIteration] = rhs->intParam_[ClpMaxNumIteration];
     
    14761449                                        numberColumns,whichColumn);
    14771450  }
    1478 #endif
    14791451  CoinSeedRandom(1234567);
    14801452}
     
    17661738  }
    17671739}
     1740// Pass in Event handler (cloned and deleted at end)
     1741void
     1742ClpModel::passInEventHandler(const ClpEventHandler * eventHandler)
     1743{
     1744  delete eventHandler_;
     1745  eventHandler_ = eventHandler->clone();
     1746}
  • trunk/ClpSimplex.cpp

    r343 r344  
    2020#include "ClpNonLinearCost.hpp"
    2121#include "ClpMessage.hpp"
     22#include "ClpEventHandler.hpp"
    2223#include "ClpLinearObjective.hpp"
    2324#include "ClpHelperFunctions.hpp"
     
    12671268    solution_[sequenceOut_]=valueOut_;
    12681269  } else {
     1270    assert (fabs(theta_)>1.0e-13);
    12691271    // flip from bound to bound
    12701272    // As Nonlinear costs may have moved bounds (to more feasible)
     
    59705972#endif
    59715973}
     5974// Pass in Event handler (cloned and deleted at end)
     5975void
     5976ClpSimplex::passInEventHandler(const ClpEventHandler * eventHandler)
     5977{
     5978  delete eventHandler_;
     5979  eventHandler_ = eventHandler->clone();
     5980  eventHandler_->setSimplex(this);
     5981}
  • trunk/ClpSimplexDual.cpp

    r343 r344  
    9494#include "CoinHelperFunctions.hpp"
    9595#include "ClpSimplexDual.hpp"
     96#include "ClpEventHandler.hpp"
    9697#include "ClpFactorization.hpp"
    9798#include "CoinPackedMatrix.hpp"
     
    373374        break;
    374375      }
    375 
     376      if (ifValuesPass&&!saveDuals) {
     377        // end of values pass
     378        ifValuesPass=0;
     379        int status = eventHandler_->event(ClpEventHandler::endOfValuesPass);
     380        if (status>=0) {
     381          problemStatus_=status;
     382          secondaryStatus_=ClpEventHandler::endOfValuesPass;
     383          break;
     384        }
     385      }
     386      // Check event
     387      {
     388        int status = eventHandler_->event(ClpEventHandler::endOfFactorization);
     389        if (status>=0) {
     390          problemStatus_=status;
     391          secondaryStatus_=ClpEventHandler::endOfFactorization;
     392          break;
     393        }
     394      }
    376395      // Do iterations
    377396      whileIterating(saveDuals);
     
    957976          returnCode=3;
    958977          break;
     978        }
     979        // Check event
     980        {
     981          int status = eventHandler_->event(ClpEventHandler::endOfIteration);
     982          if (status>=0) {
     983            problemStatus_=status;
     984            secondaryStatus_=ClpEventHandler::endOfIteration;
     985            returnCode=4;
     986            break;
     987          }
    959988        }
    960989      } else {
  • trunk/ClpSimplexPrimal.cpp

    r343 r344  
    8989#include "ClpPrimalColumnPivot.hpp"
    9090#include "ClpMessage.hpp"
     91#include "ClpEventHandler.hpp"
    9192#include <cfloat>
    9293#include <cassert>
     
    384385      }
    385386
    386       if (firstFree_<0)
    387         ifValuesPass=0;
     387      if (firstFree_<0) {
     388        if (ifValuesPass) {
     389          // end of values pass
     390          ifValuesPass=0;
     391          int status = eventHandler_->event(ClpEventHandler::endOfValuesPass);
     392          if (status>=0) {
     393            problemStatus_=status;
     394            secondaryStatus_=ClpEventHandler::endOfValuesPass;
     395            break;
     396          }
     397        }
     398      }
     399      // Check event
     400      {
     401        int status = eventHandler_->event(ClpEventHandler::endOfFactorization);
     402        if (status>=0) {
     403          problemStatus_=status;
     404          secondaryStatus_=ClpEventHandler::endOfFactorization;
     405          break;
     406        }
     407      }
    388408      // Iterate
    389409      whileIterating(ifValuesPass ? 1 : 0);
     
    23682388      returnCode =-2; // refactorize
    23692389    }
     2390    // Check event
     2391    {
     2392      int status = eventHandler_->event(ClpEventHandler::endOfIteration);
     2393      if (status>=0) {
     2394        problemStatus_=status;
     2395        secondaryStatus_=ClpEventHandler::endOfIteration;
     2396        returnCode=4;
     2397      }
     2398    }
    23702399  }
    23712400  if (solveType_==2&&(returnCode == -2||returnCode==-3)) {
  • trunk/Makefile.Clp

    r343 r344  
    1414LIBSRC += ClpDualRowPivot.cpp
    1515LIBSRC += ClpDualRowSteepest.cpp
     16LIBSRC += ClpEventHandler.cpp
    1617LIBSRC += ClpFactorization.cpp
    1718LIBSRC += ClpMatrixBase.cpp
     
    2728LIBSRC += ClpDummyMatrix.cpp
    2829LIBSRC += ClpGubMatrix.cpp
     30LIBSRC += ClpDynamicMatrix.cpp
     31LIBSRC += ClpDynamicExampleMatrix.cpp
    2932LIBSRC += ClpPrimalColumnDantzig.cpp
    3033LIBSRC += ClpPrimalColumnPivot.cpp
  • trunk/Samples/testGub.cpp

    r343 r344  
    3131    printf("Using ClpDynamicExampleMatrix\n");
    3232  }
    33   FILE * fp;
    34   if ((fp=fopen("in.sol","r"))) {
    35     double * solution = model.primalColumnSolution();
    36     int numberColumns = model.numberColumns();
    37     int numberRows = model.numberRows();
    38     char * status = new char [numberColumns];
    39     char * rowStatus = new char[numberRows];
    40     int n;
    41     n = fread(solution,sizeof(double),numberColumns,fp);
    42     assert (n==numberColumns);
    43     n = fread(status,sizeof(char),numberColumns,fp);
    44     assert (n==numberColumns);
    45     n = fread(model.primalRowSolution(),sizeof(double),numberRows,fp);
    46     assert (n==numberRows);
    47     n = fread(rowStatus,sizeof(char),numberRows,fp);
    48     assert (n==numberRows);
    49 #if 0
    50     int i;
    51     for (i=0;i<numberColumns;i++) {
    52       if (status[i]==0)
    53         model.setStatus(i,ClpSimplex::basic);
    54       else if (status[i]==1)
    55         model.setStatus(i,ClpSimplex::atLowerBound);
    56       else if (status[i]==2)
    57         model.setStatus(i,ClpSimplex::atUpperBound);
    58       else if (status[i]==3)
    59         model.setStatus(i,ClpSimplex::isFixed);
    60     }
    61     for (i=0;i<numberRows;i++) {
    62       if (rowStatus[i]==0)
    63         model.setRowStatus(i,ClpSimplex::basic);
    64       else if (rowStatus[i]==1)
    65         model.setRowStatus(i,ClpSimplex::atLowerBound);
    66       else if (rowStatus[i]==2)
    67         model.setRowStatus(i,ClpSimplex::atUpperBound);
    68       else if (rowStatus[i]==3)
    69         model.setRowStatus(i,ClpSimplex::isFixed);
    70     }
    71 #endif
    72     fclose(fp);
    73     delete [] status;
    74     delete [] rowStatus;
    75     printf("checking solution\n");
    76     model.primal(1);
    77   }
    7833  // find gub
    7934  int numberRows = model.numberRows();
     
    9853    columnLower = model.columnLower();
    9954    columnUpper = model.columnUpper();
    100 #if 0
    101     CoinMpsIO writer;
    102     writer.setMpsData(*model.matrix(), COIN_DBL_MAX,
    103                       model.getColLower(), model.getColUpper(),
    104                       model.getObjCoefficients(),
    105                       (const char*) 0 /*integrality*/,
    106                       model.getRowLower(), model.getRowUpper(),
    107                       NULL, NULL);
    108     writer.writeMps("cza.mps",0,0,1);
    109 #endif
    11055  }
    11156  double * lower = new double[numberRows];
     
    271216      gubStart[iSet+1]=numberColumns;
    272217    }
     218    printf("** Before adding matrix there are %d rows and %d columns\n",
     219           model2.numberRows(),model2.numberColumns());
    273220    if (argc>3) {
    274221      ClpDynamicMatrix * newMatrix = new ClpDynamicMatrix(&model2,numberGub,
     
    290237      newMatrix->setRefreshFrequency(1000);
    291238    }
     239    printf("** While after adding matrix there are %d rows and %d columns\n",
     240           model2.numberRows(),model2.numberColumns());
    292241    model2.setSpecialOptions(4); // exactly to bound
    293242    // For now scaling off
     
    453402          abort();
    454403      }
     404      // Coding below may not work if gub rows not at end
    455405      FILE * fp=fopen ("xx.sol","w");
    456406      fwrite(gubSolution,sizeof(double),numberTotalColumns,fp);
  • trunk/Test/ClpMain.cpp

    r343 r344  
    1414#include "CoinPragma.hpp"
    1515#include "CoinHelperFunctions.hpp"
    16 #define CLPVERSION "0.99.4"
     16#define CLPVERSION "0.99.5"
    1717
    1818#include "CoinMpsIO.hpp"
  • trunk/Test/Makefile.test

    r298 r344  
    3535TESTSRC += unitTest.cpp
    3636TESTSRC += MyMessageHandler.cpp
     37TESTSRC += MyEventHandler.cpp
    3738
    3839###############################################################################
  • trunk/Test/unitTest.cpp

    r343 r344  
    2828#include "ClpPlusMinusOneMatrix.hpp"
    2929#include "MyMessageHandler.hpp"
     30#include "MyEventHandler.hpp"
    3031
    3132#include "ClpPresolve.hpp"
     
    494495                         m.getRowLower(),m.getRowUpper());
    495496    solution.dual();
     497    // Test event handling
     498    MyEventHandler handler;
     499    solution.passInEventHandler(&handler);
     500    int numberRows=solution.numberRows();
     501    // make sure values pass has something to do
     502    for (int i=0;i<numberRows;i++)
     503      solution.setRowStatus(i,ClpSimplex::basic);
     504    solution.primal(1);
     505    assert (solution.secondaryStatus()==102); // Came out at end of pass
    496506  }
    497507  // Test Message handler
  • trunk/include/ClpModel.hpp

    r335 r344  
    1414#include "ClpParameters.hpp"
    1515#include "ClpObjective.hpp"
     16class ClpEventHandler;
    1617
    1718// Plus infinity
     
    251252       3 - scaled problem optimal - unscaled problem has dual infeasibilities
    252253       4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities
     254       100 up - translation of enum from ClpEventHandler
    253255   */
    254256   inline int secondaryStatus() const            { return secondaryStatus_; }
     
    410412   void setLogLevel(int value)    { handler_->setLogLevel(value); }
    411413   int logLevel() const           { return handler_->logLevel(); }
     414   /// Pass in Event handler (cloned and deleted at end)
     415   void passInEventHandler(const ClpEventHandler * eventHandler);
    412416   /// length of names (0 means no names0
    413417   inline int lengthNames() const { return lengthNames_; }
     
    582586  /// Flag to say if default handler (so delete)
    583587  bool defaultHandler_;
     588  /// Event handler
     589  ClpEventHandler * eventHandler_;
    584590  /// Row names
    585591  std::vector<std::string> rowNames_;
  • trunk/include/ClpSimplex.hpp

    r343 r344  
    148148  void borrowModel(ClpModel & otherModel);
    149149  void borrowModel(ClpSimplex & otherModel);
     150   /// Pass in Event handler (cloned and deleted at end)
     151   void passInEventHandler(const ClpEventHandler * eventHandler);
    150152  //@}
    151153
Note: See TracChangeset for help on using the changeset viewer.