Skip to content
Snippets Groups Projects
Commit 1aaa824f authored by gianlucarossi15's avatar gianlucarossi15
Browse files

Minor changes

parent f49685e0
No related branches found
No related tags found
1 merge request!1New code version
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
#include "io.h" #include "io.h"
#include <string> #include <string>
#include "hash.h" #include "hash.h"
#include <omp.h>
#include <pthread.h>
#define NUM_TRIALS 10 #define NUM_TRIALS 10
...@@ -14,22 +13,11 @@ ...@@ -14,22 +13,11 @@
using namespace std; using namespace std;
namespace po = boost::program_options; namespace po = boost::program_options;
//static void *handler(void *args){
// string mode = *(string *) args;
// if(mode=="Random"){
// g2 = compress_graph_basic(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
// var["directed"].as<bool>());
//
// }else if(mode=="LP"){
// g2 = compress_graph_LP(g, e_s, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
// var["directed"].as<bool>());
// }
//}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
srand((unsigned)time(NULL)); srand((unsigned)time(NULL));
pthread_t threads[NUM_TRIALS];
po::options_description desc("Allowed options"); po::options_description desc("Allowed options");
desc.add_options() desc.add_options()
...@@ -71,42 +59,49 @@ int main(int argc, char *argv[]) { ...@@ -71,42 +59,49 @@ int main(int argc, char *argv[]) {
double elapsed_time = 0; double elapsed_time = 0;
auto[g, e_s] = read_graph_from_file(file_name, var["directed"].as<bool>()); auto[g, e_s] = read_graph_from_file(file_name, var["directed"].as<bool>());
auto start = chrono::steady_clock::now();
string execMode=var["algorithm"].as<string>(); string execMode=var["algorithm"].as<string>();
for (int i=0; i<NUM_TRIALS; i++) {
auto start = chrono::steady_clock::now();
// pthread_create(&threads[i], NULL, handler, NULL);
#pragma omp parallel for num_threads(NUM_TRIALS)
for (int i = 0; i < NUM_TRIALS; i++) {
auto start = std::chrono::steady_clock::now();
if (execMode == "Random") { if (execMode == "Random") {
g2 = compress_graph_basic(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(), g2 = compress_graph_basic(g, var["depth"].as<int>(), var["proportions"].as<std::vector<double>>(),
var["directed"].as<bool>()); var["directed"].as<bool>());
} else if (execMode == "LP") { } else if (execMode == "LP") {
g2 = compress_graph_LP(g, e_s, var["depth"].as<int>(), var["proportions"].as<vector<double>>(), g2 = compress_graph_LP(g, e_s, var["depth"].as<int>(), var["proportions"].as<std::vector<double>>(),
var["directed"].as<bool>()); var["directed"].as<bool>());
} else if (execMode == "SA") { } else if (execMode == "SA") {
g2 = Simulated_annealing(1000, 10, 0.99, g, var["directed"].as<bool>(), var["depth"].as<int>(), g2 = Simulated_annealing(1000, 10, 0.99, g, var["directed"].as<bool>(), var["depth"].as<int>(),
var["proportions"].as<vector<double>>()); var["proportions"].as<std::vector<double>>());
}else if (execMode == "Greedy") { } else if (execMode == "Greedy") {
g2 = compress_graph_greedy(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(), g2 = compress_graph_greedy(g, var["depth"].as<int>(), var["proportions"].as<std::vector<double>>(),
var["directed"].as<bool>()); var["directed"].as<bool>());
} }
auto finish = chrono::steady_clock::now(); auto finish = std::chrono::steady_clock::now();
vector<edge> edges_original = get_edges(g, var["directed"].as<bool>());
edges_compressed += get_edges(g2, var["directed"].as<bool>()).size();
elapsed_time += chrono::duration_cast<chrono::duration<double>>(finish - start).count(); // Update edges_compressed and elapsed_time in a thread-safe manner
// compression_rate = ((double) (edges_original.size() - edges_compressed.size()) / #pragma omp critical
// edges_original.size()); {
// c.push_back(compression_rate); vector<edge> edges_original = get_edges(g, var["directed"].as<bool>());
// s.push_back(edges_compressed); edges_compressed += get_edges(g2, var["directed"].as<bool>()).size();
elapsed_time += std::chrono::duration_cast<std::chrono::duration<double>>(finish - start).count();
}
} }
//graph_to_file(var, elapsed_time, compression_rate, edges_compressed);
// graph_to_file(var, elapsed_time, compression_rate, edges_compressed);
// cout << "compression rate: " << compression_rate << endl; // cout << "compression rate: " << compression_rate << endl;
cout <<endl << "compression time: " << elapsed_time/NUM_TRIALS << endl; cout <<endl << "compression time: " << elapsed_time/NUM_TRIALS << endl;
cout << "Average of compressed edges: " << edges_compressed/NUM_TRIALS; cout << "Average of compressed edges: " << edges_compressed/NUM_TRIALS;
......
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