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

refactor: aggregate file

parent b6dfe544
No related branches found
No related tags found
No related merge requests found
#include "aggregate.hpp"
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
void Aggregate::initWeightColumns(std::set<int> outputTrans) {
for (int t : outputTrans) {
void Aggregate::InitWeightColumns(const std::set<int>& output_trans) {
for (int t : output_trans) {
columns.push_back(t);
}
}
void Aggregate::addRowWeight(const int in, const std::vector<int> weightRow) {
void Aggregate::AddWeightRow(const int in, const std::vector<int>& weight_row) {
rows.push_back(in);
weight.push_back(weightRow);
weight.push_back(weight_row);
}
int Aggregate::posTransOutWeight(int t) {
for (int i = 0; i < columns.size(); i++)
if (columns[i] == t)
int Aggregate::PosTransOutWeight(const int t) const {
for (int i = 0; i < columns.size(); i++) {
if (columns[i] == t) {
return i;
}
}
return -1;
}
int Aggregate::posTransInWeight(int t) {
for (int i = 0; i < rows.size(); i++)
if (rows[i] == t)
int Aggregate::PosTransInWeight(const int t) const {
for (int i = 0; i < rows.size(); i++) {
if (rows[i] == t) {
return i;
}
}
return -1;
}
int Aggregate::weightInOut(int in, int out) {
return weight[posTransInWeight(in)][posTransOutWeight(out)];
int Aggregate::WeightInOut(const int in, const int out) const {
return weight[PosTransInWeight(in)][PosTransOutWeight(out)];
}
Aggregate* Aggregate::predbytrans(const int t) const {
for (Edge p : predecessors) {
Aggregate* Aggregate::GetPredecessorsOfTrans(const int t) const {
for (const Edge p : predecessors) {
if (p.transition == t) {
return p.state;
}
}
return nullptr;
}
\ No newline at end of file
}
......@@ -31,49 +31,51 @@ class Aggregate {
* BDD of the aggregate
*/
bdd state;
/*
* Input transitions of the aggregate
*/
std::vector<int> rows;
/**
* Output transitions of the aggregate
*/
std::vector<int> columns;
/* returns the bdd representing the aggregate */
bdd getbddstate() const {
return state;
}
/*
* Matrix representing the weights of the shortest paths inside the aggregate
*/
std::vector<int> rows; // input transitions of the aggregate
std::vector<int> columns; // output transitions of the aggregate
std::vector<std::vector<int>> weight;
/* returns the column of the output transitions */
std::vector<int> getColumnsWeight() const {
return columns;
}
/*initializes the columns with the output transitions*/
void initWeightColumns(std::set<int>);
/* adds a row corresponding to a given input transition (in) to the matrix of
* weight*/
/* rerns the tu*/ void addRowWeight(const int in, const std::vector<int> r);
/* gives (int in, int out);the position of transition t in output
* transitions vector
/**
* Initialize the columns with the output transitions
*/
int posTransOutWeight(int t);
/* gives the weight for a given pair of input and output transition */
int weightInOut(int in, int out);
/* gives the position of transition t in input transitions vector */
void InitWeightColumns(const std::set<int>& output_trans);
int posTransInWeight(int t);
/**
* Add a row corresponding to a given input transition (in) to the matrix of
* weight
* */
void AddWeightRow(int in, const std::vector<int>& weight_row);
/**
* Return the position of transition t in output transitions vector
*/
int PosTransOutWeight(int t) const;
/*returns the predecessor of the aggregate by a given transition*/
Aggregate* predbytrans(const int t) const;
/**
* Gives the position of transition t in input transitions vector
*/
int PosTransInWeight(int t) const;
/**
* Flag to indicate if the state loops using epsilon transitions
* Gives the weight for a given pair of input and output transition
*/
bool loop{false};
int WeightInOut(int in, int out) const;
/**
* Flag to indicate if there exists a blocking state
* Return the predecessor of the aggregate by a given transition
*/
bool blocking{false};
Aggregate* GetPredecessorsOfTrans(int t) const;
/**
* Flag to indicate if the state was visited
......
......@@ -310,7 +310,7 @@ Set PetriNetSOG::FirableObservableTrans(const bdd &from) const {
int PetriNetSOG::ComputeSingleWeight(Aggregate *aggr, const int in,
const int out) const {
bdd source = SearchExitPoints(aggr->state, out);
const bdd dest = relation[in][(aggr->predbytrans(in))->getbddstate()];
const bdd dest = relation[in][(aggr->GetPredecessorsOfTrans(in))->state];
// backtracking from t_target until t_source
int counter = 0;
......@@ -324,11 +324,11 @@ int PetriNetSOG::ComputeSingleWeight(Aggregate *aggr, const int in,
/* compute one raw of the weight matrix corresponding to the input transition */
void PetriNetSOG::computeRowWeight(const int in, Aggregate *a) {
std::vector<int> r;
std::vector<int> col = a->getColumnsWeight();
std::vector<int> col = a->columns;
for (int out : col) {
r.push_back(ComputeSingleWeight(a, in, out));
}
a->addRowWeight(in, r);
a->AddWeightRow(in, r);
}
void PetriNetSOG::GenerateSOG(SOG &sog) {
Stack st;
......@@ -345,7 +345,7 @@ void PetriNetSOG::GenerateSOG(SOG &sog) {
Set firable_trans = FirableObservableTrans(complete_aggr);
// initialize the raws of Weight
new_aggregate->initWeightColumns(firable_trans);
new_aggregate->InitWeightColumns(firable_trans);
st.emplace(new_aggregate, firable_trans);
while (!st.empty()) {
......@@ -378,14 +378,16 @@ void PetriNetSOG::GenerateSOG(SOG &sog) {
st.emplace(succ_aggr, firable_trans);
// initialize the raws of Weight
succ_aggr->initWeightColumns(firable_trans);
// succ_aggr->initWeightColumns(firable_trans);
// compute a row weight for the input transition t and add it to the
// succ aggregate
computeRowWeight(t, succ_aggr);
// computeRowWeight(t, succ_aggr);
}
} else {
sog.AddArc(curr_aggr.aggregate, pos, t);
// computeRowWeight(t, pos);
delete succ_aggr;
}
}
......
......@@ -115,13 +115,6 @@ void SOG::ExportGraphToDotFile(const std::string &filename) const {
void SOG::PrintSuccessors(const Aggregate *state) const {
std::cout << bddtable << state->state << '\n';
if (state->loop) {
std::cout << "\n\tLooping with epsilon transitions\n";
}
if (state->blocking) {
std::cout << "\n\tExisting a blocking state\n";
}
std::cout << "\n\tIts successors are ( " << state->successors.size()
<< " ):\n\n";
......
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