4 /// A class for managing computational experiments
6 /// (c) 2005 P. J. Cowans
8 // TODO - implement a way of sharing data between related runs
17 cExperiment(const std::string
& oPrefix
) {
19 std::string
oParameterLogFilename(oPrefix
+ ".params");
20 std::string
oDataLogFilename(oPrefix
+ ".data");
22 oParameterLog
.open(oParameterLogFilename
.c_str());
23 oDataLog
.open(oDataLogFilename
.c_str());
28 oParameterLog
.close();
34 // TODO - can we do anything sensible with templates?
36 inline void SetParameterInt(const std::string
& sName
, int iValue
) {
37 oParameterMapInt
[sName
] = iValue
;
40 inline void SetParameterString(const std::string
& sName
, const std::string
& sValue
) {
41 oParameterMapString
[sName
] = sValue
;
46 inline int GetParameterInt(const std::string
& sName
) const {
47 // TODO - handle case when parameter is not set (throw an exception)
49 std::map
< std::string
, int >::const_iterator
it(oParameterMapInt
.find(sName
));
51 if(it
== oParameterMapInt
.end()) {
52 std::cerr
<< "Error - asked for non-initialised parameter " << sName
<< std::endl
;
56 std::cerr
<< sName
<< " " << it
->second
<< std::endl
;
62 inline std::string
GetParameterString(const std::string
& sName
)const {
63 // TODO - handle case when parameter is not set (throw an exception)
65 std::map
< std::string
, std::string
>::const_iterator
it(oParameterMapString
.find(sName
));
67 if(it
== oParameterMapString
.end()) {
68 std::cerr
<< "Error - asked for non-initialised parameter " << sName
<< std::endl
;
72 std::cerr
<< sName
<< " " << it
->second
<< std::endl
;
78 /// Dump a list of the parameters
80 void DumpParameters() {
81 for(std::map
< std::string
, int >::iterator
it(oParameterMapInt
.begin()); it
!= oParameterMapInt
.end(); ++it
)
82 oParameterLog
<< it
->first
<< ": " << it
->second
<< std::endl
;
84 for(std::map
< std::string
, std::string
>::iterator
it(oParameterMapString
.begin()); it
!= oParameterMapString
.end(); ++it
)
85 oParameterLog
<< it
->first
<< ": " << it
->second
<< std::endl
;
88 /// Records a string in the log file
90 void RecordData(const std::string
& oData
) {
94 /// Actually do the experiment
101 /// This method needs to be implemented by the child class - the actual work of doing the experiment happens here.
103 virtual double Execute() = 0;
106 std::map
< std::string
, int >oParameterMapInt
;
107 std::map
< std::string
, std::string
> oParameterMapString
;
108 std::ofstream oParameterLog
;
109 std::ofstream oDataLog
;