// File: /workspace/github_cpp_makefile_star2_O1/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 0xf9ba
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 0xf2a6
movq 0x20(%rsp), %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
movzbl (%r12,%r13), %edi
callq 0x3060
cmpl $0x1, %eax
sbbq $-0x1, %r14
incq %r13
cmpq %r13, %r15
jne 0xf288
incl %r14d
jmp 0xf2ac
movl $0x1, %r14d
leaq 0x7ff5(%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 0x5628
leaq 0x8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movl %r14d, %edx
callq 0x3b80
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xf30b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %r15
subq 0x8(%rsp), %r15
callq 0x3380
movq %rax, %r13
movq 0x7c94(%rip), %rdi      # 0x16fb8
leaq 0x26d7(%rip), %rsi      # 0x11a02
movl $0x12, %edx
callq 0x32d0
movl $0xe8, %edi
callq 0x3280
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10502
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
callq 0x4998
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xf375
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x7c3c(%rip), %r12      # 0x16fb8
leaq 0x23d0(%rip), %rsi      # 0x11753
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 0x7c09(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r12
leaq 0x158(%rsp), %rdi
movq %rbx, %rsi
callq 0xcb58
leaq 0x158(%rsp), %rdi
callq 0xcb6e
callq 0x3380
leaq 0xb0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movl %ebp, %edx
callq 0xa7ee
movq %r13, (%rsp)
callq 0x3380
movq %rax, %rbx
callq 0x3380
movq %rax, 0x40(%rsp)
movq 0x7b9e(%rip), %rdi      # 0x16fb8
leaq 0x25f4(%rip), %rsi      # 0x11a15
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 0xe29c
testl %r15d, %r15d
jle 0xf485
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 0xe480
incl %r12d
movl %r12d, %eax
cltd
idivl %ebp
incq %r13
movl %edx, %r12d
cmpq %r13, %r15
jne 0xf45d
movq 0x7b2c(%rip), %r14      # 0x16fb8
leaq 0x22c0(%rip), %rsi      # 0x11753
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 0x7afa(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0xe8d2
movq (%rsp), %r12
callq 0x3380
movq %rax, %r15
movq 0x7ac8(%rip), %rdi      # 0x16fb8
leaq 0x2531(%rip), %rsi      # 0x11a28
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 0x7a8f(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %r12
leaq 0x2258(%rip), %rsi      # 0x11790
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 0x7a44(%rip), %rdi      # 0x16fb8
leaq 0x24ec(%rip), %rsi      # 0x11a67
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 0x7a13(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x21dc(%rip), %rsi      # 0x11790
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 0x10582
leaq 0x120(%rsp), %rdi
callq 0x9722
movsd %xmm0, (%rsp)
leaq 0x120(%rsp), %rdi
callq 0x91c8
movq 0x7968(%rip), %rdi      # 0x16fb8
leaq 0x2435(%rip), %rsi      # 0x11a8c
movl $0x1e, %edx
callq 0x32d0
movq 0x7950(%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 0x10582
leaq 0xe8(%rsp), %rdi
callq 0x9b1a
movsd %xmm0, (%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x91c8
movq 0x78ad(%rip), %rdi      # 0x16fb8
leaq 0x2399(%rip), %rsi      # 0x11aab
movl $0x13, %edx
callq 0x32d0
movq 0x7895(%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 0x785a(%rip), %rdi      # 0x16fb8
leaq 0x235a(%rip), %rsi      # 0x11abf
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 0x7829(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1ff2(%rip), %rsi      # 0x11790
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 0x77df(%rip), %rdi      # 0x16fb8
leaq 0x2316(%rip), %rsi      # 0x11af6
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 0x77b0(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1f79(%rip), %rsi      # 0x11790
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 0xe568
movsd %xmm0, (%rsp)
movq 0x7757(%rip), %rdi      # 0x16fb8
leaq 0x22ab(%rip), %rsi      # 0x11b13
movl $0x21, %edx
callq 0x32d0
movq 0x773f(%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 0xef10
movsd %xmm0, (%rsp)
movq 0x76f5(%rip), %rdi      # 0x16fb8
leaq 0x226b(%rip), %rsi      # 0x11b35
movl $0x16, %edx
callq 0x32d0
movq 0x76dd(%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 0xe3d8
leaq 0xb0(%rsp), %rdi
callq 0x91c8
leaq 0x735b(%rip), %rax      # 0x16c88
leaq 0x168(%rsp), %rbx
movq %rax, -0x10(%rbx)
leaq 0x210(%rsp), %rdi
callq 0x5246
leaq 0x1d8(%rsp), %rdi
callq 0x51d6
leaq 0x1a0(%rsp), %rdi
callq 0x52b6
movq %rbx, %rdi
callq 0x5326
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xf97f
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xf99b
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 0x1fef(%rip), %rdi      # 0x119b0
leaq 0x1ff5(%rip), %rsi      # 0x119bd
leaq 0x2009(%rip), %rcx      # 0x119d8
movl $0x1f, %edx
callq 0x3170
movq %rax, %r14
leaq 0xe8(%rsp), %rdi
jmp 0xf9f1
movq %rax, %r14
leaq 0x120(%rsp), %rdi
callq 0x91c8
jmp 0xfa86
jmp 0xfa83
jmp 0xfa02
movq %rax, %r14
jmp 0xfa90
jmp 0xfa0c
movq %rax, %r14
jmp 0xfa9d
jmp 0xfa76
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xfa35
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
jmp 0xfa35
movq %rax, %r14
movl $0xe8, %esi
movq %rbx, %rdi
callq 0x3290
jmp 0xfaaa
jmp 0xfa76
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0xfac1
movq 0xa0(%rsp), %rsi
incq %rsi
jmp 0xfabc
jmp 0xfa67
jmp 0xfa83
movq %rax, %r14
jmp 0xfac1
jmp 0xfa83
jmp 0xfa83
jmp 0xfa83
jmp 0xfa83
jmp 0xfa83
movq %rax, %r14
jmp 0xfaaa
jmp 0xfa83
jmp 0xfa83
jmp 0xfa83
jmp 0xfa83
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0xe3d8
leaq 0xb0(%rsp), %rdi
callq 0x91c8
leaq 0x158(%rsp), %rdi
callq 0x905e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfac1
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xfadd
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x260(%rsp), %rdi
callq 0x3090
movq %r14, %rdi
callq 0x34a0