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

Go to the documentation of this file.
00001 /* $Id: sumStandardize.cpp 490 2011-01-14 16:07:12Z 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-10.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #include <stdio.h>
00012 
00013 #include "CouenneExprQuad.hpp"
00014 
00015 #include "CouenneExprSum.hpp"
00016 #include "CouenneExprSub.hpp"
00017 #include "CouenneExprOpp.hpp"
00018 #include "CouenneExprGroup.hpp"
00019 #include "CouenneLQelems.hpp"
00020 
00021 using namespace Couenne;
00022 
00027 
00028 exprAux *exprSum::standardize (CouenneProblem *p, bool addAux) {
00029 
00030   // turn all elements of arglist_ and of the linear part into an exprQuad.
00031   // count all potential quadratic terms for exprQuad
00032 
00033   LinMap lmap;
00034   QuadMap qmap;
00035 
00036   int cod = code ();
00037 
00038   CouNumber c0 = 0; // final constant term
00039 
00041 
00042   // initialize linear/quad maps with the original values/indices of
00043   // the linear part
00044 
00045   if ((cod == COU_EXPRGROUP) ||
00046       (cod == COU_EXPRQUAD)) {  // fill linear structure
00047 
00048     exprGroup *eg = dynamic_cast <exprGroup *> (this);
00049     exprGroup::lincoeff &lcoe = eg -> lcoeff ();
00050 
00051     c0 += eg -> getc0 ();
00052 
00053     for (exprGroup::lincoeff::iterator el = lcoe.begin (); el != lcoe.end (); ++el)
00054       lmap.insert (el -> first -> Index (), el -> second);
00055 
00056     if (cod == COU_EXPRQUAD) { // fill quadratic structure
00057 
00058       exprQuad *eq = dynamic_cast <exprQuad *> (this);
00059       exprQuad::sparseQ &M = eq -> getQ ();
00060 
00061       // derive quadratic part (obtain linear part)
00062       for (exprQuad::sparseQ::iterator row = M.begin (); row != M.end (); ++row) {
00063 
00064         int xind = row -> first -> Index ();
00065 
00066         for (exprQuad::sparseQcol::iterator col = row -> second.begin (); 
00067              col != row -> second.end (); ++col)
00068           qmap.insert (xind, col -> first -> Index (), col -> second);
00069       }
00070     }
00071   }
00072 
00074   //
00075   // standardize all nonlinear arguments and put them into linear or
00076   // quadratic form
00077 
00078   for (int i=0; i<nargs_; i++)
00079     p -> decomposeTerm (arglist_ [i], 1, c0, lmap, qmap);
00080 
00082 
00083   if (p -> Jnlst () -> ProduceOutput (Ipopt::J_ALL, J_REFORMULATE)) {
00084     printf ("decompTerm: lin [");
00085     for (std::map <int, CouNumber>::iterator i = lmap.Map().begin (); i != lmap.Map().end (); ++i)
00086       printf ("<%d,%g>", i -> first, i -> second);
00087     printf ("] -- quad [");
00088     for (std::map <std::pair <int, int>, CouNumber>::iterator i = qmap.Map ().begin (); 
00089          i != qmap.Map ().end (); ++i)
00090       printf ("<%d,%d,%g>", i -> first.first, i -> first.second, i -> second);
00091     printf ("] (%g)\n", c0);
00092   }
00093 
00094   return p -> linStandardize (addAux, c0, lmap, qmap);
00095 }
00096 
00097 
00102 
00103 exprAux *exprOpp::standardize (CouenneProblem *p, bool addAux) {
00104 
00105   // turn all elements of arglist_ and of the linear part into an exprQuad.
00106   // count all potential quadratic terms for exprQuad
00107 
00108   LinMap lmap;
00109   QuadMap qmap;
00110 
00111   CouNumber c0 = 0;   // final constant term
00112 
00113   p -> decomposeTerm (argument_, -1., c0, lmap, qmap);
00114 
00115   return p -> linStandardize (addAux, c0, lmap, qmap);
00116 }
00117 
00118 
00123 
00124 exprAux *exprSub::standardize (CouenneProblem *p, bool addAux) {
00125 
00126   // turn all elements of arglist_ and of the linear part into an exprQuad.
00127   // count all potential quadratic terms for exprQuad
00128 
00129   LinMap lmap;
00130   QuadMap qmap;
00131 
00132   CouNumber c0 = 0;   // final constant term
00133 
00135 
00136   // standardize all nonlinear arguments and put them into linear or
00137   // quadratic form
00138 
00139   p -> decomposeTerm (arglist_ [0],  1, c0, lmap, qmap);
00140   p -> decomposeTerm (arglist_ [1], -1, c0, lmap, qmap);
00141 
00142   return p -> linStandardize (addAux, c0, lmap, qmap);
00143 }

Generated on Thu Nov 10 03:05:46 2011 by  doxygen 1.4.7