Ipopt  trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
IpTripletToCSRConverter.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2005, 2008 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Eclipse Public License.
00004 //
00005 // $Id$
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2005-03-13
00008 
00009 #ifndef __IPTRIPLETTOCSRCONVERTER_HPP__
00010 #define __IPTRIPLETTOCSRCONVERTER_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpReferenced.hpp"
00014 namespace Ipopt
00015 {
00016 
00023   class TripletToCSRConverter: public ReferencedObject
00024   {
00026     class TripletEntry
00027     {
00028     public:
00032       TripletEntry()
00033       {}
00034 
00036       ~TripletEntry()
00037       {}
00038 
00040       TripletEntry(const TripletEntry& rhs)
00041       {
00042         i_row_ = rhs.i_row_;
00043         j_col_ = rhs.j_col_;
00044         i_pos_triplet_ = rhs.i_pos_triplet_;
00045       }
00046 
00048       TripletEntry& operator=(const TripletEntry& rhs)
00049       {
00050         if (this!=&rhs) {
00051           i_row_ = rhs.i_row_;
00052           j_col_ = rhs.j_col_;
00053           i_pos_triplet_ = rhs.i_pos_triplet_;
00054         }
00055         return *this;
00056       }
00058 
00060       void Set(Index i_row, Index j_col, Index i_pos_triplet)
00061       {
00062         if (i_row>j_col) {
00063           i_row_ = j_col;
00064           j_col_ = i_row;
00065         }
00066         else {
00067           i_row_ = i_row;
00068           j_col_ = j_col;
00069         }
00070         i_pos_triplet_ = i_pos_triplet;
00071       }
00072 
00076       Index IRow() const
00077       {
00078         return i_row_;
00079       }
00081       Index JCol() const
00082       {
00083         return j_col_;
00084       }
00086       Index PosTriplet() const
00087       {
00088         return i_pos_triplet_;
00089       }
00091 
00093       bool operator< (const TripletEntry& Tentry) const
00094       {
00095         return ((i_row_ < Tentry.i_row_) ||
00096                 (i_row_==Tentry.i_row_ && j_col_<Tentry.j_col_));
00097       }
00098 
00099     private:
00109       //TripletEntry();
00110 
00112       /*
00113       TripletEntry(const TripletEntry&);
00114       */
00116 
00119       Index i_row_;
00120       Index j_col_;
00121       Index i_pos_triplet_;
00123     };
00124 
00125   public:
00127     enum ETriFull {
00129       Triangular_Format,
00131       Full_Format
00132     };
00133 
00136     /* Constructor.  If offset is 0, then the counting of indices in
00137        the compressed format starts a 0 (C-style numbering); if offset
00138        is 1, then the counting starts at 1 (Fortran-type
00139        numbering). */
00140     TripletToCSRConverter(Index offset, ETriFull hf = Triangular_Format);
00141 
00143     virtual ~TripletToCSRConverter();
00145 
00156     Index InitializeConverter(Index dim, Index nonzeros,
00157                               const Index* airn,
00158                               const Index* ajcn);
00159 
00163     const Index* IA() const
00164     {
00165       DBG_ASSERT(initialized_);
00166       return ia_;
00167     }
00168 
00170     const Index* JA() const
00171     {
00172       DBG_ASSERT(initialized_);
00173       return ja_;
00174     }
00175     const Index* iPosFirst() const
00176     {
00177       DBG_ASSERT(initialized_);
00178       return ipos_first_;
00179     }
00181 
00187     void ConvertValues(Index nonzeros_triplet, const Number* a_triplet,
00188                        Index nonzeros_compressed, Number* a_compressed);
00189 
00190   private:
00200     TripletToCSRConverter();
00201 
00203     TripletToCSRConverter(const TripletToCSRConverter&);
00204 
00206     void operator=(const TripletToCSRConverter&);
00208 
00210     Index offset_;
00211 
00213     ETriFull hf_;
00214 
00216     Index* ia_;
00217 
00219     Index* ja_;
00220 
00222     Index dim_;
00223 
00225     Index nonzeros_triplet_;
00226 
00228     Index nonzeros_compressed_;
00229 
00231     Index num_doubles_;
00232 
00234     bool initialized_;
00235 
00242     Index* ipos_first_;
00248     Index* ipos_double_triplet_;
00250     Index* ipos_double_compressed_;
00252   };
00253 
00254 
00255 } // namespace Ipopt
00256 
00257 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines