OKlibrary  0.2.1.6
ComputeScores.cpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 17.6.2005 (Swansea)
00002 /* Copyright 2005 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00027 #include <string>
00028 #include <iterator>
00029 #include <algorithm>
00030 #include <iostream>
00031 #include <cstring>
00032 #include <cassert>
00033 
00034 #include <OKlib/Experimentation/Competition/ParsingSingleResult.hpp>
00035 #include <OKlib/Experimentation/Competition/Scoring.hpp>
00036 
00037 namespace {
00038 
00039   template <bool with_extension, bool without_exception>
00040   struct Scoring_from_file {
00041     typedef OKlib::SATCompetition::Scoring_from_file<OKlib::SATCompetition::ParserThreeElements, OKlib::SATCompetition::Result, OKlib::SATCompetition::ConstantSeriesPurse> type;
00042   };
00043   template <>
00044   struct Scoring_from_file<false, false> {
00045     typedef OKlib::SATCompetition::Scoring_from_file<> type;
00046   };
00047   template <>
00048   struct Scoring_from_file<true, false> {
00049     typedef OKlib::SATCompetition::Scoring_from_file<OKlib::SATCompetition::ParserThreeElements> type;
00050   };
00051   template <>
00052   struct Scoring_from_file<false, true> {
00053     typedef OKlib::SATCompetition::Scoring_from_file<OKlib::SATCompetition::ParserEmpty, OKlib::SATCompetition::Result, OKlib::SATCompetition::ConstantSeriesPurse> type;
00054   };
00055   
00056   
00057   template <typename InputIterator>
00058   void output_sequence(const InputIterator& begin, const InputIterator& end) {
00059     typedef typename InputIterator::value_type value_type;
00060     std::copy(begin, end, std::ostream_iterator<value_type>(std::cout, "\n"));
00061   }
00062   
00063   template <bool with_extension, bool without_exception>
00064   struct Evaluation {
00065     const std::string& filename;
00066     const char* const specifier;
00067     const char* const policy;
00068     typedef typename Scoring_from_file<with_extension, without_exception>::type scoring_from_file;
00069     typedef typename scoring_from_file::number_type number_type;
00070     Evaluation(const std::string& filename, const char* const specifier, const char* const policy) : filename(filename), specifier(specifier), policy(policy) {
00071       if (with_extension)
00072         assert(specifier);
00073       if (without_exception)
00074         assert(policy);
00075     }
00076     void operator() (const number_type standard_problem_purse = 1000, const number_type standard_speed_factor = 1, const number_type standard_series_factor = 3) const {
00077       
00078       const scoring_from_file scores(filename, standard_problem_purse, standard_speed_factor, standard_series_factor);
00079       std::cout << "\nFile name = " << filename;
00080       if (specifier)
00081         std::cout << "\nsyntax specifier = " << specifier << "\n";
00082       if (policy)
00083         std::cout << "series policy = " << policy << "\n";
00084       std::cout << "\n";
00085       std::cout << "Standard problem purse = " << standard_problem_purse << "\n";
00086       std::cout << "Standard speed factor = " << standard_speed_factor << "\n";
00087       std::cout << "Standard series factor = " << standard_series_factor << "\n";
00088       std::cout << "\nALL results: ---------------------------------------------------------------------------------------------------------------------\n\n";
00089       output_sequence(scores.scores_all.begin(), scores.scores_all.end());
00090       std::cout << "\nSAT results: ---------------------------------------------------------------------------------------------------------------------\n\n";
00091       output_sequence(scores.scores_sat.begin(), scores.scores_sat.end());
00092       std::cout << "\nUNSAT results: ---------------------------------------------------------------------------------------------------------------------\n\n";
00093       output_sequence(scores.scores_unsat.begin(), scores.scores_unsat.end());
00094     }
00095   };
00096 }
00097 
00098 int main(const int argc, const char* const argv[]) {
00099 
00100   if (argc <= 1 or argc >= 5) {
00101     std::cerr << "One, two or three arguments required (the name of the file, optionally a syntax specifier \"syntax=...\", optionally a series policy specifier \"series=...\").\n";
00102     return EXIT_FAILURE;
00103   }
00104   bool specifier = false;
00105   const char* specifier_text = (const char*)(0);
00106   bool policy = false;
00107   const char* policy_text = (const char*)(0);
00108   const std::string& file_name(argv[1]);
00109   for (int i = 2; i < argc; ++i) {
00110     const int prefix_length = 6 + 1;
00111     assert(prefix_length >= 0);
00112     if (std::strlen(argv[i]) <= (unsigned int)prefix_length) {
00113       std::cerr << "Parameter \"" << argv[i] << "\" is not \"syntax=+\" or \"series=+\".\n";
00114       return EXIT_FAILURE;
00115     }
00116     if (std::strncmp(argv[i], "syntax=", prefix_length) == 0) {
00117       specifier = true;
00118       specifier_text = argv[i] + prefix_length;
00119     }
00120     else if (std::strncmp(argv[i], "series=", prefix_length) == 0) {
00121       policy = true;
00122       policy_text = argv[i] + prefix_length;
00123     }
00124     else {
00125       std::cerr << "Parameter \"" << argv[i] << "\" does not start with \"syntax=\" or \"series=\".\n";
00126       return EXIT_FAILURE;
00127     }
00128   }
00129 
00130   if (specifier) {
00131     if (policy)
00132       Evaluation<true, true>(file_name, specifier_text, policy_text)();
00133     else
00134       Evaluation<true, false>(file_name, specifier_text, policy_text)();
00135   }
00136   else {
00137     if (policy)
00138       Evaluation<false, true>(file_name, specifier_text, policy_text)();
00139     else
00140       Evaluation<false, false>(file_name, specifier_text, policy_text)();
00141   }
00142 }