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

amas implementation ended

parent 261b7804
No related branches found
No related tags found
No related merge requests found
...@@ -7,11 +7,11 @@ Action::~Action(){} ...@@ -7,11 +7,11 @@ Action::~Action(){}
/* Gets */ /* Gets */
string Action::get_name(){ string Action::get_name(){
return name_; return this->name_;
} }
/* Sets */ /* Sets */
void Action::set_name(string name){ void Action::set_name(string name){
name_ = name; this->name_ = name;
} }
\ No newline at end of file
...@@ -26,5 +26,6 @@ void Automata::set_automaton_ids(set<int> automaton_ids){ ...@@ -26,5 +26,6 @@ void Automata::set_automaton_ids(set<int> automaton_ids){
void Automata::add_automaton(Automaton *new_automaton){ void Automata::add_automaton(Automaton *new_automaton){
auto automaton_in_automata = this->automaton_ids_.find(new_automaton->get_id()) == this->automaton_ids_.end(); auto automaton_in_automata = this->automaton_ids_.find(new_automaton->get_id()) == this->automaton_ids_.end();
assert(("automaton can't be in the automata to allow their addition", automaton_in_automata)); assert(("automaton can't be in the automata to allow their addition", automaton_in_automata));
this->automaton_ids_.insert(new_automaton->get_id());
this->vector_automaton_.push_back(new_automaton); this->vector_automaton_.push_back(new_automaton);
} }
\ No newline at end of file
...@@ -17,10 +17,112 @@ State* Automaton::get_initial_state(){ ...@@ -17,10 +17,112 @@ State* Automaton::get_initial_state(){
return this->initial_state_; return this->initial_state_;
} }
set<int> Automaton::get_transition_ids(){
return this->transition_ids_;
}
set<int> Automaton::get_state_ids(){
return this->state_ids_;
}
vector<State*> Automaton::get_states(){
return this->vector_states_;
}
vector<Transition*> Automaton::get_transitions(){
return this->vector_transitions_;
}
/* Sets */ /* Sets */
void Automaton::set_initial_state(State* initial_state){ void Automaton::set_initial_state(State* initial_state){
this->initial_state_ = initial_state; this->initial_state_ = initial_state;
} }
int Automaton::current_id = 0; void Automaton::set_transition_ids(set<int> transition_ids){
\ No newline at end of file this->transition_ids_ = transition_ids;
}
void Automaton::set_state_ids(set<int> state_ids){
this->state_ids_ = state_ids;
}
void Automaton::set_states(vector<State*> vector_states){
this->vector_states_ = vector_states;
}
void Automaton::set_transitions(vector<Transition*> vector_transitions){
this->vector_transitions_ = vector_transitions;
}
int Automaton::current_id = 0;
/* Other methods */
// Adding...
void Automaton::add_transition(string goal, State *source_state, State *destination_state, Action *action){
auto source_state_in_automaton = this->state_ids_.find(source_state->get_id()) != this->state_ids_.end();
auto dest_state_in_automaton = this->state_ids_.find(destination_state->get_id()) == this->state_ids_.end();
assert(("both states have to exist already in the automaton", source_state_in_automaton && dest_state_in_automaton));
Transition *new_transition = new Transition(goal, source_state, destination_state, action);
vector<Transition*> tmp_transitions = source_state->get_transitions();
tmp_transitions.push_back(new_transition);
source_state->set_transitions(tmp_transitions);
tmp_transitions = destination_state->get_transitions();
tmp_transitions.push_back(new_transition);
destination_state->set_transitions(tmp_transitions);
this->transition_ids_.insert(new_transition->get_id());
this->vector_transitions_.push_back(new_transition);
}
void Automaton::add_state(State *new_state){
auto state_in_automaton = this->state_ids_.find(new_state->get_id()) == this->state_ids_.end();
assert(("state can't be added to the automaton because it exists already", state_in_automaton));
this->state_ids_.insert(new_state->get_id());
this->vector_states_.push_back(new_state);
}
// Removing...
void Automaton::remove_transition(Transition *cur_transition){
auto transition_in_automaton = this->transition_ids_.find(cur_transition->get_id()) != this->transition_ids_.end();
assert(("transition can't be removed since it doesn't belong to this automaton", transition_in_automaton));
vector<Transition*> tmp_transitions = cur_transition->get_source_state()->get_transitions();
auto it = tmp_transitions.begin();
for(; it != tmp_transitions.end() && (*it)->get_id() != cur_transition->get_id(); it++){}
it = tmp_transitions.erase(it);
cur_transition->get_source_state()->set_transitions(tmp_transitions);
tmp_transitions = cur_transition->get_destination_state()->get_transitions();
it = tmp_transitions.begin();
for(; it != tmp_transitions.end() && (*it)->get_id() != cur_transition->get_id(); it++){}
it = tmp_transitions.erase(it);
cur_transition->get_destination_state()->set_transitions(tmp_transitions);
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 */
delete cur_transition;
}
void Automaton::remove_state(State *cur_state){
auto state_in_automaton = this->state_ids_.find(cur_state->get_id()) != this->state_ids_.end();
assert(("state can't be removed since it doesn't belong to this automaton", state_in_automaton));
vector<Transition*> tmp_transitions = cur_state->get_transitions();
tmp_transitions.clear();
cur_state->set_transitions(tmp_transitions);
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 */
}
...@@ -9,6 +9,11 @@ class Automaton ...@@ -9,6 +9,11 @@ class Automaton
int id; int id;
static int current_id; static int current_id;
State *initial_state_; State *initial_state_;
set<int> state_ids_;
set<int> transition_ids_;
vector<State*> vector_states_;
vector<Transition*> vector_transitions_;
public: public:
Automaton(State *initial_state = nullptr) { } Automaton(State *initial_state = nullptr) { }
~Automaton() { } ~Automaton() { }
...@@ -16,9 +21,26 @@ class Automaton ...@@ -16,9 +21,26 @@ class Automaton
/* Gets */ /* Gets */
int get_id(); int get_id();
State* get_initial_state(); State* get_initial_state();
set<int> get_state_ids();
set<int> get_transition_ids();
vector<State*> get_states();
vector<Transition*> get_transitions();
/* Sets */ /* Sets */
void set_initial_state(State *initial_state); void set_initial_state(State *initial_state);
void set_state_ids(set<int> state_ids);
void set_transition_ids(set<int> transition_ids);
void set_states(vector<State*> vector_states);
void set_transitions(vector<Transition*> vector_transitions);
/* Other methods */
// Adding...
void add_transition(string goal, State *source_state, State *destination_state, Action *action);
void add_state(State *new_state);
// Remving...
void remove_transition(Transition *cur_transition);
void remove_state(State *cur_state);
}; };
#endif #endif
\ No newline at end of file
...@@ -7,11 +7,11 @@ Channel::~Channel(){} ...@@ -7,11 +7,11 @@ Channel::~Channel(){}
/* Gets */ /* Gets */
int Channel::get_channel_type(){ int Channel::get_channel_type(){
return static_cast<int>(channel_type_); return static_cast<int>(this->channel_type_);
} }
/* Sets */ /* Sets */
void Channel::set_channel_type(ChannelType channel_type){ void Channel::set_channel_type(ChannelType channel_type){
channel_type_ = channel_type; this->channel_type_ = channel_type;
} }
\ No newline at end of file
...@@ -18,10 +18,6 @@ StateType State::get_state_type(){ ...@@ -18,10 +18,6 @@ StateType State::get_state_type(){
return this->state_type_; return this->state_type_;
} }
set<int> State::get_transiton_ids(){
return this->transition_ids_;
}
vector<Transition*> State::get_transitions(){ vector<Transition*> State::get_transitions(){
return this->transitions_; return this->transitions_;
} }
...@@ -32,10 +28,6 @@ void State::set_state_type(StateType state_type){ ...@@ -32,10 +28,6 @@ void State::set_state_type(StateType state_type){
this->state_type_ = state_type; this->state_type_ = state_type;
} }
void State::set_transiton_ids(set<int> transition_ids){
this->transition_ids_ = transition_ids;
}
void State::set_transitions(vector<Transition*> transitions){ void State::set_transitions(vector<Transition*> transitions){
this->transitions_ = transitions; this->transitions_ = transitions;
} }
...@@ -44,8 +36,3 @@ int State::current_id = 0; ...@@ -44,8 +36,3 @@ int State::current_id = 0;
/* Other methods */ /* Other methods */
void State::add_transition(Transition *new_transition){
auto already_transition = this->transition_ids_.find(new_transition->get_id()) == this->transition_ids_.end();
assert(("transition can't be added to the state because it is already a transition", already_transition));
this->transitions_.push_back(new_transition);
}
\ No newline at end of file
...@@ -13,7 +13,6 @@ class State ...@@ -13,7 +13,6 @@ class State
int id; int id;
static int current_id; static int current_id;
StateType state_type_; StateType state_type_;
set<int> transition_ids_;
vector<Transition*> transitions_; vector<Transition*> transitions_;
public: public:
...@@ -24,13 +23,11 @@ class State ...@@ -24,13 +23,11 @@ class State
/* Gets */ /* Gets */
int get_id(); int get_id();
StateType get_state_type(); StateType get_state_type();
set<int> get_transiton_ids();
vector<Transition*> get_transitions(); vector<Transition*> get_transitions();
/* Sets */ /* Sets */
void set_state_type(StateType state_type); void set_state_type(StateType state_type);
void set_transiton_ids(set<int> transition_ids);
void set_transitions(vector<Transition*> transitions); void set_transitions(vector<Transition*> transitions);
/* Other methods */ /* Other methods */
......
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