00001 //$Header: /home/ben/Mapper/c++/RCS/constraint.cpp,v 6.3 2002/06/14 22:28:47 ben Exp $
00002 // Copyright Benedict Adamson 2002.
00003 // This file is part of Mapper.
00004
00005 // Mapper is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009
00010 // Mapper is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 // GNU General Public License for more details.
00014
00015 // You should have received a copy of the GNU General Public License
00016 // along with Mapper; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018
00029 #include <cassert>
00030
00031 #include "constraint.h"
00032 #include "vector2.h"
00033
00034
00035
00036 constraint::constraint(
00037 const double u
00038 )
00039 :
00040 uncertainty_( u )
00041 {
00042 {//postconditions:
00043 assert( this->uncertainty() == u );
00044 assert( this->points().empty() );
00045 };
00046 }
00047
00048
00049
00050 constraint::~constraint(void)
00051 {
00052 }
00053
00054
00055
00056 void constraint::uncertainty(
00057 const double u
00058 )
00059 {
00060 {//preconditions:
00061 assert( 0.0 <= u );
00062 };
00063 this->uncertainty_ = u;
00064 {//postconditions:
00065 assert( this->uncertainty() == u );
00066 };
00067 }
00068
00069
00070
00071 double constraint::energy(
00072 const double tol
00073 ) const
00074 {
00075 //tol is a dimensionless calculation tolerance.
00076 //A dimensionless measure of the potential energy of the constraint.
00077 //Larger values indicate the constraint is less well satisfied.
00078 //Conventionally, 0 is defined as the minimum possible energy,
00079 //And energy <= 1 indicates that the constraint is satisifed
00080 //to within the uncertainty of the constraint.
00081 {//precondition:
00082 assert( 0 < tol && tol < 1 );
00083 //assert( this->points()[i] ) for all i
00084 };
00085 const unsigned n = this->points().size();
00086 vector< vector2 > p(n), dedp(n);
00087 for( unsigned i = 0; i < n; i++ ){
00088 assert( this->points()[i] );
00089 p[i] = *(this->points()[i]);
00090 };
00091 double e;
00092 this->energy( tol, p, e, dedp );
00093 return e;
00094 }
00095