20 PTIImpl(
const char*
const fileName, istream &defaultInputStream, ostream &outputStream):
21 outputStream(outputStream),
22 instances(loadParameterInstances(fileName, defaultInputStream)) {
25 static const char*
getStringArgument(
const char*
const option,
const int argc,
const char*
const argv[]) {
26 assert(option != NULL);
27 for (
int i = 0; i < argc - 1; i++) {
28 if (0 == strcmp(option, argv[i]))
34 static int getIntegerArgument(
const char*
const option,
const int argc,
const char*
const argv[]) {
35 assert(option != NULL);
37 throw invalid_argument(
string(
"PTI::PTIImpl: argc is negative."));
39 throw invalid_argument(
string(
"PTI::PTIImpl: argv is NULL."));
40 for (
int i = 0; i < argc - 1; i++) {
41 if (0 == strcmp(option, argv[i]))
42 return atoi(argv[i+1]);
51 istream *
const input(fileName ?
new ifstream(fileName, ifstream::in) : &defaultInputStream);
54 if (!dynamic_cast<ifstream*>(input)->is_open())
55 throw invalid_argument(
string(
"PTI::PTIImpl: Failed to open file") +
string(fileName) +
string(
"."));
61 dynamic_cast<ifstream*
>(input)->close();
68 return instances.get() != NULL;
72 PTI::PTI(
const int argc,
const char*
const argv[], ostream &outputStream):
73 impl(new
PTIImpl(
PTIImpl::getStringArgument(
"-f", argc, argv), cin, outputStream)) {
78 PTI::PTI(
const int argc,
const char*
const argv[], ostream &outputStream, istream &defaultInputStream):
79 impl(new
PTIImpl(
PTIImpl::getStringArgument(
"-f", argc, argv), defaultInputStream, outputStream)) {
88 return string(
"\nThis program should be called with 3 arguments:\n\n") +
89 string(
"./a.out [filename]\n\n") +
90 string(
"<filename> is the name of the csv parameter file to be read.\n\n") +
91 string(
"Format of csv file: Each row represents a single \nindividual, while \ 92 each csv represents a min or max value for a parameter. \nEach csv is a float.\ 93 If there are 4 individuals with 4 parameters, \nthen there will be four rows, \ 94 each with 8 csv (2 for each parameter).\n\n");
98 experiment.
run(*(impl.get()->instances.get()), impl.get()->outputStream);
103 return impl.get()->repOK();
PTI(const int argc, const char *const argv[], ostream &outputStream)
PTIImpl(const char *const fileName, istream &defaultInputStream, ostream &outputStream)
static const char * getStringArgument(const char *const option, const int argc, const char *const argv[])
static int getIntegerArgument(const char *const option, const int argc, const char *const argv[])
static ParameterInstances * loadParameterInstances(const char *const fileName, istream &defaultInputStream)
void runExperiment(const Experiment &experiment) const
const unique_ptr< ParameterInstances > instances
virtual void run(const ParameterInstances ¶meters, std::ostream &outputStream) const =0