00001 /***************************************************************************
00002 invariant.h
00003 -----------
00004
00005 begin : Tue May 16 2000
00006 copyright : (C) 2000 by Michael Peeters
00007 email : Michael.Peeters@vub.ac.be
00008 ***************************************************************************/
00009
00010 /***************************************************************************
00011 * *
00012 * This program is free software; you can redistribute it and/or modify *
00013 * it under the terms of the GNU General Public License as published by *
00014 * the Free Software Foundation; either version 2 of the License, or *
00015 * (at your option) any later version. *
00016 * *
00017 ***************************************************************************/
00018
00019 #ifndef INVARIANT_H
00020 #define INVARIANT_H
00021
00022 #include "lusolve.h"
00023 #include "invariant.h"
00024
00025 namespace MODEL{
00029 template <integer dims, class NT = NumericTraits<number,dims> >
00030 class Invariant
00031 {
00032 public:
00033
00034 typedef typename NT::number numT;
00035 typedef typename NT::vect vect;
00036 typedef typename NT::matrix matrix;
00037 typedef typename NT::vf vf;
00038
00039 Invariant(const matrix& ma) : m(ma) {}
00040
00047 numT calculate(integer i,integer done=0);
00048
00050 NO_COPY(Invariant);
00051
00052 private:
00053 matrix m;
00054 };
00055
00056 template <integer dims, class NT>
00057 Invariant<dims,NT>::numT
00058 Invariant<dims,NT>::calculate(integer i,integer done=0)
00059 {
00060 numT result(0.);
00061
00062 //cout << "M:" << m << endl;
00063
00064 // Previously: typedef NumVector<dims-1,NumericTraits< NumVector<dims-1, NumericTraits<numT, dims-1> >,dims-1 > > smallermatrix;
00065 typedef NumVector<dims-1,numT,NT> smallervector;
00066 typedef NumVector<dims-1,smallervector,NT> smallermatrix;
00067 typedef Invariant<dims-1, NumericTraits< numT,dims-1> > smallerinv;
00068
00069 if (i==(dims-1)) {LUSolve<dims,NT> l(m,true); return l.det();}
00070 else
00071 {
00072 for(integer remove=done;remove<dims;remove++) // pick a row to be removed
00073 {
00074 smallermatrix mr(0.);
00075 integer s(0);
00076 for(integer j=0;j<dims;j++) // loop over rows
00077 {
00078 if (j!=remove)
00079 {
00080 integer t(0);
00081 for (integer k=0;k<dims;k++) // loop over colums
00082 {
00083 if (k!=remove)
00084 {
00085 mr[s][t] = m[j][k]; // make smaller matrix
00086 t++;
00087 }
00088 }
00089 s++;
00090 }
00091 }
00092 //cout << "mr:" << mr << endl;
00093 smallerinv inmo(mr); // Take a copy
00094 result += inmo.calculate(i,remove); // Calculate smaller one
00095 }
00096 }
00097 return result;
00098 }
00099
00101 template < class NT >
00102 class Invariant<1,NT>
00103 {
00104 public:
00105
00106 typedef typename NT::number numT;
00107 typedef typename NT::vect vect;
00108 typedef typename NT::matrix matrix;
00109 typedef typename NT::vf vf;
00110
00111 Invariant(const matrix& ma) : m(ma) {}
00112
00114 numT calculate(integer i,integer done=0);
00115
00116 private:
00118 NO_COPY(Invariant);
00119
00120 private:
00121 matrix m;
00122 };
00123
00124 template <class NT>
00125 Invariant<1,NT>::numT
00126 Invariant<1,NT>::calculate(integer i,integer done=0)
00127 {
00128 return m[0][0];
00129 }
00130
00131 } // end namespace
00132
00133 #endif
00134
00135 /*********************************************************************
00136 CVS INFO: $Id: invariant.h,v 1.1 2001/05/22 10:54:55 mpeeters Exp $
00137 **********************************************************************
00138
00139 $Log: invariant.h,v $
00140 Revision 1.1 2001/05/22 10:54:55 mpeeters
00141 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00142
00143 Revision 1.6 2000/09/22 08:51:45 mpeeters
00144 Added NumericTraits NT template parameter to all declarations and
00145 definitions. Not really needed, but cleaner this way.
00146
00147 Revision 1.5 2000/09/15 10:26:31 mpeeters
00148 Cleaned out header and added CVS tails to files, removed superfuous
00149 @author comments, inserted dates
00150
00151 Revision 1.4 2000/09/15 08:28:30 mpeeters
00152 Still getting to know cvs. Testfile: invariant.h
00153 (which is why my version number is going nuts)
00154
00155 Revision 1.3 2000/09/14 13:54:51 mpeeters
00156 Added code template file
00157
00158 Revision 1.2 2000/09/14 13:37:19 mpeeters
00159 First step towards cleaner sources: CVS tags test
00160
00161 *********************************************************************/
00162
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.