Skip to content

Commit

Permalink
Fixed merge conflict: I kept the renumbering in. I think it should be…
Browse files Browse the repository at this point in the history
… properly fixed by my suggestion in tudelft-cda-lab#23.
  • Loading branch information
hwalinga committed Jan 31, 2024
2 parents a0b3f9d + 93f4557 commit 7808854
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 207 deletions.
63 changes: 29 additions & 34 deletions source/apta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "utility/loguru.hpp"
#include "input/abbadingoreader.h"
#include "input/inputdatalocator.h"
#include "input/parsers/abbadingoparser.h"

using namespace std;

Expand Down Expand Up @@ -40,11 +41,9 @@ apta::apta(){
}

void apta::print_dot(iostream& output){
int ncounter = 0;
// needed for the correct printing of intermediate models after undoing merges
for(APTA_iterator Ait = APTA_iterator(root); *Ait != 0; ++Ait){
(*Ait)->number = ncounter++;
}
// Hielke: Fix numbering of states properly with suggestion in #23.
merger->renumber_states();

output << "digraph DFA {\n";
output << "\t" << root->find()->number << " [label=\"root\" shape=box];\n";
Expand All @@ -70,23 +69,19 @@ void apta::print_dot(iostream& output){

output << "\t" << n->number << " [ label=\"";
if(DEBUGGING){
output << n << ":#" << "\n";
output << "rep#" << n->representative << "\n";
output << n << ":#" << "\\n";
output << "rep#" << n->representative << "\\n";
}

output << n->number << ":#" << n->size << "\n";
output << n->number << " #" << n->size << " ";
n->data->print_state_label(output);
output << "\" ";
n->data->print_state_style(output);
if (!n->red) output << " style=dotted";

//output << n->number << " #" << n->size << "\" ";
//if (n->is_red()) output << ", style=filled, fillcolor=\"firebrick1\"";
//else if (n->is_blue()) output << ", style=filled, fillcolor=\"dodgerblue1\"";
//else if (n->is_white()) output << ", style=filled, fillcolor=\"ghostwhite\"";
//output << ", width=" << log(1 + log(1 + n->size));
//output << ", height=" << log(1 + log(1 + n->size));
output << "\" ";

if (n->is_red()) output << ", style=filled, fillcolor=\"firebrick1\"";
else if (n->is_blue()) output << ", style=filled, fillcolor=\"dodgerblue1\"";
else if (n->is_white()) output << ", style=filled, fillcolor=\"ghostwhite\"";
output << ", width=" << log(1 + log(1 + n->size));
output << ", height=" << log(1 + log(1 + n->size));
output << ", penwidth=" << log(1 + n->size);
output << "];\n";

Expand All @@ -108,18 +103,14 @@ void apta::print_dot(iostream& output){

output << "\t\t" << n->number << " -> " << child->number << " [label=\"";

output << inputdata_locator::get()->get_symbol(it->first) << endl;

//n->data->print_transition_label(output, it->first);


output << inputdata_locator::get()->get_symbol(it->first) << " ";
n->data->print_transition_label(output, it->first);
for(auto & min_attribute_value : g->min_attribute_values){
output << " " << inputdata_locator::get()->get_attribute(min_attribute_value.first) << " >= " << min_attribute_value.second;
output << "\\n" << inputdata_locator::get()->get_attribute(min_attribute_value.first) << " >= " << min_attribute_value.second;
}
for(auto & max_attribute_value : g->max_attribute_values){
output << " " << inputdata_locator::get()->get_attribute(max_attribute_value.first) << " < " << max_attribute_value.second;
output << "\\n" << inputdata_locator::get()->get_attribute(max_attribute_value.first) << " < " << max_attribute_value.second;
}

output << "\" ";
output << ", penwidth=" << log(1 + n->size);
output << " ];\n";
Expand Down Expand Up @@ -176,12 +167,10 @@ void apta_node::print_json_transitions(iostream& output){

void apta::print_json(iostream& output){
set_json_depths();
int count = 0;
root->depth = 0;
for(merged_APTA_iterator Ait = merged_APTA_iterator(root); *Ait != nullptr; ++Ait){
apta_node* n = *Ait;
n->number = count++;
}
// needed for the correct printing of intermediate models after undoing merges
// Hielke: Fix numbering of states properly with suggestion in #23.
merger->renumber_states();

output << "{\n";
output << "\t\"types\" : [\n";
Expand Down Expand Up @@ -330,8 +319,13 @@ void apta::read_json(istream& input_stream){
string trace = n["trace"];
istringstream trace_stream(trace);
node->access_trace = mem_store::create_trace();
// TODO: verify this with Sicco (robert)
// idat.read_abbadingo_sequence(trace_stream,node->access_trace);

auto parser = abbadingoparser::single_trace(trace_stream);
auto strategy = read_all();
auto trace_maybe = inputdata_locator::get()->read_trace(parser, strategy);
if (trace_maybe.has_value()) {
node->access_trace = trace_maybe.value();
}
}
for (int i = 1; i < read_apta["nodes"].size(); ++i) {
json n = read_apta["nodes"][i];
Expand Down Expand Up @@ -447,7 +441,8 @@ void apta_node::initialize(apta_node* n){
representative_of = nullptr;
tails_head = nullptr;
access_trace = nullptr;
number = -1;
// keep the old node number
// number = -1;
size = 0;
final = 0;
depth = 0;
Expand Down Expand Up @@ -821,4 +816,4 @@ void apta::set_json_depths() const {
it++;
}
}
}
}
2 changes: 1 addition & 1 deletion source/evaluation/mealy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void mealy::reset(state_merger* merger){


void mealy_data::print_transition_label(iostream& output, int symbol){
output << int_output[outputs[symbol]];
output << "/" << int_output[outputs[symbol]];
};

string mealy_data::predict_data(tail* t){
Expand Down
20 changes: 19 additions & 1 deletion source/input/parsers/abbadingoparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <sstream>
#include <chrono>

void abbadingoparser::parse_header() {
void abbadingoparser::parse_header(std::istream &inputstream) {
std::string line;
std::getline(inputstream, line);

Expand Down Expand Up @@ -166,3 +166,21 @@ std::optional<symbol_info> abbadingoparser::next() {
symbols.pop_front();
return cur_symbol;
}

/**
* Helper method to read a single abbadingo formatted trace
* Currently does not support trace or symbol attributes
*
* @param trace an input stream containing an abbadingo formatted trace.
* @return a parser for the trace.
*/
abbadingoparser abbadingoparser::single_trace(std::istream &trace) {

abbadingoparser parser(trace, false);

std::stringstream header;
header << "1 0\n";
parser.parse_header(header);

return parser;
}
12 changes: 9 additions & 3 deletions source/input/parsers/abbadingoparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ class abbadingoparser: public parser {
std::vector<attribute_info> trace_attr_prototypes;
std::vector<attribute_info> symbol_attr_prototypes;



public:
abbadingoparser(std::istream &input)
explicit abbadingoparser(std::istream &input, bool header = true)
: inputstream(input)
{
parse_header();
if (header) {
parse_header(inputstream);
}
}

void parse_header();
void parse_header(std::istream &inputstream);

bool read_abbadingo_trace();

std::optional<symbol_info> next();

static abbadingoparser single_trace(std::istream &input);
};


Expand Down
2 changes: 1 addition & 1 deletion source/input/parsers/grammar/abbadingoheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace {

// The complete abbadingo header: number:dsft/name1,... number:dsft/name2,...
struct abbadingo_header_p {
static constexpr auto rule = dsl::twice(dsl::p<abbadingo_header_part_p>, dsl::trailing_sep(dsl::ascii::space));
static constexpr auto rule = dsl::twice(dsl::p<abbadingo_header_part_p>, dsl::trailing_sep(dsl::ascii::space)) + (dsl::newline | dsl::eof);
static constexpr auto value = lexy::construct<abbadingo_header_info>;
};
}
Expand Down
6 changes: 6 additions & 0 deletions source/state_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,12 @@ void state_merger::print_dot(const string& file_name)
output1.close();
}

void state_merger::print_dot(ostream& output)
{
todot();
output << dot_output;
}

void state_merger::print_json(const string& file_name)
{
tojson();
Expand Down
1 change: 1 addition & 0 deletions source/state_merger.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class state_merger{
bool split_init(apta_node *red, tail *t, int attr, int depth, bool evaluate, bool perform, bool test);

void print_dot(const string& file_name);
void print_dot(ostream& output);

void print_json(const string& file_name);

Expand Down
Loading

0 comments on commit 7808854

Please sign in to comment.