// File: /workspace/github_cpp_makefile_star2_O2/fjamour[P]icentral/src/experiments.cc
// Function: insertion_test_qube(graph_t&, int)
void insertion_test_qube(graph_t& graph, int num_edges_to_insert)
{
    //1. prepare structures to store the results for each edge 
    //2. generate random edges
    //3. run Brandes and find time
    //4. run update after each edge insertion and record results
    //5. print the results progressively
    //int num_edges_to_insert = 2;
    
    printf("==========================================================\n");
    printf("Graph: \t\t\t%s\n", graph.graph_name.c_str());
    printf("Graph # nodes: \t\t%d\n", graph.size());
    printf("Graph # edges: \t\t%d\n", graph.edge_set.size());
    double brandes_time, muc_find_time;
    timer tm;
    
    printf("Brandes runtime: \t");
    tm.start();
    vector<double> bc_vec = brandes_betweenness_centrality(graph);
    tm.stop();
    brandes_time = tm.interval();
    printf("%f\n", brandes_time);
    
    printf("# MUCs: \t\t");
    tm.start();
    graph.find_mucs();
    tm.stop();
    muc_find_time = tm.interval();
    printf("%d\n", graph.get_num_mucs());
    printf("Time to find MUCs: \t%f\n", muc_find_time);
    
    vector<edge_t> rand_edge_vec;
    printf("Generating edges..n\n");
    for(int i = 0; i < num_edges_to_insert; ++i) {
        edge_t rand_edge;
        node_id_t src, dst;
        do {
            src = rand()%graph.size();
            dst = rand()%graph.size();
            rand_edge.first    = src;
            rand_edge.second   = dst;
        } while(graph.has_edge(rand_edge));
        rand_edge_vec.push_back(rand_edge);
    }

    vector<edge_stat_t> edge_stat_vec;
    
    //==========================================================
//    node_id_t nd = rand_edge_vec[0].first;
//    muc_id_t muc_id = graph.node_to_muc_vec[nd];
//    graph.muc_vec[muc_id].muc_subgraph.print_graph(false);
//    return;
    //==========================================================
    
    for(int i = 0; i < rand_edge_vec.size(); ++i) {
        edge_t rand_edge = rand_edge_vec[i];
        edge_stat_t edge_stat;
        printf("Adding edge (%d, %d)\n", rand_edge.first, rand_edge.second);
        tm.start();
        graph.insert_edge_update_muc(rand_edge.first, rand_edge.second);
        tm.stop();
        edge_stat.edge_ins_time = tm.interval();
        printf("\tTime to update MUCs: \t%f\n", edge_stat.edge_ins_time);

        muc_id_t muc_id = graph.node_to_muc_vec[rand_edge.first];
        edge_stat.muc_num_edges = graph.muc_vec[muc_id].muc_subgraph.edge_set.size();
        edge_stat.muc_num_nodes = graph.muc_vec[muc_id].muc_subgraph.nodes_map.size();
        tr1::unordered_map<node_id_t, double> bc_map;
        tm.start();
        graph.muc_vec[muc_id].compute_bc(bc_map);
        tm.stop();
        edge_stat.muc_bc_update_time = tm.interval();
        printf("\tTime to update BC: \t%f\n", edge_stat.muc_bc_update_time);
        printf("\tSpeedup: \t\t%f\n", brandes_time/edge_stat.muc_bc_update_time);
        printf("\tMUC # nodes: \t\t%d\n", edge_stat.muc_num_nodes);
        printf("\tMUC # edges: \t\t%d\n", edge_stat.muc_num_edges);
        edge_stat_vec.push_back(edge_stat);
    }
    
    
    double total_muc_update_time = 0;
    for(int i = 0; i < edge_stat_vec.size(); ++i) {
        total_muc_update_time += edge_stat_vec[i].muc_bc_update_time;
    }
    double avg_speedup = (num_edges_to_insert*brandes_time)/total_muc_update_time;
    
    printf("[[Average speedup: %f]]\n", avg_speedup);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %esi, %ebp
movq %rdi, %r14
leaq 0x15c2d(%rip), %rdi     # 0x28b00
callq 0x2360
movq 0x108(%r14), %rsi
leaq 0x1532a(%rip), %rdi     # 0x28210
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x18d3c
leaq 0x15322(%rip), %rdi     # 0x2821e
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
movq 0x58(%r14), %rsi
leaq 0x15322(%rip), %rdi     # 0x28233
xorl %eax, %eax
callq 0x2030
leaq 0x15329(%rip), %rdi     # 0x28248
xorl %eax, %eax
callq 0x2030
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0xb094
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0x8b38
movq %rbx, %rdi
callq 0xb09c
movq %rbx, %rdi
callq 0xb0a8
leaq 0x154bd(%rip), %rdi     # 0x2841a
movsd %xmm0, 0x20(%rsp)
movb $0x1, %al
callq 0x2030
leaq 0x152ea(%rip), %rdi     # 0x2825b
xorl %eax, %eax
callq 0x2030
movq %rbx, %rdi
callq 0xb094
movq %r14, %rdi
callq 0x2058a
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0xb09c
movq %rbx, %rdi
callq 0xb0a8
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x20b20
leaq 0x15333(%rip), %rdi     # 0x282e8
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x1529e(%rip), %rdi     # 0x28266
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x2030
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x15ad0(%rip), %rdi     # 0x28abe
callq 0x2360
testl %ebp, %ebp
movl $0x0, %eax
movl %ebp, 0x1c(%rsp)
cmovgl %ebp, %eax
movl %eax, 0x10(%rsp)
leaq 0x80(%rsp), %r15
cmpl 0x10(%rsp), %ebx
je 0x13085
andq $0x0, 0x80(%rsp)
callq 0x2070
movl %eax, %ebp
movq %r14, %rdi
callq 0x18d3c
movq %rax, %r12
callq 0x2070
movl %eax, %r13d
movq %r14, %rdi
callq 0x18d3c
movq %rax, %rcx
movslq %r13d, %rsi
movslq %ebp, %rax
xorl %edx, %edx
divq %r12
movq %rdx, %rdi
movq %rsi, %rax
xorl %edx, %edx
divq %rcx
movl %edi, 0x80(%rsp)
movl %edx, 0x84(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x191b4
testb %al, %al
jne 0x1301c
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x117e2
incl %ebx
jmp 0x1300d
xorpd %xmm0, %xmm0
leaq 0x40(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0xc8(%rsp), %r13
leaq 0x80(%rsp), %rbx
xorl %r15d, %r15d
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x131f3
movl (%rax,%r15,8), %ebp
movl 0x4(%rax,%r15,8), %r12d
leaq 0x151aa(%rip), %rdi     # 0x2827e
movl %ebp, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2030
movq %r13, %rdi
callq 0xb094
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x20972
movq %r13, %rdi
callq 0xb09c
movq %r13, %rdi
callq 0xb0a8
movsd %xmm0, 0x28(%rsp)
leaq 0x15182(%rip), %rdi     # 0x28294
movb $0x1, %al
callq 0x2030
movq 0x18(%r14), %rax
movq 0x60(%r14), %rcx
movl (%rax,%rbp,4), %eax
imulq $0x568, %rax, %rbp      # imm = 0x568
movl 0xb8(%rcx,%rbp), %eax
movl %eax, 0x3c(%rsp)
movl 0x78(%rcx,%rbp), %eax
movl %eax, 0x38(%rsp)
movq %rbx, %rdi
pushq $0xa
popq %rsi
leaq 0xf(%rsp), %rdx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
callq 0xb770
movq %r13, %rdi
callq 0xb094
addq 0x60(%r14), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
pushq $-0x1
popq %rdx
callq 0x20b58
movq %r13, %rdi
callq 0xb09c
movq %r13, %rdi
callq 0xb0a8
movsd %xmm0, 0x30(%rsp)
leaq 0x15120(%rip), %rdi     # 0x282af
movb $0x1, %al
callq 0x2030
movsd 0x20(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
leaq 0x1511f(%rip), %rdi     # 0x282c8
movb $0x1, %al
callq 0x2030
movl 0x38(%rsp), %esi
leaq 0x1511d(%rip), %rdi     # 0x282d8
xorl %eax, %eax
callq 0x2030
movl 0x3c(%rsp), %esi
leaq 0x1511f(%rip), %rdi     # 0x282ec
xorl %eax, %eax
callq 0x2030
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1637e
movq %rbx, %rdi
callq 0xb070
incq %r15
jmp 0x130aa
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
addq $0x8, %rcx
xorpd %xmm2, %xmm2
movl 0x1c(%rsp), %edx
subq $0x1, %rax
jb 0x13224
addsd (%rcx), %xmm2
addq $0x18, %rcx
jmp 0x13214
cvtsi2sd %edx, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
leaq 0x150c3(%rip), %rdi     # 0x28300
movb $0x1, %al
callq 0x2030
leaq 0x40(%rsp), %rdi
callq 0x16772
leaq 0x60(%rsp), %rdi
callq 0x16656
leaq 0xb0(%rsp), %rdi
callq 0x5754
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x132ae
jmp 0x1327e
movq %rax, %rbx
jmp 0x13295
jmp 0x132a1
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb070
leaq 0x40(%rsp), %rdi
callq 0x16772
jmp 0x132a4
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x16656
leaq 0xb0(%rsp), %rdi
callq 0x5754
movq %rbx, %rdi
callq 0x23d0