Changeset 446 for trunk/ClpPresolve.cpp


Ignore:
Timestamp:
Sep 16, 2004 12:44:18 PM (15 years ago)
Author:
lou-oss
Message:

Compatibility w/ CoinPresolve? modifications.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ClpPresolve.cpp

    r393 r446  
    22// Corporation and others.  All Rights Reserved.
    33
    4 //#define       CHECK_CONSISTENCY       1
     4//#define       PRESOLVE_CONSISTENCY    1
     5//#define       PRESOLVE_DEBUG  1
    56
    67#include <stdio.h>
     
    178179  }
    179180
    180 
     181  // CoinPostsolveMatrix object assumes ownership of sol, acts, colstat;
     182  // will be deleted by ~CoinPostsolveMatrix. delete[] operations below
     183  // cause duplicate free. In case where saveFile == "", as best I can see
     184  // arrays are owned by originalModel_. fix is to
     185  // clear fields in prob to avoid delete[] in ~CoinPostsolveMatrix.
    181186  CoinPostsolveMatrix prob(presolvedModel_,
    182187                       ncols0,
     
    196201    originalModel_->restoreModel(saveFile_.c_str());
    197202    memcpy(originalModel_->primalRowSolution(),acts,nrows0*sizeof(double));
    198     delete [] acts;
     203    // delete [] acts;
    199204    memcpy(originalModel_->primalColumnSolution(),sol,ncols0*sizeof(double));
    200     delete [] sol;
     205    // delete [] sol;
    201206    if (updateStatus) {
    202207      memcpy(originalModel_->statusArray(),colstat,nrows0+ncols0);
    203       delete [] colstat;
    204     }
     208      // delete [] colstat;
     209    }
     210  } else {
     211    prob.sol_ = 0 ;
     212    prob.acts_ = 0 ;
     213    prob.colstat_ = 0 ;
    205214  }
    206215  // put back duals
     
    281290{
    282291 return true;
    283 #if     DEBUG_PRESOLVE || PRESOLVE_SUMMARY
     292#if     PRESOLVE_DEBUG || PRESOLVE_SUMMARY
    284293  if (getenv(name)) {
    285294    int val = atoi(getenv(name));
     
    297306}
    298307#endif
    299 //#define DEBUG_PRESOLVE 1
    300 #if DEBUG_PRESOLVE
     308//#define PRESOLVE_DEBUG 1
     309#if PRESOLVE_DEBUG
    301310void check_sol(CoinPresolveMatrix *prob,double tol)
    302311{
     
    378387    doDualStuff=false;
    379388
    380 #if     CHECK_CONSISTENCY
    381   presolve_links_ok(prob->rlink_, prob->mrstrt_, prob->hinrow_, prob->nrows_);
     389#if     PRESOLVE_CONSISTENCY
     390//  presolve_links_ok(prob->rlink_, prob->mrstrt_, prob->hinrow_, prob->nrows_);
     391    presolve_links_ok(prob,false,true) ;
    382392#endif
    383393
     
    443453
    444454    int iLoop;
    445 #if     DEBUG_PRESOLVE
     455#if     PRESOLVE_DEBUG
    446456    check_sol(prob,1.0e0);
    447457#endif
     
    509519        }
    510520
    511 #if     DEBUG_PRESOLVE
     521#if     PRESOLVE_DEBUG
    512522        check_sol(prob,1.0e0);
    513523#endif
    514524
    515 #if     CHECK_CONSISTENCY
    516         presolve_links_ok(prob->rlink_, prob->mrstrt_, prob->hinrow_,
    517                           prob->nrows_);
    518 #endif
    519 
    520 #if     DEBUG_PRESOLVE
    521         presolve_no_zeros(prob->mcstrt_, prob->colels_, prob->hincol_,
    522                           prob->ncols_);
    523 #endif
    524 #if     CHECK_CONSISTENCY
    525         prob->consistent();
     525#if     PRESOLVE_CONSISTENCY
     526//      presolve_links_ok(prob->rlink_, prob->mrstrt_, prob->hinrow_,
     527//                        prob->nrows_);
     528        presolve_links_ok(prob,false,true) ;
     529#endif
     530
     531//#if   PRESOLVE_DEBUG
     532//      presolve_no_zeros(prob->mcstrt_, prob->colels_, prob->hincol_,
     533//                        prob->ncols_);
     534//#endif
     535//#if   PRESOLVE_CONSISTENCY
     536//      prob->consistent();
     537//#endif
     538#if     PRESOLVE_CONSISTENCY
     539        presolve_no_zeros(prob,true,false) ;
     540        presolve_consistent(prob,true) ;
    526541#endif
    527542
     
    608623        }
    609624      }
    610 #if     DEBUG_PRESOLVE
     625#if     PRESOLVE_DEBUG
    611626      check_sol(prob,1.0e0);
    612627#endif
     
    616631          break;
    617632      }
    618 #if     DEBUG_PRESOLVE
     633#if     PRESOLVE_DEBUG
    619634        check_sol(prob,1.0e0);
    620635#endif
     
    625640          break;
    626641      }
    627 #if     DEBUG_PRESOLVE
     642#if     PRESOLVE_DEBUG
    628643      check_sol(prob,1.0e0);
    629644#endif
     
    653668  if (!prob->status_) {
    654669    paction_ = drop_zero_coefficients(prob, paction_);
    655 #if     DEBUG_PRESOLVE
     670#if     PRESOLVE_DEBUG
    656671        check_sol(prob,1.0e0);
    657672#endif
     
    659674    paction_ = drop_empty_cols_action::presolve(prob, paction_);
    660675    paction_ = drop_empty_rows_action::presolve(prob, paction_);
    661 #if     DEBUG_PRESOLVE
     676#if     PRESOLVE_DEBUG
    662677        check_sol(prob,1.0e0);
    663678#endif
     
    726741  const CoinPresolveAction *paction = paction_;
    727742
     743#if     PRESOLVE_DEBUG
    728744  if (prob.colstat_)
    729    prob.check_nbasic();
     745    presolve_check_nbasic(&prob) ;
    730746 
    731 #if     DEBUG_PRESOLVE
    732   check_djs(&prob);
     747//check_djs(&prob);
     748  presolve_check_reduced_costs(&prob) ;
    733749#endif
    734750 
    735751 
    736752  while (paction) {
    737 #if     DEBUG_PRESOLVE
     753#if     PRESOLVE_DEBUG
    738754    printf("POSTSOLVING %s\n", paction->name());
    739755#endif
     
    741757    paction->postsolve(&prob);
    742758   
    743 #if     DEBUG_PRESOLVE
     759#if     PRESOLVE_DEBUG
    744760    if (prob.colstat_)
    745       prob.check_nbasic();
     761      presolve_check_nbasic(&prob) ;
    746762#endif
    747763    paction = paction->next;
    748 #if     DEBUG_PRESOLVE
    749     check_djs(&prob);
     764#if     PRESOLVE_DEBUG
     765//  check_djs(&prob);
     766    presolve_check_reduced_costs(&prob) ;
    750767#endif
    751768  }   
    752769 
    753 #if     0 && DEBUG_PRESOLVE
     770#if     0 && PRESOLVE_DEBUG
    754771  for (i=0; i<ncols0; i++) {
    755772    if (!cdone[i]) {
     
    776793#endif
    777794 
    778 #if     0 && DEBUG_PRESOLVE
     795#if     0 && PRESOLVE_DEBUG
    779796  // debug check:  make sure we ended up with same original matrix
    780797  {
     
    841858  ncols_(si->getNumCols()),
    842859  ncols0_(ncols_in),
     860  nrows0_(nrows_in),
    843861  nelems_(si->getNumElements()),
     862
     863  handler_(0),
     864  defaultHandler_(false),
     865  messages_(),
    844866
    845867  mcstrt_(new CoinBigIndex[ncols_in+1]),
     
    865887  int ncols = si->getNumCols();
    866888  int nrows = si->getNumRows();
     889
     890  setMessageHandler(si->messageHandler()) ;
    867891
    868892  ClpDisjointCopyN(si->getColLower(), ncols, clo_);
     
    901925  return (! (i >= 0));
    902926}
    903 #if     DEBUG_PRESOLVE
     927#if     PRESOLVE_DEBUG
    904928static void matrix_bounds_ok(const double *lo, const double *up, int n)
    905929{
     
    913937#endif
    914938CoinPresolveMatrix::CoinPresolveMatrix(int ncols0_in,
    915                                      double maxmin_,
     939                                     double maxmin,
    916940                                     // end prepost members
    917941
     
    931955  dobias_(0.0),
    932956
    933   nrows_(si->getNumRows()),
    934957
    935958  // temporary init
     
    938961  rowels_(new double[2*nelems_in]),
    939962  hcol_(new int[2*nelems_in]),
    940   integerType_(new char[ncols0_in]),
     963  integerType_(new unsigned char[ncols0_in]),
    941964  feasibilityTolerance_(0.0),
    942965  status_(-1),
     
    952975{
    953976  const int bufsize = 2*nelems_in;
     977
     978  nrows_ = si->getNumRows() ;
    954979
    955980  // Set up change bits etc
     
    9961021    memcpy(integerType_,si->integerInformation(),ncols_*sizeof(char));
    9971022  } else {
    998     ClpFillN<char>(integerType_, ncols_, 0);
     1023    ClpFillN<unsigned char>(integerType_, ncols_, (unsigned char) 0);
    9991024  }
    10001025
     
    10591084  si->resize(0,0);
    10601085
    1061 #if     DEBUG_PRESOLVE
     1086#if     PRESOLVE_DEBUG
    10621087  matrix_bounds_ok(rlo_, rup_, nrows_);
    10631088  matrix_bounds_ok(clo_, cup_, ncols_);
     
    10791104  mrstrt_[nrows_] = bufsize-1;
    10801105
    1081 #if     CHECK_CONSISTENCY
    1082   consistent(false);
     1106#if     PRESOLVE_CONSISTENCY
     1107//consistent(false);
     1108  presolve_consistent(this,false) ;
    10831109#endif
    10841110}
     
    10981124  }
    10991125  if (numberIntegers)
    1100     si->copyInIntegerInformation(integerType_);
     1126    si->copyInIntegerInformation((const char *) integerType_);
    11011127  else
    11021128    si->copyInIntegerInformation(NULL);
     
    11291155                                       CoinBigIndex nelems0,
    11301156                                   
    1131                                        double maxmin_,
     1157                                       double maxmin,
    11321158                                       // end prepost members
    11331159
     
    11461172     
    11471173  cdone_(new char[ncols0_]),
    1148   rdone_(new char[nrows0_in]),
    1149 
    1150   nrows_(si->getNumRows()),
    1151   nrows0_(nrows0_in)
    1152 {
     1174  rdone_(new char[nrows0_in])
     1175
     1176{
     1177  bulk0_ = maxlink_ ;
     1178  nrows_ = si->getNumRows() ;
     1179  ncols_ = si->getNumCols() ;
    11531180
    11541181  sol_=sol_in;
     
    11611188
    11621189  // this is the *reduced* model, which is probably smaller
    1163   int ncols1 = si->getNumCols();
    1164   int nrows1 = si->getNumRows();
     1190  int ncols1 = ncols_ ;
     1191  int nrows1 = nrows_ ;
    11651192
    11661193  const CoinPackedMatrix * m = si->matrix();
     
    11751202  ClpDisjointCopyN(m->getVectorStarts(), ncols1, mcstrt_);
    11761203  CoinZeroN(mcstrt_+ncols1,ncols0_-ncols1);
    1177   mcstrt_[ncols_] = nelems0;    // ??
     1204  mcstrt_[ncols1] = nelems0;    // ??    (should point to end of bulk store   -- lh --)
    11781205  ClpDisjointCopyN(m->getVectorLengths(),ncols1,  hincol_);
    11791206  ClpDisjointCopyN(m->getIndices(),      nelemsr, hrow_);
     
    11811208
    11821209
    1183 #if     0 && DEBUG_PRESOLVE
     1210#if     0 && PRESOLVE_DEBUG
    11841211  presolve_check_costs(model, &colcopy);
    11851212#endif
     
    12071234  rcosts_ = new double[ncols0_];
    12081235  ClpDisjointCopyN(si->getReducedCost(), ncols1, rcosts_);
    1209   if (maxmin_<0.0) {
     1236  if (maxmin<0.0) {
    12101237    // change so will look as if minimize
    12111238    int i;
     
    12291256      link_[k] = k+1;
    12301257    }
     1258    link_[kce-1] = NO_LINK ;
    12311259  }
    12321260  {
     
    12381266  }
    12391267  free_list_ = nelemsr;
     1268# if PRESOLVE_DEBUG || PRESOLVE_CONSISTENCY
     1269/*
     1270  These are used to track the action of postsolve transforms during debugging.
     1271*/
     1272  CoinFillN(cdone_,ncols1,PRESENT_IN_REDUCED) ;
     1273  CoinZeroN(cdone_+ncols1,ncols0_in-ncols1) ;
     1274  CoinFillN(rdone_,nrows1,PRESENT_IN_REDUCED) ;
     1275  CoinZeroN(rdone_+nrows1,nrows0_in-nrows1) ;
     1276# endif
    12401277}
    12411278/* This is main part of Presolve */
     
    13121349      }
    13131350    }
    1314     prob.handler_ = presolvedModel_->messageHandler();
    1315     prob.messages_ = CoinMessage(presolvedModel_->messages().language());
    13161351
    13171352    // move across feasibility tolerance
Note: See TracChangeset for help on using the changeset viewer.