1 // $Id: HOPSPACK_CacheManager.hpp 149 2009-11-12 02:40:41Z tplante $ 2 // $URL: https://software.sandia.gov/svn/hopspack/trunk/src/src-framework/HOPSPACK_CacheManager.hpp $ 3 4 //@HEADER 5 // ************************************************************************ 6 // 7 // HOPSPACK: Hybrid Optimization Parallel Search Package 8 // Copyright 2009 Sandia Corporation 9 // 10 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 11 // the U.S. Government retains certain rights in this software. 12 // 13 // This file is part of HOPSPACK. 14 // 15 // HOPSPACK is free software; you can redistribute it and/or modify 16 // it under the terms of the GNU Lesser General Public License as 17 // published by the Free Software Foundation; either version 2.1 of the 18 // License, or (at your option) any later version. 19 // 20 // This library is distributed in the hope that it will be useful, but 21 // WITHOUT ANY WARRANTY; without even the implied warranty of 22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 // Lesser General Public License for more details. 24 // 25 // You should have received a copy of the GNU Lesser General Public 26 // License along with this library. If not, see http://www.gnu.org/licenses/. 27 // 28 // Questions? Contact Tammy Kolda (tgkolda@sandia.gov) 29 // or Todd Plantenga (tplante@sandia.gov) 30 // 31 // ************************************************************************ 32 //@HEADER 33 34 /*! \file HOPSPACK_CacheManager.hpp 35 \brief Class declaration for HOPSPACK::CacheManager 36 */ 37 38 #ifndef HOPSPACK_CACHEMANAGER_HPP 39 #define HOPSPACK_CACHEMANAGER_HPP 40 41 #include "HOPSPACK_CachePoint.hpp" 42 #include "HOPSPACK_CacheSplayTree.hpp" 43 #include "HOPSPACK_ParameterList.hpp" 44 #include "HOPSPACK_Vector.hpp" 45 46 namespace HOPSPACK 47 { 48 49 /*! 50 \brief Manages cached points efficiently. 51 52 The cache supports the ability to read and/or write cached function 53 values from files. Each line corresponds to one point and its values. 54 A typical single line may look like the following. 55 56 \verbatim 57 x=[ 0.0000e+00 -1.2500e-02 ] f=[ 3.1250e-04 ] ceq=[ (empty)] cineq=[ (empty) ] 58 \endverbatim 59 60 The line is parsed as follows: 61 <ul> 62 <li> The line must begin with "x=[". 63 <li> This is followed by a minimum of one space. 64 <li> Entries of x, separated by spaces, are read until "]" is 65 encountered, surrounded by white space. 66 <li> This is followed by a minimum of one space. 67 <li> The next characters are "f=[". 68 <li> This is followed by a minimum of one space. 69 <li> Entries of f, separated by spaces, are read until "]" is 70 encountered, surrounded by white space. The single entry "(empty)" 71 is allowed, meaning that f has no value. 72 <li> The next characters are "ceq=[". 73 <li> Another vector of entries follows for nonlinear equality constraints, 74 following the same format as "f=[". 75 <li> The next characters are "cineq=[". 76 <li> Another vector of entries follows for nonlinear inequality constraints, 77 following the same format as "f=[". 78 </ul> 79 80 Any line that does not conform to the above format is ignored. 81 Comments are not allowed, but empty lines can be inserted to delimit sections. 82 83 \author H. Alton Patrick, Summer 2000<br> 84 Todd Plantenga, Tamara G. Kolda 85 */ 86 class CacheManager 87 { 88 89 public: 90 91 /*! Constructor */ 92 /*! 93 * @param[in] params User input from "Mediator" sublist. 94 */ 95 CacheManager (const ParameterList & params); 96 97 /*! Destructor */ 98 ~CacheManager(); 99 100 //! Add the given point to the cache. 101 bool insert(const Vector& x, 102 const Vector& f, 103 const Vector& cEqs, 104 const Vector& cIneqs); 105 106 //! Return true if x is cached and fill in the function values. 107 bool isCached(const Vector& x, 108 Vector& f, 109 Vector& cEqs, 110 Vector& cIneqs); 111 112 //! Print debug information about the instance. 113 void printDebugInfo (void) const; 114 115 private: 116 117 //! By design, there is no copy constructor. 118 CacheManager (const CacheManager &); 119 //! By design, there is no assignment operator. 120 CacheManager & operator= (const CacheManager &); 121 122 //! Parse the cache input file 123 void parseInputFile(const string & filename); 124 125 //! Process a single line from the cache input file, extracting one point 126 bool processInputLine(string& line); 127 128 bool readVectorFromLine (string & line, 129 string::size_type & line_pos, 130 Vector & result); 131 132 //! Open the output file for the cache 133 void openOutputFile(const string & filename); 134 135 //! Write a given cache point to the output file 136 void writeToOutputFile(const Vector& x, 137 const Vector& f, 138 const Vector& cEqs, 139 const Vector& cIneqs); 140 141 //! Close the output file 142 void closeOutputFile(); 143 144 145 //! Pointer to splay tree containing the cache 146 CacheSplayTree<CachePoint>* treeptr; 147 148 //! Use cache output file? 149 bool isFout; 150 151 //! Cache output file 152 ofstream fout; 153 154 string outname; 155 156 string inname; 157 bool bCanOpenInname; 158 159 //! Precision of file output (digits after the decimal point) 160 int precision; 161 }; 162 } 163 164 #endif 165