<commit_before>#include <iostream>
#include "jlog.hpp"
#include "common.hpp"
#include "algorithm/distance_without_bit_parallel.hpp"
#include "algorithm/distance_with_bit_parallel.hpp"
#include "gflags/gflags.h"
#include <unordered_map>
#include <numeric>
#include <algorithm>
using namespace std;

DEFINE_string(graph_file, "-", "Input graph file");
DEFINE_int32(num_queries, 10000, "The number of vertex pairs.");
DEFINE_int32(num_updates,  100, "The number of dynamic updates.");
DEFINE_int32(num_trials ,  3, "The number of trials.");
DEFINE_int32(max_i, 5, "");


int main(int argc, char *argv[]) {
  JLOG_INIT(&argc, argv);
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  vector<pair<int, int> > es;
  vector<int> sources, targets, answers;
  int n;
  JLOG_PUT_BENCHMARK("setting.read_time") {
    n = ReadGraph(FLAGS_graph_file, es);
  }
  
  JLOG_PUT("setting.dataset", FLAGS_graph_file);
  JLOG_PUT("setting.num_vs", n);
  JLOG_PUT("setting.num_es", es.size());
  JLOG_PUT("setting.num_queries", FLAGS_num_queries);

  srand(0);
  for (int q = 0; q < FLAGS_num_queries; q++) {
    sources.push_back(rand() % n);
    targets.push_back(rand() % n);
  }

  // prepare distances for validation
  JLOG_PUT_BENCHMARK("time.prepare_answer") {
    GraphDistance<20> bps(n, es);
    for (int q = 0; q < FLAGS_num_queries; q++) {
      answers.push_back(bps.QueryDistance(sources[q], targets[q]));
    }
  }


  vector<int> dists(FLAGS_num_queries);
  vector<vector<pair<int, int > > > del_ess, ins_ess;
  for (int trial = 0; trial < FLAGS_num_trials; trial++) {
    random_shuffle(es.begin(), es.end());
    vector<pair<int, int> > upd_es(es.end() - FLAGS_num_updates, es.end());
    del_ess.push_back(upd_es);
    reverse(upd_es.begin(), upd_es.end());
    ins_ess.push_back(upd_es);
  }


  for (int i = 0; i <= FLAGS_max_i; i++) {
    string is = "reduction_" + to_string(i);
    
    JLOG_OPEN(is.c_str()) {
      GraphDistance<20, BitParallelLandmarks<20, DegreeLS<64>> > bpd;
      JLOG_PUT_BENCHMARK("time.construct") {
        bpd.Build(n, es, i);
      }
      JLOG_PUT("index_size", bpd.IndexSize());
      JLOG_PUT("graph_size", bpd.GraphSize());
      JLOG_PUT("memory_usage", jlog_internal::get_memory_usage());
      JLOG_PUT("initial_degree", bpd.DegreeSum());

      for (int trial = 0; trial < FLAGS_num_trials; trial++) {
        double q_start = jlog_internal::get_current_time_sec();<commit_msg>Fix duplicated edge updates in a benchmarker<commit_after>#include <iostream>
#include "jlog.hpp"
#include "common.hpp"
#include "algorithm/distance_without_bit_parallel.hpp"
#include "algorithm/distance_with_bit_parallel.hpp"
#include "gflags/gflags.h"
#include <unordered_map>
#include <numeric>
#include <algorithm>
using namespace std;

DEFINE_string(graph_file, "-", "Input graph file");
DEFINE_int32(num_queries, 10000, "The number of vertex pairs.");
DEFINE_int32(num_updates,  100, "The number of dynamic updates.");
DEFINE_int32(num_trials ,  3, "The number of trials.");
DEFINE_int32(max_i, 5, "");


int main(int argc, char *argv[]) {
  JLOG_INIT(&argc, argv);
  gflags::ParseCommandLineFlags(&argc, &argv, true);
  if (!FLAGS_undirected) {
    cerr << "The option --undirected must be specified to run this script." << endl;
    return 1;
  }

  vector<pair<int, int> > es;
  vector<int> sources, targets, answers;
  int n;
  JLOG_PUT_BENCHMARK("setting.read_time") {
    n = ReadGraph(FLAGS_graph_file, es);
  }
  
  JLOG_PUT("setting.dataset", FLAGS_graph_file);
  JLOG_PUT("setting.num_vs", n);
  JLOG_PUT("setting.num_es", es.size());
  JLOG_PUT("setting.num_queries", FLAGS_num_queries);

  srand(0);
  for (int q = 0; q < FLAGS_num_queries; q++) {
    sources.push_back(rand() % n);
    targets.push_back(rand() % n);
  }

  // prepare distances for validation
  JLOG_PUT_BENCHMARK("time.prepare_answer") {
    GraphDistance<20> bps(n, es);
    for (int q = 0; q < FLAGS_num_queries; q++) {
      answers.push_back(bps.QueryDistance(sources[q], targets[q]));
    }
  }
  
  
  vector<int> dists(FLAGS_num_queries);
  vector<vector<pair<int, int > > > del_ess, ins_ess;
  for (int trial = 0; trial < FLAGS_num_trials; trial++) {
    vector<pair<int, int> > tmp_es = es;
    for (auto &e: tmp_es) {
      int source = min(e.fst, e.snd);
      int target = max(e.fst, e.snd);
      e = make_pair(source, target);
    }
    sort(tmp_es.begin(), tmp_es.end());
    tmp_es.erase(unique(tmp_es.begin(), tmp_es.end()), tmp_es.end());
    random_shuffle(tmp_es.begin(), tmp_es.end());

    if (tmp_es.size() < size_t(FLAGS_num_updates)) {
      cerr << "FLAGS_num_updates must be smaller than the number of unique undirected edges." << endl;
      return 1;
    }
    
    vector<pair<int, int> > upd_es(tmp_es.end() - FLAGS_num_updates, tmp_es.end());
    del_ess.push_back(upd_es);
    reverse(upd_es.begin(), upd_es.end());
    ins_ess.push_back(upd_es);
  }


  for (int i = 0; i <= FLAGS_max_i; i++) {
    string is = "reduction_" + to_string(i);
    
    JLOG_OPEN(is.c_str()) {
      GraphDistance<20, BitParallelLandmarks<20, DegreeLS<64>> > bpd;
      JLOG_PUT_BENCHMARK("time.construct") {
        bpd.Build(n, es, i);
      }
      JLOG_PUT("index_size", bpd.IndexSize());
      JLOG_PUT("graph_size", bpd.GraphSize());
      JLOG_PUT("memory_usage", jlog_internal::get_memory_usage());
      JLOG_PUT("initial_degree", bpd.DegreeSum());

      for (int trial = 0; trial < FLAGS_num_trials; trial++) {
        double q_start = jlog_internal::get_current_time_sec();
{'fraction_non_alphanumeric': 0.15689122934447067, 'fraction_numerical': 0.011984746686035955, 'mean_word_length': 4.23574144486692, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7308480', 'n_tokens_mistral': 2150, 'n_tokens_neox': 2055, 'n_words': 401}