Commit 05fceb59 authored by Gijs van Cuyck's avatar Gijs van Cuyck

found a bug in reachable_submachine and removed the method call untill bug is solved.

This removes support for machine definitions that aren't fully
reachable.
parent 4d2101a6
No preview for this file type
@echo off
IF EXIST "do_copy" copy ..\cmake-build-debug\main.exe main.exe
for /r %%i in (..\test_benchmarks\*) do (
for /R "..\benchmarks\" %%i in (*) do (
echo running agorithm for %%~nxi
main.exe -a -f %%i
echo.
......
......@@ -5,7 +5,7 @@
using namespace std;
mealy reachable_submachine(mealy&& in, state start) {
mealy reachable_submachine(const mealy& in, state start) {
using state_out = state;
state_out max_state = 0;
map<state, state_out> new_state;
......
......@@ -4,4 +4,4 @@
struct mealy;
mealy reachable_submachine( mealy&& in, std::uint16_t start);
mealy reachable_submachine( const mealy& in, std::uint16_t start);
......@@ -38,14 +38,6 @@ struct translation {
state max_state = 0;
};
//todo: check of dit nog gebruikt wordt
/*
struct reverse_translation{
std::vector<std::string> inputs;
std::vector<std::string> outputs;
std::vector<std::string> states;
};
*/
/// \brief inverts the input_indices and output_indices maps
std::vector<std::string> create_reverse_map(const std::unordered_map<std::string, input> & indices);
......
#include "splitting_tree.hpp"
#include "partition.hpp"
#include "types.hpp"
#include "vector_printing.hpp"
#include <algorithm>
#include <cassert>
......@@ -9,7 +11,6 @@
#include <unordered_set>
#include <tuple>
#include <iostream>
#include <types.hpp>
using namespace std;
......@@ -61,6 +62,7 @@ bool update_valid_set(unordered_set<state> &original, const unordered_set<state>
//assuming the input is a partition of those states based on the output they give when symbol is applied.
unordered_set<state> is_valid_for(const size_t &N, const mealy &g, list<list<state>> const &blocks, input symbol)
{
unordered_set<state> ret;
for (auto &&block : blocks)
{
......@@ -294,7 +296,9 @@ splitting_tree create_splitting_tree(const mealy &g)
if (valid_set.empty())
targets = unordered_set<state>(boom.states.begin(),boom.states.end());
else
{
targets = unordered_set<state>(valid_set);
}
//a list of all the splits that were made.
//they are saved in a list so that they can be modified if required before they are pushed onto the work_list.
......@@ -313,7 +317,7 @@ splitting_tree create_splitting_tree(const mealy &g)
for (input symbol : all_inputs)
{
auto new_blocks = partition_(
std::list<std::list<state>> new_blocks = partition_(
begin(boom.states),
end(boom.states), [symbol, depth, &g](state state)
{
......@@ -325,7 +329,6 @@ splitting_tree create_splitting_tree(const mealy &g)
if (new_blocks.size() == 1) continue;
unordered_set<state> new_valid_set = is_valid_for(N,g,new_blocks, symbol);
bool updated_separator = false;
//compare current split with best general split so far. Update if necessary.
......@@ -359,12 +362,15 @@ splitting_tree create_splitting_tree(const mealy &g)
//if a valid split has been found for all the targets the work is done and progression is made.
if (targets.empty())
goto has_split;
break;
}
//if there are still some states for which we have failed to find a valid split on output, we will now look for valid splits on state.
for (input symbol : all_inputs)
{
if (targets.empty())
break;
vector<bool> successor_states(N, false);
for (auto &&state : boom.states)
{
......@@ -421,9 +427,6 @@ splitting_tree create_splitting_tree(const mealy &g)
best_split_index = splits.size()-1;
}
if (targets.empty())
break;
}
//if we get here, then we tried all the possible partialy valid splits.
......
......@@ -8,6 +8,7 @@
#include <string>
#include <sstream>
#include <vector>
#include <list>
/// \brief turns a vector of printable objects into a string, putting a sepperator between every two elements and
/// a concluder after the last one.
......@@ -45,4 +46,30 @@ std::ostream & operator<<(std::ostream & s,std::vector<T> v)
return s;
}
//turns a list into a vector.
//used for debugging, since lists are not very human readable and vectors are.
template <typename T>
std::vector<T> list_to_vector(const std::list<T> & input)
{
std::vector<T> ret;
ret.reserve(input.size());
std::copy(std::begin(input), std::end(input), std::back_inserter(ret));
return ret;
}
//turns a list of lists into a vector of vectors.
//used for debugging, since lists are not very human readable and vectors are.
template <typename T>
std::vector<std::vector<T>> double_list_to_vector(const std::list<std::list<T>> & input)
{
std::vector<std::vector<T>> ret;
for(std::list<T> element: input)
{
ret.push_back(list_to_vector(element));
}
return ret;
}
#endif //COMPLETE_ADS_PRINTING_H
......@@ -67,7 +67,8 @@ struct main_options
//"lee_yannakakis_difficult.dot";
//"lee_yannakakis_distinguishable.dot";
//"esm-manual-controller.dot";
string input_filename = input_directory + "lee_yannakakis_difficult.dot";
//"ABP_Sender.flat_0_1.dot";
string input_filename = input_directory + "ABP_Sender.flat_0_1.dot";
string output_filename = "";
};
......@@ -183,19 +184,30 @@ int main(int argc, char *argv[])
return read_mealy_from_dot(filename);
}();
const auto &machine = reachable_submachine(move(machine_and_translation.first), 0U);
//todo: check if this is required
const auto &reachable_machine = reachable_submachine(machine_and_translation.first, 0U);
const auto &machine = machine_and_translation.first;
if(machine.graph_size!=reachable_machine.graph_size)
throw runtime_error("machine is not fully reachable");
const auto &translation = machine_and_translation.second;
vector<string> input_translation = create_reverse_map(translation.input_indices);
vector<string> state_translation = create_reverse_map(translation.state_indices);
//only usefull for debugging
//only useful for debugging
/*
ofstream translation_file(output_directory + "translations.txt");
translation_file << "input translation\n";
translation_file << input_translation;
translation_file << "\noutput translation\n";
translation_file << create_reverse_map(translation.output_indices);
translation_file << "\nstate translation\n";
translation_file << state_translation;
translation_file.close();
*/
cout << "creating splitting tree\n";
......@@ -204,20 +216,24 @@ int main(int argc, char *argv[])
cout << "creating readable splitting tree\n";
readable_splitting_tree translated_tree = translate_splitting_tree(complete_splitting_tree, input_translation,
state_translation);
ofstream out_file(args.output_filename);
out_file << "the splitting tree:\n\n";
rst_to_stream(translated_tree, out_file) << "\n\n\n";
cout << "creating separating family\n";
separating_family family = create_separating_family(complete_splitting_tree, machine);
out_file << "the separating family:\n\n";
separating_family_to_stream(out_file, family, input_translation, state_translation);
out_file.close();
//making sure the results are actually correct.
assert(test_separating_family(family, machine));
ofstream out_file(args.output_filename);
out_file << "the splitting tree:\n\n";
rst_to_stream(translated_tree, out_file) << "\n\n\n";
out_file << "the separating family:\n\n";
separating_family_to_stream(out_file, family, input_translation, state_translation);
out_file.close();
cout << "finished!\n";
exit(0);
......
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