Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# APPSPACK_Value.cpp

Go to the documentation of this file.

    00001 // $Id: APPSPACK_Value.cpp,v 1.8 2003/11/26 16:27:11 tgkolda Exp $
    00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Value.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
    00037 #include "APPSPACK_Value.hpp"
    00038 #include "APPSPACK_Print.hpp"
    00039
    00040 APPSPACK::Value::Value() :
    00041   isValue(false),
    00042   value(0)
    00043 {
    00044 }
    00045
    00046 APPSPACK::Value::Value(bool isValue_in, double value_in) :
    00047   isValue(isValue_in),
    00048   value(value_in)
    00049 {
    00050 }
    00051
    00052 APPSPACK::Value::Value(double value_in) :
    00053   isValue(true),
    00054   value(value_in)
    00055 {
    00056 }
    00057
    00058 APPSPACK::Value::Value(const Value& source) :
    00059   isValue(source.isValue),
    00060   value(source.value)
    00061 {
    00062 }
    00063
    00064 APPSPACK::Value::~Value()
    00065 {
    00066
    00067 }
    00068
    00069 bool APPSPACK::Value::getIsValue() const
    00070 {
    00071   return isValue;
    00072 }
    00073
    00074 double APPSPACK::Value::getValue() const
    00075 {
    00076   return value;
    00077 }
    00078
    00079 void APPSPACK::Value::operator=(const Value& source)
    00080 {
    00081   isValue = source.isValue;
    00082   value = source.value;
    00083 }
    00084
    00085 void APPSPACK::Value::operator=(double source)
    00086 {
    00087   isValue = true;
    00088   value = source;
    00089 }
    00090
    00091 void  APPSPACK::Value::setValueTo(bool isValue_in, double value_in)
    00092 {
    00093   isValue = isValue_in;
    00094   value = value_in;
    00095 }
    00096
    00097 void  APPSPACK::Value::setValueTo(double value_in)
    00098 {
    00099   isValue = true;
    00100   value = value_in;
    00101 }
    00102
    00103 void APPSPACK::Value::setValueToUnknown()
    00104 {
    00105   isValue = false;
    00106   value = 0;
    00107 }
    00108
    00109 bool APPSPACK::Value::operator<(const Value& source) const
    00110 {
    00111   // Case I: f(x) = infty
    00112   if (!isValue)
    00113     return false;
    00114
    00115   // Case II: f(y) = infty and f(x) is finite
    00116   if (!source.isValue)
    00117     return true;
    00118
    00119   // Case III: f(x) and f(y) are finite
    00120   return (value < source.value);
    00121 }
    00122
    00123 bool APPSPACK::Value::operator>(const Value& source) const
    00124 {
    00125   // Case I: f(y) = infty
    00126   if (!source.isValue)
    00127     return false;
    00128
    00129   // Case II: f(x) = infty and f(y) is finite
    00130   if (!isValue)
    00131     return true;
    00132
    00133   // Case III: f(x) and f(y) are finite
    00134   return (value > source.value);
    00135 }
    00136
    00137 bool APPSPACK::Value::operator==(const Value& source) const
    00138 {
    00139   // Case I: f(x) = infty, so return true if f(y) is also infty and
    00140   // false otherwise.
    00141   if (!isValue)
    00142     return (!source.isValue);
    00143
    00144   // Case II: f(x) is finite and f(y) = infty.
    00145   if (!source.isValue)
    00146     return false;
    00147
    00148   // Case III: Both f(x) and f(y) are finite.
    00149   return (value == source.value);
    00150 }
    00151
    00152 bool APPSPACK::Value::isSufficientDecrease
    00153 (const Value& source, double rho) const
    00154 {
    00155   // Case I: f(x) = infty
    00156   if (!isValue)
    00157     return false;
    00158
    00159   // Case II: f(x) is finite and f(y) = infty
    00160   if (!source.isValue)
    00161     return true;
    00162
    00163   // Case III: f(x) and f(y) are finite
    00164   return (value < (source.value - rho));
    00165 }
    00166
    00167
    00168 ostream& APPSPACK::Value::leftshift(ostream& stream) const
    00169 {
    00170   // Print point to the given stream.
    00171
    00172   if (isValue)
    00173     stream << Print::formatDouble(value);
    00174   else
    00175   {
    00176     stream << "<null>";
    00177     for (int i = 0; i < APPSPACK::Print::precision + 1; i ++)
    00178       stream << " ";
    00179   }
    00180
    00181   return stream;
    00182 }
    00183
    00184 ostream& operator<<(ostream& stream, const APPSPACK::Value& value)
    00185 {
    00186   return value.leftshift(stream);
    00187 }

© Sandia Corporation | Site Contact | Privacy and Security

Generated on Wed Dec 14 18:41:05 2005 for APPSPACK 4.0.2 by 1.3.8 written by Dimitri van Heesch, © 1997-2002