Changeset 1009


Ignore:
Timestamp:
Jan 10, 2008 2:14:33 PM (12 years ago)
Author:
ladanyi
Message:

rewrote BonIpopiWarmStart? to use only promail/dual vector pair and that IpoptSolver? can use a CoinWarmstartPrimalDual?

Location:
trunk/Bonmin
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bonmin/experimental/Bcp/BM.cpp

    r964 r1009  
    2828    BM_init user_init;
    2929    int retcode = -1;
    30 #if 0
     30#if 1
    3131    retcode = bcp_main(argc, argv, &user_init);
    3232#else
  • trunk/Bonmin/experimental/Bcp/BM_lp_branch.cpp

    r964 r1009  
    1717#include "BonLpBranchingSolver.hpp"
    1818#include "BonOsiTMINLPInterface.hpp"
     19#include "BonIpoptWarmStart.hpp"
    1920
    2021#define DEBUG_PRINT
     
    161162  bm_buf.pack(itmp);
    162163  send_message(parent(), bm_buf);
    163 
    164164}
    165165
     
    288288
    289289#ifdef DEBUG_PRINT
    290   double t = CoinWallclockTime();
     290  const double t = CoinWallclockTime();
    291291  printf("LP %.3f: node: %i  depth: %i  obj: %f  infNum: %i  feasNum: %i  soltime: %.3f\n",
    292292         t-start_time(), current_index(), current_level(),
     
    350350  bm_buf.pack(branchInfo.objectiveValue_);
    351351  bm_buf.pack(branchInfo.cutoff_);
    352   BCP_pack_warmstart(ws, bm_buf);
     352  bool has_ws = ws != NULL;
     353  bm_buf.pack(has_ws);
     354  if (has_ws) {
     355    BCP_pack_warmstart(ws, bm_buf);
     356  }
    353357 
    354358  const int fixed_size = bm_buf.size();
     
    417421    const double old_bd = solver->getColUpper()[ind];
    418422    solver->setColUpper(ind, floor(val));
    419     solver->setWarmStart(cws);
     423    if (cws) {
     424      solver->setWarmStart(cws);
     425    }
    420426    solver->resolve();
    421427    sbres.branchEval |= 1;
     
    434440    const double old_bd = solver->getColLower()[ind];
    435441    solver->setColLower(ind, ceil(val));
    436     solver->setWarmStart(cws);
     442    if (cws) {
     443      solver->setWarmStart(cws);
     444    }
    437445    solver->resolve();
    438446    sbres.branchEval |= 2;
    439447    sbres.status[1] =
    440       (solver->isAbandoned()           ? BCP_Abandoned : 0) |
    441       (solver->isProvenOptimal()       ? BCP_ProvenOptimal : 0) |
     448      (solver->isAbandoned()              ? BCP_Abandoned : 0) |
     449      (solver->isProvenOptimal()          ? BCP_ProvenOptimal : 0) |
    442450      (solver->isProvenPrimalInfeasible() ? BCP_ProvenPrimalInf : 0);
    443451    sbres.objval[1] =
     
    714722  clear_SB_results();
    715723
     724  CoinWarmStart* cws = solver->getWarmStart();
     725  Bonmin::IpoptWarmStart* iws = dynamic_cast<Bonmin::IpoptWarmStart*>(cws);
     726  if (iws && iws->empty()) {
     727    delete cws;
     728    cws = NULL;
     729  }
    716730  BCP_lp_prob* p = getLpProblemPointer();
    717   CoinWarmStart* cws = solver->getWarmStart();
    718   BCP_warmstart* ws = BCP_lp_convert_CoinWarmStart(*p, cws);
    719 
    720 
    721   // FIXME: This test will have to be changed to >= 1
     731  CoinWarmStart* cws_tmp = cws->clone(); // the next call destroys it
     732  BCP_warmstart* ws = cws ? BCP_lp_convert_CoinWarmStart(*p, cws_tmp) : NULL;
     733
    722734  if (pidNum >= 0) {
    723735    if (pidNum > 0) {
     
    958970  buf.unpack(objvalOrig);
    959971  buf.unpack(cutoff);
    960   BCP_warmstart* ws = BCP_unpack_warmstart(buf);
     972  bool has_ws;
     973  buf.unpack(has_ws);
     974  BCP_warmstart* ws = has_ws ? BCP_unpack_warmstart(buf) : NULL;
    961975  int changeType;
    962976  int objInd;
     
    981995  }
    982996
    983   CoinWarmStart* cws = ws->convert_to_CoinWarmStart();
    984   nlp.setWarmStart(cws);
    985  
    986   nlp.resolve();
    987  
     997  if (ws) {
     998    CoinWarmStart* cws = ws->convert_to_CoinWarmStart();
     999    nlp.setWarmStart(cws);
     1000    nlp.resolve();
     1001    delete cws;
     1002    delete ws;
     1003  } else {
     1004    nlp.initialSolve();
     1005  }
     1006
    9881007  int status =
    9891008    (nlp.isAbandoned()              ? BCP_Abandoned : 0) |
     
    10211040  delete[] cub;
    10221041
    1023   delete cws;
    1024   delete ws;
    1025 
    10261042  bm_stats.incNumberSbSolves();
    10271043}
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.cpp

    r1000 r1009  
    2222
    2323#include "Ipopt/BonIpoptSolver.hpp"
     24#include "Ipopt/BonIpoptWarmStart.hpp"
    2425#ifdef COIN_HAS_FILTERSQP
    2526#include "Filter/BonFilterSolver.hpp"
     27#include "Filter/BonFilterWarmStart.hpp"
     28#include "Filter/BonBqpdWarmStart.hpp"
    2629#endif
    2730
     
    311314    problem_(NULL),
    312315    app_(NULL),
     316    warmstart_(NULL),
    313317    rowsense_(NULL),
    314318    rhs_(NULL),
     
    499503  }
    500504
     505  warmstart_ = source.warmstart_ ? source.warmstart_->clone() : NULL;
     506
    501507  if(source.obj_) {
    502508    obj_ = new double[source.getNumCols()];
     
    537543    pushValue_ = rhs.pushValue_;
    538544
     545    delete warmstart_;
     546    warmstart_ = NULL;
     547
    539548    if(IsValid(rhs.tminlp_)) {
    540549
     
    542551      problem_ = new TMINLP2TNLP(tminlp_);
    543552      app_ = rhs.app_->clone();
     553
     554      warmstart_ = rhs.warmstart_ ? rhs.warmstart_->clone() : NULL;
    544555
    545556      feasibilityProblem_ = new TNLP2FPNLP
     
    587598      tminlp_ =NULL;
    588599      problem_ = NULL;
    589 app_ = NULL;
     600      app_ = NULL;
    590601      feasibilityProblem_ = NULL;
    591602    }
     
    647658  delete [] obj_;
    648659  delete oaHandler_;
     660  delete warmstart_;
    649661}
    650662
     
    698710OsiTMINLPInterface::resolveForCost(int numsolve)
    699711{
     712  // This method assumes that a problem has just been solved and we try for a
     713  // different solution. So disregard (in fact, clear out) any warmstart info
     714  // we might have, and acquire a new one before returning.
     715  delete warmstart_;
     716  warmstart_ = NULL;
     717 
    700718  /** Save current optimum. */
    701719  vector<double> point(getNumCols()*3+ getNumRows());
     
    773791  optimizationStatus_ = app_->ReOptimizeTNLP(GetRawPtr(problem_));
    774792  hasBeenOptimized_ = true;
     793
     794  if (exposeWarmStart_) {
     795    warmstart_ = app_->getWarmStart(problem_);
     796  }
    775797}
    776798
     
    778800OsiTMINLPInterface::resolveForRobustness(int numsolve)
    779801{
     802  // This method assumes that a problem has just been solved and we try for a
     803  // different solution. So disregard (in fact, clear out) any warmstart info
     804  // we might have, and acquire a new one before returning.
     805  delete warmstart_;
     806  warmstart_ = NULL;
     807 
    780808  //std::cerr<<"Resolving the problem for robustness"<<std::endl;
    781809  //First remove warm start point and resolve
     
    801829
    802830  if(!isAbandoned()) {
    803     messageHandler()->message(WARN_SUCCESS_WS,
    804         messages_)
    805     << CoinMessageEol ;
     831    messageHandler()->message(WARN_SUCCESS_WS, messages_) << CoinMessageEol ;
     832    // re-enable warmstart and get it
     833    app_->enableWarmStart();
     834    if (exposeWarmStart_) {
     835      warmstart_ = app_->getWarmStart(problem_);
     836    }
    806837    return; //we won go on
    807838  }
     
    834865
    835866    if(!isAbandoned()) {
    836       messageHandler()->message(WARN_SUCCESS_RANDOM,
    837           messages_)
    838       <<f+2
    839       << CoinMessageEol ;
     867      messageHandler()->message(WARN_SUCCESS_RANDOM, messages_)
     868        << f+2 << CoinMessageEol ;
     869      // re-enable warmstart and get it
     870      app_->enableWarmStart();
     871      if (exposeWarmStart_) {
     872        warmstart_ = app_->getWarmStart(problem_);
     873      }
    840874      return; //we have found a solution and continue
    841875    }
     
    856890                           probName);
    857891  }
     892  // Do NOT get warmstart in other cases
    858893}
    859894
     
    12031238OsiTMINLPInterface::getWarmStart() const
    12041239{
    1205   if (exposeWarmStart_) {
    1206     return app_->getWarmStart(problem_);
     1240  if (exposeWarmStart_ && warmstart_) {
     1241    return warmstart_->clone();
    12071242  }
    12081243  else {
     
    12131248      the warmstart information was accepted or not. */
    12141249bool
    1215 OsiTMINLPInterface::setWarmStart(const CoinWarmStart* warmstart)
    1216 {
     1250OsiTMINLPInterface::setWarmStart(const CoinWarmStart* ws)
     1251{
     1252  delete warmstart_;
     1253  warmstart_ = NULL;
    12171254  hasBeenOptimized_ = false;
    12181255  if (exposeWarmStart_) {
    1219     return app_->setWarmStart(warmstart, problem_);
     1256    if (ws == NULL) {
     1257      return true;
     1258    }
     1259    // Let's look at the warmstart...
     1260    const IpoptWarmStart* iws = dynamic_cast<const IpoptWarmStart*>(ws);
     1261    if (iws) {
     1262      warmstart_ = ws->clone();
     1263      return true;
     1264    }
     1265#ifdef COIN_HAS_FILTERSQP
     1266    const FilterWarmStart* fws = dynamic_cast<const FilterWarmStart*>(ws);
     1267    if (fws) {
     1268      warmstart_ = ws->clone();
     1269      return true;
     1270    }
     1271    const BqpdWarmStart* bws = dynamic_cast<const BqpdWarmStart*>(ws);
     1272    if (bws) {
     1273      warmstart_ = ws->clone();
     1274      return true;
     1275    }
     1276#endif
     1277    // See if it is anything else than the CoinWarmStartBasis that all others
     1278    // derive from
     1279    const CoinWarmStartPrimalDual* pdws =
     1280      dynamic_cast<const CoinWarmStartPrimalDual*>(ws);
     1281    if (pdws) {
     1282      // Must be an IpoptWarmStart, since the others do not derive from this.
     1283      // Accept it.
     1284      warmstart_ = new IpoptWarmStart(*pdws);
     1285      return true;
     1286    }
     1287    return false;
     1288    // return app_->setWarmStart(warmstart, problem_);
    12201289  }
    12211290  else {
     
    23042373  assert(IsValid(problem_));
    23052374
     2375  // Discard warmstart_ if we had one
     2376  delete warmstart_;
     2377  warmstart_ = NULL;
     2378 
    23062379  if(!hasPrintedOptions) {
    23072380    int printOptions;
     
    23382411    }
    23392412  firstSolve_ = false;
     2413
     2414  // if warmstart_ is not empty then had to use resolveFor... and that created
     2415  // the warmstart at the end, and we have nothing to do here. Otherwise...
     2416  if (! warmstart_ && ! isAbandoned()) {
     2417    if (exposeWarmStart_) {
     2418      warmstart_ = app_->getWarmStart(problem_);
     2419    }
     2420  }
    23402421}
    23412422
     
    23472428  assert(IsValid(app_));
    23482429  assert(IsValid(problem_));
     2430 
     2431  int has_warmstart = warmstart_ == NULL ? 0 : 1;
     2432  // Let's look at the warmstart...
     2433  if (has_warmstart == 1) {
     2434    const IpoptWarmStart* iws = dynamic_cast<const IpoptWarmStart*>(warmstart_);
     2435    if (iws) {
     2436      has_warmstart = iws->empty() ? 0 : 2;
     2437    }
     2438  }
     2439#ifdef COIN_HAS_FILTERSQP
     2440  if (has_warmstart == 1) {
     2441    const FilterWarmStart* fws=dynamic_cast<const FilterWarmStart*>(warmstart_);
     2442    if (fws) {
     2443      has_warmstart = fws->empty() ? 0 : 2;
     2444    }
     2445  }
     2446  if (has_warmstart == 1) {
     2447    const BqpdWarmStart* bws = dynamic_cast<const BqpdWarmStart*>(warmstart_);
     2448    if (bws) {
     2449      has_warmstart = bws->empty() ? 0 : 2;
     2450    }
     2451  }
     2452#endif
     2453  assert(has_warmstart != 1); // FIXME LL: this should be removed.
     2454  if (has_warmstart < 2) {
     2455    // empty (or unrecognized) warmstart
     2456    initialSolve();
     2457    return;
     2458  }
     2459  app_->setWarmStart(warmstart_, problem_);
     2460  delete warmstart_;
     2461  warmstart_ = NULL;
     2462
    23492463  if (INT_BIAS > 0.) {
    23502464    app_->options()->SetStringValue("warm_start_same_structure", "yes");
     
    23712485  else if(numRetryResolve_ ||
    23722486          (numRetryInfeasibles_ && isProvenPrimalInfeasible() ))
    2373           resolveForCost(max(numRetryResolve_, numRetryInfeasibles_));
    2374  
     2487    resolveForCost(max(numRetryResolve_, numRetryInfeasibles_));
     2488
     2489  // if warmstart_ is not empty then had to use resolveFor... and that created
     2490  // the warmstart at the end, and we have nothing to do here. Otherwise...
     2491  if (! warmstart_ && ! isAbandoned()) {
     2492    if (exposeWarmStart_) {
     2493      warmstart_ = app_->getWarmStart(problem_);
     2494    }
     2495  }
    23752496}
    23762497
  • trunk/Bonmin/src/Interfaces/BonOsiTMINLPInterface.hpp

    r908 r1009  
    3535  /** Solvers for solving nonlinear programs.*/
    3636  enum Solver{
    37     EIpopt=0 /** <a href="http://projects.coin-or.org/Ipopt">
    38     Ipopt </a> interior point algorithm.*/,
     37    EIpopt=0 /** <a href="http://projects.coin-or.org/Ipopt"> Ipopt </a> interior point algorithm.*/,
    3938    EFilterSQP /** <a href="http://www-unix.mcs.anl.gov/~leyffer/solvers.html"> filterSQP </a> Sequential Quadratic Programming algorithm.*/
    4039  };
     
    170169
    171170  /** Resolve the continuous relaxation after problem modification.
    172       Have to call initialSolve before calling this
     171      initialSolve may or may not have been called before this is called. In
     172      any case, this must solve the problem, and speed the process up if it
     173      can reuse any remnants of data that might exist from a previous solve.
    173174   */
    174175  virtual void resolve();
    175176
    176   /** Resolve the problem with different random starting points
    177       to try to find a better solution (only makes sense for a non-convex problem.*/
     177  /** Resolve the problem with different random starting points to try to find
     178      a better solution (only makes sense for a non-convex problem.*/
    178179  virtual void resolveForCost(int numretry);
    179180
     
    10641065  //@}
    10651066
     1067  /** Warmstart information for reoptimization */
     1068  CoinWarmStart* warmstart_;
     1069
    10661070  /**@name Cached information on the problem */
    10671071  //@{
  • trunk/Bonmin/src/Interfaces/Ipopt/BonIpoptSolver.cpp

    r996 r1009  
    281281    int numcols = tnlp->num_variables();
    282282    int numrows = tnlp->num_constraints();
    283     const double * colLow = tnlp->x_l();
    284     const double * colUp = tnlp->x_u();
    285     for (int i = 0; i < numcols ; i++) {
    286       CoinWarmStartBasis::Status status = ws->getStructStatus(i);
    287       if (status == CoinWarmStartBasis::atLowerBound) {
    288         tnlp->setxInit(i,colLow[i]);
    289         tnlp->setDualInit(i + numcols,0.);
    290       }
    291       else if (status == CoinWarmStartBasis::atUpperBound) {
    292         tnlp->setxInit(i,colUp[i]);
    293         tnlp->setDualInit(i ,0.);
    294       }
    295       else {
    296         tnlp->setDualInit(i ,0.);
    297         tnlp->setDualInit(i + numcols , 0.);
    298       }
    299     }
    300     for (int i = 0; i < numrows ; i++) {
    301       CoinWarmStartBasis::Status status = ws->getArtifStatus(i);
    302       if (status == CoinWarmStartBasis::atLowerBound) {
    303         tnlp->setDualInit(i + 2*numcols , 0.);
    304       }
    305     }
    306     int nElem = ws->values()->getNumElements();
    307     const int * inds = ws->values()->getIndices();
    308     const double * elems = ws->values()->getElements();
    309 
    310     for (int i = 0 ; i < nElem ; i++) {
    311       tnlp->setxInit(inds[i],elems[i]);
    312     }
     283
     284    assert(numcols == ws->primalSize());
     285    assert(2*numcols + numrows == ws->dualSize());
     286    tnlp->setxInit(ws->primalSize(), ws->primal());
     287    tnlp->setDualsInit(ws->dualSize(), ws->dual());
    313288
    314289    if (IsValid(ws->warm_starter()))
    315290      tnlp->SetWarmStarter(ws->warm_starter());
     291
    316292    return 1;
    317293  }
  • trunk/Bonmin/src/Interfaces/Ipopt/BonIpoptWarmStart.cpp

    r916 r1009  
    99// Date : 02/15/2006
    1010
    11 
    1211#include "BonIpoptWarmStart.hpp"
    1312#include "CoinHelperFunctions.hpp"
    14 
    15 
    1613
    1714#include "BonTMINLP2TNLP.hpp"
     
    2421  IpoptWarmStart::IpoptWarmStart
    2522  (bool empty, int numvars, int numcont):
     23      CoinWarmStartPrimalDual(),
    2624      CoinWarmStartBasis(),
    27       values_(),
    28       tempValues_(NULL),
    2925      warm_starter_(NULL),
    3026      empty_(empty)
     
    3531  IpoptWarmStart::IpoptWarmStart(const Ipopt::SmartPtr<TMINLP2TNLP> tnlp,
    3632      SmartPtr<IpoptInteriorWarmStarter> warm_starter):
    37       values_(),
    38       tempValues_(NULL),
     33      CoinWarmStartPrimalDual(tnlp->num_variables(),
     34                              2*tnlp->num_variables()+tnlp->num_constraints(),
     35                              tnlp->x_sol(), tnlp->duals_sol()),
     36      CoinWarmStartBasis(),
    3937      warm_starter_(warm_starter),
    4038      empty_(false)
     
    4240    int numcols = tnlp->num_variables();
    4341    int numrows = tnlp->num_constraints();
     42    // initialize the size in the CoinWarmStartBasis part
    4443    setSize(numcols,numrows);
    45     values_.reserve(numcols+numrows); //AW: Factor 2 is missing?
    46     //PB: I don't think so (but it is not obvious)
    47 
    48     double epsilon = 1e-08;//ipopt.getPushFact();
    49     const double * primals = tnlp->x_sol();
    50     const double * duals = tnlp->duals_sol();
    51     const double * colLo = tnlp->x_l();
    52     const double * colUp = tnlp->x_u();
    53     for (int i = 0 ; i < numcols ; i++) {
    54       if (primals[i] - colLo[i] < epsilon) {
    55         setStructStatus(i, atLowerBound);
    56         if (fabs(duals[i]) > epsilon) {
    57           values_.insert(i + numcols ,duals[i]);
    58         }
    59 
    60 //       assert(duals[i +numrows + numcols] <= 100 * epsilon
    61 //           ||
    62 //           colUp[i] - colLo[i] <= epsilon
    63 //             ||
    64 //           colUp[i] - colLo[i] > 1e50);
    65 
    66       }
    67       else if ( colUp[i] - primals[i] < epsilon) {
    68         setStructStatus(i, atUpperBound);
    69         if (fabs(duals[i + numcols]) > epsilon) {
    70           values_.insert(i + 2 * numcols ,duals[i + numcols]);
    71         }
    72 //       assert(duals[i + numrows] <= epsilon
    73 //           ||
    74 //           colUp[i] - colLo[i] <= epsilon
    75 //           ||
    76 //           colUp[i] - colLo[i] > 1e100);
    77       }
    78       else {
    79         setStructStatus(i, basic);
    80 //       assert((duals[i + numrows] <= epsilon && duals[i+ numrows +numcols] <= epsilon)
    81 //           ||
    82 //           colUp[i] - colLo[i] <= epsilon
    83 //           ||
    84 //           colUp[i] - colLo[i] > 1e100);
    85 
    86         values_.insert(i , primals[i]);
    87       }
    88     }
    89 
    90     // int i2 = 2*numcols;
    91     for (int i = 0 ; i < numrows ; i++) {
    92       if (fabs(duals[i + 2*numcols])> 0.01) {
    93         values_.insert(i + 3 * numcols,duals[i + 2*numcols]);
    94         setArtifStatus(i, atLowerBound);
    95       }
    96       else {
    97         setArtifStatus(i, basic);
    98       }
    99 
    100     }
    101     values_.sortIncrIndex();
    10244  }
    10345
    10446/// Copy constructor
    10547  IpoptWarmStart::IpoptWarmStart( const IpoptWarmStart &other, bool ownValues):
    106       CoinWarmStartBasis(other),
    107       values_(other.values_),
    108       tempValues_(other.tempValues_),
    109       warm_starter_(NULL),//(other.warm_starter_),
    110       empty_(other.empty_)
     48    CoinWarmStartPrimalDual(other),
     49    CoinWarmStartBasis(other),
     50    warm_starter_(NULL /*other.warm_starter_*/),
     51    empty_(other.empty_)
    11152  {
    11253    //  if(ownValues_ && other.values_ != NULL)
    11354  }
    11455
    115 
     56/// A constructor from a CoinWarmStartPrimalDual
     57  IpoptWarmStart::IpoptWarmStart(const CoinWarmStartPrimalDual& pdws) :
     58    CoinWarmStartPrimalDual(pdws),
     59    CoinWarmStartBasis(),
     60    warm_starter_(NULL),
     61    empty_(false)
     62  {   
     63  }
     64 
    11665  CoinWarmStartDiff*
    11766  IpoptWarmStart::generateDiff(const CoinWarmStart *const oldCWS) const
    11867  {
    119     CoinWarmStartDiff * diff = CoinWarmStartBasis::generateDiff(oldCWS);
    120     CoinWarmStartBasisDiff * basisDiff =
    121       dynamic_cast<CoinWarmStartBasisDiff *>(diff);
     68    IpoptWarmStart const * const ws =
     69      dynamic_cast<IpoptWarmStart const * const > (oldCWS);
     70    assert(ws);
    12271
     72    CoinWarmStartDiff * diff = CoinWarmStartPrimalDual::generateDiff(ws);
     73
     74    CoinWarmStartPrimalDualDiff * pdDiff =
     75      dynamic_cast<CoinWarmStartPrimalDualDiff*>(diff);
    12376
    12477    CoinWarmStartDiff* retval =
    125       new IpoptWarmStartDiff(basisDiff, values_, NULL);//warm_starter_);
     78      new IpoptWarmStartDiff(pdDiff, NULL);//warm_starter_);
    12679    delete diff;
     80
    12781    return retval;
    12882  }
     
    13286  IpoptWarmStart::applyDiff (const CoinWarmStartDiff *const cwsdDiff)
    13387  {
    134     CoinWarmStartBasis::applyDiff(cwsdDiff);
    13588    IpoptWarmStartDiff const * const ipoptDiff =
    13689      dynamic_cast<IpoptWarmStartDiff const * const > (cwsdDiff);
    137 
    138     tempValues_ = ipoptDiff->diffValues_;
    139     //  ownValues_ = 0;
     90    assert(ipoptDiff);
     91    CoinWarmStartPrimalDual::applyDiff(ipoptDiff);
    14092    warm_starter_ = ipoptDiff->warm_starter();
    14193  }
     
    14799  IpoptWarmStart::flushPoint()
    148100  {
    149     if (values_.getNumElements() > 0)
    150       values_.clear();
     101    CoinWarmStartPrimalDual::clear();
    151102  }
    152103
     
    154105  IpoptWarmStartDiff::flushPoint()
    155106  {
    156     if (diffValues_) {
    157       delete diffValues_;
    158       diffValues_ = NULL;
    159     }
     107    CoinWarmStartPrimalDualDiff::clear();
    160108  }
    161109}
  • trunk/Bonmin/src/Interfaces/Ipopt/BonIpoptWarmStart.hpp

    r916 r1009  
    1313#define IpoptWarmStart_HPP
    1414#include "CoinWarmStartBasis.hpp"
     15#include "CoinWarmStartPrimalDual.hpp"
    1516#include "CoinPackedVector.hpp"
    1617#include "BonIpoptInteriorWarmStarter.hpp"
     
    2223
    2324  /** \brief Class for storing warm start informations for Ipopt.<br>
    24    * For practical reason (integration in Cbc) this class inherits from
     25   * This class inherits from CoinWarmStartPrimalDual, because that's what
     26   * this warmstart really is. <br>
     27   * For practical reason (integration in Cbc) this class also inherits from
    2528   * CoinWarmStartBasis. <br>
    2629   * This class stores a starting point (primal and dual values) for Ipopt.
     30   * <br>
     31   * <p>
     32   * The primal part of the base class contains the value of each primal
     33   * variable.
     34   * <p>
     35   * The dual part of the base class consists of three sections (the number of
     36   * values is 2*numcols+numrows):
     37     <UL>
     38     <li> First, values for dual variables associated with the lower bound
     39          constraints on structurals, i.e., primal variables (constraints
     40          \f$ l \leq x \f$);
     41     <li> Then values for dual variables associated with upper bound
     42           constraints on structurals (constraints \f$ x \leq u\f$).
     43     <li> the values for dual variables associated with regular constraints
     44          (constraints \f$ g(x) \leq 0 \f$)
     45     </UL>
    2746   */
    28   class IpoptWarmStart : public CoinWarmStartBasis
     47  class IpoptWarmStart :
     48    public virtual CoinWarmStartPrimalDual, public virtual CoinWarmStartBasis
    2949  {
    3050  public:
     
    3757    /// Copy constructor
    3858    IpoptWarmStart( const IpoptWarmStart &other, bool ownValues = 1);
     59    /// A constructor from a CoinWarmStartPrimalDual
     60    IpoptWarmStart(const CoinWarmStartPrimalDual& pdws);
    3961    /// Abstract destructor
    4062    virtual ~IpoptWarmStart();
     
    5476    virtual void
    5577    applyDiff (const CoinWarmStartDiff *const cwsdDiff);
    56     /** Access to values_ vector. */
    57     const CoinPackedVector * values() const
    58     {
    59       if (tempValues_)
    60         return tempValues_;
    61       else
    62         return &values_;
    63     }
     78
    6479    /** Accessor to warm start information obecjt */
    6580    SmartPtr<IpoptInteriorWarmStarter> warm_starter() const
     
    7792    }
    7893  private:
    79     /** Non zero values of the starting point. Primal and dual values are stored in the following order <p>
    80         <UL>
    81         <li> From 1 to CoinWarmStartBasis::numStrtucturals_ : values for primal variables (\f$ x \f$ ),
    82         <li> From numStructurals_+1 to  2 * numStructurals_ : values for dual variables associated to lower bound constraints on structurals (constraints \f$ l \leq x \f$).
    83         <li> From 2 numStructurals_+1 to  3 * numStructurals_ : values for dual variables associated to upper bound constraints on structurals (constraints \f$ x \leq u\f$).
    84         <li> From 3 numStructurals_+1 to  3 * numStructurals_ + numArtificials_ : values for dual variables associated with regular constraints (constraints \f$ g(x) \leq 0 \f$).
    85         </UL>
    86     */
    87     mutable CoinPackedVector values_;
    88     /** Temporary values not owned by this. */
    89     mutable CoinPackedVector * tempValues_;
    9094    /** warm start information object */
    9195    mutable SmartPtr<IpoptInteriorWarmStarter> warm_starter_;
     
    9498  };
    9599
     100  //###########################################################################
     101
    96102  /** \brief Diff class for IpoptWarmStart.
    97103   * Actually get the differences from CoinWarmStartBasis and stores the
     
    99105   \todo Find a way to free unused values.
    100106  */
    101   class IpoptWarmStartDiff : public CoinWarmStartBasisDiff
     107  class IpoptWarmStartDiff : public CoinWarmStartPrimalDualDiff
    102108  {
    103109  public:
    104110    friend class IpoptWarmStart;
    105     /** Usefull constructor*/
    106     IpoptWarmStartDiff(CoinWarmStartBasisDiff * diff, const CoinPackedVector &values,
    107         SmartPtr<IpoptInteriorWarmStarter> warm_starter):
    108         CoinWarmStartBasisDiff(*diff),
    109         diffValues_(NULL),
    110         warm_starter_(NULL)//(warm_starter)
     111    /** Useful constructor; takes over the data in \c diff */
     112    IpoptWarmStartDiff(CoinWarmStartPrimalDualDiff * diff,
     113                       SmartPtr<IpoptInteriorWarmStarter> warm_starter):
     114      CoinWarmStartPrimalDualDiff(),
     115      warm_starter_(NULL)//(warm_starter)
    111116    {
    112       if (values.getNumElements()>0)
    113         diffValues_ = new CoinPackedVector(values);
     117      CoinWarmStartPrimalDualDiff::swap(*diff);
    114118    }
    115119    /** Copy constructor. */
    116120    IpoptWarmStartDiff(const IpoptWarmStartDiff &other):
    117         CoinWarmStartBasisDiff(other),
    118         diffValues_(NULL),
    119         warm_starter_(NULL)//other.warm_starter_)
    120     {
    121       if (other.diffValues_)
    122         diffValues_ = new CoinPackedVector(*other.diffValues_);
    123     }
     121        CoinWarmStartPrimalDualDiff(other),
     122        warm_starter_(NULL /*other.warm_starter_*/) {}
    124123
    125124    /// Abstract destructor
    126     virtual ~IpoptWarmStartDiff()
    127     {
    128       delete diffValues_;
    129     }
     125    virtual ~IpoptWarmStartDiff() {}
    130126
    131127    /// `Virtual constructor'
     
    142138    void flushPoint();
    143139  private:
    144     /** Values of the vector. */
    145     CoinPackedVector * diffValues_;
    146140
    147141    /** warm start information object */
Note: See TracChangeset for help on using the changeset viewer.