Commit 3481e128 authored by Gijs van Cuyck's avatar Gijs van Cuyck

finalized create splitting tree algorithm.

results still very buggy. further testing needed before use.
parent 53a4dff4
......@@ -4,6 +4,6 @@ file(GLOB_RECURSE headers "*.hpp")
set(libs)
add_library(common ${headers} ${sources} vector_printing.hpp readable_splitting_tree.hpp readable_splitting_tree.cpp)
add_library(common ${headers} ${sources})
target_link_libraries(common ${libs})
target_include_directories(common PUBLIC ".")
......@@ -164,9 +164,10 @@ std::vector<string> create_reverse_map(const std::unordered_map<string, input> &
return create_reverse_map_impl(indices);
}
std::vector<std::vector<state>> create_reverse_map(const std::unordered_map<state, size_t> & indices,size_t size){
std::vector<vector<state>> ret(size);
for(pair<state,size_t> kv_pair: indices)
std::vector<std::vector<std::string>> create_reverse_map(const std::unordered_map<std::string, size_t> & indices,size_t size)
{
std::vector<std::vector<std::string>> ret(size);
for(pair<std::string,size_t> kv_pair: indices)
{
ret[kv_pair.second].push_back( kv_pair.first);
}
......
......@@ -50,7 +50,7 @@ struct reverse_translation{
std::vector<std::string> create_reverse_map(const std::unordered_map<std::string, input> & indices);
std::vector<std::string> create_reverse_map(const std::unordered_map<std::string, output> & indices);
std::vector<std::vector<state>> create_reverse_map(const std::unordered_map<state, size_t> & indices,size_t size);
std::vector<std::vector<std::string>> create_reverse_map(const std::unordered_map<std::string, size_t> & indices,size_t size);
//todo: check of dit nog gebruikt wordt
/*
......
......@@ -6,8 +6,8 @@
#include "read_mealy.hpp"
#include <algorithm>
//todo: check if this is ever used.
/*
const std::vector<readable_splitting_tree> & readable_splitting_tree::get_children(state s) const {
if (children.size() < 1)
throw std::runtime_error("get_children called when there were no children");
......@@ -19,13 +19,13 @@ const std::vector<readable_splitting_tree> & readable_splitting_tree::get_childr
const std::vector<std::string> &readable_splitting_tree::get_seperator(state s) const {
if (children.size() < 1)
throw std::runtime_error("get_seperator called when there were no seperators");
throw std::runtime_error("get_separator called when there were no seperators");
else if (valid_map.size() < 1 || valid_map.count(s) < 1)
return separators[0];
else
return separators[valid_map.at(s)];
}
*/
readable_splitting_tree translate_splitting_tree(splitting_tree & tree, std::vector<std::string> & inputs, std::vector<std::string> & states) {
......@@ -37,6 +37,10 @@ readable_splitting_tree translate_splitting_tree(splitting_tree & tree, std::vec
transform(tree.separators[i].begin(),tree.separators[i].end(),new_seperator.begin(),[&inputs](input i){return inputs[i];});
translated_tree.separators.push_back(new_seperator);
}
for(std::pair<state,size_t> kv: tree.valid_map)
{
translated_tree.valid_map[states[kv.first]] = kv.second;
}
for (std::vector<splitting_tree> children : tree.children) {
std::vector<readable_splitting_tree> new_children(children.size());
transform(children.begin(), children.end(), new_children.begin(),
......@@ -50,7 +54,7 @@ readable_splitting_tree translate_splitting_tree(splitting_tree & tree, std::vec
void rst_to_stream(readable_splitting_tree & tree, std::ostream & output, int ident){
std::string indentations(ident,'\t');
std::vector<std::vector<state>> reverse_valid_map;
std::vector<std::vector<std::string>> reverse_valid_map;
if(tree.children.size()>1)
reverse_valid_map = create_reverse_map(tree.valid_map,tree.children.size());
......@@ -59,7 +63,7 @@ void rst_to_stream(readable_splitting_tree & tree, std::ostream & output, int id
for(int i =0; i<tree.children.size(); i++)
{
output <<indentations << "seperator target: ";
if(reverse_valid_map.size()<=1)
if(reverse_valid_map.size()<1)
output << "all states\n";
else
output << "{" << join(reverse_valid_map[i].begin(),reverse_valid_map[i].end(),",","}") << "\n";
......
......@@ -18,12 +18,13 @@ struct readable_splitting_tree {
std::vector<std::string> states;
std::vector<std::vector<readable_splitting_tree>> children;
std::vector<std::vector<std::string>> separators;
std::unordered_map<state, size_t> valid_map;
std::unordered_map<std::string, size_t> valid_map;
size_t depth = 0;
/* todo: check if this is ever used.
const std::vector<readable_splitting_tree> &get_children(state s) const;
const std::vector<std::string> &get_seperator(state s) const;
*/
};
readable_splitting_tree translate_splitting_tree(splitting_tree & tree, std::vector<std::string> & inputs, std::vector<std::string> & states);
......
This diff is collapsed.
......@@ -25,9 +25,9 @@ struct splitting_tree {
return children[valid_map.at(s)];
}
const word & get_seperator(state s) const {
const word & get_separator(state s) const {
if (children.size() < 1)
throw std::runtime_error("get_seperator called when there were no seperators");
throw std::runtime_error("get_separator called when there were no separators");
else if (valid_map.size() < 1 || valid_map.count(s) < 1)
return separators[0];
else
......@@ -123,20 +123,7 @@ const options randomized_lee_yannakakis_style = {true, false, true, true,true};
const options randomized_hopcroft_style = {false, false, false, true,false};
const options randomized_min_hopcroft_style = {false, true, false, true,false};
/// \brief The algorithm produces more than just a splitting tree, all results are put here.
struct result {
result(size_t N) : root(N, 0), successor_cache(), is_complete(N <= 1) {}
// The splitting tree as described in Lee & Yannakakis
splitting_tree root;
// Encodes f_u : depth -> state -> state, where only the depth of u is of importance
std::vector<std::vector<state>> successor_cache;
// false <-> no adaptive distinguishing sequence
bool is_complete;
};
/// \brief Creates a splitting tree by partition refinement.
/// \returns a splitting tree and other calculated structures.
result create_splitting_tree(mealy const & m, options opt, uint_fast32_t random_seed);
splitting_tree create_splitting_tree(mealy const & m);
......@@ -58,7 +58,7 @@ struct main_options {
unsigned long k_max = 1; // 3 means 2 extra states. currently not supported
unsigned long seed = 0; // 0 for unset/noise. currently not supported
string input_filename = "../examples/lee_yannakakis_distinguishable.dot";
string input_filename = "../examples/coffe_machine.dot";
string output_filename = "";
};
......@@ -163,7 +163,7 @@ int main(int argc, char * argv[]){
const auto & translation = machine_and_translation.second;
splitting_tree complete_splitting_tree = create_splitting_tree(machine,complete_ads,0).root;
splitting_tree complete_splitting_tree = create_splitting_tree(machine);
vector<string> input_translation = create_reverse_map(translation.input_indices);
vector<string> state_translation = create_reverse_map(translation.state_indices);
readable_splitting_tree translated_tree = translate_splitting_tree(complete_splitting_tree,input_translation,state_translation);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment