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

refactor: add AddArc method

parent 50e50b6e
No related branches found
No related tags found
No related merge requests found
Pipeline #9311 failed with stage
......@@ -340,20 +340,17 @@ void PetriNetSOG::GenerateSOG(SOG &sog, map<int, int> trans_obs) const {
// if aggregate does not exist in the sog
if (!pos) {
curr_aggr.aggregate->successors.insert(
curr_aggr.aggregate->successors.begin(), Edge(succ_aggr, t));
sog.AddState(succ_aggr);
sog.AddPredecessor(succ_aggr, Edge(curr_aggr.aggregate, t));
sog.AddArc(curr_aggr.aggregate, succ_aggr, t);
// if the successor has fireable transitions, it is added to the stack
// if the successor has fireable transitions, it is added to the
// stack
firable_trans = FirableObservableTrans(complete_succ_aggr);
if (!firable_trans.empty()) {
st.emplace(succ_aggr, firable_trans);
}
} else {
curr_aggr.aggregate->successors.insert(
curr_aggr.aggregate->successors.begin(), Edge(pos, t));
sog.AddPredecessor(pos, Edge(curr_aggr.aggregate, t));
sog.AddArc(curr_aggr.aggregate, pos, t);
delete succ_aggr;
}
}
......@@ -427,13 +424,9 @@ Paths PetriNetSOG::ObservablePaths(SOG &sog, map<int, int> trans_obs) const {
if (!pos) {
firable_trans = FirableObservableTrans(complete_aggr);
// add transitions
elt.aggregate->successors.insert(elt.aggregate->successors.begin(),
Edge(reached_aggr, t));
// add the aggregate and its predecessors to the graph
sog.AddState(reached_aggr);
sog.AddPredecessor(reached_aggr, Edge(elt.aggregate, t));
sog.AddArc(elt.aggregate, reached_aggr, t);
// if the aggregate has no firable transitions
if (firable_trans.empty()) {
......@@ -453,11 +446,8 @@ Paths PetriNetSOG::ObservablePaths(SOG &sog, map<int, int> trans_obs) const {
ReinitCycle(current_trace, trans_obs);
current_trace.pop_back();
sog.AddArc(elt.aggregate, pos, t);
delete reached_aggr;
elt.aggregate->successors.insert(elt.aggregate->successors.begin(),
Edge(pos, t));
sog.AddPredecessor(pos, Edge(elt.aggregate, t));
old = true;
}
}
......
......@@ -22,8 +22,6 @@ Aggregate *SOG::FindState(const Aggregate *state) const {
void SOG::AddState(Aggregate *state) {
state->visited = false;
this->states.push_back(state);
nb_edges += state->predecessors.size();
nb_edges += state->successors.size();
nb_states++;
}
......@@ -136,8 +134,9 @@ void SOG::PrintSuccessors(const Aggregate *state) const {
}
}
void SOG::AddPredecessor(Aggregate *state, const Edge edge) {
state->predecessors.insert(state->predecessors.begin(), edge);
void SOG::AddArc(Aggregate *from, Aggregate *to, const int t) {
from->successors.insert(from->successors.begin(), Edge(to, t));
to->predecessors.insert(to->predecessors.begin(), Edge(from, t));
nb_edges++;
}
......
......@@ -53,11 +53,12 @@ class SOG {
void PrintSuccessors(const Aggregate *state) const;
/**
* Add a predecessor to an state
* @param state state to add a predecessor
* @param edge the edge to add
* Add an arc to the graph
* @param from source state
* @param to target state
* @param t transition identifier
*/
void AddPredecessor(Aggregate *state, Edge edge);
void AddArc(Aggregate *from, Aggregate *to, int t);
/**
* Print predecessors of an state
......
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