/home/coin/SVN-release/OS-2.0.0/Couenne/src/standardize/constrStandardize.cpp

Go to the documentation of this file.
00001 /* $Id: constrStandardize.cpp 154 2009-06-16 18:52:53Z pbelotti $ */
00002 /*
00003  * Name:    constrStandardize.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: standardization of constraints
00006  *
00007  * (C) Carnegie-Mellon University, 2007. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "CouenneProblemElem.hpp"
00012 #include "CouenneProblem.hpp"
00013 
00014 #include "exprAux.hpp"
00015 #include "depGraph.hpp"
00016 
00017 //#define DEBUG
00018 
00020 
00021 exprAux *CouenneConstraint::standardize (CouenneProblem *p) {
00022 
00023   // spot an auxiliary variable in constraint's body w - f(x) and move
00024   // the explicit w into the vector of auxiliary variables
00025   //
00026   // do it only if this is an equality constraint and there is at
00027   // least one variable that did not show up so far (need a problem
00028   // structure)
00029 
00030 #ifdef DEBUG
00031   printf ("################################\nStandardizing constraint: "); print ();
00032 
00033   printf (" ["); fflush (stdout); lb_ -> print ();
00034   printf (","); fflush (stdout);  ub_ -> print (); fflush (stdout);
00035   /*  printf ("] {with auxset = ");
00036   for (std::set <exprAux *, compExpr>::iterator i = p -> AuxSet () -> begin ();
00037        i != p -> AuxSet () -> end (); i++) {
00038     printf ("<"); (*i) -> print (); 
00039     printf (","); (*i) -> Image () -> print (); printf ("> ");
00040     }*/
00041   printf ("]\n");
00042 #endif
00043 
00044   if (compareExpr (&lb_, &ub_) == 0) {
00045 
00046     // this is an equality constraint, and could be the definition of
00047     // an auxiliary
00048 
00049     expression *rest;
00050 
00051     // split w from f(x)
00052     int wind = p -> splitAux ((*lb_) (), body_, rest, p -> Commuted ());
00053 
00054     if (wind >= 0) { // this IS the definition of an auxiliary variable w = f(x)
00055 
00056       p -> Commuted () [wind] = true;
00057 
00058 #ifdef DEBUG
00059       printf ("---> %d & ", wind); fflush (stdout);
00060       rest -> print (); printf ("\n");
00061 #endif
00062 
00063       assert (p -> Var (wind) -> Type () == VAR);
00064 
00065       // create new variable, it has to be integer if original variable was integer
00066       exprAux *w = new exprAux (rest, wind, 1 + rest -> rank (),
00067                                 p -> Var (wind) -> isInteger () ? 
00068                                 exprAux::Integer : exprAux::Continuous,
00069                                 p -> domain ());
00070 
00071       std::set <exprAux *, compExpr>::iterator i = p -> AuxSet () -> find (w);
00072 
00073       // no such expression found in the set:
00074       if (i == p -> AuxSet () -> end ()) {
00075 
00076         p -> AuxSet      () -> insert (w); // 1) beware of useless copies
00077         p -> getDepGraph () -> insert (w); // 2) introduce it in acyclic structure
00078 
00079 #ifdef DEBUG
00080         printf ("now replacing x [%d] with ", wind);
00081         w -> print (); printf (" := ");
00082         w -> Image () -> print (); printf ("\n");
00083 #endif
00084 
00085         // replace ALL occurrences of original variable (with index
00086         // wind) with newly created auxiliary
00087         p -> auxiliarize (w);
00088       } 
00089 
00090 #ifdef DEBUG
00091       else {
00092         printf ("found aux occurrence of "); 
00093         w -> print (); printf (" := ");
00094         w -> Image () -> print (); printf (" ... ");
00095         (*i) -> print (); printf (" := ");
00096         (*i) -> Image () -> print (); printf ("\n");
00097       }
00098 #endif
00099 
00100       return NULL;
00101     }
00102   }
00103 
00104 #ifdef DEBUG
00105   printf ("\nnormal\n-----------------\n");
00106 #endif
00107 
00108   return body_ -> standardize (p);
00109 }

Generated on Mon Aug 3 03:02:21 2009 by  doxygen 1.4.7