Changeset 1076 for trunk


Ignore:
Timestamp:
May 14, 2014 3:32:08 AM (6 years ago)
Author:
pbelotti
Message:

normalize terms of FP; fix option help strings for lp_solver

Location:
trunk/Couenne/src
Files:
3 edited

Legend:

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

    r1063 r1076  
    104104  // (the latter being equivalent to
    105105  //
    106   // - z_i <=   P^i (x - x^0)  or  P^i x + z_i >= P^i x^0 (***)
     106  // - z_i <=   P^i (x - x^0)  or  P^i x + z_i >= P^i x^0 (***))
    107107  //
    108108  // so we'll use this instead as most coefficients don't change)
     
    146146    for (int i=0; i<n; i++)
    147147      if (fp -> Problem () -> Var (i) -> Multiplicity () > 0)
    148         P[i].insert (i, 1.);
     148        P[i].insert (i, 1. / sqrt ((double) n));
    149149  }
    150150
     
    162162    //
    163163    // amending MIP AND (integer variable OR FP_DIST_ALL)
    164     // amending ssLP  AND fractional variable
     164    // amending LP  AND fractional variable
    165165
    166166    bool intVar = lp -> isInteger (i);
     
    210210                        CouenneSparseMatrix *hessian,
    211211                        CoinPackedVector *P) {
     212
    212213  int
    213214    objInd = fp -> Problem () -> Obj (0) -> Body () -> Index (),
     
    258259      A [*col * n + *row] = fp -> multHessMILP () * *val;
    259260
     261  val -= num;
     262  row -= num;
     263  col -= num; 
     264
     265  double sqrt_trace = 0;
     266
     267  // Add Hessian part -- only lower triangular part
     268  for (int i=0; i<num; ++i, ++row, ++col)
     269    if (*col == *row)
     270      sqrt_trace += fabs (A [*col * n + *row]);
     271
     272  sqrt_trace = sqrt (sqrt_trace);
     273
     274  row -= num;
     275  col -= num;
     276
     277  // Add Hessian part -- only lower triangular part
     278  if (sqrt_trace > COUENNE_EPS)
     279    for (int i=0; i<num; ++i, ++row, ++col)
     280      A [*col * n + *row] /= sqrt_trace;
     281
     282  row -= num;
     283  col -= num;
     284
    260285  // Add distance part
    261286  for (int i=0; i<n; ++i)
    262287    if (fp -> Problem () -> Var (i) -> Multiplicity () > 0)
    263       A [i * (n+1)] += fp -> multDistMILP ();
     288      A [i * (n+1)] += fp -> multDistMILP () / sqrt (n);
    264289
    265290  // Add gradient-parallel term to the hessian, (x_z - x_z_0)^2. This
  • trunk/Couenne/src/heuristics/CouenneFeasPumpConstructors.cpp

    r1074 r1076  
    283283    // multHessMILP_, of the distance and the Hessian respectively
    284284
    285     bool *diag = NULL;
    286 
    287     if (multDistNLP_ != 0.) { // only use this if distance is used
    288 
    289       diag = new bool [problem_ -> nVars ()];
    290       CoinFillN (diag, problem_ -> nVars (), false);
    291     }
     285    //bool *diag = NULL;
     286
     287    // if (multDistNLP_ != 0.) { // only use this if distance is used
     288    //   diag = new bool [problem_ -> nVars ()];
     289    //   CoinFillN (diag, problem_ -> nVars (), false);
     290    // }
    292291
    293292    int    *row = nlp_ -> optHessian () -> row ();
     
    296295
    297296    int     num = nlp_ -> optHessian () -> num ();
     297
     298    double
     299      trace_H = 0,
     300      nActualTerms = 0;
     301
     302    // create the argument list (x_i - x_i^0)^2 for all i's
     303    for (int i=0; i<problem_ -> nVars (); ++i)
     304      if (!((problem_ -> Var (i) -> Multiplicity () <= 0) ||
     305            (compDistInt_ == FP_DIST_INT &&
     306             !(problem_ -> Var (i) -> isInteger ()))))
     307        nActualTerms += 1;
     308
     309    nActualTerms = (nActualTerms == 0) ? 1 : (1 / sqrt (nActualTerms));
     310
     311    // Add Hessian part -- only lower triangular part
     312    for (int i=0; i<num; ++i, ++val)
     313      if (*row++ == *col++)
     314        trace_H += fabs (*val);
     315
     316    trace_H = (trace_H < COUENNE_EPS) ? 1 : (1 / sqrt (trace_H));
     317
     318    row = nlp_ -> optHessian () -> row ();
     319    col = nlp_ -> optHessian () -> col ();
     320    val = nlp_ -> optHessian () -> val ();
    298321
    299322    // Add Hessian part -- only lower triangular part
     
    315338      if (*col < *row) { // that is, lower triangular
    316339
    317         if (2. * *val == 1.) // check if this would have trivial coefficient when doubled (off-diagonal element)
     340        if (2. * *val * trace_H == 1.) // check if this would have trivial coefficient when doubled (off-diagonal element)
    318341
    319342          list [nTerms++] = new exprMul (new exprSub (new exprClone (problem_ -> Var (*row)), new exprConst (iSol [*row])),
    320343                                         new exprSub (new exprClone (problem_ -> Var (*col)), new exprConst (iSol [*col])));
    321344
    322         else if (fabs (*val) > COUENNE_EPS) { // we don't need extreme precision...
     345        else if (fabs (*val * trace_H) > COUENNE_EPS) { // we don't need extreme precision...
    323346
    324347          expression **mlist = new expression * [3];
    325348
    326           mlist [0] = new exprConst (2. * *val);  // twice elements off diagonal
     349          mlist [0] = new exprConst (2. * *val * trace_H);  // twice elements off diagonal
    327350          mlist [1] = new exprSub (new exprClone (problem_ -> Var (*row)), new exprConst (iSol [*row]));
    328351          mlist [2] = new exprSub (new exprClone (problem_ -> Var (*col)), new exprConst (iSol [*col]));
     
    333356      } else if (*col == *row) { // or diagonal elements
    334357
    335         if (multDistNLP_ != 0.)
    336           diag [*col] = true;
    337 
    338         if (*val + multDistNLP () == 1.)
     358        //if (multDistNLP_ != 0.)
     359        //diag [*col] = true;
     360
     361        if (trace_H * *val + multDistNLP () * nActualTerms == 1.) // the plus is for the distance term
    339362
    340363          list [nTerms++] = new exprPow (new exprSub (new exprClone (problem_ -> Var (*row)),
     
    342365                                         new exprConst (2.));
    343366
    344         else if (fabs (*val + multDistNLP ()) > COUENNE_EPS)
    345 
    346           list [nTerms++] = new exprMul (new exprConst (*val + multDistNLP ()),
     367        else if (fabs (trace_H * *val + nActualTerms * multDistNLP ()) > COUENNE_EPS)
     368
     369          list [nTerms++] = new exprMul (new exprConst (trace_H * *val + nActualTerms * multDistNLP ()),
    347370                                         new exprPow (new exprSub (new exprClone (problem_ -> Var (*row)),
    348371                                                                   new exprConst (iSol [*row])),
     
    351374    }
    352375
    353     // third, add missing diagonal elements
    354 
     376    // third, add missing diagonal elements. NO! Already added above (fewer terms)
     377    /*
    355378    if (multDistNLP () > 0.) {
    356379
     
    372395        else                base = new exprSub (new exprClone (problem_ -> Var (i)), new exprConst  (*iS));
    373396
     397        base = new exprMul (base, new exprConst (nActualTerms));
     398
    374399        list [nTerms++] = new exprPow (base, new exprConst (2.));
    375400      }
    376401
    377402      delete [] diag;
    378     }
     403    } */
    379404  }
     405
     406  // as per latest development: objective is multiplied by one to
     407  // normalize it with distance and Hessian-based objective
    380408
    381409  if (multObjFNLP () != 0.)
     
    391419  expression *retexpr = new exprSum (list, nTerms);
    392420
    393   //printf ("new objective: "); retexpr -> print (); printf ("\n");
     421  // printf ("new objective: "); retexpr -> print (); printf ("\n");
    394422
    395423  return retexpr;
  • trunk/Couenne/src/main/BonCouenneSetup.cpp

    r1028 r1076  
    923923                                "Linear Programming solver for the linearization",
    924924                                "clp",
    925                                 "clp",    "Use the COIN-OR Open Source solver CLP",
     925                                "clp",    "Use the COIN-OR Open Source solver CLP (default)",
    926926                                "cplex",  "Use the commercial solver Cplex (license is needed)",
    927927                                "gurobi", "Use the commercial solver Gurobi (license is needed)",
    928928                                "soplex", "Use the freely available Soplex",
    929                                "xpress-mp", "Use the commercial solver Xpress MP (license is needed)"
     929                                "xpress-mp", "Use the commercial solver Xpress MP (license is needed)"
    930930                                );
    931931
Note: See TracChangeset for help on using the changeset viewer.