OKlibrary  0.2.1.6
LexicographicalEvaluation_Tests.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 25.10.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 
00015 #ifndef LEXICOGRAPHICALEVALUATIONTESTS_bzklapao0
00016 #define LEXICOGRAPHICALEVALUATIONTESTS_bzklapao0
00017 
00018 #include <string>
00019 #include <cassert>
00020 
00021 #include <boost/lexical_cast.hpp>
00022 
00023 #include <OKlib/General/IteratorHandling.hpp>
00024 
00025 #include <OKlib/Structures/Sets/SetAlgorithms/BasicMapOperations.hpp>
00026 
00027 #include <OKlib/TestSystem/TestBaseClass.hpp>
00028 #include <OKlib/TestSystem/TestExceptions.hpp>
00029 
00030 #include <OKlib/Structures/Sets/SetAlgorithms/SequenceOperations.hpp>
00031 #include <OKlib/General/IteratorHandling.hpp>
00032 
00033 #include <OKlib/Experimentation/Competition/SingleResult.hpp>
00034 #include <OKlib/Experimentation/Competition/ResultProcessing.hpp>
00035 #include <OKlib/Experimentation/Competition/ParsingSingleResult.hpp>
00036 #include <OKlib/Experimentation/Competition/AnalysisTools.hpp>
00037 #include <OKlib/Experimentation/Competition/ParsingResultSequences_Tests.hpp>
00038 
00039 #include <OKlib/Experimentation/Competition/LexicographicalEvaluationPolicies.hpp>
00040 
00041 namespace OKlib {
00042   namespace SATCompetition {
00043 
00051     template < template <class IndexedDatabase, class SeriesPolicy = LexicographicalSeriesPolicy<Result>, typename NumberType = double> class LexicographicalEvaluation >
00052     class Test_RepresentationSolverSeries : public ::OKlib::TestSystem::TestBase {
00053     public :
00054       typedef Test_RepresentationSolverSeries test_type;
00055       Test_RepresentationSolverSeries() {
00056         insert(this);
00057       }
00058     private :
00059 
00060       void perform_test_trivial() {
00061         typedef Result result_type;
00062         typedef Result_database_from_file<ParserResult, result_type> result_database;
00063         typedef typename result_database::database_type database;
00064         typedef ElementaryAnalysis<database> indexed_database;
00065         typedef LexicographicalEvaluation<indexed_database, LexicographicalSeriesPolicy<result_type> > lexicographical_evaluation_type;
00066         typedef typename lexicographical_evaluation_type::size_type size_type;
00067         typedef typename lexicographical_evaluation_type::number_type number_type;
00068         typedef typename lexicographical_evaluation_type::numerics_solver_on_series_type numerics_solver_on_series_type;
00069 
00070         // Actually, like below, we should have a function template test_result, which
00071         // allows for testing of the two main cases (it should not depend on the
00072         // result type, but we can test it).
00073 
00074         // We have a model of FullyConstructibleLinearOrder.
00075 
00076         // Using the systematic sporadic test for the representative cases
00077         // [(0,0), (0,0.5), (0, 1)], [(1,0), (1,0)], [(1,0.5), (1,0.5)], [(1,1), (1,1)], [(2,0)], [(2,0.5)], [(2,1)]
00078       }
00079 
00080     };
00081 
00082 
00083 
00084     // ##################################################
00085 
00092     template < template <class IndexedDatabase, class SeriesPolicy = LexicographicalSeriesPolicy<Result>, typename NumberType = double> class LexicographicalEvaluation >
00093     class Test_LexicographicalEvaluation : public ::OKlib::TestSystem::TestBase {
00094     public :
00095       typedef Test_LexicographicalEvaluation test_type;
00096       Test_LexicographicalEvaluation() {
00097         insert(this);
00098       }
00099     private :
00100 
00101       void perform_test_trivial() {
00102 
00103         test_result<Result>(filename_large_industrial, line_count_large_industrial);
00104         test_result<ResultRandomSat>(filename_large_random, line_count_large_random);
00105 
00106       }
00107 
00108       template <class result_type>
00109       void test_result(const std::string& filename, const unsigned int line_count) {
00110 
00111         typedef Result_database_from_file<ParserResult, result_type> result_database;
00112         typedef typename result_database::database_type database;
00113         typedef ElementaryAnalysis<database> indexed_database;
00114         typedef LexicographicalEvaluation<indexed_database, LexicographicalSeriesPolicy<result_type> > lexicographical_evaluation_type;
00115         typedef typename lexicographical_evaluation_type::size_type size_type;
00116         typedef typename lexicographical_evaluation_type::number_type number_type;
00117         typedef typename lexicographical_evaluation_type::map_solver_evaluation_type map_solver_evaluation_type;
00118         typedef typename lexicographical_evaluation_type::numerics_solver_on_series_type numerics_solver_on_series_type;
00119 
00120         result_database rdb(filename);
00121         assert(rdb.result_sequence.size() == line_count);
00122         indexed_database idb(rdb.db);
00123         lexicographical_evaluation_type lexicographical_evaluation(idb);
00124 
00125         typedef typename indexed_database::map_solver_benchmarks map_solver_benchmarks;
00126         typedef typename IteratorHandling::IteratorFirst<typename map_solver_benchmarks::const_iterator>::type iterator;
00127         const map_solver_benchmarks& map_benchmarks(idb.solved_benchmarks());
00128         const iterator end(map_benchmarks.end());
00129         for (iterator i(map_benchmarks.begin()); i != end; ++i) { // loop over all solvers
00130           const Solver& solver(*i);
00131           
00132           const map_solver_evaluation_type& map(lexicographical_evaluation.evaluation(solver));
00133           typedef typename map_solver_evaluation_type::const_iterator iterator;
00134           typedef typename IteratorHandling::IteratorSecond<iterator>::type iterator_second;
00135           OKLIB_TEST_EQUAL(OKlib::SetAlgorithms::sum_sizes(iterator_second(map.begin()), iterator_second(map.end())), OKlib::SetAlgorithms::map_value(idb.solved_series(), solver).size());
00136           size_type sum = 0;
00137           const iterator& end(map.end());
00138           for (iterator j(map.begin()); j != end; ++j) {
00139             typedef typename lexicographical_evaluation_type::map_series_numerics_type map_series_numerics_type;
00140             const map_series_numerics_type& map(j -> second);
00141 
00142             typedef typename map_series_numerics_type::const_iterator iterator;
00143             const iterator& end(map.end());
00144             for (iterator k(map.begin()); k != end; ++k) {
00145               const numerics_solver_on_series_type& n(k -> second);
00146 
00147               if (n.first <= 0)
00148                 OKLIB_THROW("n.first <= 0, namely n.first = " + boost::lexical_cast<std::string>(n.first));
00149               sum += n.first;
00150               if (n.first != 0 and n.second < 0)
00151                 OKLIB_THROW("n.first = " +  boost::lexical_cast<std::string>(n.first) + ", and n.second < 0, namely n.second = " + boost::lexical_cast<std::string>(n.second));
00152             }
00153           }
00154           if (sum != OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size())
00155             OKLIB_THROW("sum != OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size(), namely sum = " +  boost::lexical_cast<std::string>(sum) + ", while map_value(map_benchmarks, solver).size() = " + boost::lexical_cast<std::string>(OKlib::SetAlgorithms::map_value(map_benchmarks, solver).size()) + "\nContext: solver = " + boost::lexical_cast<std::string>(solver));
00156         }
00157                 
00158       }
00159 
00160     };
00161 
00162     // ##################################################
00163 
00172     template < template <class IndexedDatabase, template <class solver_evaluation_pair_type> class SortingPolicy = LexicographicalSortingPolicy_unfolded_lexicographical, typename NumberType = double> class LexicographicalEvaluationRandom >
00173     class Test_LexicographicalEvaluationRandom : public ::OKlib::TestSystem::TestBase {
00174     public :
00175       typedef Test_LexicographicalEvaluationRandom test_type;
00176       Test_LexicographicalEvaluationRandom() {
00177         insert(this);
00178       }
00179     private :
00180       
00181       void perform_test_trivial() {
00182         test_result(filename_large_random, line_count_large_random);
00183       }
00184 
00185       void test_result(const std::string& filename, const unsigned int line_count) {
00186 
00187         typedef ResultRandomSat result_type;
00188 
00189         typedef Result_database_from_file<ParserResult, result_type> result_database;
00190         typedef typename result_database::database_type database;
00191         typedef ElementaryAnalysis<database> indexed_database;
00192         typedef LexicographicalEvaluationRandom<indexed_database> lexicographical_evaluation_random_unfolded_type;
00193         typedef typename lexicographical_evaluation_random_unfolded_type::size_type size_type;
00194         typedef typename lexicographical_evaluation_random_unfolded_type::number_type number_type;
00195         typedef typename lexicographical_evaluation_random_unfolded_type::numerics_solver_on_series_type numerics_solver_on_series_type;
00196 
00197         result_database rdb(filename);
00198         assert(rdb.result_sequence.size() == line_count);
00199         indexed_database idb(rdb.db);
00200         lexicographical_evaluation_random_unfolded_type lexicographical_evaluation(idb);
00201 
00202         // ###############################################                
00203       }
00204 
00205     };
00206 
00207   }
00208 
00209 }
00210 
00211 #endif