// File: /workspace/github_cpp_makefile_star2_O3/sebastienmeyer2[P]mst-clustering/src/compare_clustering.cpp
// Function: compare_clustering(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void compare_clustering(std::string file_to_read, int k)
{
    /*!
     * @brief From a file given as entry and an integer k for the number of 
     * clusters to draw, establishes a comparison between kmeans and MST clustering
     * 
     * @param file_to_read Path to the data
     * @param k Number of clusters to draw
     * 
     */

	// get points from datafile

	std::ifstream is(file_to_read);
	assert(is.is_open());

	std::string header_line;
	std::getline(is, header_line);

	const int d = nb_columns(header_line) - 1;
    Point::d = d;

    std::vector<Point*> points = Point::read_points_from_file(file_to_read, d);
    int n = points.size();

    // run MST clustering 

    std::chrono::steady_clock::time_point graph_creation = std::chrono::steady_clock::now();

    std::cout << "\nCreating graph...";
    Graph* g = new Graph(points);
    std::cout << "[OK]" << std::endl;

    std::chrono::steady_clock::time_point kruskal_algo = std::chrono::steady_clock::now();

    KruskalAlgorithm kruskal = KruskalAlgorithm(g);
    kruskal.compute_mst();

    std::chrono::steady_clock::time_point kruskal_clustering = std::chrono::steady_clock::now();

    std::unordered_map<Node*, Node*> clusters = kruskal.compute_clustering(k);

    std::chrono::steady_clock::time_point mst_end = std::chrono::steady_clock::now();

    // run kmeans 

    std::chrono::steady_clock::time_point cloud_creation = std::chrono::steady_clock::now();

    std::cout << "\nCreating cloud...";

    Cloud cloud = Cloud(d, n, k);

    int label = 0;
    for (int i = 0; i < n; i ++) {
        cloud.add_point(*points[i], label);
        label = (label+1) % k;
    }

    std::cout << "[OK]" << std::endl;

    std::chrono::steady_clock::time_point kmeans_algo = std::chrono::steady_clock::now();

    cloud.kmeans();

    std::chrono::steady_clock::time_point kmeans_end = std::chrono::steady_clock::now();

    // comparison

    std::cout << "\nTotal time spent by MST clustering including graph creation: ";
    std::cout << std::chrono::duration_cast<std::chrono::microseconds>(mst_end - graph_creation).count() << " µs" << std::endl;

    std::cout << "Total time spent by MST clustering: ";
    std::cout << std::chrono::duration_cast<std::chrono::microseconds>(mst_end - kruskal_algo).count() << " µs" << std::endl;

    double mst_variance = intracluster_variance(clusters);
    std::cout << "Intracluster variance in MST: ";
    std::cout << mst_variance << std::endl;

    double mst_silhouette = silhouette(clusters);
    std::cout << "Silhouette in MST: ";
    std::cout << mst_silhouette << std::endl;

    std::cout << "\nTotal time spent by kmeans including cloud creation: ";
    std::cout << std::chrono::duration_cast<std::chrono::microseconds>(kmeans_end - cloud_creation).count() << " µs" << std::endl;

    std::cout << "Total time spent by kmeans: ";
    std::cout << std::chrono::duration_cast<std::chrono::microseconds>(kmeans_end - kmeans_algo).count() << " µs" << std::endl;

    double kmeans_variance = cloud.intracluster_variance();
    std::cout << "Intracluster variance in kmeans: ";
    std::cout << kmeans_variance << std::endl;

    double kmeans_silhouette = cloud.silhouette();
    std::cout << "Silhouette in kmeans: ";
    std::cout << kmeans_silhouette << std::endl;

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x260(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x3430
leaq 0x2d8(%rsp), %rdi
callq 0x3080
testb %al, %al
je 0xfe31
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x260(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %edx
leaq 0x260(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x34c0
movq 0x28(%rsp), %r15
testq %r15, %r15
je 0xf71d
movq 0x20(%rsp), %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
movzbl (%r12,%r13), %edi
callq 0x3060
cmpl $0x1, %eax
sbbl $-0x1, %r14d
incq %r13
cmpq %r13, %r15
jne 0xf6ff
incl %r14d
jmp 0xf723
movl $0x1, %r14d
leaq 0x7b7e(%rip), %rax      # 0x172a8
movl %r14d, (%rax)
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0x5610
leaq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movl %r14d, %edx
callq 0x3b80
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xf782
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %r15
subq 0x8(%rsp), %r15
callq 0x3380
movq %rax, %r13
movq 0x781d(%rip), %rdi      # 0x16fb8
leaq 0x22e0(%rip), %rsi      # 0x11a82
movl $0x12, %edx
callq 0x32d0
movl $0xe8, %edi
callq 0x3280
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10972
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x4978
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xf7ec
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x77c5(%rip), %r12      # 0x16fb8
leaq 0x1f99(%rip), %rsi      # 0x11793
movl $0x4, %edx
movq %r12, %rdi
callq 0x32d0
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq 0x7792(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r12
leaq 0x158(%rsp), %rdi
movq %rbx, %rsi
callq 0xce20
leaq 0x158(%rsp), %rdi
callq 0xce36
callq 0x3380
leaq 0xb0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movl %ebp, %edx
callq 0xa9ae
movq %r13, (%rsp)
callq 0x3380
movq %rax, %rbx
callq 0x3380
movq %rax, 0x40(%rsp)
movq 0x7727(%rip), %rdi      # 0x16fb8
leaq 0x21fd(%rip), %rsi      # 0x11a95
movl $0x12, %edx
callq 0x32d0
movq %r12, 0x48(%rsp)
shrq $0x3, %r15
leaq 0x70(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movl %ebp, %ecx
callq 0xe620
testl %r15d, %r15d
jle 0xf8fc
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
leaq 0x70(%rsp), %r14
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movl %r12d, %edx
callq 0xe808
incl %r12d
movl %r12d, %eax
cltd
idivl %ebp
incq %r13
movl %edx, %r12d
cmpq %r13, %r15
jne 0xf8d4
movq 0x76b5(%rip), %r14      # 0x16fb8
leaq 0x1e89(%rip), %rsi      # 0x11793
movl $0x4, %edx
movq %r14, %rdi
callq 0x32d0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq 0x7683(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0xec54
movq (%rsp), %r12
callq 0x3380
movq %rax, %r15
movq 0x7651(%rip), %rdi      # 0x16fb8
leaq 0x213a(%rip), %rsi      # 0x11aa8
movl $0x3e, %edx
callq 0x32d0
movq %rbx, %rax
subq %r12, %rax
movabsq $0x20c49ba5e353f7cf, %rbp # imm = 0x20C49BA5E353F7CF
imulq %rbp
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x7618(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %r12
leaq 0x1e21(%rip), %rsi      # 0x117d0
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x75cd(%rip), %rdi      # 0x16fb8
leaq 0x20f5(%rip), %rsi      # 0x11ae7
movl $0x24, %edx
callq 0x32d0
subq 0x48(%rsp), %rbx
movq %rbx, %rax
imulq %rbp
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x759c(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1da5(%rip), %rsi      # 0x117d0
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
xorl %eax, %eax
leaq 0x120(%rsp), %rdi
movq %rax, (%rdi)
leaq 0xb0(%rsp), %rsi
movq 0x8(%rsi), %rcx
movq 0x18(%rsi), %rdx
movq %rcx, 0x8(%rdi)
movq %rax, 0x10(%rdi)
movq %rdx, 0x18(%rdi)
movups 0x20(%rsi), %xmm0
movups %xmm0, 0x20(%rdi)
movq %rax, 0x30(%rdi)
leaq 0x68(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x109f2
leaq 0x120(%rsp), %rdi
callq 0x954a
movsd %xmm0, (%rsp)
leaq 0x120(%rsp), %rdi
callq 0x90a2
movq 0x74f1(%rip), %rdi      # 0x16fb8
leaq 0x203e(%rip), %rsi      # 0x11b0c
movl $0x1e, %edx
callq 0x32d0
movq 0x74d9(%rip), %rdi      # 0x16fb8
movsd (%rsp), %xmm0
callq 0x3420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0xd0(%rsp), %rax
xorl %ecx, %ecx
leaq 0xe8(%rsp), %rdi
movq %rcx, (%rdi)
movq -0x18(%rax), %rdx
movq -0x8(%rax), %rsi
movq %rdx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movq %rsi, 0x18(%rdi)
movups (%rax), %xmm0
movups %xmm0, 0x20(%rdi)
movq %rcx, 0x30(%rdi)
leaq 0x68(%rsp), %rdx
movq %rdi, (%rdx)
leaq 0xb0(%rsp), %rsi
callq 0x109f2
leaq 0xe8(%rsp), %rdi
callq 0x99f0
movsd %xmm0, (%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x90a2
movq 0x7436(%rip), %rdi      # 0x16fb8
leaq 0x1fa2(%rip), %rsi      # 0x11b2b
movl $0x13, %edx
callq 0x32d0
movq 0x741e(%rip), %rdi      # 0x16fb8
movsd (%rsp), %xmm0
callq 0x3420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x73e3(%rip), %rdi      # 0x16fb8
leaq 0x1f63(%rip), %rsi      # 0x11b3f
movl $0x36, %edx
callq 0x32d0
movq %r15, %rax
subq 0x40(%rsp), %rax
imulq %rbp
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x73b2(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1bbb(%rip), %rsi      # 0x117d0
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x7368(%rip), %rdi      # 0x16fb8
leaq 0x1f1f(%rip), %rsi      # 0x11b76
movl $0x1c, %edx
callq 0x32d0
subq %r14, %r15
movq %r15, %rax
imulq %rbp
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x7339(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1b42(%rip), %rsi      # 0x117d0
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x70(%rsp), %rdi
callq 0xe8f2
movsd %xmm0, (%rsp)
movq 0x72e0(%rip), %rdi      # 0x16fb8
leaq 0x1eb4(%rip), %rsi      # 0x11b93
movl $0x21, %edx
callq 0x32d0
movq 0x72c8(%rip), %rdi      # 0x16fb8
movsd (%rsp), %xmm0
callq 0x3420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x70(%rsp), %rdi
callq 0xf388
movsd %xmm0, (%rsp)
movq 0x727e(%rip), %rdi      # 0x16fb8
leaq 0x1e74(%rip), %rsi      # 0x11bb5
movl $0x16, %edx
callq 0x32d0
movq 0x7266(%rip), %rdi      # 0x16fb8
movsd (%rsp), %xmm0
callq 0x3420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
leaq 0x70(%rsp), %rdi
callq 0xe760
leaq 0xb0(%rsp), %rdi
callq 0x90a2
leaq 0x6ee4(%rip), %rax      # 0x16c88
leaq 0x168(%rsp), %rbx
movq %rax, -0x10(%rbx)
leaq 0x210(%rsp), %rdi
callq 0x522c
leaq 0x1d8(%rsp), %rdi
callq 0x51bc
leaq 0x1a0(%rsp), %rdi
callq 0x529c
movq %rbx, %rdi
callq 0x530c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfdf6
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xfe12
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x260(%rsp), %rdi
callq 0x3090
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bf8(%rip), %rdi      # 0x11a30
leaq 0x1bfe(%rip), %rsi      # 0x11a3d
leaq 0x1c12(%rip), %rcx      # 0x11a58
movl $0x1f, %edx
callq 0x3170
movq %rax, %r14
leaq 0xe8(%rsp), %rdi
jmp 0xfe68
movq %rax, %r14
leaq 0x120(%rsp), %rdi
callq 0x90a2
jmp 0xfefd
jmp 0xfefa
jmp 0xfe79
movq %rax, %r14
jmp 0xff07
jmp 0xfe83
movq %rax, %r14
jmp 0xff14
jmp 0xfeed
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xfeac
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
jmp 0xfeac
movq %rax, %r14
movl $0xe8, %esi
movq %rbx, %rdi
callq 0x3290
jmp 0xff21
jmp 0xfeed
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xff38
movq 0xa0(%rsp), %rsi
incq %rsi
jmp 0xff33
jmp 0xfede
jmp 0xfefa
movq %rax, %r14
jmp 0xff38
jmp 0xfefa
jmp 0xfefa
jmp 0xfefa
jmp 0xfefa
jmp 0xfefa
movq %rax, %r14
jmp 0xff21
jmp 0xfefa
jmp 0xfefa
jmp 0xfefa
jmp 0xfefa
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0xe760
leaq 0xb0(%rsp), %rdi
callq 0x90a2
leaq 0x158(%rsp), %rdi
callq 0x8f38
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xff38
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xff54
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x260(%rsp), %rdi
callq 0x3090
movq %r14, %rdi
callq 0x34a0