Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

column.cc

00001 #include<scil/column_entry.h>
00002 #include<scil/column.h>
00003 
00004 using namespace SCIL;
00005 
00006 int column::size() const {
00007   /*{\Mop returns the number of entries in the column.}*/
00008   return NZ.size();
00009 }
00010 
00011 column::column(double d) 
00012 {
00013   /*{\Mcreate Creates the column $d$.}*/
00014   NZ.push_back(column_entry(nil, d));
00015 }
00016 
00017 column::column (cons v)
00018 {
00019   NZ.push_back (column_entry (v, 1));
00020 }
00021 
00022 column::column (std::list<column_entry> &L)
00023 {
00024   NZ = L;
00025 }
00026 
00027 void
00028 column::normalize ()
00029 {
00030   NZ.sort();
00031   std::list<column_entry>::iterator ce;
00032   std::list<column_entry>::iterator next;
00033   foreach( ce, NZ ){
00034     next = ce;
00035     next++;
00036     while( (next!=NZ.end()) && (ce->Cons==next->Cons) ){
00037       ce->coeff += next->coeff;
00038       next = NZ.erase(next);
00039     } 
00040   }
00041 }
00042 
00043 column
00044 column::operator * (double d)
00045 {
00046   std::list<column_entry>::iterator ce;
00047   std::list < column_entry > NNZ;
00048   foreach( ce, NZ ){
00049     NNZ.push_back( column_entry( ce->Cons, d * ce->coeff ));
00050   };
00051   return column (NNZ);
00052 }
00053 
00054 column
00055 column::operator + (column r)
00056 {
00057   std::list < column_entry > NNZ;
00058 
00059   std::list<column_entry>::const_iterator rit = r.NZ.begin();
00060   std::list<column_entry>::const_iterator it;
00061 
00062   double d;
00063   foreach (it, NZ)
00064   {
00065     d = 0;
00066     while ((rit != r.NZ.end()) && (rit->Cons <= it->Cons))
00067       {
00068         if (rit->Cons != it->Cons)
00069           {
00070             NNZ.push_back (*rit);
00071           }
00072         else
00073           {
00074             d = rit->coeff;
00075           }
00076         rit++;
00077       }
00078     NNZ.push_back (column_entry (it->Cons, it->coeff + d));
00079   }
00080   return column (NNZ);
00081 }
00082 
00083 column & column::operator += (column r)
00084 {
00085   std::list<column_entry>::const_iterator ce;
00086 
00087   foreach (ce, r.NZ)
00088   {
00089     NZ.push_back (*ce);
00090   }
00091   return *this;
00092 }
00093 
00094 column & column::operator -= (column r)
00095 {
00096   std::list<column_entry>::const_iterator ce;
00097   foreach (ce, r.NZ)
00098   {
00099     NZ.push_back (column_entry (ce->Cons, -ce->coeff));
00100   };
00101   return *this;
00102 }
00103 
00104 column
00105 column::operator + (cons v)
00106 {
00107   return operator + (column (v));
00108 };
00109 
00110 column
00111 column::operator + (double d)
00112 {
00113   return operator + (column (d));
00114 };
00115 
00116 column
00117 column::operator - (column r)
00118 {
00119   std::list<column_entry>::const_iterator it;
00120   std::list<column_entry>::const_iterator rit = r.NZ.begin();
00121 
00122   std::list < column_entry > NNZ;
00123   double d;
00124   foreach (it, NZ)
00125   {
00126     d = 0;
00127     while ((rit != r.NZ.end()) && (rit->Cons <= it->Cons))
00128       {
00129         if (rit->Cons != it->Cons)
00130           {
00131             NNZ.push_back (column_entry (rit->Cons, -rit->coeff));
00132           }
00133         else
00134           {
00135             d = -rit->coeff;
00136           }
00137         rit++;
00138       }
00139     NNZ.push_back (column_entry (it->Cons, it->coeff + d));
00140   }
00141   return column (NNZ);
00142 }
00143 
00144 
00145 column operator *(double d, cons i)
00146 {
00147   return column (i) * d;
00148 };
00149 
00150 column operator *(double d, column c)
00151 {
00152   return c * d;
00153 };
00154 
00155 std::list<column_entry>::const_iterator column::begin() const {
00156   return NZ.begin();
00157 };
00158 
00159 std::list<column_entry>::const_iterator column::end() const {
00160   return NZ.end();
00161 };
00162 
00163 std::list<column_entry>::iterator column::begin() {
00164   return NZ.begin();
00165 };
00166 
00167 std::list<column_entry>::iterator column::end() {
00168   return NZ.end();
00169 };
00170 
Generated on Mon Mar 28 22:03:47 2011 for SCIL by  doxygen 1.6.3