summaryrefslogtreecommitdiff
path: root/casa/io
diff options
context:
space:
mode:
Diffstat (limited to 'casa/io')
-rw-r--r--casa/io/ConstraintFile.C50
-rw-r--r--casa/io/ConstraintFile.H35
-rw-r--r--casa/io/OutputFile.C50
-rw-r--r--casa/io/OutputFile.H38
-rw-r--r--casa/io/SpecificationFile.C39
-rw-r--r--casa/io/SpecificationFile.H37
-rw-r--r--casa/io/Usage.C187
-rw-r--r--casa/io/Usage.H38
8 files changed, 474 insertions, 0 deletions
diff --git a/casa/io/ConstraintFile.C b/casa/io/ConstraintFile.C
new file mode 100644
index 0000000..6ea05b2
--- /dev/null
+++ b/casa/io/ConstraintFile.C
@@ -0,0 +1,50 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "io/ConstraintFile.H"
+
+using namespace std;
+
+ConstraintFile::ConstraintFile(const string&filename) {
+ if (!filename.size()) {
+ return;
+ }
+ ifstream fileInputStream(filename.data());
+ unsigned clauseCount;
+ fileInputStream >> clauseCount;
+ clauses = Array<InputClause>(clauseCount);
+ for (unsigned i = 0; i < clauseCount; ++i) {
+ InputClause&clause = clauses[i];
+ unsigned termCount;
+ fileInputStream >> termCount;
+ while (termCount--) {
+ char sign;
+ unsigned symbol;
+ do {
+ fileInputStream >> sign;
+ } while (sign != '-' && sign != '+');
+ fileInputStream >> symbol;
+ clause.append(InputTerm(sign == '-', symbol));
+ }
+ }
+ fileInputStream.close();
+}
+
+const Array<InputClause>&ConstraintFile::getClauses() const {
+ return clauses;
+}
diff --git a/casa/io/ConstraintFile.H b/casa/io/ConstraintFile.H
new file mode 100644
index 0000000..cfdb685
--- /dev/null
+++ b/casa/io/ConstraintFile.H
@@ -0,0 +1,35 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef CONSTRAINT_FILE_H
+#define CONSTRAINT_FILE_H
+
+#include <fstream>
+#include <string>
+
+#include "Array.H"
+#include "sat/SAT.H"
+
+class ConstraintFile {
+ Array<InputClause> clauses;
+public:
+ ConstraintFile(const std::string&filename);
+ const Array<InputClause>&getClauses() const;
+};
+
+#endif
diff --git a/casa/io/OutputFile.C b/casa/io/OutputFile.C
new file mode 100644
index 0000000..43000ff
--- /dev/null
+++ b/casa/io/OutputFile.C
@@ -0,0 +1,50 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "io/OutputFile.H"
+
+using namespace std;
+
+OutputFile::OutputFile(const string&filename) :
+ filename(filename) {}
+
+void OutputFile::setCoveringArray(const CoveringArray&array) {
+ unsigned rows = array.getRows();
+ unsigned options = array.getOptions();
+ this->array = Array<Array<unsigned> >(rows);
+ for (unsigned i = rows; i--;) {
+ Array<unsigned>&row = this->array[i] = Array<unsigned>(options);
+ for (unsigned j = options; j--;) {
+ row[j] = array(i, j);
+ }
+ }
+}
+
+void OutputFile::write() const {
+ ofstream fileOutputStream(filename.data());
+ fileOutputStream << array.getSize() << '\n';
+ for (unsigned i = 0;i < array.getSize(); ++i) {
+ const Array<unsigned>&row = array[i];
+ fileOutputStream << row[0];
+ for (unsigned j = 1; j < row.getSize(); ++j) {
+ fileOutputStream << ' ' << row[j];
+ }
+ fileOutputStream << '\n';
+ }
+ fileOutputStream.close();
+}
diff --git a/casa/io/OutputFile.H b/casa/io/OutputFile.H
new file mode 100644
index 0000000..b89345b
--- /dev/null
+++ b/casa/io/OutputFile.H
@@ -0,0 +1,38 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef OUTPUT_FILE_H
+#define OUTPUT_FILE_H
+
+#include <fstream>
+#include <string>
+
+#include "Array.H"
+#include "covering/state/CoveringArray.H"
+
+class OutputFile {
+protected:
+ std::string filename;
+ Array<Array<unsigned> > array;
+public:
+ OutputFile(const std::string&filename);
+ void setCoveringArray(const CoveringArray&array);
+ void write() const;
+};
+
+#endif
diff --git a/casa/io/SpecificationFile.C b/casa/io/SpecificationFile.C
new file mode 100644
index 0000000..8fba427
--- /dev/null
+++ b/casa/io/SpecificationFile.C
@@ -0,0 +1,39 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include "io/SpecificationFile.H"
+
+using namespace std;
+
+SpecificationFile::SpecificationFile(const string&filename) {
+ ifstream fileInputStream(filename.data());
+ unsigned optionCount;
+ fileInputStream >> strength >> optionCount;
+ Array<unsigned>values(optionCount);
+ for(unsigned i = 0; i < optionCount; ++i) {
+ fileInputStream >> values[i];
+ }
+ options = Options(values);
+ fileInputStream.close();
+}
+unsigned SpecificationFile::getStrength() const {
+ return strength;
+}
+const Options&SpecificationFile::getOptions() const {
+ return options;
+}
diff --git a/casa/io/SpecificationFile.H b/casa/io/SpecificationFile.H
new file mode 100644
index 0000000..b027460
--- /dev/null
+++ b/casa/io/SpecificationFile.H
@@ -0,0 +1,37 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef SPECIFICATION_FILE_H
+#define SPECIFICATION_FILE_H
+
+#include <fstream>
+#include <string>
+
+#include "Array.H"
+#include "covering/bookkeeping/Options.H"
+
+class SpecificationFile {
+ unsigned strength;
+ Options options;
+public:
+ SpecificationFile(const std::string&filename);
+ unsigned getStrength() const;
+ const Options&getOptions() const;
+};
+
+#endif
diff --git a/casa/io/Usage.C b/casa/io/Usage.C
new file mode 100644
index 0000000..676e374
--- /dev/null
+++ b/casa/io/Usage.C
@@ -0,0 +1,187 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#include <cstdlib>
+#include <iostream>
+#include <posix/getopt.h>
+
+#include "io/Usage.H"
+
+using namespace std;
+
+const char*PROGRAM_NAME =
+ "Covering Arrays by Simulated Annealing (CASA)";
+
+const char*PROGRAM_VERSION =
+ "1.1b";
+
+const char*BUG_ADDRESS =
+ "bgarvin@cse.unl.edu";
+
+static const char*PROGRAM_DOC =
+ "Builds mixed-level covering arrays under constraints\n"
+ "\n"
+ "Copyright 2008, 2009 Brady J. Garvin\n"
+ "\n"
+ "CASA is free software: you can redistribute it and/or modify it\n"
+ "under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation, either version 3 of the License, or\n"
+ "(at your option) any later version.\n"
+ "\n"
+ "CASA is distributed in the hope that it will be useful, but\n"
+ "WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n"
+ "\n"
+ "You should have received a copy of the GNU General Public License\n"
+ "along with CASA. If not, see <http://www.gnu.org/licenses/>.\n";
+
+static const char*USAGE_DOC =
+ "[OPTIONS] [MODEL_FILE]";
+
+static const char*ARG_DOC =
+ " -o, --output [FILE] write to the given file, regardless of seed\n"
+ " -c, --constrain [FILE] incorporate the given constraint file\n"
+ "\n"
+ " -s, --seed [SEED] set the seed value for the random number generator\n"
+ "\n"
+ " -i, --iterations [COUNT] set the initial number of iterations allowed at each array size\n"
+ " -r, --retries [COUNT] set the number of retries allowed at the same array size\n"
+ " -p, --partition [RATIO] set the weight of the upper bound in the binary search parition\n"
+ "\n"
+ " -t, --temperature [TEMP] set the initial temperature\n"
+ " -d, --multiplier [RATIO] set the temperature multiplier applied each iteration\n"
+ "\n"
+ " -l, --lower-bound [SIZE] let the covering array be no smaller than the given size\n"
+ " -u, --upper-bound [SIZE] let the covering array be no larger than the given size\n"
+ " -n, --known-size [SIZE] lock the covering array at the given size\n"
+ "\n"
+ " -v, --version show the current version and exit\n"
+ " -h, --help show this help and exit\n";
+
+static const char*shortOptions =
+ "o:c:s:i:r:p:t:d:l:u:n:vh";
+
+static struct option longOptions[] = {
+ {"output", required_argument, NULL, 'o'},
+ {"constrain", required_argument, NULL, 'c'},
+ {"seed", required_argument, NULL, 's'},
+ {"iterations", required_argument, NULL, 'i'},
+ {"retries", required_argument, NULL, 'r'},
+ {"partition", required_argument, NULL, 'p'},
+ {"temperature", required_argument, NULL, 't'},
+ {"decrement", required_argument, NULL, 'd'},
+ {"lower-bound", required_argument, NULL, 'l'},
+ {"upper-bound", required_argument, NULL, 'u'},
+ {"known-size", required_argument, NULL, 'n'},
+ {"version", no_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0 }};
+
+bool verbose = true;
+const char* modelFile = NULL;
+const char* constraintFile = NULL;
+const char* outputFile = NULL;
+bool seeded = false;
+int seed;
+double startingTemperature = 0.5L;
+double decrement = 0.99999L;
+unsigned iterations = 256;
+unsigned retries = 2;
+unsigned lowerBound = 0;
+unsigned upperBound = 0;
+double searchPartition = 2.L/3.L;
+
+static void version() {
+ cerr << PROGRAM_NAME << ' ' << PROGRAM_VERSION << '\n';
+ exit(0);
+}
+
+static const char*name;
+static void usage(int error) {
+ cerr << PROGRAM_NAME << ' ' << PROGRAM_VERSION << " - " << PROGRAM_DOC <<
+ "\n\nUsage: " << name << ' ' << USAGE_DOC << "\n\n" << ARG_DOC << "\n\n" <<
+ "Send bug reports to <" << BUG_ADDRESS << ">.\n";
+ exit(error);
+}
+
+void parseOptions(int argc, char*const*argv) {
+ name = *argv;
+ bool seen[256];
+ (void)seen; // Workaround for a bug in some versions of GCC
+ for (unsigned i = 256; i-- > 0;) {
+ seen[i] = false;
+ }
+ for (;;) {
+ int index = 0;
+ int found = getopt_long(argc, argv, shortOptions, longOptions, &index);
+ switch (found) {
+ case 'o': // output
+ outputFile = optarg;
+ break;
+ case 'c': // constrain
+ constraintFile = optarg;
+ break;
+ case 's': // seed
+ seeded = true;
+ seed = atoi(optarg);
+ break;
+ case 'i': // iterations
+ iterations = atoi(optarg);
+ break;
+ case 'r': // retries
+ retries = atoi(optarg);
+ break;
+ case 'p': // partition
+ searchPartition = atof(optarg);
+ break;
+ case 't': // temperature
+ startingTemperature = atof(optarg);
+ break;
+ case 'd': // decrement
+ decrement = atof(optarg);
+ break;
+ case 'l': // lower-bound
+ lowerBound = atoi(optarg);
+ break;
+ case 'u': // upper-bound
+ upperBound = atoi(optarg);
+ break;
+ case 'n': // known-size
+ lowerBound = upperBound = atoi(optarg);
+ break;
+ case 'v': // version
+ version();
+ break;
+ case 'h': // help
+ usage(0);
+ break;
+ default: // done with options
+ if (argc - optind < 1) {
+ usage(1);
+ }
+ if (argc - optind > 1) {
+ cerr << "Warning: ignoring extraneous arguments after model file ``" <<
+ argv[optind] << "''." << endl;
+ }
+ modelFile = argv[optind];
+ return;
+ }
+ seen[(unsigned)found] = true;
+ }
+}
diff --git a/casa/io/Usage.H b/casa/io/Usage.H
new file mode 100644
index 0000000..a817be3
--- /dev/null
+++ b/casa/io/Usage.H
@@ -0,0 +1,38 @@
+// Copyright 2008, 2009 Brady J. Garvin
+
+// This file is part of Covering Arrays by Simulated Annealing (CASA).
+
+// CASA is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// CASA is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with CASA. If not, see <http://www.gnu.org/licenses/>.
+
+
+#ifndef USAGE_H
+#define USAGE_H
+
+extern bool verbose;
+extern const char* modelFile;
+extern const char* constraintFile;
+extern const char* outputFile;
+extern bool seeded;
+extern int seed;
+extern double startingTemperature;
+extern double decrement;
+extern unsigned iterations;
+extern unsigned retries;
+extern unsigned lowerBound;
+extern unsigned upperBound;
+extern double searchPartition;
+
+void parseOptions(int argc, char*const*argv);
+
+#endif