// File: pollo[P]graph-partitioning/run_experiment.cpp
// Function: main
int main(int argc, char** argv)
{
  Graph graph;

  if (argc != 2)
  {
    printf("Invalid number of parameters\n");
    printf("Usage: %s <dataset file>\n",
           argv[0]);
    exit(1);
  }

  if (strstr(argv[1],"twitter") != NULL)
    twitter_loader(&graph);
  else if (strstr(argv[1],"4elt") != NULL)
    elt_loader(&graph);
  else
    snap_loader(&graph, argv[1]);

  //printf("Dataset;Experiment #;Heuristic;K;Edge cut;"           
  //       "Communication Volume; Normalized Maximum Load;Runtime\n");
  for (int experiment = 1; experiment<=N_EXPERIMENTS; experiment++)
  {
    for (int heuristic = 0; heuristic<3; heuristic++)
    {
      for (int partitions_number = 2;
           partitions_number<=1024;
           partitions_number *= 2)
      {
        Partition partition;
        time_t start = time(0);
        const char* h_name;

        if (heuristic == 0)
        {
          linear_deterministic_greedy(graph,
                                      partitions_number,
                                      &partition);
          h_name = "LDG";
        }
        else if (heuristic == 1)
        {
          fennel(graph,
                 partitions_number,
                 &partition);
          h_name = "FENNEL";
        }
        else
        {
          non_neighbors_greedy(graph,
                               partitions_number,
                               &partition);
          h_name = "NNEIGHBORS";
        }
        time_t end = time(0);
        int time = difftime(end, start);

        double fraction_edges_cut = graph.get_fraction_edges_cut(partition);
        double communication_volume = graph.get_communication_volume(partition);
        double maximum_load = graph.get_normalized_maximum_load(partition);

        printf("%s;%d;%s;%d;%lf;%lf;%lf;%d\n",
               argv[1], experiment, h_name, partitions_number,
               fraction_edges_cut, communication_volume, maximum_load, time);

      }
    }
  }


  return 0;
}

// Assembly:
subq $0xd8, %rsp
movl $0x0, 0xd4(%rsp)
movl %edi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x27a0
cmpl $0x2, 0xd0(%rsp)
je 0x2436
leaq 0x9c15(%rip), %rdi      # 0xc004
xorl %eax, %eax
callq 0x2030
jmp 0x23f8
movq 0xc8(%rsp), %rax
movq (%rax), %rsi
leaq 0x9c18(%rip), %rdi      # 0xc022
xorl %eax, %eax
callq 0x2030
jmp 0x2413
movl $0x1, %edi
callq 0x21c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x271d
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9bf3(%rip), %rsi      # 0xc03c
callq 0x2060
cmpq $0x0, %rax
je 0x2465
leaq 0xa0(%rsp), %rdi
callq 0x7dd0
jmp 0x2463
jmp 0x24b3
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x9bcc(%rip), %rsi      # 0xc044
callq 0x2060
cmpq $0x0, %rax
je 0x2494
leaq 0xa0(%rsp), %rdi
callq 0x7ba0
jmp 0x2492
jmp 0x24b1
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x7950
jmp 0x24af
jmp 0x24b1
jmp 0x24b3
movl $0x1, 0x90(%rsp)
cmpl $0xa, 0x90(%rsp)
jg 0x26f6
movl $0x0, 0x8c(%rsp)
cmpl $0x3, 0x8c(%rsp)
jge 0x26de
movl $0x2, 0x88(%rsp)
cmpl $0x400, 0x88(%rsp) # imm = 0x400
jg 0x26c6
leaq 0x50(%rsp), %rdi
callq 0x2740
xorl %eax, %eax
movl %eax, %edi
callq 0x2140
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x8c(%rsp)
jne 0x256f
movl 0x88(%rsp), %esi
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x8ea0
jmp 0x253e
leaq 0x9b04(%rip), %rax      # 0xc049
movq %rax, 0x40(%rsp)
jmp 0x25cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x2770
jmp 0x271d
cmpl $0x1, 0x8c(%rsp)
jne 0x25a2
movl 0x88(%rsp), %esi
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x9720
jmp 0x2594
leaq 0x9ab2(%rip), %rax      # 0xc04d
movq %rax, 0x40(%rsp)
jmp 0x25c9
movl 0x88(%rsp), %esi
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x9390
jmp 0x25bd
leaq 0x9a90(%rip), %rax      # 0xc054
movq %rax, 0x40(%rsp)
jmp 0x25cb
xorl %eax, %eax
movl %eax, %edi
callq 0x2140
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x20c0
cvttsd2si %xmm0, %eax
movl %eax, 0x34(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x3560
movsd %xmm0, 0x10(%rsp)
jmp 0x260a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x36a0
movsd %xmm0, 0x8(%rsp)
jmp 0x2630
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x39c0
movsd %xmm0, (%rsp)
jmp 0x2655
movsd (%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xc8(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x90(%rsp), %edx
movq 0x40(%rsp), %rcx
movl 0x88(%rsp), %r8d
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movl 0x34(%rsp), %r9d
leaq 0x99c1(%rip), %rdi      # 0xc05f
movb $0x3, %al
callq 0x2030
jmp 0x26a7
leaq 0x50(%rsp), %rdi
callq 0x2770
movl 0x88(%rsp), %eax
shll %eax
movl %eax, 0x88(%rsp)
jmp 0x24f0
jmp 0x26c8
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0x24d7
jmp 0x26e0
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x24be
movl $0x0, 0xd4(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x27d0
movl 0xd4(%rsp), %eax
addq $0xd8, %rsp
retq
leaq 0xa0(%rsp), %rdi
callq 0x27d0
movq 0x98(%rsp), %rdi
callq 0x2250
nopw (%rax,%rax)