-
gianlucarossi15 authored1aaa824f
main.cpp 3.51 KiB
#include <iostream>
#include "p_k_compression.h"
#include <boost/program_options.hpp>
#include "graph.h"
#include "io.h"
#include <string>
#include "hash.h"
#include <omp.h>
#define NUM_TRIALS 10
using namespace std;
namespace po = boost::program_options;
int main(int argc, char *argv[]) {
srand((unsigned)time(NULL));
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("input", po::value<string>(), "graph file name")
("directed", po::value<bool>()->default_value(true), "is the graph directed?")
("algorithm",po::value<string>()->default_value("Random"), "The compression Algorithm")
("depth",po::value<int>()->default_value(2),"the depth of the compression")
("proportions",po::value<std::vector<double> >()->multitoken(),"the preserving proportions")
("output_file",po::value<string>(), "the path of the compressed graph");
po::variables_map var;
po::store(po::parse_command_line(argc, argv, desc), var);
po::notify(var);
if(var.count("help")) {
cout << desc << "\n";
return 0;
}
if(!var.count("input")) {
cout << "Missing argument --input.\n";
return 1;
}
if(!var.count("output_file")) {
cout << "Missing argument --output_file.\n";
return 1;
}
graph g2;
vector<int> s ;
vector<double> c ;
int edges_compressed = 0;
string file_name = var["input"].as<string>();
double compression_rate = 0;
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>();
#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<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<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<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 = std::chrono::steady_clock::now();
// 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);
// cout << "compression rate: " << compression_rate << endl;
cout <<endl << "compression time: " << elapsed_time/NUM_TRIALS << endl;
cout << "Average of compressed edges: " << edges_compressed/NUM_TRIALS;
}