00001 // Copyright (C) 2005, 2008 International Business Machines and others. 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // $Id: IpTripletToCSRConverter.hpp 1210 2008-04-05 03:01:56Z andreasw $ 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 00043 TripletEntry(const TripletEntry&) 00044 {} 00046 00048 void Set(Index i_row, Index j_col, Index i_pos_triplet) 00049 { 00050 if (i_row>j_col) { 00051 i_row_ = j_col; 00052 j_col_ = i_row; 00053 } 00054 else { 00055 i_row_ = i_row; 00056 j_col_ = j_col; 00057 } 00058 i_pos_triplet_ = i_pos_triplet; 00059 } 00060 00064 Index IRow() const 00065 { 00066 return i_row_; 00067 } 00069 Index JCol() const 00070 { 00071 return j_col_; 00072 } 00074 Index PosTriplet() const 00075 { 00076 return i_pos_triplet_; 00077 } 00079 00081 bool operator< (const TripletEntry& Tentry) const 00082 { 00083 return ((i_row_ < Tentry.i_row_) || 00084 (i_row_==Tentry.i_row_ && j_col_<Tentry.j_col_)); 00085 } 00086 00087 private: 00097 //TripletEntry(); 00098 00100 /* 00101 TripletEntry(const TripletEntry&); 00102 */ 00103 00105 void operator=(const TripletEntry&); 00107 00110 Index i_row_; 00111 Index j_col_; 00112 Index i_pos_triplet_; 00114 }; 00115 00116 public: 00119 /* Constructor. If offset is 0, then the counting of indices in 00120 the compressed format starts a 0 (C-style numbering); if offset 00121 is 1, then the counting starts at 1 (Fortran-type 00122 numbering). */ 00123 TripletToCSRConverter(Index offset); 00124 00126 virtual ~TripletToCSRConverter(); 00128 00139 Index InitializeConverter(Index dim, Index nonzeros, 00140 const Index* airn, 00141 const Index* ajcn); 00142 00146 const Index* IA() const 00147 { 00148 DBG_ASSERT(initialized_); 00149 return ia_; 00150 } 00151 00153 const Index* JA() const 00154 { 00155 DBG_ASSERT(initialized_); 00156 return ja_; 00157 } 00158 const Index* iPosFirst() const 00159 { 00160 DBG_ASSERT(initialized_); 00161 return ipos_first_; 00162 } 00164 00170 void ConvertValues(Index nonzeros_triplet, const Number* a_triplet, 00171 Index nonzeros_compressed, Number* a_compressed); 00172 00173 private: 00183 TripletToCSRConverter(); 00184 00186 TripletToCSRConverter(const TripletToCSRConverter&); 00187 00189 void operator=(const TripletToCSRConverter&); 00191 00193 Index offset_; 00194 00196 Index* ia_; 00197 00199 Index* ja_; 00200 00202 Index dim_; 00203 00205 Index nonzeros_triplet_; 00206 00208 Index nonzeros_compressed_; 00209 00211 bool initialized_; 00212 00219 Index* ipos_first_; 00225 Index* ipos_double_triplet_; 00227 Index* ipos_double_compressed_; 00229 }; 00230 00231 00232 } // namespace Ipopt 00233 00234 #endif