Skip to content
Snippets Groups Projects
Commit a856955c authored by Giann Karlo Aguirre Samboní's avatar Giann Karlo Aguirre Samboní
Browse files

example implementation first attempt

parent 703f1997
No related merge requests found
#include "ad_tree.hpp"
#include "transition.hpp"
#include "automata.hpp"
int main(){
//ADtree tree;
ADtree *tree = new ADtree();
tree->create_node(10);
tree->create_node(6);
tree->create_node(14);
tree->create_node(5);
tree->create_node(8);
tree->create_node(11);
tree->create_node(18);
tree->preorder_print();
tree->inorder_print();
tree->postorder_print();
tree->get_root()->set_goal("Hola Giann Karlo");
std::cout << tree->get_root()->get_goal() << std::endl;
std::cout << tree->get_root()->get_id() << std::endl;
std::cout << tree->get_root()->get_first_child()->get_value() << std::endl;
std::cout << tree->get_root()->get_first_child()->get_id() << std::endl;
std::cout << tree->get_root()->get_first_child()->get_next_sibling()->get_value() << std::endl;
std::cout << tree->get_root()->get_first_child()->get_next_sibling()->get_id() << std::endl;
delete tree;
NodeType nodeTest{NodeType::Defence};
cout << "node type = " << static_cast<int>(nodeTest) << endl;
// Transitions
Transition *tran = new Transition();
Transition *tran2 = new Transition();
Channel *chan = new Channel();
Label *lbl = new Label();
State *ini_ste = new State();
State *fin_ste = new State();
cout << tran->get_id() << endl;
cout << tran2->get_id() << endl;
tran->set_action(chan);
tran->set_source_state(ini_ste);
tran->set_destination_state(fin_ste);
tran->get_source_state()->set_state_type(StateType::Initial);
cout << "source transition state: " << to_string(tran->get_source_state()->get_state_type()) << endl;
//System
Automata *amata = new Automata();
//A bunch of automaton
Automaton *amaton_one = new Automaton();
Automaton *amaton_two = new Automaton();
Automaton *amaton_three = new Automaton();
Automaton *amaton_four = new Automaton();
Automaton *amaton_five = new Automaton();
Automaton *amaton_six = new Automaton();
Automaton *amaton_seven = new Automaton();
Automaton *amaton_eight = new Automaton();
Automaton *amaton_nine = new Automaton();
//A bunch of states
State *state_zero = new State({StateType::Initial});
State *state_one = new State({StateType::Normal});
State *state_two = new State({StateType::Normal});
State *state_three = new State({StateType::Normal});
State *state_four = new State({StateType::Normal});
//A bunch of actions
Channel *channel_one = new Channel("TF_ok", {ChannelType::Receive});
Channel *channel_two = new Channel("p_nok", {ChannelType::Receive});
Channel *channel_three = new Channel("TF_nok", {ChannelType::Receive});
Channel *channel_four = new Channel("p_ok", {ChannelType::Receive});
Channel *channel_five = new Channel("TS_ok", {ChannelType::Send});
Channel *channel_six = new Channel("TS_nok", {ChannelType::Send});
Label *label_one = new Label("TS");
//Adding states
amaton_one->add_state(state_zero);
amaton_one->add_state(state_one);
amaton_one->add_state(state_two);
amaton_one->add_state(state_three);
amaton_one->add_state(state_four);
//Adding transitions
amaton_one->add_transition("", state_zero, state_one, channel_one);
amaton_one->add_transition("", state_one, state_two, channel_two);
amaton_one->add_transition("", state_two, state_three, label_one);
amaton_one->add_transition("", state_three, state_three, channel_five);
amaton_one->add_transition("", state_zero, state_four, channel_three);
amaton_one->add_transition("", state_zero, state_three, channel_four);
amaton_one->add_transition("", state_four, state_four, channel_six);
StateType stateTest{StateType::Normal};
......
......@@ -2,5 +2,5 @@
cmake_minimum_required(VERSION 3.0.0)
# Asynchronous Multi-Agent System Library
add_library(amas_lib action.cpp channel.cpp channel_type.cpp label.cpp state.cpp state_type.cpp transition.cpp)
add_library(amas_lib action.cpp channel.cpp channel_type.cpp label.cpp transition.cpp state.cpp state_type.cpp automata.cpp automaton.cpp)
target_include_directories(amas_lib PUBLIC ${CMAKE_CURRENT_LIST_DIR})
#include "automata.hpp"
Automata::Automata(vector<Automaton*> vector_automaton) : vector_automaton_(vector_automaton){}
Automata::Automata(vector<Automaton*> vector_automaton, set<int> automaton_ids) : vector_automaton_(vector_automaton),
automaton_ids_(automaton_ids)
{}
Automata::~Automata(){}
......
......@@ -2,6 +2,7 @@
#define AUTOMATA_HPP
#include "automaton.hpp"
#include "transition.hpp"
class Automata
{
......@@ -9,8 +10,8 @@ class Automata
set<int> automaton_ids_;
vector<Automaton*> vector_automaton_;
public:
Automata(vector<Automaton*> vector_automaton = {}) { }
~Automata() { }
Automata(vector<Automaton*> vector_automaton = {}, set<int> automaton_ids = {});
~Automata();
/* Gets */
vector<Automaton*> get_vector_automaton();
......
......@@ -108,7 +108,7 @@ void Automaton::remove_transition(Transition *cur_transition){
it = this->vector_transitions_.begin();
for(; it != this->vector_transitions_.end() && (*it)->get_id() != cur_transition->get_id(); it++){}
it = this->vector_transitions_.erase(it);
//this->state_ids_.insert(new_state->get_id()); /* falta eliminar del set de ids */
this->transition_ids_.erase(cur_transition->get_id());
delete cur_transition;
}
......@@ -123,6 +123,6 @@ void Automaton::remove_state(State *cur_state){
auto it = this->vector_states_.begin();
for(; it != this->vector_states_.end() && (*it)->get_id() != cur_state->get_id(); it++){}
it = this->vector_states_.erase(it);
//this->state_ids_.insert(new_state->get_id()); /* falta eliminar del set de ids */
it = this->vector_states_.erase(it);
this->state_ids_.erase(cur_state->get_id());
}
......@@ -15,8 +15,8 @@ class Automaton
vector<Transition*> vector_transitions_;
public:
Automaton(State *initial_state = nullptr) { }
~Automaton() { }
Automaton(State *initial_state = nullptr);
~Automaton();
/* Gets */
int get_id();
......
#include "channel.hpp"
Channel::Channel(ChannelType channel_type) : channel_type_(channel_type){}
Channel::Channel(string name, ChannelType channel_type) : channel_type_(channel_type),
Action(name){}
Channel::~Channel(){}
......
......@@ -12,7 +12,7 @@ class Channel: public Action
public:
Channel(ChannelType channel_type = static_cast<ChannelType>(0));
Channel(string name = "", ChannelType channel_type = static_cast<ChannelType>(0));
~Channel();
/* Gets */
......
#include "label.hpp"
Label::Label(){}
Label::Label(string name) : Action(name){}
Label::~Label(){}
\ No newline at end of file
......@@ -6,7 +6,7 @@
class Label: public Action
{
public:
Label();
Label(string name);
~Label();
};
......
......@@ -32,7 +32,7 @@ void State::set_transitions(vector<Transition*> transitions){
this->transitions_ = transitions;
}
int State::current_id = 0;
int State::current_id = -1;
/* Other methods */
......@@ -6,6 +6,7 @@
using namespace std;
class Transition;
class State
{
private:
......
......@@ -9,7 +9,7 @@
using namespace std;
class State;
class Transition
{
private:
......
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