# CouenneLQelems.hpp

Go to the documentation of this file.

    00001 /* $Id: CouenneLQelems.hpp 490 2011-01-14 16:07:12Z pbelotti $
    00002  *
    00003  * Name:    lqelems.hpp
    00004  * Author:  Pietro Belotti
    00005  * Purpose: definition of elemental elements of linear and bilinear expressions
    00006  *
    00007  * (C) Carnegie-Mellon University, 2007.
    00008  * This file is licensed under the Eclipse Public License (EPL)
    00009  */
    00010
    00011 #ifndef COUENNE_LQELEMS_H
    00012 #define COUENNE_LQELEMS_H
    00013
    00014 #include <map>
    00015
    00016 #include "CouenneTypes.hpp"
    00017
    00018 namespace Couenne {
    00019
    00020 class quadElem {
    00021
    00022 private:
    00023   exprVar   *varI_;
    00024   exprVar   *varJ_;
    00025   CouNumber  coeff_;
    00026
    00027 public:
    00028
    00029   quadElem (exprVar *i, exprVar *j, CouNumber c):
    00030     varI_ (i),
    00031     varJ_ (j),
    00032     coeff_ (c) {}
    00033
    00034   quadElem (const quadElem &src):
    00035     varI_ (src.varI_),
    00036     varJ_ (src.varJ_),
    00037     coeff_ (src.coeff_) {}
    00038
    00039   quadElem *clone ()
    00040   {return new quadElem (*this);}
    00041
    00042   inline exprVar   *varI  () {return varI_;}
    00043   inline exprVar   *varJ  () {return varJ_;}
    00044   inline CouNumber  coeff () {return coeff_;}
    00045 };
    00046
    00047
    00048 class LinMap {
    00049
    00050 private:
    00051   std::map <int, CouNumber> lmap_;
    00052
    00053 public:
    00054
    00056   std::map <int, CouNumber> &Map ()
    00057   {return lmap_;}
    00058
    00060   void insert (int index, CouNumber coe) {
    00061
    00062     std::map <int, CouNumber>::iterator i = lmap_.find (index);
    00063
    00064     if (i != lmap_.end()) {
    00065       if (fabs (i -> second += coe) < COUENNE_EPS)
    00066         lmap_.erase (i);
    00067     } else {
    00068       std::pair <int, CouNumber> npair (index, coe);
    00069       lmap_.insert (npair);
    00070     }
    00071   }
    00072 };
    00073
    00074
    00075 class QuadMap {
    00076
    00077 private:
    00078   std::map <std::pair <int, int>, CouNumber> qmap_;
    00079
    00080 public:
    00081
    00083   std::map <std::pair <int, int>, CouNumber> &Map ()
    00084   {return qmap_;}
    00085
    00087   void insert (int indI, int indJ, CouNumber coe) {
    00088
    00089     std::pair <int, int> nind (indI, indJ);
    00090     std::map  <std::pair <int, int>, CouNumber>::iterator i = qmap_.find (nind);
    00091
    00092     if (i != qmap_.end()) {
    00093       if (fabs (i -> second += coe) < COUENNE_EPS)
    00094         qmap_.erase (i);
    00095     } else {
    00096       std::pair <std::pair <int, int>, CouNumber> npair (nind, coe);
    00097       qmap_.insert (npair);
    00098     }
    00099   }
    00100 };
    00101
    00102 }
    00103
    00104 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines