Changeset 700


Ignore:
Timestamp:
Jul 22, 2007 7:25:44 PM (12 years ago)
Author:
forrest
Message:

changes for postprocess loop and LOS

Location:
trunk/Cbc/src
Files:
5 edited

Legend:

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

    r687 r700  
    127127    // Used to be automatically set
    128128    osiclp->setSpecialOptions(osiclp->specialOptions()|(128+64));
     129    ClpSimplex * lpSolver = osiclp->getModelPtr();
     130    lpSolver->setSpecialOptions(lpSolver->specialOptions()|0x01000000); // say is Cbc (and in branch and bound)
    129131  }
    130132#endif
     
    196198        returnCode=model.isProvenOptimal() ? 3 : 1;
    197199        // post process
     200#ifdef COIN_HAS_CLP
     201        OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (model.solver());
     202        if (clpSolver) {
     203          ClpSimplex * lpSolver = clpSolver->getModelPtr();
     204          lpSolver->setSpecialOptions(lpSolver->specialOptions()|0x01000000); // say is Cbc (and in branch and bound)
     205        }
     206#endif
    198207        process.postProcess(*model.solver());
    199208        if (solver->isProvenOptimal()) {
  • trunk/Cbc/src/CbcLinked.cpp

    r696 r700  
    667667            CglTemporary * gen2 = dynamic_cast<CglTemporary *> (gen);
    668668            if (gen2) {
     669              double * solution2 = NULL;
     670              int numberColumns = quadraticModel_->numberColumns();
     671              int depth=6;
     672              if (depth<5) {
     673                ClpSimplex qpTemp(*quadraticModel_);
     674                double * lower = qpTemp.columnLower();
     675                double * upper = qpTemp.columnUpper();
     676                double * lower2 = modelPtr_->columnLower();
     677                double * upper2 = modelPtr_->columnUpper();
     678                for (int i=0;i<numberColumns;i++) {
     679                  lower[i]=lower2[i];
     680                  upper[i]=upper2[i];
     681                }
     682                qpTemp.primal();
     683                assert (!qpTemp.problemStatus());
     684                if (qpTemp.objectiveValue()<bestObjectiveValue_-1.0e-3&&!qpTemp.problemStatus()) {
     685                } else {
     686                  printf("QP says expensive - kill\n");
     687                }
     688              }
    669689              cbcModel_->lockThread();
    670690              const double * solution = getColSolution();
    671691              // add OA cut
    672692              double offset=0.0;
    673               int numberColumns = quadraticModel_->numberColumns();
    674693              double * gradient = new double [numberColumns+1];
    675694              // gradient from bilinear
     
    723742                gen2->addCut(-COIN_DBL_MAX,offset+1.0e-7,n,column,gradient);
    724743                //printf("added cut with %d elements\n",n);
     744              }
     745              if (solution2) {
     746                doAOCuts(gen2, solution, solution2);
     747                delete [] solution2;
    725748              }
    726749              delete [] gradient;
     
    821844    modelPtr_->setObjectiveValue(COIN_DBL_MAX);
    822845  }
     846}
     847// Do OA cuts
     848int
     849OsiSolverLink::doAOCuts(CglTemporary * cutGen, const double * solution, const double * solution2)
     850{
     851  cbcModel_->lockThread();
     852  // add OA cut
     853  double offset=0.0;
     854  int numberColumns = quadraticModel_->numberColumns();
     855  double * gradient = new double [numberColumns+1];
     856  // gradient from bilinear
     857  int i;
     858  CoinZeroN(gradient,numberColumns+1);
     859  //const double * objective = modelPtr_->objective();
     860  assert (objectiveRow_>=0);
     861  const double * element = originalRowCopy_->getElements();
     862  const int * column2 = originalRowCopy_->getIndices();
     863  const CoinBigIndex * rowStart = originalRowCopy_->getVectorStarts();
     864  //const int * rowLength = originalRowCopy_->getVectorLengths();
     865  //int numberColumns2 = coinModel_.numberColumns();
     866  for ( i=rowStart[objectiveRow_];i<rowStart[objectiveRow_+1];i++)
     867    gradient[column2[i]] = element[i];
     868  //const double * columnLower = modelPtr_->columnLower();
     869  //const double * columnUpper = modelPtr_->columnUpper();
     870  for ( i =0;i<numberObjects_;i++) {
     871    OsiBiLinear * obj = dynamic_cast<OsiBiLinear *> (object_[i]);
     872    if (obj) {
     873      int xColumn = obj->xColumn();
     874      int yColumn = obj->yColumn();
     875      if (xColumn!=yColumn) {
     876        double coefficient = /* 2.0* */obj->coefficient();
     877        gradient[xColumn] += coefficient*solution2[yColumn];
     878        gradient[yColumn] += coefficient*solution2[xColumn];
     879        offset += coefficient*solution2[xColumn]*solution2[yColumn];
     880      } else {
     881        double coefficient = obj->coefficient();
     882        gradient[xColumn] += 2.0*coefficient*solution2[yColumn];
     883        offset += coefficient*solution2[xColumn]*solution2[yColumn];
     884      }
     885    }
     886  }
     887  // assume convex
     888  double rhs = 0.0;
     889  int * column = new int[numberColumns+1];
     890  int n=0;
     891  for (int i=0;i<numberColumns;i++) {
     892    double value = gradient[i];
     893    if (fabs(value)>1.0e-12) {
     894      gradient[n]=value;
     895      rhs += value*solution[i];
     896      column[n++]=i;
     897    }
     898  }
     899  gradient[n]=-1.0;
     900  assert (objectiveVariable_>=0);
     901  rhs -= solution[objectiveVariable_];
     902  column[n++]=objectiveVariable_;
     903  int returnCode=0;
     904  if (rhs>offset+1.0e-5) {
     905    cutGen->addCut(-COIN_DBL_MAX,offset+1.0e-7,n,column,gradient);
     906    //printf("added cut with %d elements\n",n);
     907    returnCode=1;
     908  }
     909  delete [] gradient;
     910  delete [] column;
     911  cbcModel_->unlockThread();
     912  return returnCode;
    823913}
    824914
  • trunk/Cbc/src/CbcLinked.hpp

    r692 r700  
    1717class OsiObject;
    1818class CglStored;
     19class CglTemporary;
    1920/**
    2021   
     
    6364  */
    6465  double * heuristicSolution(int numberPasses,double deltaTolerance,int mode);
     66 
     67  /// Do OA cuts
     68  int doAOCuts(CglTemporary * cutGen, const double * solution, const double * solution2);
    6569  //@}
    6670 
  • trunk/Cbc/src/CbcSolver.cpp

    r699 r700  
    14051405  OsiClpSolverInterface * originalSolver = dynamic_cast<OsiClpSolverInterface *> (model.solver());
    14061406  assert (originalSolver);
    1407   CoinMessageHandler * generalMessageHandler = originalSolver->messageHandler()->clone();
     1407  CoinMessageHandler * generalMessageHandler = originalSolver->messageHandler();
    14081408  CoinMessages generalMessages = originalSolver->getModelPtr()->messages();
    14091409  char generalPrint[10000];
     
    14631463    int * cut=NULL;
    14641464    int * sosPriority=NULL;
     1465    CglStored storedAmpl;
    14651466#ifdef COIN_HAS_ASL
    14661467    CoinModel * coinModel = NULL;
    1467     CglStored storedAmpl;
    14681468    ampl_info info;
    14691469    CoinModel saveCoinModel;
     
    15521552        OsiSolverLink solver1;
    15531553        OsiSolverInterface * solver2 = solver1.clone();
    1554         model.assignSolver(solver2,true);
     1554        model.assignSolver(solver2,false);
    15551555        OsiSolverLink * si =
    15561556          dynamic_cast<OsiSolverLink *>(model.solver()) ;
     
    27222722              if (logLevel<=1)
    27232723                model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
    2724 #ifdef COIN_HAS_LINK
    27252724              {
    27262725                OsiSolverInterface * solver = model.solver();
     
    27422741                    OsiSolverLink solver1;
    27432742                    OsiSolverInterface * solver2 = solver1.clone();
    2744                     model.assignSolver(solver2,true);
     2743                    model.assignSolver(solver2,false);
    27452744                    OsiSolverLink * si =
    27462745                      dynamic_cast<OsiSolverLink *>(model.solver()) ;
     
    28802879                      clpModel->dual();  // clean up
    28812880                      cbcModel->initialSolve();
     2881#ifdef CBC_THREAD
     2882                      int numberThreads =parameters[whichParam(THREADS,numberParameters,parameters)].intValue();
     2883                      cbcModel->setNumberThreads(numberThreads%100);
     2884                      cbcModel->setThreadMode(numberThreads/100);
     2885#endif
    28822886                      cbcModel->branchAndBound();
    28832887                      OsiSolverLinearizedQuadratic * solver3 = dynamic_cast<OsiSolverLinearizedQuadratic *> (model2.solver());
     
    29242928                si->setSpecialOptions(0x40000000);
    29252929              }
    2926 #endif
    29272930              if (!miplib) {
    29282931                if (!preSolve) {
     
    44894492                  }
    44904493                }
     4494#endif
    44914495                if (storedAmpl.sizeRowCuts()) {
    44924496                  //babModel->addCutGenerator(&storedAmpl,1,"AmplStored");
     
    44974501                  }
    44984502                }
    4499 #endif
    45004503                // If defaults then increase trust for small models
    45014504                if (!strongChanged) {
     
    45484551                }
    45494552                model = *babModel;
    4550                 delete generalMessageHandler;
    45514553                return 777;
    45524554              } else {
     
    45904592                  int n = saveSolver->getNumCols();
    45914593                  bestSolution = new double [n];
     4594                  OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (babModel->solver());
     4595                  ClpSimplex * lpSolver = clpSolver->getModelPtr();
     4596                  lpSolver->setSpecialOptions(lpSolver->specialOptions()|0x01000000); // say is Cbc (and in branch and bound)
    45924597                  process.postProcess(*babModel->solver());
    45934598                  // Solution now back in saveSolver
     
    46064611                  double * solution = original->primalColumnSolution();
    46074612                  int n = original->numberColumns();
    4608                   assert (!n||n==babModel->solver()->getNumCols());
     4613                  //assert (!n||n==babModel->solver()->getNumCols());
    46094614                  for (int i=0;i<n;i++) {
    46104615                    solution[i]=bestSolution[i];
     
    49804985                OsiSolverLink solver1;
    49814986                OsiSolverInterface * solver2 = solver1.clone();
    4982                 model.assignSolver(solver2,true);
     4987                model.assignSolver(solver2,false);
    49834988                OsiSolverLink * si =
    49844989                  dynamic_cast<OsiSolverLink *>(model.solver()) ;
     
    63006305  dmalloc_shutdown();
    63016306#endif
    6302   delete generalMessageHandler;
    63036307  return 0;
    63046308}   
  • trunk/Cbc/src/ClpAmplStuff.cpp

    r690 r700  
    916916  return type;
    917917}
     918#else
     919#include "ClpSimplex.hpp"
     920#include "ClpConstraint.hpp"
     921int
     922ClpSimplex::loadNonLinear(void * amplInfo, int & numberConstraints,
     923                          ClpConstraint ** & constraints)
     924{
     925  abort();
     926  return 0;
     927}
    918928#endif
Note: See TracChangeset for help on using the changeset viewer.