Changeset 1025 for trunk


Ignore:
Timestamp:
Dec 1, 2013 10:47:56 AM (6 years ago)
Author:
pbelotti
Message:

backwards compatible changes to FP

Location:
trunk/Couenne/src/heuristics
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/heuristics/CouenneFeasPump.cpp

    r1011 r1025  
    4343  double time0 = CoinCpuTime();
    4444
    45   if (//(problem_ -> nIntVars () <= 0) ||                   // feas pump on NLP? Why not?
     45  if ((nCalls_ == 0) ||                                     // check upper limit on number of runs
     46      //(problem_ -> nIntVars () <= 0) ||                   // feas pump on NLP? Why not?
    4647      (CoinCpuTime () > problem_ -> getMaxCpuTime ()) ||  // don't start if time is out
    4748      ((numberSolvePerLevel_ >= 0) &&                     // stop FP after a certain level
     
    5152    return 0;
    5253
     54  if (nCalls_ > 0) // only decrease it if positive. If -1, no limit on # calls
     55    --nCalls_;
     56
    5357  problem_ -> Jnlst () -> Printf (J_WARNING, J_NLPHEURISTIC, "==================================================== FP: BEGIN\n");
    54 
    55   problem_ -> Jnlst () -> Printf (J_ERROR, J_NLPHEURISTIC, "[FeasPump] Initializing\n");
     58  problem_ -> Jnlst () -> Printf (J_ERROR,   J_NLPHEURISTIC, "[FeasPump] Initializing\n");
    5659
    5760  // Solve NLP once at the beginning ////////////////////////
     
    7578  ////////////////////////////////////////////////////////////////
    7679
    77   if ((multHessNLP_  > 0.) ||
    78       (multHessMILP_ > 0.))
     80  if ((multHessNLP_  != 0.) ||
     81      (multHessMILP_ != 0.))
    7982    nlp_ -> getSaveOptHessian () = true;
    8083
     
    108111    problem_ -> Jnlst () -> Printf (J_WARNING, J_NLPHEURISTIC, "Feasibility Pump: error in initial NLP problem\n");
    109112
    110   if ((multHessNLP_  > 0.) ||
    111       (multHessMILP_ > 0.))
     113  if ((multHessNLP_  != 0.) ||
     114      (multHessMILP_ != 0.))
    112115    nlp_ -> getSaveOptHessian () = false;
    113116
     
    170173
    171174  expression *originalObjective = problem_ -> Obj (0) -> Body ();
     175
     176  double
     177    save_mDN = multDistNLP_,
     178    save_mHN = multHessNLP_,
     179    save_mON = multObjFNLP_,
     180    save_mDM = multDistMILP_,
     181    save_mHM = multHessMILP_,
     182    save_mOM = multObjFMILP_;
    172183
    173184  do {
     
    640651    }
    641652
     653    // update weights for hessian, distance, and objective, for both
     654    // MILP and NLP parts
     655
     656    //multHessNLP_ *= save_multHessNLP_; // exponential reduction
     657
     658    multDistNLP_  *= fabs (save_mDN); // update within loop
     659    multHessNLP_  *= fabs (save_mHN);
     660    multObjFNLP_  *= fabs (save_mON);
     661    multDistMILP_ *= fabs (save_mDM);
     662    multHessMILP_ *= fabs (save_mHM);
     663    multObjFMILP_ *= fabs (save_mOM);
     664
    642665  } while ((niter++ < maxIter_) &&
    643666           (retval == 0));
     
    752775  }
    753776
     777  // post-call fading update of coefficients
     778
     779  multDistNLP_  = save_mDN * fadeMult_;
     780  multHessNLP_  = save_mHN * fadeMult_;
     781  multObjFNLP_  = save_mON * fadeMult_;
     782  multDistMILP_ = save_mDM * fadeMult_;
     783  multHessMILP_ = save_mHM * fadeMult_;
     784  multObjFMILP_ = save_mOM * fadeMult_;
     785
    754786  if (iSol) delete [] iSol;
    755787  if (nSol) delete [] nSol;
     
    768800  problem_ -> Jnlst () -> Printf
    769801    (J_WARNING, J_NLPHEURISTIC, "FP: done ===================\n");
     802
     803  if (!retval)
     804    problem_ -> Jnlst () -> Printf
     805      (J_ERROR, J_NLPHEURISTIC, "FP: No solution found\n");
    770806
    771807  return retval;
  • trunk/Couenne/src/heuristics/CouenneFeasPump.hpp

    r1011 r1025  
    1717#include "CouenneTypes.hpp"
    1818#include "CbcHeuristic.hpp"
    19 
    20 #include "CouenneConfig.h"
    21 
    2219#include "CouenneFPpool.hpp"
    23 
    2420#include "IpOptionsList.hpp"
    2521
     
    3026struct Scip;
    3127class OsiSolverInterface;
     28
     29//
     30// A fading coefficient decreases from a to a^k at every iteration if
     31// a > 0. If a is negative, then it increases from 1-|a| = 1+a to
     32// 1-|a|^k and eventually converges to 1
     33//
     34
     35inline double fadingCoeff (double a)
     36{return (a<0) ? a+1 : a;}
    3237
    3338namespace Ipopt {
     
    138143    /// up to 1 for MILP and for NLP):
    139144
    140     double multDistNLP  () const {return multDistNLP_;}  ///< weight of distance  in NLP
    141     double multHessNLP  () const {return multHessNLP_;}  ///< weight of Hessian   in NLP
    142     double multObjFNLP  () const {return multObjFNLP_;}  ///< weight of objective in NLP
    143 
    144     double multDistMILP () const {return multDistMILP_;} ///< weight of distance  in MILP
    145     double multHessMILP () const {return multHessMILP_;} ///< weight of Hessian   in MILP
    146     double multObjFMILP () const {return multObjFMILP_;} ///< weight of objective in MILP
     145    double multDistNLP  () const {return fadingCoeff (multDistNLP_);}  ///< weight of distance  in NLP
     146    double multHessNLP  () const {return fadingCoeff (multHessNLP_);}  ///< weight of Hessian   in NLP
     147    double multObjFNLP  () const {return fadingCoeff (multObjFNLP_);}  ///< weight of objective in NLP
     148
     149    double multDistMILP () const {return fadingCoeff (multDistMILP_);} ///< weight of distance  in MILP
     150    double multHessMILP () const {return fadingCoeff (multHessMILP_);} ///< weight of Hessian   in MILP
     151    double multObjFMILP () const {return fadingCoeff (multObjFMILP_);} ///< weight of objective in MILP
    147152
    148153    /// return NLP
    149154    CouenneTNLP *nlp () const
    150155    {return nlp_;}
     156
     157    /// return number of calls (can be changeD)
     158    int &nCalls ()
     159    {return nCalls_;}
    151160
    152161#ifdef COIN_HAS_SCIP
     
    234243    /// Tabu management policy: none, use from pool, random perturbation of current solution
    235244    enum fpTabuMgtPolicy tabuMgt_;
     245
     246    /// How often should it be called
     247    int nCalls_;
     248
     249    /// decrease factor for MILP/NLP multipliers of distance/Hessian/objective
     250    double fadeMult_;
    236251  };
    237252}
  • trunk/Couenne/src/heuristics/CouenneFeasPumpConstructors.cpp

    r1011 r1025  
    8585  useSCIP_             (false),
    8686  milpMethod_          (0),
    87   tabuMgt_             (FP_TABU_NONE) {
     87  tabuMgt_             (FP_TABU_NONE),
     88  nCalls_              (0),
     89  fadeMult_            (1) {
    8890
    8991  int compareTerm = INTEGER_VARS;
     
    104106    options -> GetNumericValue ("feas_pump_mult_hess_milp", multHessMILP_,    "couenne.");
    105107    options -> GetNumericValue ("feas_pump_mult_objf_milp", multObjFMILP_,    "couenne.");
     108
     109    options -> GetNumericValue ("feas_pump_fademult",  fadeMult_,     "couenne.");
    106110
    107111    options -> GetStringValue  ("feas_pump_convcuts", s, "couenne.");
     
    155159 
    156160// Copy constructor /////////////////////////////////////////////
    157 CouenneFeasPump::CouenneFeasPump (const CouenneFeasPump &other) {
    158 
    159   operator= (other);
    160 }
     161CouenneFeasPump::CouenneFeasPump (const CouenneFeasPump &other)
     162{operator= (other);}
    161163
    162164
     
    198200    milpMethod_          = rhs. milpMethod_;
    199201    tabuMgt_             = rhs. tabuMgt_;
     202    nCalls_              = rhs. nCalls_;
     203    fadeMult_            = rhs. fadeMult_;
    200204
    201205    if (rhs. pool_)
     
    281285    bool *diag = NULL;
    282286
    283     if (multDistNLP_ > 0.) { // only use this if distance is used
     287    if (multDistNLP_ != 0.) { // only use this if distance is used
    284288
    285289      diag = new bool [problem_ -> nVars ()];
     
    329333      } else if (*col == *row) { // or diagonal elements
    330334
    331         if (multDistNLP_ > 0.)
     335        if (multDistNLP_ != 0.)
    332336          diag [*col] = true;
    333337
    334         if (*val + multDistNLP_ == 1.)
     338        if (*val + multDistNLP () == 1.)
    335339
    336340          list [nTerms++] = new exprPow (new exprSub (new exprClone (problem_ -> Var (*row)),
     
    338342                                         new exprConst (2.));
    339343
    340         else if (fabs (*val + multDistNLP_) > COUENNE_EPS)
    341 
    342           list [nTerms++] = new exprMul (new exprConst (*val + multDistNLP_),
     344        else if (fabs (*val + multDistNLP ()) > COUENNE_EPS)
     345
     346          list [nTerms++] = new exprMul (new exprConst (*val + multDistNLP ()),
    343347                                         new exprPow (new exprSub (new exprClone (problem_ -> Var (*row)),
    344348                                                                   new exprConst (iSol [*row])),
     
    349353    // third, add missing diagonal elements
    350354
    351     if (multDistNLP_ > 0.) {
     355    if (multDistNLP () > 0.) {
    352356
    353357      // create the argument list (x_i - x_i^0)^2 for all i's
     
    375379  }
    376380
    377   if (multObjFNLP_ != 0.)
    378     list [nTerms++] = new exprMul (new exprConst (multObjFNLP_),
     381  if (multObjFNLP () != 0.)
     382    list [nTerms++] = new exprMul (new exprConst (multObjFNLP ()),
    379383                                   new exprClone (problem_ -> Obj (0) -> Body ()));
    380384
     
    440444void CouenneFeasPump::registerOptions (Ipopt::SmartPtr <Bonmin::RegisteredOptions> roptions) {
    441445
    442   roptions -> AddStringOption2
     446  roptions -> AddStringOption4
    443447    ("feas_pump_heuristic",
    444448     "Apply the nonconvex Feasibility Pump",
    445449     "no",
    446      "no","",
    447      "yes","",
     450     "no",   "never called",
     451     "yes",  "called any time Cbc calls heuristics",
     452     "once", "call it at most once",
     453     "only", "Call it exactly once and then exit",
    448454     "An implementation of the Feasibility Pump for nonconvex MINLPs");
     455
     456  roptions -> AddBoundedNumberOption
     457    ("feas_pump_fademult",
     458     "decrease/increase rate of multipliers",
     459     0, false,
     460     1, false,
     461     1, "1 keeps initial multipliers from one call to the next; any <1 multiplies ALL of them");
    449462
    450463  roptions -> AddLowerBoundedIntegerOption
     
    484497      roptions -> AddBoundedNumberOption
    485498        (option, help,
    486          0., false,
    487          1., false,
    488          0., "0: no weight, 1: full weight");
     499         -1., true,
     500         +1., false,
     501         0., "0: neglected; 1: full weight; a in ]0,1[: weight is a^k where k is the FP iteration; a in ]-1,0[: weight is 1-|a|^k");
    489502    }
    490503
Note: See TracChangeset for help on using the changeset viewer.