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 column_entry column::inf(const item i) const 
00005 {
00006   return NZ.inf(i);
00007 }
00008 
00009 int column::size() {
00010   /*{\Mop returns the number of entries in the column.}*/
00011   return NZ.size();
00012 }
00013 
00014 
00015 column::item column::first_item() const 
00016 {
00017   /*{\Mop Returns the first non-zero entry of the column.}*/
00018   return NZ.first_item();
00019 };
00020 
00021 
00022 column::column(double d) 
00023 {
00024   /*{\Mcreate Creates the column $d$.}*/
00025   NZ.append(column_entry(nil, d));
00026 }
00027 
00028 column::column (cons v)
00029 {
00030   NZ.append (column_entry (v, 1));
00031 }
00032 
00033 column::column (list<column_entry> &L)
00034 {
00035   NZ = L;
00036 }
00037 
00038 void
00039 column::normalize ()
00040 {
00041   NZ.sort ();
00042   list_item
00043     li;
00044   forall_items (li, NZ)
00045   {
00046     while ((NZ.succ (li) != nil) && (NZ[li].Cons == NZ[NZ.succ (li)].Cons))
00047       {
00048         NZ[li].coeff += NZ[NZ.succ (li)].coeff;
00049         NZ.del_item (NZ.succ (li));
00050       }
00051   }
00052 }
00053 
00054 column
00055 column::operator * (double d)
00056 {
00057   column_entry
00058     st;
00059   list < column_entry > NNZ;
00060   forall (st, NZ)
00061   {
00062     NNZ.append (column_entry (st.Cons, d * st.coeff));
00063   };
00064   return column (NNZ);
00065 }
00066 
00067 column
00068 column::operator + (column r)
00069 {
00070   list < column_entry > NNZ;
00071   list_item
00072     l1 = r.NZ.first ();
00073   column_entry
00074     st;
00075   double
00076     d;
00077   forall (st, NZ)
00078   {
00079     d = 0;
00080     while ((l1 != nil) && (r.NZ[l1].Cons <= st.Cons))
00081       {
00082         if (r.NZ[l1].Cons != st.Cons)
00083           {
00084             NNZ.append (r.NZ[l1]);
00085           }
00086         else
00087           {
00088             d = r.NZ[l1].coeff;
00089           }
00090         l1 = r.NZ.succ (l1);
00091       }
00092     NNZ.append (column_entry (st.Cons, st.coeff + d));
00093   }
00094   return column (NNZ);
00095 }
00096 
00097 column & column::operator += (column r)
00098 {
00099   column_entry
00100     st;
00101   forall (st, r.NZ)
00102   {
00103     NZ.append (st);
00104   }
00105   return *this;
00106 }
00107 
00108 column & column::operator -= (column r)
00109 {
00110   column_entry
00111     st;
00112   forall (st, r.NZ)
00113   {
00114     NZ.append (column_entry (st.Cons, -st.coeff));
00115   };
00116   return *this;
00117 }
00118 
00119 column
00120 column::operator + (cons v)
00121 {
00122   return operator + (column (v));
00123 };
00124 
00125 column
00126 column::operator + (double d)
00127 {
00128   return operator + (column (d));
00129 };
00130 
00131 column
00132 column::operator - (column r)
00133 {
00134   list < column_entry > NNZ;
00135   list_item
00136     l1 = r.NZ.first ();
00137   column_entry
00138     st;
00139   double
00140     d;
00141   forall (st, NZ)
00142   {
00143     d = 0;
00144     while ((l1 != nil) && (r.NZ[l1].Cons <= st.Cons))
00145       {
00146         if (r.NZ[l1].Cons != st.Cons)
00147           {
00148             NNZ.append (column_entry (r.NZ[l1].Cons, -r.NZ[l1].coeff));
00149           }
00150         else
00151           {
00152             d = -r.NZ[l1].coeff;
00153           }
00154         l1 = r.NZ.succ (l1);
00155       }
00156     NNZ.append (column_entry (st.Cons, st.coeff + d));
00157   }
00158   return column (NNZ);
00159 }
00160 
00161 
00162 column::item column::next_item(item i) const {
00163   return NZ.next_item(i);
00164 }
00165 
00166 
00167 column operator *(double d, cons i)
00168 {
00169   return column (i) * d;
00170 };
00171 
00172 column operator *(double d, column c)
00173 {
00174   return c * d;
00175 };
00176 
00177 
00178 

Generated on Tue Nov 16 15:18:14 2004 for SCIL by doxygen1.2.16