Skip to content

Commit

Permalink
parsimonious version
Browse files Browse the repository at this point in the history
  • Loading branch information
D-hash committed Feb 20, 2024
1 parent 4177c67 commit 7c256ab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
41 changes: 23 additions & 18 deletions incremental_topk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ void IncrementalTopK::deallocate_aux() {

}

uint64_t IncrementalTopK::compute_index_size() {
uint64_t sz = 0;
for (size_t dir = 0; dir < 1 + directed; dir++){
for(vertex i=0;i<graph->numberOfNodes();i++){
sz += this->loop_labels[i].size() * sizeof(dist); // loopcount
sz += this->length_labels[dir][i].label_offset.size() * (sizeof(vertex)+sizeof(dist)); // label_offset count
sz += this->length_labels[dir][i].d_array.size() * sizeof(dist); // array of distances count
}
}
return sz;
}

void IncrementalTopK::build(){

Expand All @@ -200,12 +211,8 @@ void IncrementalTopK::build(){
this->tmp_s_offset[i] = null_distance;
this->tmp_s_count[i].clear();


});
this->tmp_s_offset[graph->numberOfNodes()] = 0;




if(!this->is_from_scratch_only){
this->visited_in_update_loops = new dist[graph->numberOfNodes()];
Expand Down Expand Up @@ -248,13 +255,11 @@ void IncrementalTopK::build(){
ProgressStream loop_bar(graph->numberOfNodes());

loop_bar.label() << "Loops construction";

for(size_t v = 0; v < graph->numberOfNodes(); v++){
this->compute_loop_entries(v);
++loop_bar;
}


loops_time = build_timer.elapsed();

build_timer.restart();
Expand Down Expand Up @@ -358,7 +363,9 @@ inline void IncrementalTopK::compute_loop_entries(vertex s){


inline void IncrementalTopK::pruned_bfs(vertex s, bool reversed){


allocate_label(s, s, 0, 1, reversed);
this->tmp_offset[s] = 0;
set_temp_vars(s, reversed);

vertex curr = 0;
Expand All @@ -383,23 +390,22 @@ inline void IncrementalTopK::pruned_bfs(vertex s, bool reversed){
c = this->tmp_dist_count[curr][v];
this->tmp_dist_count[curr][v] = 0;

if(c == 0 || tmp_pruned[v]){
if(c == 0 || tmp_pruned[v]){
continue;
}
this->tmp_pruned[v] = prune(v, distance, reversed);

if(this->tmp_pruned[v]){
continue;
}

if(this->tmp_offset[v] == null_distance){
this->tmp_offset[v] = distance;
allocate_label(v, s, distance, c, reversed);
}
else{
extend_label(v, s, distance, c, reversed, 0);
if(s!=v) {
if (this->tmp_offset[v] == null_distance) {
this->tmp_offset[v] = distance;
allocate_label(v, s, distance, c, reversed);
} else {
extend_label(v, s, distance, c, reversed, 0);
}
}

for(vertex u : graph->neighborRange(reverse_ordering[v])){
to_vert = ordering[u];
if(this->tmp_count[to_vert] == 0){
Expand All @@ -416,7 +422,7 @@ inline void IncrementalTopK::pruned_bfs(vertex s, bool reversed){

if (this->node_que[next].empty()){
break;
}
}
std::swap(curr, next);
distance++;
}
Expand Down Expand Up @@ -747,7 +753,6 @@ inline bool IncrementalTopK::prune(vertex v, dist d, bool rev){
int l = dcs.size() - 1;
int c = d - tmp_s_offset[w] - idv.label_offset[pos].second;

// By using precomputed table tmp_s_count, compute the number of path with a single loop.
for (int i = 0; i <= c && i < idv.d_array[pos].size(); i++){
pcount += (int)dcs[std::min(c - i, l)] * idv.d_array[pos][i];
}
Expand Down
2 changes: 1 addition & 1 deletion incremental_topk.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class IncrementalTopK{
void update_lengths();



uint64_t compute_index_size();

double n_reached_nodes();
double n_reached_nodes_mbfs();
Expand Down
20 changes: 10 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ int main(int argc, char **argv) {
IncrementalTopK* kpll = new IncrementalTopK(graph, K, directed,ordering, false);

kpll->build();

uint64_t index_size = kpll->compute_index_size();
std::cout << "First Labeling Loop time: " << kpll->loops_time << " s | First Labeling Indexing time: " << kpll->lengths_time<< " s\n";
std::cout << "First Labeling Loop entries: " << kpll->loop_entries<<" First Labeling Length Entries: "<<kpll->length_entries<< "\n";
std::cout << "First Labeling Loop entries: " << 0 <<" First Labeling Length Entries: "<< index_size << "\n";
std::cout << "Number of Vertices: " << graph->numberOfNodes() << "\n";

std::string order_string;
Expand Down Expand Up @@ -332,7 +332,7 @@ int main(int argc, char **argv) {

ofs << "G,V,E,K,Insertions,x,y,UTLoops,UTLengths,ULoopsSize,ULengthSize,UAvgQT,UMedQT,affhubs,reached,affcycles,reachedMbfs\n";
ofs << graph_location << "," << graph->numberOfNodes() << "," << graph->numberOfEdges() << "," << K << "," << 0 << ","
<< 0 << "," << 0 << "," << kpll->loops_time << "," << kpll->lengths_time << "," << kpll->loop_entries << "," << kpll->length_entries << ","
<< 0 << "," << 0 << "," << kpll->loops_time << "," << kpll->lengths_time << "," << 0 << "," << index_size << ","
<< 0 << "," << 0 << "," << 0 << "," << 0 << "," << 0 << "," << 0 << "\n";


Expand All @@ -352,7 +352,6 @@ int main(int argc, char **argv) {


mytimer time_counter;

for(size_t t=0;t<to_add.size();t++){

kpll->x = to_add[t].first;
Expand All @@ -374,8 +373,8 @@ int main(int argc, char **argv) {
std::cout << "done! \nUpdate lengths time: " << time_counter.elapsed()<<"\n"<<std::flush;
std::cout << t+1 << "-th insertion correct!" << "\n";

index_loops_size.push_back(kpll->loop_entries);
index_lengths_size.push_back(kpll->length_entries);
index_loops_size.push_back(0);
index_lengths_size.push_back(kpll->compute_index_size());

affected_hubs.push_back(kpll->aff_hubs);
reached_nodes.push_back(kpll->n_reached_nodes());
Expand Down Expand Up @@ -404,20 +403,21 @@ int main(int argc, char **argv) {
dists.emplace_back(distances);
++query_bar;
}
vertex final_loop_entries = kpll->loop_entries, final_aff_hubs = kpll->aff_hubs, final_aff_cycles = kpll->aff_cycles;
vertex final_loop_entries = 0, final_aff_hubs = kpll->aff_hubs, final_aff_cycles = kpll->aff_cycles;
double final_reached = kpll->n_reached_nodes();
double final_reached_mbfs = kpll->n_reached_nodes_mbfs();
vertex final_leng_entries = kpll->length_entries;
uint64_t final_leng_entries = kpll->compute_index_size();
delete kpll;

IncrementalTopK* scratch_kpll = new IncrementalTopK(graph, K, directed, ordering, true);

scratch_kpll->build();
//OK, no updates
index_size = scratch_kpll->compute_index_size();
scratch_kpll->deallocate_aux();

std::cout << "From Scratch Loop time: " << scratch_kpll->loops_time << " s | From Scratch Indexing time: "<< scratch_kpll->lengths_time<< " s\n";
std::cout << "From Scratch Loop entries: " << scratch_kpll->loop_entries<<" From Scratch Length Entries: "<<scratch_kpll->length_entries<< "\n";
std::cout << " From Scratch Total Entries: "<< index_size << "\n";

assert(queries.size()==num_queries);
assert(dists.size()==num_queries);
Expand Down Expand Up @@ -476,7 +476,7 @@ int main(int argc, char **argv) {
<< graph->numberOfEdges() << ","
<< K << ","
<< num_insertions << ","
<< "scratch" << "," << "scratch" << "," << scratch_kpll->loops_time << "," << scratch_kpll->lengths_time << "," << scratch_kpll->loop_entries << "," << scratch_kpll->length_entries << ","
<< "scratch" << "," << "scratch" << "," << scratch_kpll->loops_time << "," << scratch_kpll->lengths_time << "," << 0 << "," << scratch_kpll->compute_index_size() << ","
<< average(sl_time) << ","
<< median(sl_time) << ",scratch,scratch,scratch,scratch\n";
std::cout << "done!\n";
Expand Down

0 comments on commit 7c256ab

Please sign in to comment.