Skip to content
Snippets Groups Projects
Commit 5e68dd48 authored by Jaime Arias's avatar Jaime Arias
Browse files

Add attributes to the leaf transformation

parent c8fa01b7
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ add_subdirectory(amas)
# translator library
add_library(adt2amas_lib translator.cpp)
target_link_libraries(adt2amas_lib adtree_lib amas_lib)
target_link_libraries(adt2amas_lib adtree_lib amas_lib linear_expr_lib)
target_include_directories(adt2amas_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# The main programn
......
#include "cost_attribute.hpp"
CostAttribute::CostAttribute(int value) : Attribute(value) {}
CostAttribute::CostAttribute(int value) : Attribute(value) {
this->type_ = "cost";
}
......@@ -4,9 +4,6 @@
#include "attribute.hpp"
class CostAttribute : public Attribute {
protected:
std::string type_ = "COST";
public:
CostAttribute(int value);
};
......
#include "time_attribute.hpp"
TimeAttribute::TimeAttribute(int value) : Attribute(value) {}
TimeAttribute::TimeAttribute(int value) : Attribute(value) {
this->type_ = "time";
}
......@@ -4,9 +4,6 @@
#include "attribute.hpp"
class TimeAttribute : public Attribute {
protected:
std::string type_ = "TIME";
public:
TimeAttribute(int value);
};
......
......@@ -56,7 +56,7 @@ int Automaton::current_id = 0;
// Adding...
void Automaton::add_transition(State *source_state, State *destination_state,
Action *action) {
Action *action, vector<Update *> updates) {
// Check that both states belong to the automaton
auto no_source_state_in_automaton =
this->state_ids_.find(source_state->get_id()) == this->state_ids_.end();
......@@ -68,7 +68,7 @@ void Automaton::add_transition(State *source_state, State *destination_state,
throw "both states have to exist already in the automaton";
Transition *new_transition =
new Transition(source_state, destination_state, action);
new Transition(source_state, destination_state, action, updates);
vector<Transition *> tmp_transitions = source_state->get_transitions();
tmp_transitions.push_back(new_transition);
......
......@@ -187,7 +187,7 @@ class Automaton {
same entries.
*/
void add_transition(State *source_state, State *destination_state,
Action *action);
Action *action, vector<Update *> updates = {});
//! A public method to add an State instance to an Automaton instance.
/*!
......
......@@ -47,10 +47,18 @@ void Translator::leaf_to_automaton(TreeNode *node, Automata *amata) {
Label *label_one = new Label(node->get_goal());
vector<Update *> updates;
for (auto &a : node->get_attributes()) {
auto linear_expr = new ConstantCoefficient(a->get_value());
auto variable = a->get_type() + '_' + node->get_goal();
updates.push_back(new Update(variable, linear_expr));
}
new_amaton->add_state(state_one);
new_amaton->add_state(state_two);
new_amaton->add_transition(initial_state, state_one, label_one);
new_amaton->add_transition(initial_state, state_one, label_one, updates);
new_amaton->add_transition(state_one, state_one, synchronization_one);
new_amaton->add_transition(initial_state, state_two, synchronization_two);
new_amaton->add_transition(state_two, state_two, synchronization_two);
......
......@@ -3,6 +3,7 @@
#include "ad_tree.hpp"
#include "automata.hpp"
#include "constant_coefficient.hpp"
#include "gates/and.hpp"
#include "gates/nand.hpp"
#include "gates/nor.hpp"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment