Simplex Class Reference

#include <simplex.h>

List of all members.

Public Member Functions

 Simplex (int dimension)
 ~Simplex ()
Vec_DPoperator[] (int i) const
int high (double *val=0) const
int low (double *val=0) const
void centroid (Vec_DP &vec) const
double size () const
int reflect ()
int reflect_exp ()
int contract ()
void reduce ()

Public Attributes

CoordCalcFunctionfunctionObject

Private Attributes

int nverts
Vec_DP ** verts
int dim

Detailed Description

Definition at line 16 of file simplex.h.


Constructor & Destructor Documentation

Simplex::Simplex ( int  dimension  ) 

Definition at line 19 of file simplex.cc.

00020 {
00021     dim = dimension;
00022     nverts = dim+1;
00023     verts = new Vec_DP*[nverts];
00024     for (int i=0; i<nverts; i++)
00025         verts[i] = new Vec_DP(dim);
00026 }

Simplex::~Simplex (  ) 

Definition at line 28 of file simplex.cc.

00029 {
00030     for (int i=0; i<nverts; i++)
00031         delete verts[i];
00032     delete[] verts;
00033 }


Member Function Documentation

void Simplex::centroid ( Vec_DP vec  )  const

Definition at line 69 of file simplex.cc.

Referenced by contract(), reflect(), reflect_exp(), and size().

00070 {
00071     Vec_DP ce(dim);
00072     int hi = high();
00073 
00074     for (int i=0; i<nverts; i++)
00075         if (i != hi)
00076             ce += *verts[i];
00077 
00078     vec = ce / (nverts-1);
00079 }

int Simplex::contract (  ) 

Definition at line 116 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

00117 {
00118     int hi = high();
00119     Vec_DP ce(dim);
00120 
00121     centroid(ce);
00122     *verts[hi] = ce + 0.5*(*verts[hi] - ce);
00123     return hi;
00124 }

int Simplex::high ( double *  val = 0  )  const

Definition at line 35 of file simplex.cc.

Referenced by centroid(), contract(), reflect(), reflect_exp(), and CoordCalcFunction::simplex_min().

00036 {
00037     double test;
00038     double max = functionObject->f(*verts[0]);
00039     int idx = 0;
00040     for (int i=1; i<nverts; i++) {
00041         test = functionObject->f(*verts[i]);
00042         if (test > max) {
00043             max = test;
00044             idx = i;
00045         }
00046     }
00047     if (0 != val)
00048         *val = max;
00049     return idx;
00050 }

int Simplex::low ( double *  val = 0  )  const

Definition at line 52 of file simplex.cc.

Referenced by reduce(), and CoordCalcFunction::simplex_min().

00053 {
00054     double test;
00055     double min = functionObject->f(*verts[0]);;
00056     int idx = 0;
00057     for (int i=1; i<nverts; i++) {
00058         test = functionObject->f(*verts[i]);
00059         if (test < min) {
00060             min = test;
00061             idx = i;
00062         }
00063     }
00064     if (0 != val)
00065         *val = min;
00066     return idx;
00067 }

Vec_DP& Simplex::operator[] ( int  i  )  const [inline]

Definition at line 29 of file simplex.h.

00029 {return *verts[i];}

void Simplex::reduce (  ) 

Definition at line 126 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

00127 {
00128     int lo = low();
00129 
00130     for (int i = 0; i<nverts; i++) {
00131         if (i != lo) {
00132             *verts[i] = 0.5 * (*verts[i] + *verts[lo]);
00133         }
00134     }
00135 }

int Simplex::reflect (  ) 

Definition at line 96 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

00097 {
00098     int hi = high();
00099     Vec_DP ce(dim);
00100 
00101     centroid(ce);
00102     *verts[hi] = ce + (ce - *verts[hi]);
00103     return hi;
00104 }

int Simplex::reflect_exp (  ) 

Definition at line 106 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

00107 {
00108     int hi = high();
00109     Vec_DP ce(dim);
00110 
00111     centroid(ce);
00112     *verts[hi] = ce + 2*(ce - *verts[hi]);
00113     return hi;
00114 }

double Simplex::size (  )  const

Definition at line 83 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

00084 {
00085     Vec_DP ce(dim);
00086     centroid(ce);
00087     double dp, size = 0;
00088 
00089     for (int i=0; i<nverts; i++) {
00090         dp = dot(*verts[i]-ce, *verts[i]-ce);
00091         size += sqrt(dp);
00092     }
00093     return size;
00094 }


Member Data Documentation

int Simplex::dim [private]

Definition at line 21 of file simplex.h.

Referenced by centroid(), contract(), reflect(), reflect_exp(), Simplex(), and size().

Definition at line 24 of file simplex.h.

Referenced by high(), low(), and CoordCalcFunction::simplex_min().

int Simplex::nverts [private]

Definition at line 19 of file simplex.h.

Referenced by centroid(), high(), low(), reduce(), Simplex(), size(), and ~Simplex().

Vec_DP** Simplex::verts [private]

The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:19 2010 for OverSim by  doxygen 1.6.3