Changeset 152 for trunk


Ignore:
Timestamp:
Mar 28, 2003 3:49:21 PM (17 years ago)
Author:
forrest
Message:

Phase 0 of QP

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpModel.cpp

    r150 r152  
    6464  matrix_(NULL),
    6565  rowCopy_(NULL),
     66  quadraticObjective_(NULL),
    6667  ray_(NULL),
    6768  status_(NULL),
     
    127128  delete rowCopy_;
    128129  rowCopy_=NULL;
     130  delete quadraticObjective_;
     131  quadraticObjective_ = NULL;
    129132  delete [] ray_;
    130133  ray_ = NULL;
     
    389392      rowCopy_=NULL;
    390393    }
     394    if (rhs.quadraticObjective_) {
     395      quadraticObjective_ = new CoinPackedMatrix(*rhs.quadraticObjective_);
     396    } else {
     397      quadraticObjective_=NULL;
     398    }
    391399    matrix_=NULL;
    392400    if (rhs.matrix_) {
     
    406414    matrix_ = rhs.matrix_;
    407415    rowCopy_ = rhs.rowCopy_;
     416    quadraticObjective_ = rhs.quadraticObjective_;
    408417    ray_ = rhs.ray_;
    409418    lengthNames_ = 0;
     
    451460  matrix_ = NULL;
    452461  rowCopy_ = NULL;
     462  quadraticObjective_=NULL,
    453463  delete [] otherModel.ray_;
    454464  otherModel.ray_ = ray_;
     
    686696      which[i-newNumberColumns]=i;
    687697    matrix_->deleteCols(numberColumns_-newNumberColumns,which);
     698    if (quadraticObjective_) {
     699      quadraticObjective_->deleteCols(numberColumns_-newNumberColumns,which);
     700      quadraticObjective_->deleteRows(numberColumns_-newNumberColumns,which);
     701    }
    688702    delete [] which;
    689703  }
     
    755769                              number, which, newSize);
    756770  matrix_->deleteCols(number,which);
     771  if (quadraticObjective_) {
     772    quadraticObjective_->deleteCols(number,which);
     773    quadraticObjective_->deleteRows(number,which);
     774  }
    757775  // status
    758776  if (status_) {
     
    9941012  }
    9951013}
     1014
     1015// Load up quadratic objective
     1016void
     1017ClpModel::loadQuadraticObjective(const int numberColumns, const CoinBigIndex * start,
     1018                              const int * column, const double * element)
     1019{
     1020  assert (numberColumns==numberColumns_);
     1021  quadraticObjective_ = new CoinPackedMatrix(true,numberColumns,numberColumns,
     1022                                             start[numberColumns],element,column,start,NULL);
     1023}
     1024void
     1025ClpModel::loadQuadraticObjective (  const CoinPackedMatrix& matrix)
     1026{
     1027  assert (matrix.getNumCols()==numberColumns_);
     1028  quadraticObjective_ = new CoinPackedMatrix(matrix);
     1029}
     1030// Get rid of quadratic objective
     1031void
     1032ClpModel::deleteQuadraticObjective()
     1033{
     1034  delete quadraticObjective_;
     1035  quadraticObjective_ = NULL;
     1036}
    9961037//#############################################################################
    9971038// Constructors / Destructor / Assignment
  • trunk/ClpSimplex.cpp

    r143 r152  
    8686  numberDualInfeasibilities_(0),
    8787  numberDualInfeasibilitiesWithoutFree_(0),
    88   numberPrimalInfeasibilities_(0),
     88  numberPrimalInfeasibilities_(100),
    8989  numberRefinements_(0),
    9090  pivotVariable_(NULL),
     
    11551155  numberDualInfeasibilities_(0),
    11561156  numberDualInfeasibilitiesWithoutFree_(0),
    1157   numberPrimalInfeasibilities_(0),
     1157  numberPrimalInfeasibilities_(100),
    11581158  numberRefinements_(0),
    11591159  pivotVariable_(NULL),
     
    12461246  numberDualInfeasibilities_(0),
    12471247  numberDualInfeasibilitiesWithoutFree_(0),
    1248   numberPrimalInfeasibilities_(0),
     1248  numberPrimalInfeasibilities_(100),
    12491249  numberRefinements_(0),
    12501250  pivotVariable_(NULL),
     
    23652365{
    23662366  return ((ClpSimplexPrimal *) this)->primal(ifValuesPass);
     2367}
     2368#include "ClpSimplexPrimalQuadratic.hpp"
     2369/* Solves quadratic problem using SLP - may be used as crash
     2370   for other algorithms when number of iterations small
     2371*/
     2372int
     2373ClpSimplex::quadraticSLP(int numberPasses, double deltaTolerance)
     2374{
     2375  return ((ClpSimplexPrimalQuadratic *) this)->primalSLP(numberPasses,deltaTolerance);
     2376}
     2377// Solves quadratic using Beale's algorithm - primal
     2378int
     2379ClpSimplex::quadraticBeale()
     2380{
     2381  return ((ClpSimplexPrimalQuadratic *) this)->primalBeale();
    23672382}
    23682383/* For strong branching.  On input lower and upper are new bounds
  • trunk/Makefile.Clp

    r137 r152  
    3131LIBSRC += ClpSimplexDual.cpp
    3232LIBSRC += ClpSimplexPrimal.cpp
     33LIBSRC += ClpSimplexPrimalQuadratic.cpp
    3334# and Presolve stuff
    3435LIBSRC += Presolve.cpp
  • trunk/Test/unitTest.cpp

    r128 r152  
    793793    }
    794794  }
    795  
     795#if 0 
    796796  // test network
    797797  {   
     
    956956    delete [] upperColumn;
    957957  }
     958#endif
     959  // Test quadratic
     960  {   
     961    CoinMpsIO m;
     962    std::string fn = mpsDir+"share2qp";
     963    m.readMps(fn.c_str(),"mps");
     964    ClpSimplex solution;
     965    solution.loadProblem(*m.getMatrixByCol(),m.getColLower(),m.getColUpper(),
     966                         m.getObjCoefficients(),
     967                         m.getRowLower(),m.getRowUpper());
     968    solution.dual();
     969    // get quadratic part
     970    int * start=NULL;
     971    int * column = NULL;
     972    double * element = NULL;
     973    m.readQuadraticMps(NULL,start,column,element,2);
     974    // Load up objective
     975    solution.loadQuadraticObjective(solution.numberColumns(),start,column,element);
     976    delete [] start;
     977    delete [] column;
     978    delete [] element;
     979    solution.quadraticSLP(50,1.0e-4);
     980    double objValue = solution.getObjValue();
     981    CoinRelFltEq eq(1.0e-2);
     982    assert(eq(objValue,-400.92));
     983  }
    958984 
    959985}
  • trunk/include/ClpModel.hpp

    r142 r152  
    2121#endif
    2222
    23 /** This is the base class for Linear Models
     23/** This is the base class for Linear and quadratic Models
    2424    This knows nothing about the algorithm, but it seems to
    2525    have a reasonable amount of information
     
    9292                      const double* rowlb, const double* rowub,
    9393                      const double * rowObjective=NULL);
     94  /// Load up quadratic objective
     95  void loadQuadraticObjective(const int numberColumns, const CoinBigIndex * start,
     96                              const int * column, const double * element);
     97  void loadQuadraticObjective (  const CoinPackedMatrix& matrix);
     98  /// Get rid of quadratic objective
     99  void deleteQuadraticObjective();
    94100  /// This just loads up a row objective
    95101  void setRowObjective(const double * rowObjective);
     
    264270   /// Clp Matrix
    265271   inline ClpMatrixBase * clpMatrix() const     { return matrix_; }
     272   /// Quadratic objective
     273   inline CoinPackedMatrix * quadraticObjective() const     { return quadraticObjective_; }
    266274   /// Objective value
    267275   inline double objectiveValue() const {
     
    438446  /// Row copy if wanted
    439447  ClpMatrixBase * rowCopy_;
     448  /// Quadratic objective if any
     449  CoinPackedMatrix * quadraticObjective_;
    440450  /// Infeasible/unbounded ray
    441451  double * ray_;
  • trunk/include/ClpSimplex.hpp

    r143 r152  
    138138  /** Primal algorithm - see ClpSimplexPrimal.hpp for method */
    139139  int primal(int ifValuesPass=0);
     140  /** Solves quadratic problem using SLP - may be used as crash
     141      for other algorithms when number of iterations small.
     142      Also exits if all problematical variables are changing
     143      less than deltaTolerance
     144  */
     145  int quadraticSLP(int numberPasses,double deltaTolerance);
     146  /// Solves quadratic using Beale's algorithm - primal
     147  int quadraticBeale();
    140148  /// Passes in factorization
    141149  void setFactorization( ClpFactorization & factorization);
Note: See TracChangeset for help on using the changeset viewer.