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

refactoring

parent e7d2ec63
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,13 @@
#ifndef _MDGRAPH_
#define _MDGRAPH_
using namespace std;
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
#include "Class_of_state.hpp"
typedef set<int> Set;
typedef vector<Class_Of_State *> MetaGrapheNodes;
......
......@@ -18,6 +18,22 @@ using namespace std;
double getTime() { return (double)clock() / (double)CLOCKS_PER_SEC; }
void save_observable_paths(const string& model_name,
const string& output_folder,
const set<vector<int>>& obs_paths) {
string output_file = output_folder + "/no_optimal_" + model_name + ".txt";
cout << "Saving results in " << output_file << endl;
ofstream monFlux(output_file);
monFlux << "# observable paths: " << obs_paths.size() << endl;
int n = 1;
for (auto path : obs_paths) {
monFlux << "path #" << n << ": " << path.size() << " transitions" << endl;
n++;
}
}
void print_stats(const set<vector<int>> abstract_paths) {
int sum_transtions = 0;
set<int> transitions;
......@@ -44,6 +60,29 @@ void print_stats(const set<vector<int>> abstract_paths) {
cout << "# covered transitions: " << transitions.size() << endl;
}
void print_output(const net& model, MDGraph& g,
const map<int, int>& obs_transitions,
const set<vector<int>>& obs_paths,
const set<vector<int>>& abstract_paths, float elapsed_time,
const string& model_name, const string& output_folder) {
// save observable paths in the folder
save_observable_paths(model_name, output_folder, obs_paths);
// print SOG information
g.printCompleteInformation();
cout << "\n# transition: " << model.transitions.size() << endl;
cout << "# places: " << model.places.size() << endl;
cout << "# observable transitions: " << obs_transitions.size() << endl
<< endl;
// print stats
print_stats(abstract_paths);
// print time
cout << "\nTime for computing all the paths: " << elapsed_time << " seconds"
<< endl;
}
string get_model_name(const string& filename) {
int pp = filename.find(".n") + 1;
int ps = filename.rfind("/") + 1;
......@@ -59,14 +98,45 @@ net load_net(const string& filename) {
return R;
}
void generate_paths(const string& file, const string& output_folder,
int bound = 32) {
net model = load_net(file);
string model_name = get_model_name(file);
void compute_abstract_paths(const net& model, MDGraph& g,
const map<int, int>& obs, const set<int>& unobs,
set<vector<int>>& obs_paths,
set<vector<int>>& abstract_path, int bound) {
// build the SOG
cout << "Building SOG ...";
RdPBDD DR(model, obs, unobs, bound);
cout << "done";
// compute the observable paths
obs_paths = DR.chem_obs(g, obs);
map<int, int> obs;
set<vector<int>> abstrait;
MDGraph g;
// add abstract paths
for (auto path : obs_paths) {
abstract_path.insert(DR.chem_abs(path, g));
}
}
void get_transitions_from_file(const net& model, const string& file,
map<int, int>& obs, set<int>& unobs) {
ifstream flux(file);
string ligne;
if (flux) {
while (getline(flux, ligne)) {
int tr = stoi(ligne.substr(1)); // le ligne sous forme de t1 prendre le1
obs.insert({tr, 1});
}
}
for (long unsigned int i = 0; i < model.transitions.size(); i++) {
if ((obs.find(i)) == obs.end()) {
unobs.insert(i);
}
}
}
void generate_all_paths(const string& net_file, const string& output_folder,
int bound = 32) {
net model = load_net(net_file);
string model_name = get_model_name(net_file);
double d = getTime();
......@@ -74,48 +144,26 @@ void generate_paths(const string& file, const string& output_folder,
set<int> unobs = model.calcul1();
// compute the observable transitions
map<int, int> obs;
for (long unsigned int i = 0; i < model.transitions.size(); i++) {
if ((unobs.find(i)) == unobs.end()) {
obs.insert({i, 1});
}
}
// build the SOG
cout << "Building SOG ...";
RdPBDD DR(model, obs, unobs, bound);
cout << "done";
// compute the observable paths
set<vector<int>> chemins = DR.chem_obs(g, obs);
string output_file = output_folder + "/no_optimal_" + model_name + ".txt";
ofstream monFlux(output_file);
monFlux << "le nombre de chemins observés: " << chemins.size() << endl;
int n = 1;
for (auto i : chemins) {
monFlux << "le " << n << " ch: " << i.size() << " tr." << endl;
// add abstract paths
abstrait.insert(DR.chem_abs(i, g));
n++;
}
// compute abstract paths
MDGraph g;
set<vector<int>> obs_paths;
set<vector<int>> abstract_paths;
compute_abstract_paths(model, g, obs, unobs, obs_paths, abstract_paths,
bound);
// time for generating the paths
double tps = getTime() - d;
// print SOG information
g.printCompleteInformation();
cout << "\n# transition: " << model.transitions.size() << endl;
cout << "# places: " << model.places.size() << endl;
cout << "# observable transitions: " << obs.size() << endl << endl;
// print stats
print_stats(abstrait);
// print time
cout << "\nTime for computing all the paths: " << tps << " seconds" << endl;
cout << "Saving results in " << output_file << endl;
// print output
print_output(model, g, obs, obs_paths, abstract_paths, tps, model_name,
output_folder);
}
/******************************************************************************
* Main function
......@@ -165,7 +213,11 @@ int main(int argc, char** argv) {
// reach->callback([&]() {});
// sog->callback([&]() {});
generate->callback([&]() { generate_paths(input_file, output_folder); });
generate->callback([&]() {
// if (all) {
generate_all_paths(input_file, output_folder);
// }
});
// parse arguments
CLI11_PARSE(app, argc, argv);
......
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