Public Member Functions | Public Attributes | Private Attributes

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.

{
    dim = dimension;
    nverts = dim+1;
    verts = new Vec_DP*[nverts];
    for (int i=0; i<nverts; i++)
        verts[i] = new Vec_DP(dim);
}

Simplex::~Simplex (  ) 

Definition at line 28 of file simplex.cc.

{
    for (int i=0; i<nverts; i++)
        delete verts[i];
    delete[] verts;
}


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().

{
    Vec_DP ce(dim);
    int hi = high();

    for (int i=0; i<nverts; i++)
        if (i != hi)
            ce += *verts[i];

    vec = ce / (nverts-1);
}

int Simplex::contract (  ) 

Definition at line 116 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

{
    int hi = high();
    Vec_DP ce(dim);

    centroid(ce);
    *verts[hi] = ce + 0.5*(*verts[hi] - ce);
    return hi;
}

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().

{
    double test;
    double max = functionObject->f(*verts[0]);
    int idx = 0;
    for (int i=1; i<nverts; i++) {
        test = functionObject->f(*verts[i]);
        if (test > max) {
            max = test;
            idx = i;
        }
    }
    if (0 != val)
        *val = max;
    return idx;
}

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

Definition at line 52 of file simplex.cc.

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

{
    double test;
    double min = functionObject->f(*verts[0]);;
    int idx = 0;
    for (int i=1; i<nverts; i++) {
        test = functionObject->f(*verts[i]);
        if (test < min) {
            min = test;
            idx = i;
        }
    }
    if (0 != val)
        *val = min;
    return idx;
}

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

Definition at line 29 of file simplex.h.

{return *verts[i];}

void Simplex::reduce (  ) 

Definition at line 126 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

{
    int lo = low();

    for (int i = 0; i<nverts; i++) {
        if (i != lo) {
            *verts[i] = 0.5 * (*verts[i] + *verts[lo]);
        }
    }
}

int Simplex::reflect (  ) 

Definition at line 96 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

{
    int hi = high();
    Vec_DP ce(dim);

    centroid(ce);
    *verts[hi] = ce + (ce - *verts[hi]);
    return hi;
}

int Simplex::reflect_exp (  ) 

Definition at line 106 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

{
    int hi = high();
    Vec_DP ce(dim);

    centroid(ce);
    *verts[hi] = ce + 2*(ce - *verts[hi]);
    return hi;
}

double Simplex::size (  )  const

Definition at line 83 of file simplex.cc.

Referenced by CoordCalcFunction::simplex_min().

{
    Vec_DP ce(dim);
    centroid(ce);
    double dp, size = 0;

    for (int i=0; i<nverts; i++) {
        dp = dot(*verts[i]-ce, *verts[i]-ce);
        size += sqrt(dp);
    }
    return size;
}


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: