Changeset 956


Ignore:
Timestamp:
May 19, 2013 10:18:25 AM (7 years ago)
Author:
pbelotti
Message:

restored working version. Trying to fix compilation errors on const_iterators

Location:
trunk/Couenne/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/cut/sdpcuts/CouenneMatrix.cpp

    r955 r956  
    239239    (*i) -> print ();
    240240
    241     if (!(++cnt) % WRAP)
     241    if ((++cnt) % WRAP == 0)
    242242      printf ("\n   ");
    243243  }
  • trunk/Couenne/src/cut/sdpcuts/CouenneMatrix.hpp

    r936 r956  
    105105    struct compare_pair_ind {
    106106      inline bool operator() (register const std::pair <int, CouenneSparseVector *> &a,
    107                               register const std::pair <int, CouenneSparseVector *> &b)
     107                              register const std::pair <int, CouenneSparseVector *> &b) const
    108108      {return a. first < b. first;}
    109109    };
  • trunk/Couenne/src/cut/sdpcuts/CouenneSdpCuts.cpp

    r955 r956  
    209209#endif
    210210
    211     for (std::set <std::pair <int, CouenneSparseVector *> >::const_iterator
     211    for (std::set <std::pair <int, CouenneSparseVector *>, CouenneExprMatrix::compare_pair_ind>::const_iterator
    212212           j  = (*i) -> getCols () . begin ();
    213213         j   != (*i) -> getCols () . end   (); ++j)
  • trunk/Couenne/src/cut/sdpcuts/CutGen.cpp

    r955 r956  
    109109  int indI = 0;
    110110
    111   for (std::set <std::pair <int, CouenneSparseVector *> >::const_iterator
     111 
     112  for (std::set <std::pair <int, CouenneSparseVector *>, CouenneExprMatrix::compare_pair_ind>::const_iterator
    112113         i  = minor -> getRows () . begin ();
    113114       i   != minor -> getRows () . end   (); ++i, ++indI) {
  • trunk/Couenne/src/main/BonCouenne.cpp

    r955 r956  
    4949#include "CouenneJournalist.hpp"
    5050
    51 #include "CouenneExprClone.hpp"
    52 #include "CouenneExprGroup.hpp"
    53 #include "CouenneExprAbs.hpp"
    54 #include "CouenneExprConst.hpp"
    55 #include "CouenneExprCos.hpp"
    56 #include "CouenneExprDiv.hpp"
    57 #include "CouenneExprExp.hpp"
    58 #include "CouenneExprInv.hpp"
    59 #include "CouenneExprLog.hpp"
    60 //#include "CouenneExprMax.hpp"
    61 //#include "CouenneExprMin.hpp"
    62 #include "CouenneExprMul.hpp"
    63 #include "CouenneExprOpp.hpp"
    64 #include "CouenneExprPow.hpp"
    65 #include "CouenneExprSin.hpp"
    66 #include "CouenneExprSub.hpp"
    67 #include "CouenneExprSum.hpp"
    68 #include "CouenneExprVar.hpp"
    69 
    7051#ifdef COIN_HAS_NTY
    71 // FIXME: horrible global variable. Brrr.
     52#include "Nauty.h"
     53
     54// FIXME: horrible global variables. Brrr.
    7255#include "CouenneBranchingObject.hpp"
    7356#endif
     
    9073#endif
    9174
    92 class MyTMINLP : public Bonmin::TMINLP {
    93    virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
    94        Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style) {
    95       n = 2; m = 1; nnz_jac_g = 0; nnz_h_lag = 0; index_style = Ipopt::TNLP::C_STYLE;
    96    };
    97 
    98    virtual bool get_variables_types(Ipopt::Index n, VariableType* var_types) {};
    99 
    100    virtual bool get_variables_linearity(Ipopt::Index n,
    101                  Ipopt::TNLP::LinearityType* var_types) {};
    102 
    103    virtual bool get_constraints_linearity(Ipopt::Index m,
    104                  Ipopt::TNLP::LinearityType* const_types) {};
    105 
    106    virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
    107        Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u) {};
    108 
    109    virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
    110                                    bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
    111        Ipopt::Index m, bool init_lambda,
    112        Ipopt::Number* lambda) {};
    113 
    114    virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
    115        Ipopt::Number& obj_value) {};
    116 
    117    virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
    118        Ipopt::Number* grad_f) {};
    119 
    120    virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
    121        Ipopt::Index m, Ipopt::Number* g) {};
    122 
    123    virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
    124        Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
    125        Ipopt::Index *jCol, Ipopt::Number* values) {};
    126 
    127    virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
    128        Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
    129        bool new_lambda, Ipopt::Index nele_hess,
    130        Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values) {};
    131 
    132    virtual void finalize_solution(TMINLP::SolverReturn status,
    133                                   Ipopt::Index n, const Ipopt::Number* x, Ipopt::Number obj_value) {};
    134 
    135    virtual const BranchingInfo * branchingInfo() const {};
    136 
    137    virtual const SosInfo * sosConstraints() const {};
    138 };
    139 
    14075//#define FM_FRES
     76
     77// restored working version
    14178
    14279int main (int argc, char *argv[]) {
     
    15592  char * pbName = NULL;
    15693
    157   const int infeasible = 1;
     94  bool infeasible = false;
    15895
    15996  try {
    16097
    16198    CouenneBab bb;
    162     //    bb.setUsingCouenne (true);
    16399
    164100    CouenneProblem *p = NULL;
    165101    CouenneInterface *ci = NULL;
    166102
    167     SmartPtr<Bonmin::TMINLP> tminlp;
    168 
    169 #if 1
     103#if 0
    170104    //ci = new CouenneInterface;
    171105    p = new CouenneProblem;
     
    173107    p -> addVariable (false, p -> domain ());
    174108    p -> addVariable (false, p -> domain ());
    175 
    176     double x_[2] = {0.,0.};
    177     double lb_[2] = {-COUENNE_INFINITY,-COUENNE_INFINITY};
    178     double ub_[2] = {COUENNE_INFINITY,COUENNE_INFINITY};
    179 
    180     p->domain()->push(2, x_, lb_, ub_);
    181 
    182     expression* nl[1] = { new exprOpp(new exprMul(new exprSum(new exprOpp(new exprPow(new exprClone(p->Var(1)), new exprConst(2.0))), new exprClone(p->Var(1))), new exprConst(100.0))) };
    183     exprGroup::lincoeff lin(1, std::pair<exprVar*, double>(p->Var(0), 100.0));
    184 
    185     p -> addObjective    (new exprConst(1), "min");
    186     p -> addEQConstraint (new exprGroup(0, lin, nl, 1), new exprConst (0));
    187 
    188     p->print();
    189 
    190     tminlp = new MyTMINLP();
     109    p -> addVariable (false, p -> domain ());
     110    p -> addVariable (false, p -> domain ());
     111
     112    p -> addObjective    (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), "min");
     113    p -> addLEConstraint (new exprSum (new exprClone (p->Var (0)), new exprClone (p->Var (2))), new exprConst (1));
     114    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), new exprConst (1));
     115    p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (3))), new exprConst (1));
     116    p -> addEQConstraint (new exprSum (new exprClone (p->Var (2)), new exprClone (p->Var (3))), new exprConst (1));
    191117#endif
    192118
    193119    CouenneSetup couenne;
    194 
    195     if (!couenne.InitializeCouenne (argv, p, tminlp, ci, &bb))
    196       throw infeasible;
    197 
    198     //////////////////////////////
    199120    CouenneCutGenerator *cg = NULL;
     121    ConstJnlstPtr jnlst;
     122    CouenneProblem *prob = NULL;
     123
     124    infeasible = !(couenne.InitializeCouenne (argv, p, NULL, ci, &bb));
    200125
    201126    // there is only one CouenneCutGenerator object; scan array until
     
    205130
    206131      for (std::list <Bonmin::BabSetupBase::CuttingMethod>::iterator
    207                    i  = couenne.cutGenerators () . begin ();
     132             i  = couenne.cutGenerators () . begin ();
    208133           !cg && (i != couenne.cutGenerators () . end ());
    209134           ++i)
     
    220145      cg -> setBabPtr (&bb);
    221146
    222     else {
     147    else if (!infeasible) {
     148
    223149      printf ("main(): ### ERROR: Can not get CouenneCutGenerator\n");
    224       exit (1);
     150      exit (-1);
    225151    }
    226152
    227153    // initial printout
    228154
    229     ConstJnlstPtr jnlst = couenne. couennePtr () -> Jnlst ();
    230 
    231     CouenneProblem *prob = couenne. couennePtr () -> Problem ();
     155    jnlst = couenne. couennePtr () -> Jnlst ();
     156    prob  = couenne. couennePtr () -> Problem ();
    232157
    233158    bb. setProblem (prob);
     159
     160    int retcomp = 2; // unspecified.
    234161
    235162    jnlst -> Printf (J_ERROR, J_COUENNE, "\
     
    262189    //////////////////////////////////
    263190
    264     bb (couenne); // do branch and bound
     191#ifdef COIN_HAS_NTY
     192    double symmGroupSize = prob -> orbitalBranching () ? prob -> getNtyInfo () -> getGroupSize () : -1;
     193#endif
     194
     195    if (!infeasible)
     196      bb (couenne); // do branch and bound
    265197
    266198#ifdef COIN_HAS_NTY
     
    280212
    281213#if defined (FM_TRACE_OPTSOL) || defined (FM_FRES)
    282     double cbcLb = bb.model ().getBestPossibleObjValue();
     214    double cbcLb = (infeasible ? -COIN_DBL_MAX : bb.model (). getBestPossibleObjValue ());
    283215    double printObj = 0;
    284216    bool foundSol = false;
     
    295227
    296228    if(cp != NULL) {
    297       double cbcObjVal = bb.model().getObjValue();
    298       int modelNvars = bb.model().getNumCols();
     229      double cbcObjVal = infeasible ? COIN_DBL_MAX : bb.model().getObjValue();
     230      int modelNvars = prob -> nVars ();//bb.model().getNumCols();
    299231
    300232      CouenneRecordBestSol *rs = cp->getRecordBestSol();
    301       const double *cbcSol = bb.model().getColSolution();
     233      const double *cbcSol = infeasible ? NULL : bb.model().getColSolution();
    302234      double *modCbcSol = new double[modelNvars];
    303235      double modCbcSolVal= 1e100, modCbcSolMaxViol = 0;
     
    310242      }
    311243
    312       if(cbcObjVal < 1e49) {
     244      // round cbcSol's integer coordinates
     245
     246      // for (int i=0; i<modelNvars; i++)
     247      //        if (cp -> Var (i) -> isDefinedInteger ())
     248      //          cbcSol [i] = COUENNE_round (cbcSol [i]);
     249
     250      if (cbcObjVal < 1e49 && !infeasible) {
    313251
    314252#ifdef FM_CHECKNLP2
     
    335273      bool couenneSolIsFeas = false;
    336274
     275      // round couenneSol's integer coordinates
     276
     277      // for (int i=0; i<modelNvars; i++)
     278      //        if (cp -> Var (i) -> isDefinedInteger ())
     279      //          couenneSol [i] = COUENNE_round (couenneSol [i]);
     280
    337281      if(couenneSol != NULL) {
    338282#ifdef FM_CHECKNLP2
     283        int cMS = rs->getCardModSol();
    339284        couenneSolIsFeas = cp->checkNLP2(couenneSol, 0, false,
    340285                                         false, true,
    341286                                         cp->getFeasTol());
    342         int cMS = rs->getCardModSol();
    343287        CoinCopyN(rs->getModSol(cMS), cMS, modCouenneSol);
    344288        modCouenneSolVal = rs->getModSolVal();
    345289        modCouenneSolMaxViol = rs->getModSolMaxViol();
    346290#else /* not FM_CHECKNLP2 */
     291        int cMS = cp->nVars();
    347292        couenneSolIsFeas = cp->checkNLP(couenneSol, modCouenneSolVal, true);
    348         int cMS = cp->nVars();
    349293        CoinCopyN(couenneSol, cMS, modCouenneSol);
    350294        modCouenneSolMaxViol = cp->getFeasTol();
     
    353297      }
    354298
    355       int retcomp = rs->compareAndSave(modCbcSol, modCbcSolVal,
    356                                        modCbcSolMaxViol, cbcSolIsFeas,
    357                                        modCouenneSol, modCouenneSolVal,
    358                                        modCouenneSolMaxViol, couenneSolIsFeas,
    359                                        modelNvars, cp->getFeasTol());
    360       switch (retcomp) {
    361       case -1: printf("No solution found\n"); break;
    362       case 0: printf("Best solution found by Cbc. Value: %10.4f. Tolerance: %10g\n", modCbcSolVal, modCbcSolMaxViol); break;
    363       case 1: //printf("Best solution found by Couenne  Value: %10.4f  Tolerance: %10g\n", modCouenneSolVal, modCouenneSolMaxViol); break;
    364       default: break; // never happens
    365       }
     299      retcomp = rs -> compareAndSave (modCbcSol,     modCbcSolVal,     modCbcSolMaxViol,     cbcSolIsFeas,
     300                                      modCouenneSol, modCouenneSolVal, modCouenneSolMaxViol, couenneSolIsFeas,
     301                                      modelNvars, cp->getFeasTol());
     302
     303      // switch (retcomp) {
     304      // case -1: printf("No solution found\n"); break;
     305      // case 0: printf("Best solution found by Cbc. Value: %10.4f. Tolerance: %10g\n", modCbcSolVal, modCbcSolMaxViol); break;
     306      // case 1: //printf("Best solution found by Couenne  Value: %10.4f  Tolerance: %10g\n", modCouenneSolVal, modCouenneSolMaxViol); break;
     307      // default: break; // never happens
     308      // }
    366309
    367310      if(rs->getHasSol()) {
     
    409352        fprintf(f_res, "         *");
    410353      }
    411       fprintf(f_res, " %10d %10.4f\n", bb.numNodes (),
     354      fprintf(f_res, " %10d %10.4f\n", infeasible ? 0 : bb.numNodes (),
    412355              CoinCpuTime () - time_start);
    413356      fclose(f_res);
     
    420363
    421364    double
    422       ub = bb. model (). getObjValue (),
    423       lb = bb. model (). getBestPossibleObjValue ();
     365      ub = infeasible ?  COIN_DBL_MAX : bb. model (). getObjValue (),
     366      lb = infeasible ? -COIN_DBL_MAX : bb. model (). getBestPossibleObjValue ();
    424367
    425368    if (cp -> getRecordBestSol () &&
    426         (ub > cp -> getRecordBestSol () -> getVal ())) ub = cp -> getRecordBestSol () -> getVal ();
    427 
    428     if ((fabs (lb) > COUENNE_INFINITY / 1e4) ||
    429         (lb > ub))                                     lb = ub;
     369        cp       -> getRecordBestSol () -> getHasSol () &&
     370        (ub > cp -> getRecordBestSol () -> getVal    ()))   
     371      ub = cp -> getRecordBestSol () -> getVal ();
     372
     373    if (false || //(fabs (lb) > COUENNE_INFINITY / 1e4) ||
     374        (lb > ub))
     375      lb = ub;
    430376
    431377    char
    432       *gapstr = new char [80],
    433       *lbstr  = new char [80],
    434       *ubstr  = new char [80];
     378      *gapstr = new char [40],
     379      *lbstr  = new char [40],
     380      *ubstr  = new char [40];
     381
     382    // CouenneSolverInterface <OsiClpSolverInterface> *csi = dynamic_cast <CouenneSolverInterface *> (couenne.continuousSolver ());
     383
     384    // double rootLB = csi -> rootLB ();
    435385
    436386    sprintf (lbstr,  "%10g",     lb);
     
    438388    sprintf (gapstr, "%.2f%%", fabs (100. * (ub - lb) / (1. + fabs (lb))));
    439389
    440     jnlst -> Printf (J_ERROR, J_COUENNE, "\n\
     390    if (!infeasible)
     391      jnlst -> Printf (J_ERROR, J_COUENNE, "\n\
    441392Linearization cuts added at root node:   %8d\n\
    442 Linearization cuts added in total:       %8d  (separation time: %gs)\n\
    443 Total solving time:                      %8gs (%gs in branch-and-bound)\n\
     393Linearization cuts added in total:       %8d  (separation time: %gs)\n",
     394                       nr, nt, st);
     395
     396    else jnlst -> Printf (J_ERROR, J_COUENNE, "Problem infeasible\n");
     397
     398    jnlst -> Printf (J_NONE, J_COUENNE, "\
     399Total time:                              %8gs (%gs in branch-and-bound)\n\
    444400Lower bound:                           %s\n\
    445401Upper bound:                           %s  (gap: %s)\n\
    446402Branch-and-bound nodes:                  %8d\n",
    447                      nr, nt, st,
    448403                     CoinCpuTime () - time_start,
    449404                     cg ? (CoinCpuTime () - CoinMax (time_start, cg -> rootTime ())) : CoinCpuTime () - time_start,
    450                      (lb < -9e12) ||
    451                      (lb > COUENNE_INFINITY/1e4) ? "      -inf" : lbstr,
    452                      (ub > COUENNE_INFINITY/1e4) ? "       inf" : ubstr,
    453                      (ub > COUENNE_INFINITY/1e4) ? "--" : gapstr,
    454                      bb.numNodes ());
    455 
    456     if (fabs (ub - bb. model (). getObjValue ()) > COUENNE_EPS * fabs (ub))
    457       jnlst -> Printf (J_ERROR, J_COUENNE,
    458                        "Warning: upper bounds differ between Couenne and Cbc. Saving Couenne's (more reliable).\n");
     405                     ((lb <= -8.9999e12) ||
     406                                       infeasible ||          (fabs (lb)             > COUENNE_INFINITY/1e4)) ? "      -inf" : lbstr,
     407                     ((retcomp < 0) || infeasible ||                           (ub   > COUENNE_INFINITY/1e4)) ? "       inf" : ubstr,
     408                     (                 infeasible || (CoinMax (fabs (lb), fabs (ub)) > COUENNE_INFINITY/1e4)) ? "--"        : gapstr,
     409                     infeasible ? 0 : bb.numNodes ());
     410
     411    // if (fabs (ub - bb. model (). getObjValue ()) > COUENNE_EPS * fabs (ub))
     412    //   jnlst -> Printf (J_ERROR, J_COUENNE,
     413    //                 "Warning: upper bounds differ between Couenne and Cbc. Saving Couenne's (more reliable).\n");
    459414
    460415    delete [] lbstr;
     
    464419    if (global_opt < COUENNE_INFINITY) { // some value found in couenne.opt
    465420
    466       double opt = bb.model (). getBestPossibleObjValue ();
     421      double opt = infeasible ? -COIN_DBL_MAX : bb.model (). getBestPossibleObjValue ();
    467422
    468423      printf ("Global Optimum Test on %-40s %s\n",
     
    482437        printf ("Stats: %-15s %4d [var] %4d [int] %4d [con] %4d [aux] "
    483438                "%6d [root] %8d [tot] %6g [sep] %8g [time] %8g [bb] "
    484                 "%20e [lower] %20e [upper] %7d [nodes]\n",// %s %s\n",
     439#ifdef COIN_HAS_NTY
     440                "%20e [lower] %20e [upper] %7d [nodes] %.0g [sg] %d [sgc]\n",
     441#else
     442                "%20e [lower] %20e [upper] %7d [nodes]\n",
     443#endif
    485444                cp ? cp -> problemName (). c_str () : "unknown",
    486445                (cp) ? cp -> nOrigVars     () : -1,
     
    496455                //bb.bestBound (),
    497456                //bb.bestObj (),
    498                 bb.numNodes ());
     457                infeasible ? 0 : bb.numNodes ()
     458#ifdef COIN_HAS_NTY
     459                ,symmGroupSize
     460                ,CouenneBranchingObject::nSGcomputations
     461#endif
     462);
    499463                //bb.iterationCount ());
    500464                //status.c_str (), message.c_str ());
     
    525489   std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
    526490  }
    527   catch (int generic_error) {
    528     if (generic_error == infeasible)
    529       printf ("problem infeasible\n");
    530   }
     491  // catch (int generic_error) {
     492  //   // if (generic_error == infeasible)
     493  //   //   printf ("problem infeasible\n");
     494  // }
    531495
    532496//  catch(...) {
Note: See TracChangeset for help on using the changeset viewer.