/home/coin/SVN-release/OS-2.0.1/Couenne/src/standardize/sumStandardize.cpp

Go to the documentation of this file.
00001 /* $Id: sumStandardize.cpp 154 2009-06-16 18:52:53Z pbelotti $ */
00002 /*
00003  * Name:    sumStandardize.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: check if expr{Group,Sum,Sub} contains a lot of quadratic/bilinear terms
00006  *
00007  * (C) Carnegie-Mellon University, 2007. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "exprSum.hpp"
00012 #include "exprSub.hpp"
00013 #include "exprOpp.hpp"
00014 #include "exprGroup.hpp"
00015 #include "exprQuad.hpp"
00016 #include "lqelems.hpp"
00017 
00018 //#define DEBUG
00019 
00020 
00025 
00026 exprAux *exprSum::standardize (CouenneProblem *p, bool addAux) {
00027 
00028   // turn all elements of arglist_ and of the linear part into an exprQuad.
00029   // count all potential quadratic terms for exprQuad
00030 
00031   LinMap lmap;
00032   QuadMap qmap;
00033 
00034   int cod = code ();
00035 
00036   CouNumber c0 = 0; // final constant term
00037 
00039 
00040   // initialize linear/quad maps with the original values/indices of
00041   // the linear part
00042 
00043   if ((cod == COU_EXPRGROUP) ||
00044       (cod == COU_EXPRQUAD)) {  // fill linear structure
00045 
00046     exprGroup *eg = dynamic_cast <exprGroup *> (this);
00047     exprGroup::lincoeff &lcoe = eg -> lcoeff ();
00048 
00049     c0 += eg -> getc0 ();
00050 
00051     for (exprGroup::lincoeff::iterator el = lcoe.begin (); el != lcoe.end (); ++el)
00052       lmap.insert (el -> first -> Index (), el -> second);
00053 
00054     if (cod == COU_EXPRQUAD) { // fill quadratic structure
00055 
00056       exprQuad *eq = dynamic_cast <exprQuad *> (this);
00057       exprQuad::sparseQ &M = eq -> getQ ();
00058 
00059       // derive quadratic part (obtain linear part)
00060       for (exprQuad::sparseQ::iterator row = M.begin (); row != M.end (); ++row) {
00061 
00062         int xind = row -> first -> Index ();
00063 
00064         for (exprQuad::sparseQcol::iterator col = row -> second.begin (); 
00065              col != row -> second.end (); ++col)
00066           qmap.insert (xind, col -> first -> Index (), col -> second);
00067       }
00068     }
00069   }
00070 
00072   //
00073   // standardize all nonlinear arguments and put them into linear or
00074   // quadratic form
00075 
00076   for (int i=0; i<nargs_; i++)
00077     p -> decomposeTerm (arglist_ [i], 1, c0, lmap, qmap);
00078 
00080 
00081 #ifdef DEBUG
00082   printf ("decompTerm: lin [");
00083   for (std::map <int, CouNumber>::iterator i = lmap.Map().begin (); i != lmap.Map().end (); ++i)
00084     printf ("<%d,%g>", i -> first, i -> second);
00085   printf ("] -- quad [");
00086   for (std::map <std::pair <int, int>, CouNumber>::iterator i = qmap.Map ().begin (); 
00087        i != qmap.Map ().end (); ++i)
00088     printf ("<%d,%d,%g>", i -> first.first, i -> first.second, i -> second);
00089   printf ("] (%g)\n", c0);
00090 #endif
00091 
00092   return p -> linStandardize (addAux, c0, lmap, qmap);
00093 }
00094 
00095 
00100 
00101 exprAux *exprOpp::standardize (CouenneProblem *p, bool addAux) {
00102 
00103   // turn all elements of arglist_ and of the linear part into an exprQuad.
00104   // count all potential quadratic terms for exprQuad
00105 
00106   LinMap lmap;
00107   QuadMap qmap;
00108 
00109   CouNumber c0 = 0;   // final constant term
00110 
00111   p -> decomposeTerm (argument_, -1., c0, lmap, qmap);
00112 
00113   return p -> linStandardize (addAux, c0, lmap, qmap);
00114 }
00115 
00116 
00121 
00122 exprAux *exprSub::standardize (CouenneProblem *p, bool addAux) {
00123 
00124   // turn all elements of arglist_ and of the linear part into an exprQuad.
00125   // count all potential quadratic terms for exprQuad
00126 
00127   LinMap lmap;
00128   QuadMap qmap;
00129 
00130   CouNumber c0 = 0;   // final constant term
00131 
00133 
00134   // standardize all nonlinear arguments and put them into linear or
00135   // quadratic form
00136 
00137   p -> decomposeTerm (arglist_ [0],  1, c0, lmap, qmap);
00138   p -> decomposeTerm (arglist_ [1], -1, c0, lmap, qmap);
00139 
00140   return p -> linStandardize (addAux, c0, lmap, qmap);
00141 }

Generated on Thu Oct 8 03:02:57 2009 by  doxygen 1.4.7