Ignore:
Timestamp:
Jan 25, 2012 10:07:16 PM (8 years ago)
Author:
pbelotti
Message:

Created CouenneBab? from Bonmin::Bab. Putting CouenneRecordBestSol? to good use: upper bound now saved onto .sol file using real best saved solution (should fix a lot of "infeasible" instances that were pruned by good bounds ignored by Cbc).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/main/BonCouenne.cpp

    r786 r793  
    2828
    2929#include "BonCbc.hpp"
     30#include "CouenneBab.hpp"
    3031
    3132#include "CbcCutGenerator.hpp"
     
    9091  try {
    9192
    92     Bonmin::Bab bb;
    93     bb.setUsingCouenne (true);
     93    CouenneBab bb;
     94    //    bb.setUsingCouenne (true);
    9495
    9596    CouenneProblem *p = NULL;
     
    106107
    107108    p -> addObjective    (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), "min");
    108     p -> addLEConstraint (new exprSum (new exprClone (p->Var (0)), new exprClone (p->Var (2))),
    109                           new exprConst (1));
    110     p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))),
    111                           new exprConst (1));
    112     p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (3))),
    113                           new exprConst (1));
    114     p -> addEQConstraint (new exprSum (new exprClone (p->Var (2)), new exprClone (p->Var (3))),
    115                           new exprConst (1));
     109    p -> addLEConstraint (new exprSum (new exprClone (p->Var (0)), new exprClone (p->Var (2))), new exprConst (1));
     110    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), new exprConst (1));
     111    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (3))), new exprConst (1));
     112    p -> addEQConstraint (new exprSum (new exprClone (p->Var (2)), new exprClone (p->Var (3))), new exprConst (1));
    116113#endif
    117114
     
    155152
    156153    CouenneProblem *prob = couenne. couennePtr () -> Problem ();
     154
     155    bb. setProblem (prob);
    157156
    158157    jnlst -> Printf (J_ERROR, J_COUENNE, "\
     
    192191#endif
    193192
    194     //////////////////////////////////
    195 
    196193    std::cout.precision (10);
    197194
    198     ////////////////////////////////
    199195    int nr=-1, nt=-1;
    200196    double st=-1;
     
    213209#ifdef FM_TRACE_OPTSOL
    214210
    215     FILE *fSol = fopen ("bidon.sol", "w");
    216 
    217     if(fSol == NULL) {
    218       printf("### ERROR: can not open bidon.sol\n");
    219       exit(1);
    220     }
     211    //FILE *fSol = fopen ("bidon.sol", "w");
     212
     213    // if(fSol == NULL) {
     214    //   printf("### ERROR: can not open bidon.sol\n");
     215    //   exit(1);
     216    // }
    221217
    222218    if(cp != NULL) {
     
    286282      switch (retcomp) {
    287283      case -1: printf("No solution found\n"); break;
    288       case 0: printf("Best solution found by Cbc  Value: %10.4f Tolerance: %10g\n", modCbcSolVal, modCbcSolMaxViol); break;
    289       case 1: printf("Best solution found by Couenne  Value: %10.4f  Tolerance: %10g\n", modCouenneSolVal, modCouenneSolMaxViol); break;
     284      case 0: printf("Best solution found by Cbc. Value: %10.4f. Tolerance: %10g\n", modCbcSolVal, modCbcSolMaxViol); break;
     285      case 1: //printf("Best solution found by Couenne  Value: %10.4f  Tolerance: %10g\n", modCouenneSolVal, modCouenneSolMaxViol); break;
    290286      default: break; // never happens
    291287      }
     
    297293        }
    298294        printObj = rs->getVal();
    299         rs->printSol(fSol);
     295        //rs->printSol(fSol);
    300296      }
    301297      delete[] modCbcSol;
    302298      delete[] modCouenneSol;
    303299    }
    304     fclose(fSol);
     300    //fclose(fSol);
    305301#endif /* FM_TRACE_OPTSOL */
    306302
     
    346342
    347343    double
    348       ub = bb.model (). getObjValue (),
    349       lb = bb.model (). getBestPossibleObjValue ();
    350 
    351     char *gapstr = new char [80];
    352 
    353     sprintf (gapstr, "%.2f%%", 100. * (ub - lb) / (1. + fabs (lb)));
     344      ub = bb. model (). getObjValue (),
     345      lb = bb. model (). getBestPossibleObjValue ();
     346
     347    if (cp -> getRecordBestSol ())              ub = cp -> getRecordBestSol () -> getVal ();
     348    if ((fabs (lb) > COUENNE_INFINITY / 1e4) ||
     349        (lb > ub))                              lb = ub;
     350
     351    char
     352      *gapstr = new char [80],
     353      *lbstr  = new char [80],
     354      *ubstr  = new char [80];
     355
     356    sprintf (lbstr,  "%10g",     lb);
     357    sprintf (ubstr,  "%10g",     ub);
     358    sprintf (gapstr, "%.2f%%", fabs (100. * (ub - lb) / (1. + fabs (lb))));
    354359
    355360    jnlst -> Printf (J_ERROR, J_COUENNE, "\n\
     
    357362Linearization cuts added in total:       %8d  (separation time: %gs)\n\
    358363Total solving time:                      %8gs (%gs in branch-and-bound)\n\
    359 Lower bound:                           %10g\n\
    360 Upper bound:                           %10g  (gap: %s)\n\
    361 Branch-and-bound nodes:                  %8d\n\n",
     364Lower bound:                           %s\n\
     365Upper bound:                           %s  (gap: %s)\n\
     366Branch-and-bound nodes:                  %8d\n",
    362367                     nr, nt, st,
    363368                     CoinCpuTime () - time_start,
    364369                     cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
    365                      lb,
    366                      ub,
    367                      (ub > COUENNE_INFINITY/1e4) ? "inf" : gapstr,
     370                     (lb < -9e12) ||
     371                     (lb > COUENNE_INFINITY/1e4) ? "      -inf" : lbstr,
     372                     (ub > COUENNE_INFINITY/1e4) ? "       inf" : ubstr,
     373                     (ub > COUENNE_INFINITY/1e4) ? "--" : gapstr,
    368374                     bb.numNodes ());
    369375
     376    if (fabs (ub - bb. model (). getObjValue ()) > COUENNE_EPS * ub)
     377      jnlst -> Printf (J_ERROR, J_COUENNE,
     378                       "Warning: upper bounds differ between Couenne and Cbc. Saving Couenne's (more reliable).\n");
     379
    370380    delete [] gapstr;
     381    delete [] ubstr;
    371382
    372383    if (global_opt < COUENNE_INFINITY) { // some value found in couenne.opt
     
    400411                CoinCpuTime () - time_start,
    401412                cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
    402                 bb.model (). getBestPossibleObjValue (),
    403                 bb.model (). getObjValue (),
     413                lb, //bb.model (). getBestPossibleObjValue (),
     414                ub, //bb.model (). getObjValue (),
    404415                //bb.bestBound (),
    405416                //bb.bestObj (),
Note: See TracChangeset for help on using the changeset viewer.