Changeset 294


Ignore:
Timestamp:
Feb 13, 2010 9:04:23 AM (11 years ago)
Author:
pbelotti
Message:

fixed reformulation bug affecting st_glmp_fp3

Location:
trunk/Couenne/src/standardize
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Couenne/src/standardize/constrStandardize.cpp

    r273 r294  
    55 * Purpose: standardization of constraints
    66 *
    7  * (C) Carnegie-Mellon University, 2007-09.
     7 * (C) Carnegie-Mellon University, 2007-10.
    88 * This file is licensed under the Common Public License (CPL)
    99 */
     
    1818//#define DEBUG
    1919
     20// replace a variable
     21void replace (CouenneProblem *p, int wind, int xind);
     22
     23
    2024/// decompose body of constraint through auxiliary variables
    21 
    2225exprAux *CouenneConstraint::standardize (CouenneProblem *p) {
    2326
     
    9699      if (xind >= 0) {
    97100
    98         exprVar
    99           *varStays  = p -> Variables () [xind],
    100           *varLeaves = p -> Variables () [wind];
    101 
    102         // intersect features of the two variables (integrality, bounds)
    103 
    104         varStays -> lb () = varLeaves -> lb () = CoinMax (varStays -> lb (), varLeaves -> lb ());
    105         varStays -> ub () = varLeaves -> ub () = CoinMin (varStays -> ub (), varLeaves -> ub ());
    106 
    107         if (varStays  -> isInteger () ||
    108             varLeaves -> isInteger ()) {
    109 
    110           varStays -> lb () = ceil  (varStays -> lb ());
    111           varStays -> ub () = floor (varStays -> ub ());
    112 
    113           if (varStays -> Type () == AUX)
    114             varStays -> setInteger (true);
    115           else {
    116             //expression *old = varStays; // !!! leak
    117             p -> Variables () [xind] = varStays = new exprIVar (xind, p -> domain ());
    118             p -> auxiliarize (varStays); // replace it everywhere in the problem
    119             //delete old;
    120           }
    121         }
     101        replace (p, wind, xind);
    122102
    123103        p -> auxiliarize (p -> Var (wind), p -> Var (xind));
     
    158138          (*i) -> print (); printf (" := ");
    159139          (*i) -> Image () -> print (); printf ("\n");
     140
     141          // if this is an original variable and is competing with an
     142          // auxiliary variable, or at least this has a lower index,
     143          // we better replace it throughout and eliminate that
     144          // aux. See globallib/st_glmp_fp3 for an example where this
     145          // otherwise would be a bug (x_1 unlinked from x2-x3 and
     146          // leading to unbounded)
     147         
     148          int xind = (*i) -> Index (), iMax, iMin;
     149
     150          if (xind < wind) {
     151            iMax = wind;
     152            iMin = xind;
     153          } else {
     154            iMax = xind;
     155            iMin = wind;
     156          }
     157
     158          replace (p, iMax, iMin);
     159
     160          p -> auxiliarize (p -> Var (iMax), p -> Var (iMin));
     161          p -> Var (iMax) -> zeroMult (); // redundant variable is neutralized
     162          p -> auxiliarize (w);
    160163        }
    161164#endif
     
    172175  return body_ -> standardize (p);
    173176}
     177
     178
     179// Replace a variable ////////////////////////////////
     180void replace (CouenneProblem *p, int wind, int xind) {
     181
     182  exprVar
     183    *varLeaves = p -> Variables () [wind],
     184    *varStays  = p -> Variables () [xind];
     185
     186  // intersect features of the two variables (integrality, bounds)
     187
     188  varStays -> lb () = varLeaves -> lb () = CoinMax (varStays -> lb (), varLeaves -> lb ());
     189  varStays -> ub () = varLeaves -> ub () = CoinMin (varStays -> ub (), varLeaves -> ub ());
     190
     191  if (varStays  -> isInteger () ||
     192      varLeaves -> isInteger ()) {
     193
     194    varStays -> lb () = ceil  (varStays -> lb ());
     195    varStays -> ub () = floor (varStays -> ub ());
     196
     197    if (varStays -> Type () == AUX)
     198      varStays -> setInteger (true);
     199    else {
     200      //expression *old = varStays; // !!! leak
     201      p -> Variables () [xind] = varStays = new exprIVar (xind, p -> domain ());
     202      p -> auxiliarize (varStays); // replace it everywhere in the problem
     203      //delete old;
     204    }
     205  }
     206}
  • trunk/Couenne/src/standardize/standardize.cpp

    r274 r294  
    378378  }
    379379
     380  // check how many multiplications there are
     381
     382//   int nmul = 0;
     383//   // Look for auxiliaries of the form w:=x and replace each occurrence of w with x
     384//   for (std::vector <exprVar *>::iterator i = variables_.begin ();
     385//        i != variables_.end (); ++i) {
     386
     387//     if ((*i) -> Type () != AUX ||
     388//      (*i) -> Multiplicity () <= 0)
     389//       continue;
     390
     391//     expression *img = (*i) -> Image ();
     392
     393//     if (img -> code () != COU_EXPRMUL)
     394//       continue;
     395
     396//     expression **args = img -> ArgList ();
     397
     398//     if ((args [0] -> Type () == AUX ||
     399//       args [0] -> Type () == VAR) &&
     400//      (args [1] -> Type () == AUX ||
     401//       args [1] -> Type () == VAR))
     402//       nmul++;
     403//   }
     404
     405//   printf ("MULS: %d/%d\n", nmul, variables_.size());
     406
     407//   exit (-1);
     408
    380409  // TODO: re-compute ranks
    381410
Note: See TracChangeset for help on using the changeset viewer.