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
No related merge requests found
......@@ -5,8 +5,7 @@
#include "io.h"
#include <string>
#include "hash.h"
#include <pthread.h>
#include <omp.h>
#define NUM_TRIALS 10
......@@ -14,22 +13,11 @@
using namespace std;
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[]) {
srand((unsigned)time(NULL));
pthread_t threads[NUM_TRIALS];
po::options_description desc("Allowed options");
desc.add_options()
......@@ -71,42 +59,49 @@ int main(int argc, char *argv[]) {
double elapsed_time = 0;
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>();
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") {
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>());
} 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>());
} else if (execMode == "SA") {
g2 = Simulated_annealing(1000, 10, 0.99, g, var["directed"].as<bool>(), var["depth"].as<int>(),
var["proportions"].as<vector<double>>());
}else if (execMode == "Greedy") {
g2 = compress_graph_greedy(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
var["proportions"].as<std::vector<double>>());
} else if (execMode == "Greedy") {
g2 = compress_graph_greedy(g, var["depth"].as<int>(), var["proportions"].as<std::vector<double>>(),
var["directed"].as<bool>());
}
auto finish = 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();
auto finish = std::chrono::steady_clock::now();
elapsed_time += chrono::duration_cast<chrono::duration<double>>(finish - start).count();
// compression_rate = ((double) (edges_original.size() - edges_compressed.size()) /
// edges_original.size());
// c.push_back(compression_rate);
// s.push_back(edges_compressed);
// Update edges_compressed and elapsed_time in a thread-safe manner
#pragma omp critical
{
vector<edge> edges_original = get_edges(g, var["directed"].as<bool>());
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 <<endl << "compression time: " << elapsed_time/NUM_TRIALS << endl;
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