Changeset 393 for trunk/ClpPresolve.cpp


Ignore:
Timestamp:
Jul 21, 2004 4:36:05 PM (15 years ago)
Author:
forrest
Message:

Some quadratic stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpPresolve.cpp

    r378 r393  
    1313#include "CoinPackedMatrix.hpp"
    1414#include "ClpSimplex.hpp"
     15#include "ClpQuadraticObjective.hpp"
    1516
    1617#include "ClpPresolve.hpp"
     
    215216  }
    216217  // Now check solution
     218  double offset;
    217219  memcpy(originalModel_->dualColumnSolution(),
    218          originalModel_->objective(),ncols_*sizeof(double));
     220         originalModel_->objectiveAsObject()->gradient(originalModel_,
     221                                                       originalModel_->primalColumnSolution(),
     222                                                       offset,true),ncols_*sizeof(double));
    219223  originalModel_->transposeTimes(-1.0,
    220224                                 originalModel_->dualRowSolution(),
     
    371375  // later just do individually
    372376  bool doDualStuff = (presolvedModel_->integerInformation()==NULL);
     377  if (prob->anyProhibited())
     378    doDualStuff=false;
    373379
    374380#if     CHECK_CONSISTENCY
     
    862868  ClpDisjointCopyN(si->getColLower(), ncols, clo_);
    863869  ClpDisjointCopyN(si->getColUpper(), ncols, cup_);
    864   ClpDisjointCopyN(si->getObjCoefficients(), ncols, cost_);
     870  //ClpDisjointCopyN(si->getObjCoefficients(), ncols, cost_);
     871  double offset;
     872  ClpDisjointCopyN(si->objectiveAsObject()->gradient(si,si->getColSolution(),offset,true), ncols, cost_);
    865873  ClpDisjointCopyN(si->getRowLower(), nrows,  rlo_);
    866874  ClpDisjointCopyN(si->getRowUpper(), nrows,  rup_);
     
    991999  }
    9921000
     1001#ifndef NO_RTTI
     1002    ClpQuadraticObjective * quadraticObj = (dynamic_cast< ClpQuadraticObjective*>(si->objectiveAsObject()));
     1003#else
     1004    ClpQuadraticObjective * quadraticObj = NULL;
     1005    if (si->objectiveAsObject()->type()==2)
     1006      quadraticObj = (static_cast< ClpQuadraticObjective*>(si->objectiveAsObject()));
     1007#endif
    9931008  // Set up prohibited bits if needed
    9941009  if (nonLinearValue) {
     
    10081023        setColProhibited(icol);
    10091024    }
     1025  } else if (quadraticObj) {
     1026    CoinPackedMatrix * quadratic = quadraticObj->quadraticObjective();
     1027    //const int * columnQuadratic = quadratic->getIndices();
     1028    //const CoinBigIndex * columnQuadraticStart = quadratic->getVectorStarts();
     1029    const int * columnQuadraticLength = quadratic->getVectorLengths();
     1030    //double * quadraticElement = quadratic->getMutableElements();
     1031    int numberColumns = quadratic->getNumCols();
     1032    anyProhibited_ = true;
     1033    for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     1034      if (columnQuadraticLength[iColumn]) {
     1035        setColProhibited(iColumn);
     1036        //printf("%d prohib\n",iColumn);
     1037      }
     1038    }
    10101039  } else {
    10111040    anyProhibited_ = false;
     
    10621091  si->loadProblem(ncols_, nrows_, mcstrt_, hrow_, colels_, hincol_,
    10631092                 clo_, cup_, cost_, rlo_, rup_);
    1064 
    10651093  delete [] si->integerInformation();
    10661094  int numberIntegers=0;
     
    12911319
    12921320    // Do presolve
    1293 
    12941321    paction_ = presolve(&prob);
    12951322
     
    13511378      int ncolsNow = presolvedModel_->getNumCols();
    13521379      memcpy(originalColumn_,prob.originalColumn_,ncolsNow*sizeof(int));
     1380#ifndef NO_RTTI
     1381      ClpQuadraticObjective * quadraticObj = (dynamic_cast< ClpQuadraticObjective*>(originalModel->objectiveAsObject()));
     1382#else
     1383      ClpQuadraticObjective * quadraticObj = NULL;
     1384      if (originalModel->objectiveAsObject()->type()==2)
     1385        quadraticObj = (static_cast< ClpQuadraticObjective*>(originalModel->objectiveAsObject()));
     1386#endif
     1387      if (quadraticObj) {
     1388        // set up for subset
     1389        char * mark = new char [ncols_];
     1390        memset(mark,0,ncols_);
     1391        CoinPackedMatrix * quadratic = quadraticObj->quadraticObjective();
     1392        //const int * columnQuadratic = quadratic->getIndices();
     1393        //const CoinBigIndex * columnQuadraticStart = quadratic->getVectorStarts();
     1394        const int * columnQuadraticLength = quadratic->getVectorLengths();
     1395        //double * quadraticElement = quadratic->getMutableElements();
     1396        int numberColumns = quadratic->getNumCols();
     1397        ClpQuadraticObjective * newObj = new ClpQuadraticObjective(*quadraticObj,
     1398                                                                   ncolsNow,
     1399                                                                   originalColumn_);
     1400        // and modify linear and check
     1401        double * linear = newObj->linearObjective();
     1402        memcpy(linear,presolvedModel_->objective(),ncolsNow*sizeof(double));
     1403        int iColumn;
     1404        for ( iColumn=0;iColumn<numberColumns;iColumn++) {
     1405          if (columnQuadraticLength[iColumn])
     1406            mark[iColumn]=1;
     1407        }
     1408        // and new
     1409        quadratic = newObj->quadraticObjective();
     1410        columnQuadraticLength = quadratic->getVectorLengths();
     1411        int numberColumns2 = quadratic->getNumCols();
     1412        for ( iColumn=0;iColumn<numberColumns2;iColumn++) {
     1413          if (columnQuadraticLength[iColumn])
     1414            mark[originalColumn_[iColumn]]=0;
     1415        }
     1416        presolvedModel_->setObjective(newObj);
     1417        delete newObj;
     1418        // final check
     1419        for ( iColumn=0;iColumn<numberColumns;iColumn++)
     1420          if (mark[iColumn])
     1421            printf("Quadratic column %d modified - may be okay\n",iColumn);
     1422        delete [] mark;
     1423      }
    13531424      delete [] prob.originalColumn_;
    13541425      prob.originalColumn_=NULL;
Note: See TracChangeset for help on using the changeset viewer.