Sandia Home Sandia Home
Main Page | Publications | Downloads | Configuration | Running the Code | Solver Parameters | FAQ | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

APPSPACK_Point.cpp

Go to the documentation of this file.
00001 // $Id: APPSPACK_Point.cpp,v 1.13 2006/06/30 01:42:08 tgkolda Exp $ 
00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Point.cpp,v $ 
00003 
00004 //@HEADER
00005 // ************************************************************************
00006 // 
00007 //          APPSPACK: Asynchronous Parallel Pattern Search
00008 //                 Copyright (2003) Sandia Corporation
00009 // 
00010 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00011 // license for use of this work by or on behalf of the U.S. Government.
00012 // 
00013 // This library is free software; you can redistribute it and/or modify
00014 // it under the terms of the GNU Lesser General Public License as
00015 // published by the Free Software Foundation; either version 2.1 of the
00016 // License, or (at your option) any later version.
00017 //  
00018 // This library is distributed in the hope that it will be useful, but
00019 // WITHOUT ANY WARRANTY; without even the implied warranty of
00020 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 // Lesser General Public License for more details.
00022 //                                                                                 
00023 // You should have received a copy of the GNU Lesser General Public
00024 // License along with this library; if not, write to the Free Software
00025 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00026 // USA.                                                                           .
00027 // 
00028 // Questions? Contact Tammy Kolda (tgkolda@sandia.gov) 
00029 // 
00030 // ************************************************************************
00031 //@HEADER
00032 
00038 #include "APPSPACK_Point.hpp"
00039 #include "APPSPACK_Float.hpp"
00040 #include "APPSPACK_Print.hpp"
00041 
00042 int APPSPACK::Point::staticCount = 0;
00043 
00044 APPSPACK::Point::Point(const Vector& x_in, const Vector& f_in, 
00045                        double step_in, double alpha_in,
00046                        Combiner::Generic& combiner_in) :
00047   combiner(combiner_in),
00048   x(x_in),
00049   f(f_in),
00050   tag(staticCount),
00051   step(step_in),
00052   msg("(Initial Point)"),
00053   parentTag(-1),
00054   idx(-1),
00055   parentF(APPSPACK::dne()),
00056   alpha(alpha_in),
00057   rho(0),
00058   state(Evaluated)
00059 {
00060   staticCount ++;
00061 }
00062 
00063 APPSPACK::Point::Point(const Vector& x_in, double step_in,
00064                        const Point& parent, int idx_in) :
00065   combiner(parent.combiner),
00066   x(x_in),
00067   f(),
00068   tag(staticCount),
00069   step(step_in),
00070   msg(),
00071   parentTag(parent.tag),
00072   idx(idx_in),
00073   parentF(combiner(parent.f)),
00074   alpha(parent.alpha),
00075   rho(alpha * step * step),
00076   state(Unevaluated)
00077 {
00078   staticCount ++;
00079 }
00080 
00081 APPSPACK::Point::~Point()
00082 {
00083 }
00084 
00085 const APPSPACK::Vector& APPSPACK::Point::getX() const
00086 {
00087   return x;
00088 }
00089 
00090 double APPSPACK::Point::getF() const
00091 {
00092   return combiner(f);
00093 }
00094 
00095 const APPSPACK::Vector& APPSPACK::Point::getVecF() const
00096 {
00097   return f;
00098 }
00099 
00100 int APPSPACK::Point::getTag() const
00101 {
00102   return tag;
00103 }
00104 
00105 int APPSPACK::Point::getParentTag() const
00106 {
00107   return parentTag;
00108 }
00109 
00110 int APPSPACK::Point::getIndex() const
00111 {
00112   return idx;
00113 }
00114 
00115 double APPSPACK::Point::getStep() const
00116 {
00117   return step;
00118 }
00119 
00120 void APPSPACK::Point::setCachedFunctionValue(const Vector& f_in, const string& msg_in)
00121 {
00122   f = f_in;
00123   msg = msg_in;
00124   state = (isSufficientDecrease()) ? Cached : CachedInsufficientDecrease;
00125 }
00126 
00127 void APPSPACK::Point::setEvaluatedFunctionValue(const Vector& f_in, const string& msg_in)
00128 {
00129   f = f_in;
00130   msg = msg_in;
00131   state = (isSufficientDecrease()) ? Evaluated : EvaluatedInsufficientDecrease;
00132 }
00133 
00134 void APPSPACK::Point::setInfeasible()
00135 {
00136   state = Infeasible;
00137 }
00138 
00139 bool APPSPACK::Point::operator<(const Point& other) const
00140 {
00141   // Case I: Equal tags
00142   if (tag == other.tag)
00143     return false;
00144 
00145   // Case II: This point does not have a valid function value
00146   if ((state != Cached) && (state != Evaluated))
00147     return false;
00148 
00149   // Case III: The other point does not have a valid function value
00150   if ((other.state != Cached) && (other.state != Evaluated))
00151     return true;
00152 
00153   // Case IV: f(x) < f(y)
00154   if (lessThan(other.f))                
00155     return true;
00156 
00157   // Case III: f(x) > f(y)
00158   if (greaterThan(other.f))
00159     return false;
00160 
00161   // Case IV: f(x) = f(y)
00162   return (tag < other.tag);
00163 }
00164 
00165 bool APPSPACK::Point::lessThan(const Vector& other) const
00166 {
00167   double fx = combiner(f);
00168   double fy = combiner(other);
00169 
00170   // Case I: f(x) = infty
00171   if (!exists(fx))
00172     return false;
00173   
00174   // Case II: f(y) = infty and f(x) is finite
00175   if (!exists(fy))
00176     return true;
00177   
00178   // Case III: f(x) and f(y) are finite
00179   return (fx < fy);
00180 }
00181 
00182 bool APPSPACK::Point::greaterThan(const Vector& other) const
00183 {
00184   double fx = combiner(f);
00185   double fy = combiner(other);
00186 
00187   // Case I: f(y) = infty
00188   if (!exists(fy))
00189     return false;
00190   
00191   // Case II: f(x) = infty and f(y) is finite
00192   if (!exists(fx))
00193     return true;
00194   
00195   // Case III: f(x) and f(y) are finite
00196   return (fx > fy);
00197 }
00198 
00199 // PRIVATE
00200 bool APPSPACK::Point::isSufficientDecrease() const
00201 {
00202   // No sufficient decrease criteria imposed
00203   if (rho <= 0)
00204     return true;
00205 
00206   double fx = combiner(f);
00207 
00208   // Case I: f(x) = infty
00209   if (!exists(fx))
00210     return false;
00211   
00212   // Case II: f(x) is finite and f(y) = infty
00213   if (!exists(parentF))
00214     return true;
00215   
00216   // Case III: f(x) and f(y) are finite
00217   return (fx < (parentF - rho));
00218 }
00219 
00220 
00221 ostream& APPSPACK::Point::leftshift(ostream& stream) const
00222 {
00223   // Print point to the given stream. 
00224 
00225   stream << "f=" << APPSPACK::Print::formatPositiveDouble(combiner(f));
00226   stream << " x=" << x;
00227   stream << " step=" << APPSPACK::Print::formatPositiveDouble(step);
00228   stream << " tag=" << tag;
00229   stream << " state=" << state;
00230   stream << " " << msg;
00231   return stream;
00232 }
00233 
00234 ostream& operator<<(ostream& stream, const APPSPACK::Point& point)
00235 {
00236   return point.leftshift(stream);
00237 }
00238 
00239 ostream& operator<<(ostream& stream, APPSPACK::Point::State state)
00240 {
00241   switch(state)
00242   {
00243   case APPSPACK::Point::Unevaluated:
00244     stream << "Unevaluated";
00245     break; 
00246   case APPSPACK::Point::Infeasible:
00247     stream << "Infeasible";
00248     break;
00249   case APPSPACK::Point::CachedInsufficientDecrease:
00250     stream << "CachedInsufficientDecrease";
00251     break;
00252   case APPSPACK::Point::Cached:
00253     stream << "Cached";
00254     break;
00255   case APPSPACK::Point::EvaluatedInsufficientDecrease:
00256     stream << "EvaluatedInsufficientDecrease";
00257     break;
00258   case APPSPACK::Point::Evaluated:
00259     stream << "Evaluated";
00260     break;
00261   }
00262   
00263   return stream;
00264 }

 

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Fri Feb 16 10:33:35 2007 for APPSPACK 5.0.1 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2002