OKlibrary  0.2.1.6
LexicographicalEvaluationPolicies.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 28.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 
00016 #ifndef LEXICOGRAPHICALEVALUATIONPOLICIES_j57llkkK
00017 #define LEXICOGRAPHICALEVALUATIONPOLICIES_j57llkkK
00018 
00019 #include <functional>
00020 
00021 #include <OKlib/General/IteratorHandling.hpp>
00022 
00023 #include <OKlib/Experimentation/Competition/SingleResult.hpp>
00024 #include <OKlib/Experimentation/Competition/ResultProcessing.hpp>
00025 
00026 namespace OKlib {
00027   namespace SATCompetition {
00028 
00029     // Policies for LexicographicalEvaluation ###########################
00030 
00040     template <class ResultType>
00041     struct LexicographicalSeriesPolicy;
00042 
00043     template <>
00044     struct LexicographicalSeriesPolicy<Result> {
00045       typedef SuperSeries super_series_type;
00046       typedef Series series_type;
00047 
00048       template <class SolvedBenchmark>
00049       static super_series_type super_series(const SolvedBenchmark& sb) {
00050         const ResultBasis* const rb(sb.node -> rb);
00051         return rb -> super_series();
00052       }
00053       template <class SolvedBenchmark>
00054       static series_type series(const SolvedBenchmark& sb) {
00055         const ResultBasis* const rb(sb.node -> rb);
00056         return rb -> series();
00057       }
00058     };
00059 
00060     template <>
00061     struct LexicographicalSeriesPolicy<ResultRandomSat> {
00062       typedef RandomKSat super_series_type;
00063       typedef RandomKSat_n series_type;
00064 
00065       template <class SolvedBenchmark>
00066       static super_series_type super_series(const SolvedBenchmark& sb) {
00067         const ResultBasis* const rb(sb.node -> rb);
00068         return *static_cast<const super_series_type*>(rb -> super_series().self());
00069       }
00070       template <class SolvedBenchmark>
00071       static series_type series(const SolvedBenchmark& sb) {
00072         const ResultBasis* const rb(sb.node -> rb);
00073         return *static_cast<const series_type*>(rb -> series().self());
00074       }
00075     };
00076 
00077     // Policies for LexicographicalEvaluationRandom #####################
00078 
00086     template <class solver_evaluation_pair_type>
00087     struct LexicographicalSortingPolicy_induced_lexicographical {
00088       struct comparison_type : std::binary_function<const solver_evaluation_pair_type&, const solver_evaluation_pair_type&, bool> {
00089         bool operator()(const solver_evaluation_pair_type& lhs, const solver_evaluation_pair_type& rhs) const {
00090           return lhs.second < rhs.second;
00091         }
00092       };
00093     };
00094 
00102     template <class solver_evaluation_pair_type>
00103     struct LexicographicalSortingPolicy_unfolded_lexicographical {
00104       struct comparison_type : std::binary_function<const solver_evaluation_pair_type&, const solver_evaluation_pair_type&, bool> {
00105         bool operator()(const solver_evaluation_pair_type& lhs, const solver_evaluation_pair_type& rhs) const {
00106           assert(lhs.second.size() == rhs.second.size());
00107           typedef typename solver_evaluation_pair_type::second_type second_type;
00108           typedef typename second_type::const_iterator iterator;
00109           typedef typename IteratorHandling::IteratorFirst<iterator>::type iterator_first;
00110           typedef typename IteratorHandling::IteratorSecond<iterator>::type iterator_second;
00111           const second_type& lhs_s(lhs.second), rhs_s(rhs.second);
00112           const iterator_first f_lhs_b(lhs_s.begin()), f_lhs_e(lhs_s.end()), f_rhs_b(rhs_s.begin()), f_rhs_e(rhs_s.end());
00113           const iterator_second s_lhs_b(lhs_s.begin()), s_lhs_e(lhs_s.end()), s_rhs_b(rhs_s.begin()), s_rhs_e(rhs_s.end());
00114           typedef typename iterator_first::value_type size_type;
00115           return std::lexicographical_compare(f_lhs_b, f_lhs_e, f_rhs_b, f_rhs_e, std::greater<size_type>()) or (std::equal(f_lhs_b, f_lhs_e, f_rhs_b) and std::lexicographical_compare(s_lhs_b, s_lhs_e, s_rhs_b, s_rhs_e));
00116         }
00117       };
00118     };
00119 
00120   }
00121 
00122 }
00123 
00124 #endif