Changeset 222 for branches


Ignore:
Timestamp:
Oct 9, 2003 12:12:15 PM (16 years ago)
Author:
forrest
Message:

Start of mini sprint

Location:
branches/pre
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • branches/pre/ClpPrimalColumnPivot.cpp

    r63 r222  
    6868{
    6969}
     70/* Returns number of extra columns for sprint algorithm - 0 means off.
     71   Also number of iterations before recompute
     72*/
     73int
     74ClpPrimalColumnPivot::numberSprintColumns(int & numberIterations) const
     75{
     76  return 0;
     77}
     78// Switch off sprint idea
     79void
     80ClpPrimalColumnPivot::switchOffSprint()
     81{
     82}
  • branches/pre/ClpPrimalColumnSteepest.cpp

    r221 r222  
    340340    //printf("numels %d ratio %g wanted %d\n",numberElements,ratio,numberWanted);
    341341  }
     342  int numberElements = model_->factorization()->numberElements();
     343  int numberRows = model_->numberRows();
     344  // ratio is done on number of rows here
     345  double ratio = (double) numberElements/(double) numberRows;
    342346  if(switchType==4) {
    343347    // Still in devex mode
    344     int numberElements = model_->factorization()->numberElements();
    345     int numberRows = model_->numberRows();
    346     // ratio is done on number of rows here
    347     double ratio = (double) numberElements/(double) numberRows;
    348348    // Go to steepest if lot of iterations?
    349349    if (ratio<1.0) {
     
    368368      updates->clear();
    369369    }
    370     //if (model_->numberIterations()%1000==0)
    371     //printf("numels %d ratio %g wanted %d\n",numberElements,ratio,numberWanted);
     370    if (model_->numberIterations()%1000==0)
     371    printf("numels %d ratio %g wanted %d type x\n",numberElements,ratio,numberWanted);
    372372  }
    373373  if (switchType<4) {
     
    377377      numberWanted = max(2000,number/8);
    378378    } else {
    379       int numberElements = model_->factorization()->numberElements();
    380       double ratio = (double) numberElements/(double) model_->numberRows();
    381379      if (ratio<1.0) {
    382380        numberWanted = max(2000,number/20);
    383381      } else if (ratio<5.0) {
    384382        numberWanted = max(2000,number/10);
    385         numberWanted = max(numberWanted,numberColumns/20);
     383        numberWanted = max(numberWanted,numberColumns/40);
    386384      } else if (ratio<10.0) {
    387385        numberWanted = max(2000,number/8);
     
    397395      }
    398396    }
     397    if (model_->numberIterations()%1000==0)
     398    printf("numels %d ratio %g wanted %d type %d\n",numberElements,ratio,numberWanted,
     399    switchType);
    399400  }
    400401
     
    32493250  return numberInfeasible==0;
    32503251}
     3252/* Returns number of extra columns for sprint algorithm - 0 means off.
     3253   Also number of iterations before recompute
     3254*/
     3255int
     3256ClpPrimalColumnSteepest::numberSprintColumns(int & numberIterations) const
     3257{
     3258  return 0;
     3259}
     3260// Switch off sprint idea
     3261void
     3262ClpPrimalColumnSteepest::switchOffSprint()
     3263{
     3264}
  • branches/pre/ClpSimplex.cpp

    r212 r222  
    46974697  return (specialOptions_&8)!=0;
    46984698}
     4699/* This constructor modifies original ClpSimplex and stores
     4700   original stuff in created ClpSimplex.  It is only to be used in
     4701   conjunction with originalModel */
     4702ClpSimplex::ClpSimplex (ClpSimplex * wholeModel,
     4703                        int numberColumns, const int * whichColumns)
     4704{
     4705
     4706  // Set up dummy row selection list
     4707  int * whichRow = new int [numberRows_];
     4708  int iRow;
     4709  for (iRow=0;iRow<numberRows_;iRow++)
     4710    whichRow[iRow]=iRow;
     4711  // ClpModel stuff (apart from numberColumns_)
     4712  matrix_ = wholeModel->matrix_;
     4713  rowCopy_ = wholeModel->rowCopy_;
     4714  if (wholeModel->rowCopy_) {
     4715    wholeModel->rowCopy_ = wholeModel->rowCopy_->subsetClone(numberRows_,whichRow,
     4716                                                             numberColumns,whichColumns);
     4717  } else {
     4718    wholeModel->rowCopy_=NULL;
     4719  }
     4720  assert (wholeModel->matrix_);
     4721  wholeModel->matrix_ = wholeModel->matrix_->subsetClone(numberRows_,whichRow,
     4722                                        numberColumns,whichColumns);
     4723  delete [] whichRow;
     4724  // Now ClpSimplex stuff and status_
     4725  ClpPrimalColumnSteepest * steep =
     4726    dynamic_cast< ClpPrimalColumnSteepest*>(wholeModel->primalColumnPivot_);
     4727  assert (steep);
     4728  primalColumnPivot_ = wholeModel->primalColumnPivot_;
     4729  wholeModel->primalColumnPivot_ = new ClpPrimalColumnSteepest(0);
     4730  nonLinearCost_ = wholeModel->nonLinearCost_;
     4731
     4732  // Now main arrays
     4733  int iColumn;
     4734  int numberTotal = numberRows_+numberColumns;
     4735  // mapping
     4736  int * mapping = new int[numberRows_+numberColumns_];
     4737  for (iColumn=0;iColumn<numberColumns_;iColumn++)
     4738    mapping[iColumn]=-1;
     4739  for (iRow=0;iRow<numberRows_;iRow++)
     4740    mapping[iRow+numberColumns_] = iRow+numberColumns;
     4741  lower_ = wholeModel->lower_;
     4742  wholeModel->lower_ = new double [numberTotal];
     4743  memcpy(wholeModel->lower_+numberColumns,lower_+numberColumns_,numberRows_*sizeof(double));
     4744  for (iColumn=0;iColumn<numberColumns;iColumn++) {
     4745    int jColumn = whichColumns[iColumn];
     4746    wholeModel->lower_[iColumn]=lower_[jColumn];
     4747    // and pointer back
     4748    mapping[jColumn]=iColumn;
     4749  }
     4750  // Re-define pivotVariable_
     4751  for (iRow=0;iRow<numberRows_;iRow++) {
     4752    int iPivot = pivotVariable_[iRow];
     4753    pivotVariable_[iRow]=mapping[iPivot];
     4754  }
     4755  // Reverse mapping (so extended version of whichColumns)
     4756  int iBig;
     4757  for (iColumn=0;iColumn<numberTotal;iColumn++)
     4758    if (mapping[iColumn]>=0)
     4759      mapping[iBig++]=iColumn;
     4760  // Save mapping somewhere - doesn't matter
     4761  rowUpper_ = (double *) mapping;
     4762  upper_ = wholeModel->upper_;
     4763  wholeModel->upper_ = new double [numberTotal];
     4764  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4765    int jColumn = mapping[iColumn];
     4766    wholeModel->upper_[iColumn]=upper_[jColumn];
     4767  }
     4768  cost_ = wholeModel->cost_;
     4769  wholeModel->cost_ = new double [numberTotal];
     4770  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4771    int jColumn = mapping[iColumn];
     4772    wholeModel->cost_[iColumn]=cost_[jColumn];
     4773  }
     4774  dj_ = wholeModel->dj_;
     4775  wholeModel->dj_ = new double [numberTotal];
     4776  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4777    int jColumn = mapping[iColumn];
     4778    wholeModel->dj_[iColumn]=dj_[jColumn];
     4779  }
     4780  solution_ = wholeModel->solution_;
     4781  wholeModel->solution_ = new double [numberTotal];
     4782  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4783    int jColumn = mapping[iColumn];
     4784    wholeModel->solution_[iColumn]=solution_[jColumn];
     4785  }
     4786  columnScale_ = wholeModel->columnScale_;
     4787  if (columnScale_) {
     4788    wholeModel->columnScale_ = new double [numberTotal];
     4789    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4790      int jColumn = mapping[iColumn];
     4791      wholeModel->columnScale_[iColumn]=columnScale_[jColumn];
     4792    }
     4793  }
     4794  status_ = wholeModel->status_;
     4795  wholeModel->status_ = new unsigned char [numberTotal];
     4796  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4797    int jColumn = mapping[iColumn];
     4798    wholeModel->status_[iColumn]=status_[jColumn];
     4799  }
     4800  savedSolution_ = wholeModel->savedSolution_;
     4801  if (savedSolution_) {
     4802    wholeModel->savedSolution_ = new double [numberTotal];
     4803    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4804      int jColumn = mapping[iColumn];
     4805      wholeModel->savedSolution_[iColumn]=savedSolution_[jColumn];
     4806    }
     4807  }
     4808  saveStatus_ = wholeModel->saveStatus_;
     4809  if (saveStatus_) {
     4810    wholeModel->saveStatus_ = new unsigned char [numberTotal];
     4811    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4812      int jColumn = mapping[iColumn];
     4813      wholeModel->saveStatus_[iColumn]=saveStatus_[jColumn];
     4814    }
     4815  }
     4816 
     4817 
     4818  numberColumns_ = wholeModel->numberColumns_;
     4819  wholeModel->numberColumns_ = numberColumns;
     4820  // Initialize weights
     4821  wholeModel->primalColumnPivot_->saveWeights(wholeModel,5);
     4822  // Costs
     4823  wholeModel->nonLinearCost_ = new ClpNonLinearCost(wholeModel);
     4824}
     4825/* This copies back stuff from miniModel and then deletes miniModel.
     4826   Only to be used with mini constructor */
     4827void
     4828ClpSimplex::originalModel(ClpSimplex * miniModel)
     4829{
     4830  int numberSmall = miniModel->numberColumns_;
     4831  int numberTotal = numberSmall+numberRows_;
     4832  // copy back
     4833  int iColumn;
     4834  int * mapping = (int *) miniModel->rowUpper_;
     4835  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4836    int jColumn = mapping[iColumn];
     4837    lower_[jColumn]=miniModel->lower_[iColumn];
     4838  }
     4839  delete [] miniModel->lower_;
     4840  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4841    int jColumn = mapping[iColumn];
     4842    upper_[jColumn]=miniModel->upper_[iColumn];
     4843  }
     4844  delete [] miniModel->upper_;
     4845  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4846    int jColumn = mapping[iColumn];
     4847    cost_[jColumn]=miniModel->cost_[iColumn];
     4848  }
     4849  delete [] miniModel->cost_;
     4850  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4851    int jColumn = mapping[iColumn];
     4852    dj_[jColumn]=miniModel->dj_[iColumn];
     4853  }
     4854  delete [] miniModel->dj_;
     4855  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4856    int jColumn = mapping[iColumn];
     4857    solution_[jColumn]=miniModel->solution_[iColumn];
     4858  }
     4859  delete [] miniModel->solution_;
     4860  for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4861    int jColumn = mapping[iColumn];
     4862    status_[jColumn]=miniModel->status_[iColumn];
     4863  }
     4864  delete [] miniModel->status_;
     4865  if (columnScale_) {
     4866    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4867      int jColumn = mapping[iColumn];
     4868      columnScale_[jColumn]=miniModel->columnScale_[iColumn];
     4869    }
     4870    delete [] miniModel->columnScale_;
     4871  }
     4872  if (savedSolution_) {
     4873    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4874      int jColumn = mapping[iColumn];
     4875      savedSolution_[jColumn]=miniModel->savedSolution_[iColumn];
     4876    }
     4877  }
     4878  delete [] miniModel->savedSolution_;
     4879  if (saveStatus_) {
     4880    for (iColumn=0;iColumn<numberTotal;iColumn++) {
     4881      int jColumn = mapping[iColumn];
     4882      saveStatus_[jColumn]=miniModel->saveStatus_[iColumn];
     4883    }
     4884  }
     4885  delete [] miniModel->saveStatus_;
     4886  // delete stuff
     4887  delete miniModel->matrix_;
     4888  delete miniModel->rowCopy_;
     4889  delete miniModel->primalColumnPivot_;
     4890  delete miniModel->nonLinearCost_;
     4891}
  • branches/pre/ClpSimplexPrimal.cpp

    r212 r222  
    432432void
    433433ClpSimplexPrimal::statusOfProblemInPrimal(int & lastCleaned,int type,
    434                                           ClpSimplexProgress * progress)
     434                                          ClpSimplexProgress * progress,
     435                                          ClpSimplex * originalModel)
    435436{
    436437  if (type==2) {
  • branches/pre/ClpSolve.cpp

    r221 r222  
    540540    int smallNumberColumns = min(3*numberRows,numberColumns);
    541541    smallNumberColumns = max(smallNumberColumns,3000);
     542    //int smallNumberColumns = min(12*numberRows/10,numberColumns);
     543    //smallNumberColumns = max(smallNumberColumns,3000);
     544    //smallNumberColumns = max(smallNumberColumns,numberRows+1000);
    542545    // We will be using all rows
    543546    int * whichRows = new int [numberRows];
     
    730733  return finalStatus;
    731734}
     735// General solve
     736int
     737ClpSimplex::initialSolve()
     738{
     739  // Default so use dual
     740  ClpSolve options;
     741  return initialSolve(options);
     742}
     743// General dual solve
     744int
     745ClpSimplex::initialDualSolve()
     746{
     747  ClpSolve options;
     748  // Use dual
     749  options.setSolveType(ClpSolve::useDual);
     750  return initialSolve(options);
     751}
     752// General dual solve
     753int
     754ClpSimplex::initialPrimalSolve()
     755{
     756  ClpSolve options;
     757  // Use primal
     758  options.setSolveType(ClpSolve::usePrimal);
     759  return initialSolve(options);
     760}
    732761// Default constructor
    733762ClpSolve::ClpSolve (  )
  • branches/pre/Makefile.Clp

    r221 r222  
    77# between then specify the exact level you want, e.g., -O1 or -O2
    88OptLevel := -g
    9 OptLevel := -O1
     9#OptLevel := -O1
    1010
    1111LIBNAME := Clp
  • branches/pre/Samples/driver.cpp

    r180 r222  
    1 // Copyright (C) 2002, International Business Machines
     1// Copyright (C) 2002,2003 International Business Machines
    22// Corporation and others.  All Rights Reserved.
    33
     
    55#include "ClpPresolve.hpp"
    66#include "CoinHelperFunctions.hpp"
     7#include "CoinTime.hpp"
    78#include "ClpDualRowSteepest.hpp"
    89#include "ClpPrimalColumnSteepest.hpp"
     
    2627
    2728  double time1 = CoinCpuTime();
    28   /*
    29     This driver show how to do presolve.
    30   */
    31   ClpSimplex * model2;
    32   ClpPresolve pinfo;
    33   int numberPasses=5; // can change this
    34   /* Use a tolerance of 1.0e-8 for feasibility, treat problem as
    35      not being integer, do "numberpasses" passes and throw away names
    36      in presolved model */
    37   model2 = pinfo.presolvedModel(model,1.0e-8,false,numberPasses,false);
    38   if (!model2) {
    39     fprintf(stderr,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    40             argv[1],1.0e-8);
    41     fprintf(stdout,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    42             argv[1],1.0e-8);
    43     // model was infeasible - maybe try again with looser tolerances
    44     model2 = pinfo.presolvedModel(model,1.0e-7,false,numberPasses,false);
    45     if (!model2) {
    46       fprintf(stderr,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    47               argv[1],1.0e-7);
    48       fprintf(stdout,"ClpPresolve says %s is infeasible with tolerance of %g\n",
    49               argv[1],1.0e-7);
    50       exit(2);
    51     }
    52   }
    53   // change factorization frequency from 200
    54   model2->setFactorizationFrequency(100+model2->numberRows()/50);
    5529  if (argc<3 ||!strstr(argv[2],"primal")) {
    5630    // Use the dual algorithm unless user said "primal"
    57     /* faster if bounds tightened as then dual can flip variables
    58         to other bound to stay dual feasible.  We can trash the bounds as
    59         this model is going to be thrown away
    60     */
    61     int numberInfeasibilities = model2->tightenPrimalBounds();
    62     if (numberInfeasibilities)
    63       std::cout<<"** Analysis indicates model infeasible"
    64                <<std::endl;
    65     model2->crash(1000.0,2);
    66     ClpDualRowSteepest steep(1);
    67     model2->setDualRowPivotAlgorithm(steep);
    68     model2->dual();
     31    model.initialDualSolve();
    6932  } else {
    70     ClpPrimalColumnSteepest steep(1);
    71     model2->setPrimalColumnPivotAlgorithm(steep);
    72     model2->primal();
     33    model.initialPrimalSolve();
    7334  }
    74   pinfo.postsolve(true);
    75 
    76   int numberIterations=model2->numberIterations();;
    77   delete model2;
    78   /* After this postsolve model should be optimal.
    79      We can use checkSolution and test feasibility */
    80   model.checkSolution();
    81   if (model.numberDualInfeasibilities()||
    82       model.numberPrimalInfeasibilities())
    83     printf("%g dual %g(%d) Primal %g(%d)\n",
    84            model.objectiveValue(),
    85            model.sumDualInfeasibilities(),
    86            model.numberDualInfeasibilities(),
    87            model.sumPrimalInfeasibilities(),
    88            model.numberPrimalInfeasibilities());
    89   // But resolve for safety
    90   model.primal(1);
    91 
    92   numberIterations += model.numberIterations();;
    9335  // for running timing tests
    9436  std::cout<<argv[1]<<" Objective "<<model.objectiveValue()<<" took "<<
    95     numberIterations<<" iterations and "<<
     37    model.numberIterations()<<" iterations and "<<
    9638    CoinCpuTime()-time1<<" seconds"<<std::endl;
    97 
     39 
    9840  std::string modelName;
    9941  model.getStrParam(ClpProbName,modelName);
  • branches/pre/include/ClpPrimalColumnPivot.hpp

    r180 r222  
    108108  inline int type()
    109109  { return type_;};
     110
     111  /** Returns number of extra columns for sprint algorithm - 0 means off.
     112      Also number of iterations before recompute
     113  */
     114  int numberSprintColumns(int & numberIterations) const;
     115  /// Switch off sprint idea
     116  void switchOffSprint();
    110117 
    111118  //@}
  • branches/pre/include/ClpPrimalColumnSteepest.hpp

    r212 r222  
    110110  inline int mode() const
    111111    { return mode_;};
     112  /** Returns number of extra columns for sprint algorithm - 0 means off.
     113      Also number of iterations before recompute
     114  */
     115  int numberSprintColumns(int & numberIterations) const;
     116  /// Switch off sprint idea
     117  void switchOffSprint();
     118 
    112119 //@}
    113120
  • branches/pre/include/ClpSimplex.hpp

    r212 r222  
    44/*
    55   Authors
    6   
     6 
    77   John Forrest
    88
     
    8686              int numberColumns, const int * whichColumns,
    8787              bool dropNames=true, bool dropIntegers=true);
     88  /** This constructor modifies original ClpSimplex and stores
     89      original stuff in created ClpSimplex.  It is only to be used in
     90      conjunction with originalModel */
     91  ClpSimplex (ClpSimplex * wholeModel,
     92              int numberColumns, const int * whichColumns);
     93  /** This copies back stuff from miniModel and then deletes miniModel.
     94      Only to be used with mini constructor */
     95  void originalModel(ClpSimplex * miniModel);
    8896  /// Assignment operator. This copies the data
    8997    ClpSimplex & operator=(const ClpSimplex & rhs);
     
    147155   */
    148156  int initialSolve(ClpSolve & options);
     157  /// Default initial solve
     158  int initialSolve();
     159  /// Dual initial solve
     160  int initialDualSolve();
     161  /// Primal initial solve
     162  int initialPrimalSolve();
    149163  /** Dual algorithm - see ClpSimplexDual.hpp for method */
    150164  int dual(int ifValuesPass=0);
  • branches/pre/include/ClpSimplexPrimal.hpp

    r212 r222  
    210210            - 1 normal -if good update save
    211211            - 2 restoring from saved
     212       originalModel is normally NULL but may not be if doing Sprint
    212213  */
    213214  void statusOfProblemInPrimal(int & lastCleaned, int type,
    214                              ClpSimplexProgress * progress);
     215                             ClpSimplexProgress * progress,
     216                               ClpSimplex * originalModel=NULL);
    215217  /// Perturbs problem (method depends on perturbation())
    216218  void perturb(int type);
Note: See TracChangeset for help on using the changeset viewer.