Skip to content
Snippets Groups Projects
Commit 6f06be83 authored by gianlucarossi15's avatar gianlucarossi15
Browse files

minor changes

parent 15aee6d8
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <chrono>
#include "p_k_compression.h"
#include <boost/program_options.hpp>
#include "graph.h"
#include "io.h"
#include <sstream>
#include <string>
#include <fstream>
#include "hash.h"
#include <pthread.h>
#define NUM_TRIALS 10
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()
......@@ -51,45 +63,51 @@ int main(int argc, char *argv[]) {
vector<int> s ;
vector<double> c ;
// perform 30 experiments
for (int i =0; i<30;i++) {
cout << i << endl;
string file_name = var["input"].as<string>() + to_string(i) + ".txt";
double compression_rate = 0;
auto[g, e_s] = read_graph_from_file(file_name, var["directed"].as<bool>());
auto start = chrono::steady_clock::now();
if (var["algorithm"].as<string>() == "Random") {
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>();
for (int i=0; i<NUM_TRIALS; i++) {
pthread_create(&threads[i], NULL, handler, NULL);
if (execMode == "Random") {
g2 = compress_graph_basic(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
var["directed"].as<bool>());
} else if (var["algorithm"].as<string>() == "LP") {
} else if (execMode == "LP") {
g2 = compress_graph_LP(g, e_s, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
var["directed"].as<bool>());
var["directed"].as<bool>());
} else if (var["algorithm"].as<string>() == "SA") {
} 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 (var["algorithm"].as<string>() == "Greedy") {
}else if (execMode == "Greedy") {
g2 = compress_graph_greedy(g, var["depth"].as<int>(), var["proportions"].as<vector<double>>(),
var["directed"].as<bool>());
var["directed"].as<bool>());
}
auto finish = chrono::steady_clock::now();
vector<edge> edges_original = get_edges(g, var["directed"].as<bool>());
vector<edge> edges_compressed = get_edges(g2, var["directed"].as<bool>());
double 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.size());
//graph_to_file(var, elapsed_time, compression_rate, edges_compressed);
cout << "compression time " << elapsed_time << endl;
cout << "compression rate " << compression_rate << endl;
edges_compressed += get_edges(g2, var["directed"].as<bool>()).size();
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);
}
for (int i = 0 ; i<30;i++) cout << c.at(i) << '\t' << s.at(i) << endl;
return 0;
//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;
}
......@@ -10,7 +10,7 @@ ptSpar is a C++ program implementing a Neighborhood-Preserving Graph Sparsificat
## Compilation
1. **Install Boost Library:** Ensure the Boost Program Options library is installed on your system.
2. **Compilation Command:** In the source directory, compile using `g++ -std=c++11 main.c++ -o ptSpar -lboost_program_options`.
2. **Compilation Command:** In the source directory, compile using `g++ -std=c++11 main.cpp -o ptSpar -lboost_program_options`.
## Usage
- **Basic Command Structure:**
......
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