Changeset 389


Ignore:
Timestamp:
Mar 8, 2007 7:12:23 PM (13 years ago)
Author:
pbelotti
Message:

improved detection of common expression, (finally) switched to ASL_fg

Location:
branches/Couenne/Couenne
Files:
3 added
1 deleted
43 edited

Legend:

Unmodified
Added
Removed
  • branches/Couenne/Couenne/TODO

    r388 r389  
    1 - change expression comparison
    2 - fix fake variable generation in readnl.cpp
    31- rank in expressions for branching
    42- documentation
    53- improve convexification of x/y
     4- improve power convexification (find closest point in convex hull)
    65- linear combination plus aux. vars into one single aux - extend to constraints
    76- improve bounding box with upper bound
  • branches/Couenne/Couenne/src/Makefile.am

    r387 r389  
    3737        expression/operators/exprMinMax.cpp \
    3838        expression/operators/exprGroup.cpp \
     39        expression/exprOp.cpp \
     40        expression/exprUnary.cpp \
    3941        expression/exprVar.cpp \
    4042        expression/exprAux.cpp \
     
    6668        problem/constraint.cpp \
    6769        problem/tightenBounds.cpp \
     70        problem/readASLfg.cpp \
    6871        util/rootQ.c
    6972
     
    8285libCouenne_la_SOURCES += readnl/readnl.cpp \
    8386                         readnl/nl2e.cpp \
    84                          readnl/invmap.c \
    85                          readnl/fix_asl_group.c
     87                         readnl/invmap.c
    8688endif
    8789
  • branches/Couenne/Couenne/src/Makefile.in

    r387 r389  
    4848@COIN_HAS_ASL_TRUE@am__append_1 = readnl/readnl.cpp \
    4949@COIN_HAS_ASL_TRUE@                      readnl/nl2e.cpp \
    50 @COIN_HAS_ASL_TRUE@                      readnl/invmap.c \
    51 @COIN_HAS_ASL_TRUE@                      readnl/fix_asl_group.c
     50@COIN_HAS_ASL_TRUE@                      readnl/invmap.c
    5251
    5352
     
    9089        expression/operators/exprSum.cpp \
    9190        expression/operators/exprMinMax.cpp \
    92         expression/operators/exprGroup.cpp expression/exprVar.cpp \
     91        expression/operators/exprGroup.cpp expression/exprOp.cpp \
     92        expression/exprUnary.cpp expression/exprVar.cpp \
    9393        expression/exprAux.cpp expression/expression.cpp \
    9494        simplify/simplifiers.cpp simplify/simplify.cpp \
     
    111111        convex/CouenneCutGenerator.cpp convex/generateCuts.cpp \
    112112        problem/problem.cpp problem/problemIO.cpp \
    113         problem/constraint.cpp problem/tightenBounds.cpp util/rootQ.c \
    114         readnl/readnl.cpp readnl/nl2e.cpp readnl/invmap.c \
    115         readnl/fix_asl_group.c
    116 @COIN_HAS_ASL_TRUE@am__objects_1 = readnl.lo nl2e.lo invmap.lo \
    117 @COIN_HAS_ASL_TRUE@     fix_asl_group.lo
     113        problem/constraint.cpp problem/tightenBounds.cpp \
     114        problem/readASLfg.cpp util/rootQ.c readnl/readnl.cpp \
     115        readnl/nl2e.cpp readnl/invmap.c
     116@COIN_HAS_ASL_TRUE@am__objects_1 = readnl.lo nl2e.lo invmap.lo
    118117am_libCouenne_la_OBJECTS = CouenneBranchingObject.lo CouenneObject.lo \
    119118        CouenneChooseVariable.lo getFixVarBinFun.lo exprAbs.lo \
    120119        exprDiv.lo exprExp.lo exprInv.lo exprLog.lo exprMul.lo \
    121120        exprOpp.lo exprPow.lo exprSin.lo exprCos.lo exprSub.lo \
    122         exprSum.lo exprMinMax.lo exprGroup.lo exprVar.lo exprAux.lo \
    123         expression.lo simplifiers.lo simplify.lo addEnvelope.lo \
    124         createCuts.lo conv-exprOp.lo conv-exprUnary.lo conv-exprAbs.lo \
    125         conv-exprDiv.lo conv-exprMul.lo conv-exprOpp.lo \
    126         conv-exprPow.lo conv-exprPow-getBounds.lo \
     121        exprSum.lo exprMinMax.lo exprGroup.lo exprOp.lo exprUnary.lo \
     122        exprVar.lo exprAux.lo expression.lo simplifiers.lo simplify.lo \
     123        addEnvelope.lo createCuts.lo conv-exprOp.lo conv-exprUnary.lo \
     124        conv-exprAbs.lo conv-exprDiv.lo conv-exprMul.lo \
     125        conv-exprOpp.lo conv-exprPow.lo conv-exprPow-getBounds.lo \
    127126        conv-exprPow-envelope.lo conv-exprSub.lo conv-exprSum.lo \
    128127        conv-exprInv.lo conv-exprSinCos.lo conv-exprExp.lo \
    129128        conv-exprLog.lo conv-exprGroup.lo CouenneCutGenerator.lo \
    130129        generateCuts.lo problem.lo problemIO.lo constraint.lo \
    131         tightenBounds.lo rootQ.lo $(am__objects_1)
     130        tightenBounds.lo readASLfg.lo rootQ.lo $(am__objects_1)
    132131libCouenne_la_OBJECTS = $(am_libCouenne_la_OBJECTS)
    133132depcomp = $(SHELL) $(top_srcdir)/../depcomp
     
    349348        expression/operators/exprSum.cpp \
    350349        expression/operators/exprMinMax.cpp \
    351         expression/operators/exprGroup.cpp expression/exprVar.cpp \
     350        expression/operators/exprGroup.cpp expression/exprOp.cpp \
     351        expression/exprUnary.cpp expression/exprVar.cpp \
    352352        expression/exprAux.cpp expression/expression.cpp \
    353353        simplify/simplifiers.cpp simplify/simplify.cpp \
     
    370370        convex/CouenneCutGenerator.cpp convex/generateCuts.cpp \
    371371        problem/problem.cpp problem/problemIO.cpp \
    372         problem/constraint.cpp problem/tightenBounds.cpp util/rootQ.c \
    373         $(am__append_1)
     372        problem/constraint.cpp problem/tightenBounds.cpp \
     373        problem/readASLfg.cpp util/rootQ.c $(am__append_1)
    374374COINLIBS = \
    375375        $(OSIOBJDIR)/src/libOsi.la \
     
    565565@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprMinMax.Plo@am__quote@
    566566@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprMul.Plo@am__quote@
     567@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprOp.Plo@am__quote@
    567568@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprOpp.Plo@am__quote@
    568569@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprPow.Plo@am__quote@
     
    570571@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprSub.Plo@am__quote@
    571572@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprSum.Plo@am__quote@
     573@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprUnary.Plo@am__quote@
    572574@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/exprVar.Plo@am__quote@
    573575@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/expression.Plo@am__quote@
    574 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fix_asl_group.Plo@am__quote@
    575576@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generateCuts.Plo@am__quote@
    576577@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getFixVarBinFun.Plo@am__quote@
     
    579580@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/problem.Plo@am__quote@
    580581@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/problemIO.Plo@am__quote@
     582@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readASLfg.Plo@am__quote@
    581583@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readnl.Plo@am__quote@
    582584@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rootQ.Plo@am__quote@
     
    620622@am__fastdepCC_FALSE@   $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o invmap.lo `test -f 'readnl/invmap.c' || echo '$(srcdir)/'`readnl/invmap.c
    621623
    622 fix_asl_group.lo: readnl/fix_asl_group.c
    623 @am__fastdepCC_TRUE@    if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT fix_asl_group.lo -MD -MP -MF "$(DEPDIR)/fix_asl_group.Tpo" -c -o fix_asl_group.lo `test -f 'readnl/fix_asl_group.c' || echo '$(srcdir)/'`readnl/fix_asl_group.c; \
    624 @am__fastdepCC_TRUE@    then mv -f "$(DEPDIR)/fix_asl_group.Tpo" "$(DEPDIR)/fix_asl_group.Plo"; else rm -f "$(DEPDIR)/fix_asl_group.Tpo"; exit 1; fi
    625 @AMDEP_TRUE@@am__fastdepCC_FALSE@       source='readnl/fix_asl_group.c' object='fix_asl_group.lo' libtool=yes @AMDEPBACKSLASH@
    626 @AMDEP_TRUE@@am__fastdepCC_FALSE@       DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    627 @am__fastdepCC_FALSE@   $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o fix_asl_group.lo `test -f 'readnl/fix_asl_group.c' || echo '$(srcdir)/'`readnl/fix_asl_group.c
    628 
    629624.cpp.o:
    630625@am__fastdepCXX_TRUE@   if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
     
    774769@am__fastdepCXX_FALSE@  $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o exprGroup.lo `test -f 'expression/operators/exprGroup.cpp' || echo '$(srcdir)/'`expression/operators/exprGroup.cpp
    775770
     771exprOp.lo: expression/exprOp.cpp
     772@am__fastdepCXX_TRUE@   if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT exprOp.lo -MD -MP -MF "$(DEPDIR)/exprOp.Tpo" -c -o exprOp.lo `test -f 'expression/exprOp.cpp' || echo '$(srcdir)/'`expression/exprOp.cpp; \
     773@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/exprOp.Tpo" "$(DEPDIR)/exprOp.Plo"; else rm -f "$(DEPDIR)/exprOp.Tpo"; exit 1; fi
     774@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='expression/exprOp.cpp' object='exprOp.lo' libtool=yes @AMDEPBACKSLASH@
     775@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     776@am__fastdepCXX_FALSE@  $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o exprOp.lo `test -f 'expression/exprOp.cpp' || echo '$(srcdir)/'`expression/exprOp.cpp
     777
     778exprUnary.lo: expression/exprUnary.cpp
     779@am__fastdepCXX_TRUE@   if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT exprUnary.lo -MD -MP -MF "$(DEPDIR)/exprUnary.Tpo" -c -o exprUnary.lo `test -f 'expression/exprUnary.cpp' || echo '$(srcdir)/'`expression/exprUnary.cpp; \
     780@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/exprUnary.Tpo" "$(DEPDIR)/exprUnary.Plo"; else rm -f "$(DEPDIR)/exprUnary.Tpo"; exit 1; fi
     781@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='expression/exprUnary.cpp' object='exprUnary.lo' libtool=yes @AMDEPBACKSLASH@
     782@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     783@am__fastdepCXX_FALSE@  $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o exprUnary.lo `test -f 'expression/exprUnary.cpp' || echo '$(srcdir)/'`expression/exprUnary.cpp
     784
    776785exprVar.lo: expression/exprVar.cpp
    777786@am__fastdepCXX_TRUE@   if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT exprVar.lo -MD -MP -MF "$(DEPDIR)/exprVar.Tpo" -c -o exprVar.lo `test -f 'expression/exprVar.cpp' || echo '$(srcdir)/'`expression/exprVar.cpp; \
     
    976985@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    977986@am__fastdepCXX_FALSE@  $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o tightenBounds.lo `test -f 'problem/tightenBounds.cpp' || echo '$(srcdir)/'`problem/tightenBounds.cpp
     987
     988readASLfg.lo: problem/readASLfg.cpp
     989@am__fastdepCXX_TRUE@   if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT readASLfg.lo -MD -MP -MF "$(DEPDIR)/readASLfg.Tpo" -c -o readASLfg.lo `test -f 'problem/readASLfg.cpp' || echo '$(srcdir)/'`problem/readASLfg.cpp; \
     990@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/readASLfg.Tpo" "$(DEPDIR)/readASLfg.Plo"; else rm -f "$(DEPDIR)/readASLfg.Tpo"; exit 1; fi
     991@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='problem/readASLfg.cpp' object='readASLfg.lo' libtool=yes @AMDEPBACKSLASH@
     992@AMDEP_TRUE@@am__fastdepCXX_FALSE@      DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     993@am__fastdepCXX_FALSE@  $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o readASLfg.lo `test -f 'problem/readASLfg.cpp' || echo '$(srcdir)/'`problem/readASLfg.cpp
    978994
    979995readnl.lo: readnl/readnl.cpp
  • branches/Couenne/Couenne/src/convex/CouenneCutGenerator.cpp

    r388 r389  
    2424
    2525CouenneCutGenerator::CouenneCutGenerator (Bonmin::OsiTMINLPInterface *nlp,
    26                                           const struct ASL_pfgh *asl,
     26                                          const struct ASL *asl,
    2727                                          bool addviolated,
    2828                                          enum conv_type convtype, int nSamples):
    2929
    3030  OaDecompositionBase (nlp, NULL, NULL, 0,0,0),
     31
    3132  firstcall_      (true),
    3233  addviolated_    (addviolated),
     
    4041
    4142  if (!asl) return;
    42 
    4343  problem_ = new CouenneProblem;
    4444
     
    4848
    4949  //  printf ("reading time: %.3fs\n", CoinCpuTime () - now);
    50 
    5150  //  now = CoinCpuTime ();
    52 
    5351  //  problem_ -> print (std::cout);
    5452  //  printf ("======================================\n");
     
    5654
    5755  //  printf ("standardization time: %.3fs\n", CoinCpuTime () - now);
    58 
    5956  //  problem_ -> print (std::cout);
    6057  //  printf ("======================================\n");
    61 
    6258  //  problem_ -> writeMod ("extended.mod");
    6359}
     
    112108}
    113109
     110
    114111/// methods to get values of variables and bounds
    115112const CouNumber    CouenneCutGenerator::X   (int i) {return problem_ -> X  (i);}
    116113const CouNumber   &CouenneCutGenerator::Lb  (int i) {return problem_ -> Lb (i);}
    117114const CouNumber   &CouenneCutGenerator::Ub  (int i) {return problem_ -> Ub (i);}
     115
    118116
    119117/// get arrays
  • branches/Couenne/Couenne/src/convex/createCuts.cpp

    r377 r389  
    5858        ((violation > - COUENNE_EPS) || (sign < 0)))
    5959      return NULL;
    60 
    61 
    62     // return NULL if not violated
    63     /*
    64     if (((violation <   1e-5) || (sign > 0)) &&
    65         ((violation > - 1e-5) || (sign < 0)))
    66       return NULL;
    67     */
    6860  }
    6961
  • branches/Couenne/Couenne/src/convex/generateCuts.cpp

    r388 r389  
    2828              problem_ -> nAuxs ();
    2929
    30   char *chg_bds = NULL;
     30  char *chg_bds = new char [ncols];
     31
     32  // fill it with zeros
     33  for (register int i = ncols; i--;) *chg_bds++ = 0;
     34  chg_bds -= ncols;
    3135
    3236  int nchanged = 0; // number of bounds changed;
     
    8084                          const_cast <CouNumber *> (si. getColUpper    ()));
    8185
    82     chg_bds = new char [ncols];
    83 
    84     // fill it with zeros
    85     for (register int i = ncols; i--;) *chg_bds++ = 0;
    86     chg_bds -= ncols;
    87 
    8886    // not the first call to this procedure, meaning we can be
    89     // anywhere in the B&B tree. Check, through the auxiliary
    90     // information, which bounds have changed from the parent node.
     87    // anywhere in the B&B tree but the root node. Check, through the
     88    // auxiliary information, which bounds have changed from the
     89    // parent node.
    9190
    9291    if (info.inTree) {
     
    142141  // bounds
    143142
    144   nchanged = problem_ -> tightenBounds (si, chg_bds);
     143  int ntightened = problem_ -> tightenBounds (si, chg_bds);
    145144
    146145  //  printf ("::::::::::::::::::::::::::::::::::::::::::::::\n");
     
    150149  //        expression::Ubound (i));
    151150
    152   //  if (nchanged)
    153   //    printf("%d bounds tightened\n", nchanged);
     151  //  if (ntightened)
     152  //    printf("%d bounds tightened\n", ntightened);
    154153
    155154  // For each auxiliary variable, create cut (or set of cuts) violated
     
    161160  //  if (!chg_bds) // this is the first call to generateCuts, we have to
    162161                // generate cuts for all auxiliary variable
    163     for (int i=0; i < problem_ -> nAuxs (); i++)
    164       problem_ -> Aux (i) -> generateCuts (si, cs, this);
     162
     163  for (int i=0; i < problem_ -> nAuxs (); i++)
     164    problem_ -> Aux (i) -> generateCuts (si, cs, this);
     165
    165166    /*
    166167  else          // chg_bds contains the indices of the variables whose
     
    173174  // change tightened bounds through OsiCuts
    174175
    175   if (nchanged) {
     176  if (nchanged || ntightened) {
    176177
    177178    int *indLow = new int [ncols],
     
    179180         nLow, nUpp = nLow = 0;
    180181
    181     CouNumber *bndLow = new CouNumber [nchanged],
    182               *bndUpp = new CouNumber [nchanged];
     182    CouNumber *bndLow = new CouNumber [ncols],
     183              *bndUpp = new CouNumber [ncols];
    183184
    184185    const CouNumber
     
    188189      *newUpp = problem_ -> Ub ();
    189190
    190     for (register int i=0; i<ncols; i++)
    191 
    192       if (chg_bds [i]) {
     191    for (register int i=0; i<ncols; i++) {
     192
     193      //      if (chg_bds [i]) {
    193194
    194195        CouNumber bd;
     
    203204          bndUpp [nUpp++] = bd;
    204205        }
    205       }
     206        //      }
     207    }
    206208
    207209    OsiColCut *cut = new OsiColCut;
     
    211213      cut -> setUbs (nUpp, indUpp, bndUpp);
    212214      cs.insert (cut);
    213     }
    214 
    215     delete cut;
    216 
    217     delete [] bndLow; delete indLow;
    218     delete [] bndUpp; delete indUpp;
     215      delete cut;
     216    }
     217
     218    delete [] bndLow; delete [] indLow;
     219    delete [] bndUpp; delete [] indUpp;
    219220  }
    220221
  • branches/Couenne/Couenne/src/expression/expression.cpp

    r387 r389  
    3333
    3434
    35 // General N-ary function destructor
    36 
    37 exprOp::~exprOp () {
    38 
    39   register expression *elem;
    40 
    41   if (arglist_) {
    42     for (register int i = nargs_; i--;)
    43       if ((elem = arglist_ [i]))
    44         delete elem;
    45 
    46     delete [] arglist_;
    47     arglist_ = NULL;
    48   }
    49 }
    50 
    51 
    52 // print expression
    53 
    54 void exprOp::print (std::ostream      &out = std::cout,
    55                     const std::string &op  = "unknown",
    56                     enum pos           pos = PRE)        const
    57 {
    58   if (pos == PRE)
    59     out << op;
    60 
    61   out << "("; fflush (stdout);
    62   for (int i=0; i<nargs_; i++) {
    63     if (arglist_ [i])
    64       arglist_ [i] -> print (out);
    65     fflush (stdout);
    66     if (i < nargs_ - 1) {
    67       if (pos == INSIDE) out << op;
    68       else               out << ",";
    69     }
    70     fflush (stdout);
    71   }
    72   out << ")";
    73   fflush (stdout);
    74 }
    75 
    76 
    77 // print unary expression
    78 
    79 void exprUnary::print (std::ostream      &out = std::cout,
    80                        const std::string &op = "unknown",
    81                        enum pos           pos = PRE)       const
    82 {
    83   if (pos == PRE)  out << op;
    84   out << "(";
    85   argument_ -> print (out);
    86   out << ")";
    87   if (pos == POST) out << op;
    88 }
    89 
    90 
    91 // does this expression depend on variables in varlist?
    92 
    93 bool exprOp::dependsOn (int *varlist = NULL, int n = 1) {
    94 
    95   for (register int i = nargs_; i--;)
    96     if (arglist_ [i] -> dependsOn (varlist, n))
    97       return true;
    98 
    99   return false;
    100 }
    101 
    102 
    10335// Get lower and upper bound of a generic expression
    10436
     
    12254
    12355
    124 // name () -- a string value for each expression
     56/// compare generic expression with other expression
     57int expression::compare (expression &e1) {
    12558
    126 #define MAX_NAME 10000
     59  if      (code () >= COU_EXPRUNARY)
     60    if (e1.code () >= COU_EXPRUNARY) {
    12761
    128 std::string Coutoa (CouNumber x) {
    129   char s [MAX_NAME];
    130   sprintf (s, "%f", x);
    131   return std::string (s);
     62      exprUnary *ne0 = dynamic_cast <exprUnary *> (this);
     63      exprUnary *ne1 = dynamic_cast <exprUnary *> (&e1);
     64      return ne0 -> compare (*ne1);
     65    }
     66    else return 1;
     67  else if   (code () >= COU_EXPROP)
     68    if   (e1.code () >= COU_EXPROP)
     69      if (e1.code () >= COU_EXPRUNARY) return -1;
     70      else {
     71
     72      exprOp *ne0 = dynamic_cast <exprOp *> (this);
     73      exprOp *ne1 = dynamic_cast <exprOp *> (&e1);
     74      return ne0 -> compare (*ne1);
     75      }
     76    else if (e1.code () >= COU_EXPROP) return -1;
     77    else ;
     78  else ;
     79
     80  int c0 = code (),
     81      c1 = e1. code ();
     82
     83  if      (c0 < c1) return -1;
     84  else if (c0 > c1) return  1;
     85  else { // it is either a constant or a variable
     86
     87    int i1 = e1. Index ();
     88
     89    if      (Index () < i1) return -1;
     90    else if (Index () > i1) return  1;
     91    else if (i1 != -1)      return  0; // same variables
     92    else { // both are constants
     93
     94      CouNumber v1 = e1. Value ();
     95
     96      if      (currValue_ < v1) return -1;
     97      else if (currValue_ > v1) return  1;
     98      else                      return  0;
     99    }
     100  }
    132101}
    133102
    134 std::string Indtoa (char prefix, int i) {
    135   char s [MAX_NAME];
    136   sprintf (s, "%c%d", prefix, i);
    137   return std::string (s);
    138 }
    139103
    140 const std::string exprVar::name   () const {return Indtoa ('x', varIndex_);}
    141 const std::string exprIVar::name  () const {return Indtoa ('y', varIndex_);}
    142 const std::string exprAux::name   () const {return Indtoa ('w', varIndex_);}
    143 
    144 const std::string exprLowerBound::name () const {return Indtoa ('l', varIndex_);}
    145 const std::string exprUpperBound::name () const {return Indtoa ('u', varIndex_);}
    146 
    147 const std::string exprConst::name () const {return Coutoa (currValue_);}
    148 
    149 const std::string exprCopy::name  () const {return copy_ -> Original () -> name ();}
    150 
    151 const std::string exprUnary::name () const {return name ("?");}
    152 const std::string exprOp::name    () const {return name ("?");}
    153 
    154 
    155 /**
    156  *
    157  * The functions below could have been implemented much more easily as follows:
    158  *
    159  * const std::string exprUnary::name () const
    160  *   {return "(" + argument_ -> name () + ")";}
    161  *
    162  * const std::string exprOp::   name () const {
    163  *  std::string args = "(" + arglist_ [0] -> name ();
    164  *  for (int i=1; i<nargs_; i++)
    165  *    args += "," + arglist_ [i] -> name ();
    166  *  return args + ")";
    167  * }
    168  *
    169  * But, because of a segfault occurred in some x86_64 machines, we have
    170  * decided to do it more plainly (and probably less efficiently).
    171  */
    172 
    173 const std::string exprUnary::name (const std::string &op) const {
    174 
    175   register char *s = (char *) malloc (MAX_NAME * sizeof (char));
    176   sprintf (s, "%s(%s)", op.c_str (), argument_ -> name (). c_str ());
    177 
    178   s = (char *) realloc (s, (1 + strlen (s)) * sizeof (char));
    179   std::string ret (1 + strlen (s), ' ');
    180   for (int register i=strlen (s); i--;) // no need to set eos
    181     ret [i] = s [i];
    182   free (s);
    183   return ret;
    184 }
    185 
    186 const std::string exprOp::name (const std::string &op) const {
    187 
    188   register char *s = (char *) malloc (MAX_NAME * sizeof (char));
    189   sprintf (s, "%s(%s", op.c_str (), arglist_ [0] -> name (). c_str ());
    190 
    191   for (register int i=1; i<nargs_; i++) {
    192     strcat (s, ",");
    193     strcat (s, arglist_ [i] -> name (). c_str ());
    194   }
    195 
    196   strcat (s, ")");
    197 
    198   s = (char *) realloc (s, (1 + strlen (s)) * sizeof (char));
    199   std::string ret (1 + strlen (s), ' ');
    200   for (register int i=strlen (s); i--;) // no need to set eos
    201     ret [i] = s [i];
    202   free (s);
    203   return ret;
    204 }
     104///
     105int expression::compare (exprCopy &c)
     106{return compare (const_cast <expression &> (*(c. Original ())));}
  • branches/Couenne/Couenne/src/expression/operators/exprGroup.cpp

    r388 r389  
    5858  }
    5959}
    60 
    61 #define MAX_NAME 10000
    62 
    63 /// String equivalent (for comparisons)
    64 const std::string exprGroup::name () const {
    65 
    66   std::string nl = exprSum::name ();
    67 
    68   register char *s   = (char *) malloc (MAX_NAME * sizeof (char));
    69   char          *sub = (char *) malloc (MAX_NAME * sizeof (char));
    70 
    71   sprintf (s, "%s", nl. c_str ());
    72 
    73   if (fabs (c0_) > COUENNE_EPS) {
    74     sprintf (sub, "+%f", c0_);
    75     strcat (s, sub);
    76   }
    77 
    78   for (register int *ind=index_, i=0; *ind>=0;) {
    79     sprintf (sub, "%+fx_%d", coeff_ [i++], *ind++);
    80     strcat (s, sub);
    81   }
    82 
    83   s = (char *) realloc (s, (1 + strlen (s)) * sizeof (char));
    84   std::string ret (1 + strlen (s), ' ');
    85   for (register int i=strlen (s); i--;)
    86     ret [i] = s [i];
    87 
    88   free (s);
    89   free (sub);
    90 
    91   return ret;
    92 }
    9360
    9461
     
    161128    else                            return nllin;
    162129}
     130
     131///
     132int exprGroup::compare (exprGroup &e) {
     133
     134  printf ("exprGroup::compare ");
     135  print (std::cout);
     136  e. print (std::cout);
     137  printf ("\n");
     138
     139  int ret = exprOp::compare (e);
     140
     141  if (!ret) {
     142
     143    CouNumber *coe0 = coeff_,
     144              *coe1 = e.coeff_;
     145
     146    for (register int *ind0 = index_, *ind1 = e.index_;
     147         *ind0 >= 0 || *ind1 >= 0;
     148         ind0++, ind1++, coe0++, coe1++)
     149 
     150      if      (*ind0 < *ind1) return -1;
     151      else if (*ind0 > *ind1) return  1;
     152      else if (*coe0 < *coe1 - COUENNE_EPS) return -1;
     153      else if (*coe0 > *coe1 + COUENNE_EPS) return  1;
     154
     155    return 0;
     156  } else return ret;
     157}
  • branches/Couenne/Couenne/src/include/CouenneCutGenerator.h

    r387 r389  
    2323class CouenneProblem;
    2424
    25 struct ASL_pfgh;
     25struct ASL;
    2626
    2727
     
    6464  /// constructor
    6565  CouenneCutGenerator  (Bonmin::OsiTMINLPInterface * = NULL,
    66                         const struct ASL_pfgh * = NULL,
     66                        const struct ASL * = NULL,
    6767                        bool = false,
    6868                        enum conv_type = UNIFORM_GRID,
  • branches/Couenne/Couenne/src/include/CouenneProblem.h

    r387 r389  
    1919#include <CouenneProblemElem.h>
    2020
    21 struct ASL_pfgh;
    22 struct expr2;
     21struct ASL;
     22struct expr;
     23
     24struct compExpr {
     25  bool operator () (exprAux* e0, exprAux* e1) const
     26  {return (e0 -> Image () -> compare (*(e1 -> Image ())) < 0);}
     27};
     28
    2329
    2430/// The CouenneProblem class
     
    4349  /// expression map for comparison in standardization
    4450  std::map <std::string, exprAux *> *auxMap_;
     51  std::map <exprAux *, int, compExpr> *auxMap2_; // int to count occurrences
    4552
    4653  /// number of elements in the x_, lb_, ub_ arrays
     
    5057
    5158  /// constructors, destructor
    52   CouenneProblem  () {x_ = lb_ = ub_ = NULL; auxMap_ = NULL; curnvars_ = -1;}
     59  CouenneProblem  () {x_ = lb_ = ub_ = NULL; auxMap2_ = NULL; curnvars_ = -1;}
    5360  CouenneProblem  (const CouenneProblem &);
    5461  ~CouenneProblem ();
     
    111118
    112119  /// read problem from .nl file using the Ampl Solver Library (ASL)
    113   int readnl (const struct ASL_pfgh *);
     120  int readnl (const struct ASL *);
    114121
    115122  /// read problem from .nl file using the Ampl Solver Library (ASL)
    116   expression *nl2e (struct expr2 *);
     123  expression *nl2e (struct expr *);
    117124
    118125  /// store nonlinear problem into a .mod file (with lots of defined
     
    128135};
    129136
    130 
    131 /// utility to allocate space for coeff, indices, rhs and sign based on
    132 /// the data in n and nterms
    133 
    134 void allocateCon (int n, int *nterms,                     // input data
    135                   expression ***& coeff, int **& indices, // allocated data
    136                   expression **& rhs, enum con_sign *& sign);
    137137#endif
  • branches/Couenne/Couenne/src/include/CouenneTypes.h

    r382 r389  
    1818enum conv_type      {CURRENT_ONLY, UNIFORM_GRID, AROUND_CURPOINT};
    1919
     20enum expr_type {/*COU_EXPRAUX,  COU_EXPRCLONE, COU_EXPRCOPY, */
     21                COU_EXPRESSION, /***** variables, constants **************/
     22                COU_EXPRCONST, COU_EXPRVAR, COU_EXPRLBOUND, COU_EXPRUBOUND,
     23                /*COU_EXPRIVAR, */
     24                COU_EXPROP,     /***** n-ary operators *******************/
     25                COU_EXPRSUB,  COU_EXPRSUM, COU_EXPRGROUP,
     26                COU_EXPRMIN,  COU_EXPRMUL, COU_EXPRPOW, COU_EXPRMAX, COU_EXPRDIV,
     27                /*COU_EXPRBDIV,  COU_EXPRBMUL,*/
     28                COU_EXPRUNARY,  /***** unary operators *******************/
     29                COU_EXPRCOS,  COU_EXPRABS,
     30                COU_EXPREXP,  COU_EXPRINV,   COU_EXPRLOG,   
     31                COU_EXPROPP,   COU_EXPRSIN
     32                };
     33
     34enum convexity {NONCONVEX, CONVEX, CONCAVE, AFFINE};
     35
    2036typedef double CouNumber;
    21 typedef CouNumber       (*unary_function)  (CouNumber);
     37typedef CouNumber (*unary_function) (CouNumber);
    2238
    2339#endif
  • branches/Couenne/Couenne/src/include/exprAux.h

    r385 r389  
    7373  expression *Ub () {return ub_;}
    7474
    75   // string equivalent
    76   const std::string name () const;
    77 
    7875  // I/O
    7976  void print (std::ostream &out) const
     
    9693    {return image_ -> dependsOn (indices, num);}
    9794
    98   // Get a measure of "how linear" the expression is:
    99   //
    100   // 0: a constant
    101   // 1: linear
    102   // 2: quadratic
    103   // 3: nonlinear non-quadratic
     95  // Get a measure of "how linear" the expression is (see CouenneTypes.h)
    10496  inline int Linearity ()
    10597    {return LINEAR;
  • branches/Couenne/Couenne/src/include/exprBound.h

    r357 r389  
    3535 public:
    3636
    37   // node type
     37  /// node type
    3838  inline enum nodeType Type ()
    3939    {return CONST;}
    4040
    41   // Constructors, destructor
     41  /// Constructors, destructor
    4242  exprLowerBound  (int varIndex): exprVar (varIndex) {}
    43   //  ~exprLowerBound () {}
    4443
    45   // string equivalent
    46   const std::string name () const;
    47 
    48   // I/O
     44  /// I/O
    4945  void print (std::ostream &out) const
    5046    {out << "l_" << varIndex_;}
    5147
    52   // return the value of the variable
     48  /// return the value of the variable
    5349  inline CouNumber operator () ()
    5450    {return (currValue_ = expression::lbounds_ [varIndex_]);}
    5551
    56   // differentiation
     52  /// differentiation
    5753  inline expression *differentiate (int)
    5854    {return new exprConst (0);}
    5955
    60   // dependence on variable set
     56  /// dependence on variable set
    6157  bool dependsOn (int *, int)
    6258    {return false;}
    6359
    64   // get a measure of "how linear" the expression is:
     60  /// get a measure of "how linear" the expression is:
    6561  virtual inline int Linearity ()
    6662    {return CONST;}
     63
     64  ///
     65  virtual enum expr_type code ()
     66    {return COU_EXPRLBOUND;}
    6767};
    6868
     
    8181  exprUpperBound  (int varIndex):
    8282    exprVar (varIndex) {}
    83   //  ~exprUpperBound () {}
    84 
    85   // string equivalent
    86   const std::string name () const;
    8783
    8884  // I/O
     
    105101  virtual inline int Linearity ()
    106102    {return CONST;}
     103
     104  ///
     105  virtual enum expr_type code ()
     106    {return COU_EXPRUBOUND;}
    107107};
    108108
  • branches/Couenne/Couenne/src/include/exprClone.h

    r357 r389  
    2727    exprCopy (copy) {}
    2828
    29   /// destructor
    30   //  ~exprClone () {}
    31 
    3229  /// copy constructor
    3330  exprClone (const exprClone &e):
     
    4037  /// I/O
    4138  void print (std::ostream &out) const
    42     //{out << "{"; copy_ -> Original () -> print (out); out << "}";}
    4339    {copy_ -> Original () -> print (out);}
    44     //{copy_ -> print (out);}
    45     //{out << ",";}
    4640
    4741  /// value
  • branches/Couenne/Couenne/src/include/exprConst.h

    r377 r389  
    3535    {currValue_ = value;}
    3636
    37   // Destructor
    38   //  ~exprConst () {}
    39 
    4037  // Copy constructor
    4138  exprConst (const exprConst &e)
     
    4542  virtual exprConst *clone () const
    4643    {return new exprConst (currValue_);}
    47 
    48   // string equivalent
    49   const std::string name () const;
    5044
    5145  // I/O
     
    6963    {return NULL;}
    7064
    71   // get a measure of "how linear" the expression is:
    72   //
    73   // CONSTANT  = 0: a constant
    74   // LINEAR    = 1: linear
    75   // QUADRATIC = 2: quadratic
    76   // NONLINER  = 3: nonlinear non-quadratic
     65  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    7766  inline int Linearity ()
    78     {return CONSTANT;}
     67    {return ((fabs (currValue_) < COUENNE_EPS) ? ZERO: CONSTANT);}
    7968
    8069  // Get lower and upper bound of an expression (if any)
     
    8978
    9079  // generate convexification cut for constraint w = this
    91   void generateCuts (exprAux *w, const OsiSolverInterface &si,
    92                      OsiCuts &cs, const CouenneCutGenerator *cg);
     80  void generateCuts (exprAux *, const OsiSolverInterface &,
     81                     OsiCuts &, const CouenneCutGenerator *);
     82
     83  ///
     84  virtual enum expr_type code () {return COU_EXPRCONST;}
    9385};
    9486
  • branches/Couenne/Couenne/src/include/exprCopy.h

    r357 r389  
    3434  exprCopy  (expression *copy):
    3535    copy_ (copy) {}
    36   //  ~exprCopy () {}
    3736
    3837  // copy constructor
     
    5453  inline int Index () const
    5554    {return copy_ -> Index ();}
    56 
    57   // string equivalent
    58   const std::string name () const;
    5955
    6056  // I/O
     
    8884    {return copy_ -> simplify ();}
    8985
    90   // get a measure of "how linear" the expression is:
    91   //
    92   // CONSTANT  = 0: a constant
    93   // LINEAR    = 1: linear
    94   // QUADRATIC = 2: quadratic
    95   // NONLINER  = 3: nonlinear non-quadratic
     86  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    9687  inline int Linearity ()
    9788    {return copy_ -> Linearity ();}
     
    112103  // return an index to the variable's argument that is better fixed
    113104  // in a branching rule for solving a nonconvexity gap
    114   virtual expression *getFixVar () {return copy_ -> getFixVar ();}
     105  virtual expression *getFixVar ()
     106    {return copy_ -> getFixVar ();}
     107
     108  ///
     109  virtual enum expr_type code ()
     110    {return copy_ -> code ();}
     111
     112  ///
     113  int compare (expression &e)
     114    {return copy_ -> compare (e);}
    115115};
    116116
  • branches/Couenne/Couenne/src/include/exprIVar.h

    r377 r389  
    3131    exprVar (varIndex) {}
    3232
    33   // destructor
    34   //  ~exprIVar () {}
    35 
    3633  // copy constructor
    3734  exprIVar (const exprIVar &e):
     
    4138  virtual exprIVar *clone () const
    4239    {return new exprIVar (*this);}
    43 
    44   // string equivalent
    45   const std::string name () const;
    4640
    4741  // print
  • branches/Couenne/Couenne/src/include/exprOp.h

    r382 r389  
    1414#include <expression.h>
    1515#include <CouenneTypes.h>
     16#include <exprUnary.h>
    1617
    1718
     
    6768    {return nargs_;}
    6869
    69   /// string equivalent
    70   virtual const std::string name () const;
    71   virtual const std::string name (const std::string &) const;
    72 
    7370  /// I/O
    7471  virtual void print (std::ostream &, const std::string &, enum pos) const;
     
    9491  int shrink_arglist (CouNumber, CouNumber);
    9592
    96   /// get a measure of "how linear" the expression is:
    97   ///
    98   /// CONSTANT  = 0: a constant
    99   /// LINEAR    = 1: linear
    100   /// QUADRATIC = 2: quadratic
    101   /// NONLINER  = 3: nonlinear non-quadratic
     93  /// get a measure of "how linear" the expression is (see CouenneTypes.h)
    10294  virtual inline int Linearity ()
    10395    {return NONLINEAR;}
    10496
     97  /// generate auxiliary variable
    10598  exprAux *standardize (CouenneProblem *);
    10699
     
    108101  /// in a branching rule for solving a nonconvexity gap
    109102  virtual expression *getFixVar () {return arglist_ [0];}
     103
     104  ///
     105  virtual enum expr_type code () {return COU_EXPROP;}
     106
     107  ///
     108  virtual int compare (exprOp &);
    110109};
    111110
  • branches/Couenne/Couenne/src/include/exprUnary.h

    r377 r389  
    1414#include <expression.h>
    1515#include <CouenneTypes.h>
    16 
     16#include <exprOp.h>
    1717
    1818/// zero function (used by default by exprUnary)
    19 inline CouNumber zero_fun (CouNumber x) {return 0;}
     19inline CouNumber zero_fun (CouNumber x)
     20{return 0;}
    2021
    2122
     
    4546
    4647  /// the operator itself (e.g. sin, log...)
    47   virtual inline unary_function F () {return zero_fun;}
     48  virtual inline unary_function F ()
     49    {return zero_fun;}
    4850
    4951  /// Destructor
     
    5456  virtual inline expression *Argument () const
    5557    {return argument_;}
    56 
    57   // string equivalent
    58   virtual const std::string name () const;
    59   virtual const std::string name (const std::string &) const;
    6058
    6159  // I/O
     
    7371  expression *simplify ();
    7472
    75   // get a measure of "how linear" the expression is:
    76   //
    77   // 0: a constant
    78   // 1: linear
    79   // 2: quadratic
    80   // 3: nonlinear non-quadratic
    81   //
     73  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    8274  // for general univariate functions, return nonlinear.
    8375  virtual inline int Linearity ()
     
    8678  // reduce expression in standard form, creating additional aux
    8779  // variables (and constraints)
    88   virtual exprAux *standardize (CouenneProblem *p);
     80  virtual exprAux *standardize (CouenneProblem *);
    8981
    9082  // return an index to the variable's argument that is better fixed
    9183  // in a branching rule for solving a nonconvexity gap
    92   virtual expression *getFixVar () {return argument_;}
     84  virtual expression *getFixVar ()
     85    {return argument_;}
     86
     87  /// type of operator
     88  virtual enum expr_type code ()
     89    {return COU_EXPRUNARY;}
     90
     91  /// compare two unary functions
     92  virtual int compare (exprUnary &);
    9393};
    9494
  • branches/Couenne/Couenne/src/include/exprVar.h

    r377 r389  
    5353    {return varIndex_;}
    5454
    55   // string equivalent
    56   virtual const std::string name () const;
    57 
    5855  // print
    5956  virtual void print (std::ostream &out) const
     
    7976    {return NULL;}
    8077
    81   // get a measure of "how linear" the expression is:
    82   //
    83   // CONSTANT  = 0: a constant
    84   // LINEAR    = 1: linear
    85   // QUADRATIC = 2: quadratic
    86   // NONLINER  = 3: nonlinear non-quadratic
     78  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    8779  virtual inline int Linearity ()
    8880    {return LINEAR;}
     
    10294  // in a branching rule for solving a nonconvexity gap
    10395  virtual expression *getFixVar () {return this;}
     96
     97  ///
     98  virtual enum expr_type code () {return COU_EXPRVAR;}
    10499};
    105100
  • branches/Couenne/Couenne/src/include/expression.h

    r377 r389  
    2121class OsiSolverInterface;
    2222class OsiCuts;
    23 
     23class exprUnary;
     24class exprOp;
     25class exprCopy;
    2426
    2527// expression base class
     
    123125    {return this;}
    124126
    125   /// String equivalent (for comparisons)
    126   virtual const std::string name() const
    127     {return "null_expr";}
    128 
    129127  /// I/O
    130128  virtual void print (std::ostream &s) const {s << '?';}
     
    146144    {return NULL;}
    147145
    148   /// get a measure of "how linear" the expression is:
    149   ///
    150   /// 0: a constant
    151   /// 1: linear
    152   /// 2: quadratic
    153   /// 3: nonlinear non-quadratic
     146  /// get a measure of "how linear" the expression is (see CouenneTypes.h)
    154147  virtual inline int Linearity ()
    155148    {return NONLINEAR;}
     
    182175  virtual expression *getFixVar ()
    183176    {printf ("Warning: expression::getFixIndex()\n"); return NULL;}
     177
     178  /// return integer for comparing expressions (used to recognize
     179  /// common expression)
     180  virtual enum expr_type code ()
     181    {return COU_EXPRESSION;}
     182
     183  /// either CONVEX, CONCAVE, AFFINE, or NONE
     184  virtual enum convexity convexity ()
     185    {return NONCONVEX;}
     186
     187  /// compare expressions
     188  virtual int compare (expression &);
     189  virtual int compare (exprCopy   &);
    184190};
    185191
  • branches/Couenne/Couenne/src/include/operators/exprAbs.h

    r357 r389  
    2525  exprAbs  (expression *al):
    2626    exprUnary (al) {} //< non-leaf expression, with argument list
    27   //  ~exprAbs () {}
    2827
    2928  /// the operator's function
     
    3332  expression *clone () const
    3433    {return new exprAbs (argument_ -> clone ());}
    35 
    36   // String equivalent (for comparisons)
    37   const std::string name() const
    38     {return exprUnary::name ("abs");}
    3934
    4035  // I/O
     
    5045  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    5146                     OsiCuts &cs, const CouenneCutGenerator *cg);
     47
     48  ///
     49  virtual enum expr_type code () {return COU_EXPRABS;}
    5250};
    5351
  • branches/Couenne/Couenne/src/include/operators/exprBDiv.h

    r357 r389  
    2424    exprOp (al, n) {} //< non-leaf expression, with argument list
    2525
    26   //  ~exprLBDiv () {}
    27 
    2826  // cloning method
    2927  expression *clone () const
     
    3230  // function for the evaluation of the expression
    3331  CouNumber operator () ();
    34 
    35   // String equivalent (for comparisons)
    36   const std::string name() const {return exprOp::name ("LB_div");}
    3732
    3833  // I/O
     
    7873    exprOp (al, n) {} //< non-leaf expression, with argument list
    7974
    80   //  ~exprUBDiv () {}
    81 
    8275  // cloning method
    8376  expression *clone () const
     
    8679  // function for the evaluation of the expression
    8780  CouNumber operator () ();
    88 
    89   // String equivalent (for comparisons)
    90   std::string name () {return exprOp::name ("UB_div");}
    9181
    9282  // output
  • branches/Couenne/Couenne/src/include/operators/exprBMul.h

    r357 r389  
    2424    exprOp (al, n) {} //< non-leaf expression, with argument list
    2525
    26   //  ~exprLBMul () {}
    27 
    2826  // cloning method
    2927  expression *clone () const
     
    3230  // function for the evaluation of the expression
    3331  CouNumber operator () ();
    34 
    35   // String equivalent (for comparisons)
    36   const std::string name() const {return exprOp::name ("LB_mul");}
    3732
    3833  // output
     
    8277    exprOp (al, n) {} //< non-leaf expression, with argument list
    8378
    84   //  ~exprUBMul () {}
    85 
    8679  // cloning method
    8780  expression *clone () const
     
    9083  // function for the evaluation of the expression
    9184  CouNumber operator () ();
    92 
    93   // String equivalent (for comparisons)
    94   std::string name () {return exprOp::name ("UB_mul");}
    9585
    9686  // output
  • branches/Couenne/Couenne/src/include/operators/exprCos.h

    r357 r389  
    2727    exprUnary (al) {}
    2828
    29   //  ~exprCos () {}
    30 
    3129  // cloning method
    3230  expression *clone () const
     
    3533  /// the operator's function
    3634  inline unary_function F () {return cos;}
    37 
    38   // String equivalent (for comparisons)
    39   const std::string name() const {return exprUnary::name ("cos");}
    4035
    4136  // print "cos" and argument
     
    5247  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    5348                     OsiCuts &cs, const CouenneCutGenerator *cg);
     49
     50  ///
     51  virtual enum expr_type code () {return COU_EXPRCOS;}
    5452};
    5553
  • branches/Couenne/Couenne/src/include/operators/exprDiv.h

    r357 r389  
    2727    exprOp (arg0, arg1) {}
    2828
    29   //  ~exprDiv () {}
    30 
    3129  // cloning method
    3230  expression *clone () const
    3331    {return new exprDiv (clonearglist (), nargs_);}
    34 
    35   // String equivalent (for comparisons)
    36   const std::string name () const {return exprOp::name ("/");}
    3732
    3833  // I/O
     
    4843  expression *simplify ();
    4944
    50   // get a measure of "how linear" the expression is:
    51   //
    52   // CONSTANT  = 0: a constant
    53   // LINEAR    = 1: linear
    54   // QUADRATIC = 2: quadratic
    55   // NONLINER  = 3: nonlinear non-quadratic
     45  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    5646  inline int Linearity () {
    5747
     
    7565  // in a branching rule for solving a nonconvexity gap
    7666  expression *getFixVar ();
     67
     68  ///
     69  virtual enum expr_type code () {return COU_EXPRDIV;}
    7770};
    7871
  • branches/Couenne/Couenne/src/include/operators/exprExp.h

    r357 r389  
    2222  exprExp  (expression *al):
    2323    exprUnary (al) {} //< non-leaf expression, with argument list
    24   //  ~exprExp () {}
    2524
    2625  // cloning method
    2726  expression *clone () const
    2827    {return new exprExp (argument_ -> clone ());}
    29 
    30   // String equivalent (for comparisons)
    31   const std::string name() const {return exprUnary::name ("exp");}
    3228
    3329  /// the operator's function
     
    5450  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    5551                     OsiCuts &cs, const CouenneCutGenerator *cg);
     52
     53  ///
     54  virtual enum expr_type code () {return COU_EXPREXP;}
    5655};
    5756
  • branches/Couenne/Couenne/src/include/operators/exprGroup.h

    r387 r389  
    3434  virtual ~exprGroup () {
    3535
    36     delete index_;
    37     delete coeff_;
     36    if (index_) {
     37      delete [] index_;
     38      delete [] coeff_;
     39    }
    3840  }
    3941
     
    4143  virtual expression *clone () const
    4244    {return new exprGroup (*this);}
    43 
    44   /// String equivalent (for comparisons)
    45   virtual const std::string name () const;
    4645
    4746  /// I/O
     
    7170  virtual void generateCuts (exprAux *w, const OsiSolverInterface &si,
    7271                             OsiCuts &cs, const CouenneCutGenerator *cg);
     72
     73  /// only compare with people of the same kind
     74  virtual int compare (exprGroup &);
     75
     76  ///
     77  virtual enum expr_type code () {return COU_EXPRGROUP;}
    7378};
    7479
     
    7883inline CouNumber exprGroup::operator () () {
    7984
    80   register CouNumber ret = c0_ + exprSum::operator () ();
     85  register CouNumber  ret = c0_ + exprSum::operator () (),
     86                     *coe = coeff_;
    8187
    8288  for (register int *ind = index_, i=0; *ind >= 0;)
    83     ret += coeff_ [i++] * expression::Variable (*ind++);
     89    ret += *coe++ * expression::Variable (*ind++);
    8490
    8591  return (currValue_ = ret);
  • branches/Couenne/Couenne/src/include/operators/exprInv.h

    r357 r389  
    2828  exprInv  (expression *al):
    2929    exprUnary (al) {} //< non-leaf expression, with argument list
    30   //  ~exprInv () {}
    3130
    3231  // cloning method
     
    3736  inline unary_function F () {return inv;}
    3837
    39   // String equivalent (for comparisons)
    40   const std::string name () const {return exprUnary::name ("inv");}
    41 
    4238  // output "1/argument"
    4339  void print (std::ostream&) const;
     
    4642  expression *differentiate (int index);
    4743
    48   // get a measure of "how linear" the expression is:
    49   //
    50   // CONSTANT  = 0: a constant
    51   // LINEAR    = 1: linear
    52   // QUADRATIC = 2: quadratic
    53   // NONLINER  = 3: nonlinear non-quadratic
     44  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    5445  virtual inline int Linearity () {
    5546    if (argument_ -> Type () == CONST) return CONSTANT;
     
    6354  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    6455                     OsiCuts &cs, const CouenneCutGenerator *cg);
     56
     57  ///
     58  virtual enum expr_type code () {return COU_EXPRINV;}
    6559};
    6660
  • branches/Couenne/Couenne/src/include/operators/exprLog.h

    r357 r389  
    2525    exprUnary (al) {} //< non-leaf expression, with argument list
    2626
    27   //  ~exprLog () {}
    28 
    2927  // cloning method
    3028  expression *clone () const
    3129    {return new exprLog (argument_ -> clone ());}
    32 
    33   // String equivalent (for comparisons)
    34   const std::string name () const {return exprUnary::name ("log");}
    3530
    3631  /// the operator's function
     
    5752  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    5853                     OsiCuts &cs, const CouenneCutGenerator *cg);
     54
     55  ///
     56  virtual enum expr_type code () {return COU_EXPRINV;}
    5957};
    6058
  • branches/Couenne/Couenne/src/include/operators/exprMax.h

    r377 r389  
    3030  }
    3131
    32   //  ~exprMax () {}
    33 
    3432  // cloning method
    3533  exprMax *clone () const
    3634    {return new exprMax (clonearglist (), nargs_);}
    37 
    38   // String equivalent (for comparisons)
    39   const std::string name() const {return exprOp::name ("max");}
    4035
    4136  // I/O
     
    5449    {return NULL;}
    5550
    56   // get a measure of "how linear" the expression is:
    57   //
    58   // CONSTANT  = 0: a constant
    59   // LINEAR    = 1: linear
    60   // QUADRATIC = 2: quadratic
    61   // NONLINER  = 3: nonlinear non-quadratic
     51  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    6252  virtual inline int Linearity ()
    6353    {return NONLINEAR;}
     
    7464  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    7565                     OsiCuts &cs, const CouenneCutGenerator *cg);
     66
     67  ///
     68  virtual enum expr_type code () {return COU_EXPRMAX;}
    7669};
    7770
  • branches/Couenne/Couenne/src/include/operators/exprMin.h

    r377 r389  
    2929  }
    3030
    31   //  ~exprMin () {}
    32 
    3331  // cloning method
    3432  exprMin *clone () const
    3533    {return new exprMin (clonearglist (), nargs_);}
    36 
    37   // String equivalent (for comparisons)
    38   const std::string name () const {return exprOp::name ("min");}
    3934
    4035  // I/O
     
    5348    {return NULL;}
    5449
    55   // get a measure of "how linear" the expression is:
    56   //
    57   // CONSTANT  = 0: a constant
    58   // LINEAR    = 1: linear
    59   // QUADRATIC = 2: quadratic
    60   // NONLINER  = 3: nonlinear non-quadratic
     50  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    6151  virtual inline int Linearity ()
    6252    {return NONLINEAR;}
     
    7363  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    7464                     OsiCuts &cs, const CouenneCutGenerator *cg);
     65
     66  ///
     67  virtual enum expr_type code () {return COU_EXPRMIN;}
    7568};
    7669
  • branches/Couenne/Couenne/src/include/operators/exprMul.h

    r357 r389  
    2727    exprOp (arg0, arg1) {}
    2828
    29   //  ~exprMul () {}
    30 
    3129  // cloning method
    3230  expression *clone () const
    3331    {return new exprMul (clonearglist (), nargs_);}
    34 
    35   // String equivalent (for comparisons)
    36   const std::string name () const {return exprOp::name ("*");}
    3732
    3833  // print expression
     
    6560  // in a branching rule for solving a nonconvexity gap
    6661  expression *getFixVar ();
     62
     63  ///
     64  virtual enum expr_type code () {return COU_EXPRMUL;}
    6765};
    6866
  • branches/Couenne/Couenne/src/include/operators/exprOpp.h

    r342 r389  
    2828  exprOpp  (expression *al):
    2929    exprUnary (al) {} //< non-leaf expression, with argument list
    30   ~exprOpp () {}
    3130
    3231  // cloning method
    3332  expression *clone () const
    3433    {return new exprOpp (argument_ -> clone ());}
    35 
    36   // String equivalent (for comparisons)
    37   const std::string name () const {return exprUnary::name ("opp");}
    3834
    3935  /// the operator's function
     
    4642  expression *differentiate (int index);
    4743
    48   // get a measure of "how linear" the expression is:
    49   //
    50   // CONSTANT  = 0: a constant
    51   // LINEAR    = 1: linear
    52   // QUADRATIC = 2: quadratic
    53   // NONLINER  = 3: nonlinear non-quadratic
     44  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    5445  inline int Linearity ()
    5546    {return argument_ -> Linearity ();}
     
    6152  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    6253                     OsiCuts &cs, const CouenneCutGenerator *cg);
     54
     55  ///
     56  virtual enum expr_type code () {return COU_EXPROPP;}
    6357};
    6458
  • branches/Couenne/Couenne/src/include/operators/exprPow.h

    r342 r389  
    3131    exprOp (arg0, arg1) {}
    3232
    33   ~exprPow () {}
    34 
    3533  // cloning method
    3634  expression *clone () const
    3735    {return new exprPow (clonearglist (), nargs_);}
    38 
    39   // String equivalent (for comparisons)
    40   const std::string name () const {return exprOp::name ("^");}
    4136
    4237  // I/O
     
    6964  // in a branching rule for solving a nonconvexity gap
    7065  //   getFixVar () {return arglist_ [0];}
     66
     67  ///
     68  virtual enum expr_type code () {return COU_EXPRPOW;}
    7169};
    7270
  • branches/Couenne/Couenne/src/include/operators/exprSin.h

    r342 r389  
    2525  exprSin  (expression *al):
    2626    exprUnary (al) {} //< non-leaf expression, with argument list
    27   ~exprSin () {}
    2827
    2928  // cloning method
    3029  expression *clone () const
    3130    {return new exprSin (argument_ -> clone ());}
    32 
    33   // String equivalent (for comparisons)
    34   const std::string name () const {return exprUnary::name ("sin");}
    3531
    3632  /// the operator's function
     
    5046  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    5147                     OsiCuts &cs, const CouenneCutGenerator *cg);
     48
     49  ///
     50  virtual enum expr_type code () {return COU_EXPRSIN;}
    5251};
    5352
  • branches/Couenne/Couenne/src/include/operators/exprSub.h

    r342 r389  
    2727    exprOp (arg0, arg1) {}
    2828
    29   ~exprSub () {}
    30 
    3129  // cloning method
    3230  expression *clone () const
    3331    {return new exprSub (clonearglist (), nargs_);}
    34 
    35   // String equivalent (for comparisons)
    36   const std::string name () const {return exprOp::name ("-");}
    3732
    3833  // I/O
     
    4843  expression *simplify ();
    4944
    50   // get a measure of "how linear" the expression is:
    51   //
    52   // CONSTANT  = 0: a constant
    53   // LINEAR    = 1: linear
    54   // QUADRATIC = 2: quadratic
    55   // NONLINER  = 3: nonlinear non-quadratic
     45  // get a measure of "how linear" the expression is (see CouenneTypes.h)
    5646  virtual inline int Linearity () {
    5747
     
    7363  void generateCuts (exprAux *w, const OsiSolverInterface &si,
    7464                     OsiCuts &cs, const CouenneCutGenerator *cg);
     65
     66  ///
     67  virtual enum expr_type code () {return COU_EXPRSUB;}
    7568};
    7669
  • branches/Couenne/Couenne/src/include/operators/exprSum.h

    r380 r389  
    2626    exprOp (arg0, arg1) {}
    2727
    28   ///  virtual ~exprSum () {}
    29 
    3028  /// cloning method
    3129  virtual expression *clone () const
    3230    {return new exprSum (clonearglist (), nargs_);}
    33 
    34   /// String equivalent (for comparisons)
    35   virtual const std::string name () const {return exprOp::name ("+");}
    3631
    3732  /// I/O
     
    6055  virtual void generateCuts (exprAux *w, const OsiSolverInterface &si,
    6156                             OsiCuts &cs, const CouenneCutGenerator *cg);
     57
     58  ///
     59  virtual enum expr_type code () {return COU_EXPRSUM;}
    6260};
    6361
  • branches/Couenne/Couenne/src/problem/constraint.cpp

    r356 r389  
    2121  bool samebounds = ((lb_ -> Type () == CONST) &&
    2222                     (ub_ -> Type () == CONST) &&
    23                      (lb_ -> Value () == ub_ -> Value ()))
    24                      || (lb_ -> name () == ub_ -> name ());
     23                     (fabs (lb_ -> Value () - ub_ -> Value ()) < COUENNE_EPS));
    2524
    2625  if (lb_ &&
  • branches/Couenne/Couenne/src/problem/problem.cpp

    r387 r389  
    9999/// add auxiliary variable and associate it with pointer to expression
    100100/// given as argument
    101 
     101/*
    102102exprAux *CouenneProblem::addAuxiliary (expression *symbolic) {
    103103
     
    126126  return var;
    127127}
     128*/
     129
     130
     131/// add auxiliary variable and associate it with pointer to expression
     132/// given as argument
     133
     134exprAux *CouenneProblem::addAuxiliary (expression *symbolic) {
     135
     136  // check if image is already in the expression database auxMap_
     137
     138  //  exprAux *var;
     139  //  std::string key = symbolic -> name (); // string serving as a key to the map
     140
     141  std::map <exprAux *, int, compExpr>::iterator i;
     142
     143  exprAux *w = new exprAux (symbolic, variables_ . size () + auxiliaries_ . size ());
     144
     145  if ((i = auxMap2_ -> find (w)) == auxMap2_ -> end ()) {
     146
     147    // no such expression has been found in the map,
     148    // create entry in the map
     149
     150    std::pair <exprAux *, int> newpair;
     151
     152    newpair.first = w;//new exprAux (symbolic, variables_ . size () + auxiliaries_ . size ());
     153      // and corresponding auxiliary variable
     154    newpair.second = 1;
     155
     156    auxiliaries_ . push_back (w);
     157    auxMap2_ -> insert (newpair);
     158    /*
     159    printf ("new expression: ");
     160    w -> print (std::cout);
     161    printf (" := ");
     162    w -> Image () -> print (std::cout);
     163    printf ("\n");
     164    */
     165  }
     166  else {
     167    delete w;
     168    w = i -> first; // otherwise, just return the entry's
     169                    // auxiliary var. pointer
     170    i -> second ++;
     171    /*
     172    printf ("found (%d times now): ", i -> second);
     173    i -> first -> print (std::cout);
     174    printf (" := ");
     175    i -> first -> Image () -> print (std::cout);
     176    printf ("\n");
     177    */
     178  }
     179
     180  return w;
     181}
    128182
    129183
     
    134188  // create expression map for binary search
    135189
    136   auxMap_ = new std::map <std::string, exprAux *>;
     190  auxMap_  = new std::map <std::string, exprAux *>;
     191  auxMap2_ = new std::map <exprAux *, int, compExpr>;
    137192
    138193  // standardize objectives
  • branches/Couenne/Couenne/src/readnl/invmap.c

    r276 r389  
    1111#include <stdlib.h>
    1212
    13 #include <asl_pfgh.h>
     13#include <asl.h>
    1414#include <opcode.hd>
    15 #include <nlp2.h>
     15#include <nlp.h>
    1616#include <r_opn.hd>
    1717
     
    2020
    2121typedef struct {
    22   efunc2 *fp;
    23   int     op;
     22  efunc *fp;
     23  int    op;
    2424} AslCouPair;
    2525
     
    4747/* binary search to get operator number from its efunc2* (the type of e->op) */
    4848
    49 int getOperator (efunc2 *f) {
     49int getOperator (efunc *f) {
    5050
    5151  static char first_call = 1;
  • branches/Couenne/Couenne/src/readnl/nl2e.cpp

    r388 r389  
    22 * Name:    nl2e.cpp
    33 * Author:  Pietro Belotti
    4  * Purpose: converts a nl expression into a Feline expression
     4 * Purpose: converts a nl expression into a Couenne expression
    55 *
    66 * This file is licensed under the Common Public License (CPL)
     
    2323#include <exprExp.h>
    2424
    25 #include <asl_pfgh.h>
    26 #include <nlp2.h>
     25#include <asl.h>
     26#include <nlp.h>
    2727#include <opcode.hd>
    2828
     
    3131
    3232extern "C" {
    33   int getOperator (efunc2 *);
     33  int getOperator (efunc *);
    3434}
    3535
     
    4545// converts an AMPL expression (sub)tree into an expression* (sub)tree
    4646
    47 expression *CouenneProblem::nl2e (expr2 *e) {
    48 
    49   expression **al;
    50   expr **ep;
    51   expression *arg;
    52   int j;
     47expression *CouenneProblem::nl2e (expr *e) {
    5348
    5449  switch (getOperator (e -> op)) {
    5550
    5651  case OPPLUS:   return new exprSum (nl2e (e -> L.e), nl2e (e -> R.e));
    57   case OPMINUS:  return new exprSub (nl2e (e -> L.e), nl2e (e -> R.e -> L.e));
     52  case OPMINUS:  return new exprSub (nl2e (e -> L.e), nl2e (e -> R.e));
    5853  case OPMULT:   return new exprMul (nl2e (e -> L.e), nl2e (e -> R.e));
    5954  case OPDIV:    return new exprDiv (nl2e (e -> L.e), nl2e (e -> R.e));
     
    6661  case CEIL:    return notimpl ("ceil");
    6762  case ABS:     return new exprAbs (nl2e (e -> L.e));
    68   case OPUMINUS:return new exprOpp (nl2e (e -> L.e -> L.e));
    69     //  case OPUMINUS:return new exprOpp (nl2e (e -> L.e));
     63    //  case OPUMINUS:return new exprOpp (nl2e (e -> L.e -> L.e));
     64  case OPUMINUS:return new exprOpp (nl2e (e -> L.e));
    7065  case OPIFnl:  return notimpl ("ifnl");
    7166  case OP_tanh: return notimpl ("tanh");
    72   case OP_tan: 
     67  case OP_tan: {
     68    expression *arg;
    7369    arg = nl2e (e -> L.e);
    7470    return new exprDiv (new exprSin (arg), new exprCos (new exprClone (arg)));
     71  }
    7572  case OP_sqrt:    return new exprPow (nl2e (e -> L.e), new exprConst (0.5));
    7673  case OP_sinh:    return new exprMul (new exprConst (0.5),
     
    9693  case OPSUMLIST: {
    9794    register int i=0;
    98     al = new expression * [(e->R.ep - e->L.ep)];
    99     for (ep = e->L.ep; ep < e->R.ep; ep++)
     95    expression **al = new expression * [(e->R.ep - e->L.ep)];
     96    for (expr **ep = e->L.ep; ep < e->R.ep; ep++)
    10097      al [i++] = nl2e (*ep);
    10198    return new exprSum (al, i);
     
    118115  case OPHOL:     return notimpl ("hol");
    119116  case OPVARVAL: 
    120     // check if index is above number of variables (depending on
    121     // psb_elem groups in asl)
    122     if ((j = ((expr2_v *) e) -> a) >= nVars ()) {
    123 
    124       printf ("ERROR: added %d fake variables\nAborting...", j-nVars()+1);
    125       exit (-1);
    126       //      for (int i=nVars(); i<=j; i++)
    127       //        addVariable (false);
     117    {
     118      int j;
     119      // check if index is above number of variables (depending on
     120      // psb_elem groups in asl)
     121      if ((j = ((expr_v *) e) -> a) >= nVars ()) {
     122        printf ("ERROR: unknown variable x%d\nAborting...", j);
     123        exit (-1);
     124      }
     125      return new exprClone (variables_ [j]);
    128126    }
    129     return new exprClone (variables_ [j]);
    130 
    131127  case -1:
    132128  default: printf ("ERROR: unknown operator (address %x)\nAborting...", (long int) e -> op);
  • branches/Couenne/Couenne/src/readnl/readnl.cpp

    r388 r389  
    1616#include <exprGroup.h>
    1717
    18 #include "asl_pfgh.h"
    19 #include "nlp2.h"
     18#include "asl.h"
     19#include "nlp.h"
    2020#include "getstub.h"
    2121#include "opcode.hd"
    2222
    23 #define OBJ_DE ((const ASL_pfgh *) asl) -> I.obj2_de_
    24 #define CON_DE ((const ASL_pfgh *) asl) -> I.con2_de_
    25 #define OBJ_sense ((const ASL_pfgh *) asl) -> i.objtype_
     23#define OBJ_DE    ((const ASL_fg *) asl) -> I.obj_de_
     24#define CON_DE    ((const ASL_fg *) asl) -> I.con_de_
     25#define OBJ_sense ((const ASL_fg *) asl) -> i.objtype_
    2626
    2727
     
    3535                          )));}
    3636
    37 
    38 // replaces group in original position within expression tree
    39 
    40 extern "C" {
    41   void fix_asl_group  (psg_elem *);
    42   void free_asl_group (psg_elem *);
    43 }
    44 
    45 
    4637// Reads a MINLP from an AMPL .nl file through the ASL methods
    4738
    48 int CouenneProblem::readnl (const ASL_pfgh *asl) {
     39int CouenneProblem::readnl (const ASL *asl) {
    4940
    5041  int n_intvar = niv + nbv + nlvbi + nlvci + nlvoi;
     
    6657
    6758
    68   // fix groups //////////////////////////////////////////////////////////////////////
    69 
    70   // objective functions' groups
    71 
    72   for (int k=0; k<n_obj; k++)
    73     if ((asl -> P. ops [k]. nb) || (asl -> P. ops [k]. ng)) {
    74       /*
    75       printf ("obj %d: %d nb, %d ng\n", k,
    76               asl -> P. ops [k]. nb,
    77               asl -> P. ops [k]. ng);
    78 
    79       for (int i=0; i<asl -> P. ops [k]. nb; i++) {
    80 
    81         printf ("Group %d, obj %d: %x  ", i, k, asl -> P. ops [k]. b[i].D.e);
    82         nl2e(asl -> P. ops [k]. b[i].D.e) -> print (std::cout);
    83         printf ("\n");
    84       }
    85       */
    86       int ngroups = asl -> P. ops [k]. ng;
    87       for (int i=0; i<ngroups; i++)
    88         fix_asl_group (&(asl -> P. ops [k]. g [i]));
    89     }
    90 
    91   // constraints' groups
    92 
    93   for (int k=0; k<n_con; k++)
    94     if ((asl -> P. cps [k]. nb) || (asl -> P. cps [k]. ng)) {
    95       /*
    96       printf ("con %d: %d nb, %d ng\n", k,
    97               asl -> P. cps [k]. nb,
    98               asl -> P. cps [k]. ng);
    99 
    100       for (int i=0; i<asl -> P. cps [k]. nb; i++) {
    101 
    102         printf ("Group %d, obj %d: %x  ", i, k, asl -> P. cps [k]. b[i].D.e);
    103         nl2e(asl -> P. cps [k]. b[i].D.ee) -> print (std::cout);
    104         printf ("\n");
    105       }
    106       */
    107       int ngroups = asl -> P. cps [k]. ng;
    108       for (int i=0; i<ngroups; i++)
    109         fix_asl_group (&(asl -> P. cps [k]. g [i]));
    110     }
    111 
    11259  // objective functions /////////////////////////////////////////////////////////////
    11360
    11461  for (int i = 0; i < n_obj; i++) {
    115     /*
    116     int nterms = 0;
    117 
    118     real z0 = objconst (i);
    119 
    120     // count nonzero terms in objective function (constant, linear
    121     // and nonlinear part)
    122  
    123     if (fabs (z0) > COUENNE_EPS) nterms++;
    124 
    125     for (ograd *objgrad = Ograd [i];
    126          objgrad;
    127          objgrad = objgrad -> next)
    128       if (fabs (objgrad -> coef) > COUENNE_EPS)
    129         nterms++;
    130 
    131     if ((OBJ_DE [i] . e) && (!is_expr_zero (OBJ_DE [i] . e)))
    132       nterms++;
    133 
    134     if (!nterms) // strange, but no (linear or nonlinear) terms in here
    135       continue;
    136 
    137     // now we can fill in the objective function terms
    138 
    139     expression **al = new expression * [nterms];
    140 
    141     int term = 0;
    142 
    143     if (fabs (z0) > COUENNE_EPS)
    144       al [term++] = new exprConst (z0);
    145 
    146     ograd *objgrad;
    147 
    148     for (objgrad = Ograd [i];
    149          objgrad;
    150          objgrad = objgrad -> next)
    151       if (fabs (objgrad -> coef) > COUENNE_EPS)
    152         al [term++] = new exprMul (new exprConst (objgrad -> coef),
    153                                    new exprClone (variables_ [objgrad -> varno]));
    154 
    155     if (   (OBJ_DE [i] . e)
    156            && (!is_expr_zero (OBJ_DE [i] . e)))
    157       al [term++] = nl2e (OBJ_DE [i] . e);
    158 
    159     expression *body;
    160 
    161     // if sum only has one term, this objective is rather that term than a sum...
    162     if (term==1) {
    163       body = al [0];
    164       delete [] al;
    165     }
    166     else
    167       body = new exprSum (al, term);
    168     */
    16962
    17063    ////////////////////////////////////////////////
     
    403296  delete [] alists;
    404297
    405   // restore groups for use by Ipopt: constraints
    406 
    407   for (int k=0; k<n_con; k++)
    408     if ((asl -> P. cps [k]. nb) || (asl -> P. cps [k]. ng)) {
    409 
    410       int ngroups = asl -> P. cps [k]. ng;
    411       for (int i=0; i<ngroups; i++)
    412         free_asl_group (asl -> P. cps [k]. g + i);
    413     }
    414 
    415   // and objectives
    416 
    417   for (int k=0; k<n_obj; k++)
    418     if ((asl -> P. ops [k]. nb) || (asl -> P. ops [k]. ng)) {
    419 
    420       int ngroups = asl -> P. ops [k]. ng;
    421       for (int i=0; i<ngroups; i++)
    422         free_asl_group (asl -> P. ops [k]. g + i);
    423     }
    424 
    425298  return 0;
    426299}
Note: See TracChangeset for help on using the changeset viewer.