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

# APPSPACK_Directions.cpp

Go to the documentation of this file.

    00001 // $Id: APPSPACK_Directions.cpp,v 1.13 2004/11/23 22:26:01 tgkolda Exp $
    00002 // $Source: /space/CVS-Acro/acro/packages/appspack/appspack/src/APPSPACK_Directions.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_Directions.hpp"
    00039 #include "APPSPACK_Print.hpp"
    00040 #include "APPSPACK_Utils.hpp"
    00041
    00042 APPSPACK::Directions::Directions(Parameter::List& params, const Constraints::Interface& constraints_in) :
    00043   constraints(constraints_in),
    00044   nDimensions(constraints_in.getScaling().size()),
    00045   zero(APPSPACK::createZeroVector(nDimensions)),
    00046   stepTolerance(params.getParameter("Step Tolerance", 0.01)),
    00047   minStep(params.getParameter("Minimum Step", 2 * stepTolerance)),
    00048   theta(params.getParameter("Contraction Factor", 0.5))
    00049 {
    00050   // Check parameters
    00051   if (stepTolerance <= 0)
    00052   {
    00053     cout << "APPSPACK::Directions::Directions - Error: \"Step Tolerance\" cannot be negative." << endl;
    00054     throw "APPSACK Error";
    00055   }
    00056
    00057   if (minStep <= stepTolerance)
    00058   {
    00059     cout << "APPSPACK::Directions::Directions - Error: \"Minimum Step\" must be greater than \"Step Tolerance\"." << endl;
    00060     throw "APPSACK Error";
    00061   }
    00062
    00063   if ((theta <= 0) || (theta >= 1))
    00064   {
    00065     cout << "APPSPACK::Directions::Directions - Error: \"Contraction Factor\" must be strictly between zero and one." << endl;
    00066     throw "APPSACK Error";
    00067   }
    00068
    00069   nDirections = 0;
    00070   direction.reserve(2*nDimensions);
    00071   step.reserve(2*nDimensions);
    00072   trueStep.reserve(2*nDimensions);
    00073   tag.reserve(2*nDimensions);
    00074
    00075 }
    00076
    00077
    00078 APPSPACK::Directions::~Directions()
    00079 {
    00080 }
    00081
    00082 const APPSPACK::Vector& APPSPACK::Directions::getDirection(int i) const
    00083 {
    00084   return direction[i];
    00085 }
    00086
    00087 double APPSPACK::Directions::getStep(int i) const
    00088 {
    00089   return step[i];
    00090 }
    00091
    00092 const vector<int>& APPSPACK::Directions::getDirectionIndices() const
    00093 {
    00094   idxVector.resize(0);
    00095   for (int i = 0; i < nDirections; i ++)
    00096     if ((step[i] >= stepTolerance) && (tag[i] == -1))
    00097       idxVector.push_back(i);
    00098   return idxVector;
    00099 }
    00100
    00101 void APPSPACK::Directions::computeNewDirections(const Point& newPoint)
    00102 {
    00103   // Compute the appropriate directions (only works for bounds right now)
    00104
    00105   const Vector& scaling = constraints.getScaling();
    00106   const Vector& lower = constraints.getLower();
    00107   const Vector& upper = constraints.getUpper();
    00108   const vector<bool>& isLower = constraints.getIsLower();
    00109   const vector<bool>& isUpper = constraints.getIsUpper();
    00110
    00111   const Vector& x = newPoint.getX();
    00112   direction.resize(0);
    00113   for (int i = 0; i < nDimensions; i ++)
    00114   {
    00115     tmpVector = zero;
    00116
    00117     if ( (!isUpper[i]) || (x[i] < upper[i]) )
    00118     {
    00119       // Add +e_i
    00120       tmpVector[i] = scaling[i];
    00121       direction.push_back(tmpVector);
    00122     }
    00123
    00124     if ( (!isLower[i]) || (x[i] > lower[i]) )
    00125     {
    00126       // Add -e_i
    00127       tmpVector[i] = -1 * scaling[i];
    00128       direction.push_back(tmpVector);
    00129     }
    00130
    00131   }
    00132
    00133   // Update the step, trueStep, and tag information
    00134
    00135   nDirections = direction.size();
    00136   step.resize(nDirections);
    00137   trueStep.resize(nDirections);
    00138   tag.resize(nDirections);
    00139
    00140   double newStep = max(newPoint.getStep(), minStep);
    00141
    00142   for (int i = 0; i < nDirections; i ++)
    00143   {
    00144     step[i] = newStep;
    00145     trueStep[i] = -1;
    00146     tag[i] = -1;
    00147   }
    00148
    00149 }
    00150
    00151 void APPSPACK::Directions::setTrueStepAndTag(int i, double trueStep_in, int tag_in)
    00152 {
    00153   trueStep[i] = trueStep_in;
    00154   tag[i] = tag_in;
    00155 }
    00156
    00157
    00158 void APPSPACK::Directions::print(const string label) const
    00159 {
    00160   if (!label.empty())
    00161     cout << "\n" << label << ":\n";
    00162
    00163   for (int i = 0; i < nDirections; i ++)
    00164   {
    00165     cout << setw(4) << i << " : ";
    00166
    00167     cout << "d = " << direction[i] << " ";
    00168
    00169     cout<< "step = " << Print::formatPositiveDouble(step[i]) << " ";
    00170
    00171     if (tag[i] != -1)
    00172     {
    00173       cout << "tag = " << setw(6) << tag[i] << " ";
    00174       cout << "trueStep = " <<  Print::formatPositiveDouble(trueStep[i]);
    00175     }
    00176
    00177     cout << "\n";
    00178   }
    00179 }
    00180
    00181 bool APPSPACK::Directions::isStepConverged() const
    00182 {
    00183   for (int i = 0; i < nDirections; i ++)
    00184   {
    00185     if (step[i] >= stepTolerance)
    00186       return false;
    00187   }
    00188
    00189   return true;
    00190 }
    00191
    00192
    00193 void APPSPACK::Directions::reduceStep(int i)
    00194 {
    00195   double tmpStep = theta * step[i];
    00196
    00197   step[i] = tmpStep;
    00198   trueStep[i] = -1;
    00199   tag[i] = -1;
    00200 }

© Sandia Corporation | Site Contact | Privacy and Security

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