Alps 1.5.11
Loading...
Searching...
No Matches
AlpsParameterBase.h
Go to the documentation of this file.
1/*===========================================================================*
2 * This file is part of the Abstract Library for Parallel Search (ALPS). *
3 * *
4 * ALPS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: *
8 * *
9 * Yan Xu, Lehigh University *
10 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * *
20 * Copyright (C) 2001-2023, Lehigh University, Yan Xu, and Ted Ralphs. *
21 *===========================================================================*/
22
23#ifndef AlpsParameters_h
24#define AlpsParameters_h
25
26//----------------------------------------------------------
27// AlpsParameterBase.h is modified from BCP_parameters.hpp
28//----------------------------------------------------------
29
30#include <algorithm>
31#include <cctype>
32#include <cstdio>
33#include <fstream>
34#include <iostream>
35#include <string>
36#include <utility> // for 'pair'
37#include <vector>
38
39#include "CoinError.hpp"
40
41#if defined(__GNUC__) && (__GNUC__ >= 3)
42# include <sstream>
43# include <locale>
44# define ALPS_STRINGSTREAM std::istringstream
45#else
46# include <strstream>
47# include <cctype>
48# define ALPS_STRINGSTREAM std::istrstream
49#endif
50
51class AlpsEncoded;
52
53//##############################################################################
54
72
73//##############################################################################
74
78
79 private:
85 int index_;
88 public:
89 // default copy constructor and assignment operator are fine
95 AlpsParameter(const AlpsParameterT t, const int i) :
96 type_(t), index_(i) {}
104 AlpsParameterT type() const { return type_; }
107 int index() const { return index_; }
109};
110
111//##############################################################################
112
135 protected:
140 std::vector< std::pair<std::string, AlpsParameter> > keys_;
141
144 std::string prefix_;
145
148 std::vector<std::string> obsoleteKeys_;
149
151 bool* bpar_;
152
154 int* ipar_;
155
157 double* dpar_;
158
160 std::string* spar_;
161
164 std::vector<std::string>* sapar_;
165
167 //---------------------------------------------------------------------------
168
169 public:
176 virtual void createKeywordList() = 0;
177
179 virtual void setDefaultEntries() = 0;
186 virtual void pack(AlpsEncoded& buf) {
187 throw CoinError("can't call pack()", "pack", " AlpsParameterSet");
188 }
189
191 virtual void unpack(AlpsEncoded& buf){
192 throw CoinError("can't call unpack()", "unpack", " AlpsParameterSet");
193 }
195
196 //---------------------------------------------------------------------------
197
198 public:
199
208 // This the one used in readFromStream()
209 void setEntry(const AlpsParameter key, const char * val) {
210 switch (key.type()){
211 case AlpsNoPar: break;
212 case AlpsBoolPar: bpar_ [key.index()] = atoi(val) ? true : false; break;
213 case AlpsIntPar: ipar_ [key.index()] = atoi(val); break;
214 case AlpsDoublePar: dpar_ [key.index()] = atof(val); break;
215 case AlpsStringPar: spar_ [key.index()] = val; break;
216 case AlpsStringArrayPar: sapar_[key.index()].push_back(val); break;
217 }
218 }
219
233 void readFromStream(std::istream& parstream);
234
236 void readFromFile(const char * paramfile);
237
239 void readFromArglist(const int argnum, const char * const * arglist);
240
244 void writeToStream(std::ostream& outstream) const;
245
247 AlpsParameterSet(int c, int i, int d, int s, int sa) :
248 keys_(),
249 prefix_("Alps"),
250 bpar_(new bool[c]),
251 ipar_(new int[i]),
252 dpar_(new double[d]),
253 spar_(new std::string[s]),
254 sapar_(new std::vector<std::string>[sa])
255 {}
256
259 keys_.clear();
260 obsoleteKeys_.clear();
261 delete[] bpar_; bpar_ = 0;
262 delete[] ipar_; ipar_ = 0;
263 delete[] dpar_; dpar_ = 0;
264 delete[] spar_; spar_ = 0;
265 delete[] sapar_; sapar_ = 0;
266 }
267};
268
269#endif
AlpsParameterT
This enumerative constant describes the possible parameter types.
@ AlpsStringArrayPar
The parameter is an array of strings.
@ AlpsDoublePar
Double parameter.
@ AlpsNoPar
The type is not yet specified.
@ AlpsStringPar
String parameter (E.g., data file name.).
@ AlpsBoolPar
Bool parameter.
@ AlpsIntPar
Integer parameter.
This data structure is to contain the packed form of an encodable knowledge.
Definition AlpsEncoded.h:25
This is the class serves as a holder for a set of parameters.
std::vector< std::pair< std::string, AlpsParameter > > keys_
The keyword, parameter pairs.
virtual void pack(AlpsEncoded &buf)
Pack the parameter set into the buffer.
std::vector< std::string > * sapar_
void readFromStream(std::istream &parstream)
Read the parameters from the stream specified in the argument.
virtual void createKeywordList()=0
Method for creating the list of keyword looked for in the parameter file.
void setEntry(const AlpsParameter key, const char *val)
First, there is the assignment operator that sets the whole parameter set at once.
int * ipar_
The integer parameters.
std::vector< std::string > obsoleteKeys_
list of obsolete keywords.
virtual ~AlpsParameterSet()
The destructor deletes all data members.
int numSa_
The "vector of string" parameters.
void writeToStream(std::ostream &outstream) const
Write keyword-value pairs to the stream specified in the argument.
AlpsParameterSet(int c, int i, int d, int s, int sa)
The constructor allocate memory for parameters.
virtual void setDefaultEntries()=0
Method for setting the default values for the parameters.
bool * bpar_
The bool parameters.
virtual void unpack(AlpsEncoded &buf)
Unpack the parameter set from the buffer.
std::string prefix_
Prefix to be used for looking up parameters.
double * dpar_
The double parameters.
void readFromFile(const char *paramfile)
Read parameters from a file.
void readFromArglist(const int argnum, const char *const *arglist)
Read parameters from the command line.
std::string * spar_
The string (actually, std::string) parameters.
This parameter indeintifies a single parameter entry.
AlpsParameterT type_
The type of the parameter (e.g., AlpsIntPar).
int index() const
Return the index of the parameter within all parameters of the same type.
AlpsParameterT type() const
Return the type of the parameter.
AlpsParameter()
The default constructor creates a phony parameter.
~AlpsParameter()
The destructor.
AlpsParameter(const AlpsParameterT t, const int i)
Constructor where members are specified.
int index_
The index of this parameter within all parameters of the same type.