1
Fork 0
mirror of https://github.com/Jaxan/hybrid-ads.git synced 2025-04-27 15:07:45 +02:00

Adds test suite size thingy

This commit is contained in:
Joshua Moerman 2015-04-20 10:09:07 +02:00
parent 69942cd683
commit 114ad8c8b7
3 changed files with 102 additions and 13 deletions

View file

@ -1,9 +1,17 @@
#include "trie.hpp"
std::vector<std::vector<size_t>> flatten(const trie& t) {
std::vector<std::vector<size_t>> flatten(const trie & t) {
std::vector<std::vector<size_t>> ret;
t.for_each([&ret](auto&& w) { ret.push_back(w); });
t.for_each([&ret](auto && w) { ret.push_back(w); });
return ret;
}
std::pair<size_t, size_t> total_size(const trie & t) {
size_t count = 0;
size_t total_count = 0;
t.for_each([&count, &total_count](auto && w) {
++count;
total_count += w.size();
});
return {count, total_count};
}

View file

@ -37,7 +37,6 @@ struct trie {
b = trie();
b->insert(begin, end);
count++;
return true;
}
@ -53,32 +52,35 @@ struct trie {
/// \brief Empties the complete set
void clear() {
count = 0;
branches.clear();
}
private:
template <typename Fun> void for_each_impl(Fun && function, std::vector<size_t> & word) const {
if (count == 0) {
const auto & cword = word;
function(cword); // we don't want function to modify word
return;
}
size_t count = 0;
for (size_t i = 0; i < branches.size(); ++i) {
auto const & b = branches[i];
if (b) {
++count;
word.push_back(i);
b->for_each_impl(function, word);
word.resize(word.size() - 1);
}
}
if (count == 0) {
const auto & cword = word;
function(cword); // we don't want function to modify word
return;
}
}
size_t count = 0;
std::vector<boost::optional<trie>> branches;
};
/// \brief Flattens a trie \p t
/// \returns an array of words (without the prefixes)
std::vector<std::vector<size_t>> flatten(trie const & t);
/// \brief Returns size and total sum of symbols
std::pair<size_t, size_t> total_size(trie const & t);

79
src/methods.cpp Normal file
View file

@ -0,0 +1,79 @@
#include <adaptive_distinguishing_sequence.hpp>
#include <read_mealy_from_dot.hpp>
#include <seperating_family.hpp>
#include <seperating_matrix.hpp>
#include <trie.hpp>
#include <splitting_tree.hpp>
#include <transfer_sequences.hpp>
#include <future>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char * argv[]) {
if (argc != 2) return 1;
const string filename = argv[1];
const size_t k_max = 1;
const auto machine = read_mealy_from_dot(filename).first;
auto sequence_fut = async([&] {
const auto tree = create_splitting_tree(machine, randomized_lee_yannakakis_style);
return create_adaptive_distinguishing_sequence(tree);
});
auto pairs_fut = async([&] {
const auto tree = create_splitting_tree(machine, randomized_hopcroft_style);
return create_all_pair_seperating_sequences(tree.root);
});
auto prefixes_fut = async([&] {
return create_transfer_sequences(machine, 0);
});
auto middles_fut = async([&] {
vector<word> all_sequences(1);
for (size_t k = 0; k < k_max; ++k) {
const auto new_sequences = all_seqs(0, machine.input_size, all_sequences);
all_sequences.reserve(all_sequences.size() + new_sequences.size());
copy(begin(new_sequences), end(new_sequences), back_inserter(all_sequences));
}
return all_sequences;
});
clog << "getting sequence and pairs" << endl;
auto suffixes_fut = async([&] {
return create_seperating_family(sequence_fut.get(), pairs_fut.get());
});
clog << "getting prefixes, middles and suffixes" << endl;
const auto prefixes = prefixes_fut.get();
const auto middles = middles_fut.get();
const auto suffixes = suffixes_fut.get();
trie test_suite;
clog << "start testing" << endl;
const state start = 0;
const word empty = {};
for (auto && p : prefixes) {
const state s1 = apply(machine, start, begin(p), end(p)).to;
const word w1 = concat(empty, p);
for (auto && m : middles) {
const state s2 = apply(machine, s1, begin(m), end(m)).to;
const word w2 = concat(w1, m);
const auto & suffixes_for_state = (m.size() == k_max) ? suffixes[s2].local_suffixes
: suffixes[s2].global_suffixes;
for (auto && s : suffixes_for_state) {
word test = concat(w2, s);
test_suite.insert(test);
}
}
}
const auto p = total_size(test_suite);
cout << p.first << endl;
cout << p.second << endl;
}