// File: /workspace/github_cpp_makefile_star2_O3/sebastienmeyer2[P]mst-clustering/src/compare_clustering.cpp
// Function: compare_inconsistency(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double)
void compare_inconsistency(std::string file_to_read, double cutoff)
{
    /*!
     * @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 Inconsistency method 

    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 inc_clustering = std::chrono::steady_clock::now();

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

    std::unordered_map<Node*, int> clusters_size;
    for (auto kv : clusters) {
        if(clusters_size.find(kv.second) != clusters_size.end()) {
            clusters_size.at(kv.second) += 1;
        } else {
            clusters_size.insert(std::pair<Node*, int>(kv.second, 1));
        }
    }
    std::cout << "In total, there are " << clusters_size.size() << " clusters when cutoff = " << cutoff << std::endl;

    int big_clusters = 0;
    for (auto kv : clusters_size) {
        if (kv.second > 1) {
            big_clusters += 1;
        }
    }
    std::cout << "There are " << big_clusters << " clusters of size at least 2" << std::endl;

    std::chrono::steady_clock::time_point inc_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, clusters.size());

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

    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 Inconsistency clustering including graph creation: ";
    std::cout << std::chrono::duration_cast<std::chrono::microseconds>(inc_end - graph_creation).count() << " µs" << std::endl;

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

    double inc_variance = intracluster_variance(clusters);
    std::cout << "Intracluster variance with Inconsistency clustering: ";
    std::cout << inc_variance << 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;

    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movsd %xmm0, (%rsp)
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 0x10826
leaq 0x30(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
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), %r14
testq %r14, %r14
je 0x10023
movq 0x20(%rsp), %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
movzbl (%r15,%r12), %edi
callq 0x3060
cmpl $0x1, %eax
sbbl $-0x1, %ebp
incq %r12
cmpq %r12, %r14
jne 0x10007
incl %ebp
jmp 0x10028
movl $0x1, %ebp
leaq 0x7279(%rip), %rax      # 0x172a8
movl %ebp, (%rax)
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x5610
leaq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
movl %ebp, %edx
callq 0x3b80
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x10085
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %r15
subq 0x8(%rsp), %r15
callq 0x3380
movq %rax, %r14
movq 0x6f1a(%rip), %rdi      # 0x16fb8
leaq 0x19dd(%rip), %rsi      # 0x11a82
movl $0x12, %edx
callq 0x32d0
movl $0xe8, %edi
callq 0x3280
movq %rax, %r12
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10972
leaq 0x70(%rsp), %rsi
movq %r12, %rdi
callq 0x4978
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x100f2
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x6ebf(%rip), %rbx      # 0x16fb8
leaq 0x1693(%rip), %rsi      # 0x11793
movl $0x4, %edx
movq %rbx, %rdi
callq 0x32d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq 0x6e8d(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, 0x60(%rsp)
leaq 0x158(%rsp), %rdi
movq %r12, %rsi
callq 0xce20
leaq 0x158(%rsp), %rdi
callq 0xce36
movq %r14, 0x68(%rsp)
callq 0x3380
leaq 0xe0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0xacde
leaq 0xd8(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0xf0(%rsp), %r14
testq %r14, %r14
je 0x10271
leaq 0xa8(%rsp), %rbx
leaq 0x40(%rsp), %r12
movq 0x10(%r14), %rcx
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x1024d
movq %rdx, %rsi
movq (%rax), %r9
movq 0x8(%r9), %r10
movq %r9, %r11
cmpq %r10, %rcx
je 0x10247
movq (%r11), %r11
testq %r11, %r11
je 0x1024d
movq 0x8(%r11), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x1024d
cmpq %rdi, %rcx
jne 0x101fe
cmpq %r10, %rcx
je 0x10247
movq (%r9), %r9
testq %r9, %r9
je 0x1081a
movq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
cmpq %rsi, %rdx
jne 0x1081a
cmpq %rdi, %rcx
jne 0x10221
incl 0x10(%r9)
jmp 0x10265
movq %rcx, 0x40(%rsp)
movl $0x1, 0x48(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9246
movq (%r14), %r14
testq %r14, %r14
jne 0x101c7
movq 0x6d40(%rip), %rdi      # 0x16fb8
leaq 0x197d(%rip), %rsi      # 0x11bfc
movl $0x14, %edx
callq 0x32d0
movq 0xc0(%rsp), %rsi
movq 0x6d20(%rip), %rdi      # 0x16fb8
callq 0x3190
movq %rax, %rbx
leaq 0x110f(%rip), %rsi      # 0x113b6
movl $0x18, %edx
movq %rax, %rdi
callq 0x32d0
movq %rbx, %rdi
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 0xb8(%rsp), %rax
xorl %ebx, %ebx
testq %rax, %rax
je 0x1030a
xorl %ecx, %ecx
cmpl $0x2, 0x10(%rax)
setge %cl
addl %ecx, %ebx
movq (%rax), %rax
jmp 0x102f5
movq 0x6ca7(%rip), %rdi      # 0x16fb8
leaq 0x10e6(%rip), %rsi      # 0x113fe
movl $0xa, %edx
callq 0x32d0
movq 0x6c8f(%rip), %rdi      # 0x16fb8
movl %ebx, %esi
callq 0x3490
movq %rax, %rbx
leaq 0x18d7(%rip), %rsi      # 0x11c11
movl $0x1c, %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
callq 0x3380
movq %rax, %rbx
callq 0x3380
movq %rax, %r12
movq 0x6c33(%rip), %rdi      # 0x16fb8
leaq 0x1709(%rip), %rsi      # 0x11a95
movl $0x12, %edx
callq 0x32d0
shrq $0x3, %r15
movl 0xf8(%rsp), %ecx
leaq 0x40(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0xe620
testl %r15d, %r15d
jle 0x103f3
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
leaq 0x40(%rsp), %r13
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq %r13, %rdi
movl %ebp, %edx
callq 0xe808
incl %ebp
movslq %ebp, %rax
xorl %edx, %edx
divq 0xf8(%rsp)
incq %r14
movq %rdx, %rbp
cmpq %r14, %r15
jne 0x103c6
movq 0x6bbe(%rip), %r15      # 0x16fb8
leaq 0x1392(%rip), %rsi      # 0x11793
movl $0x4, %edx
movq %r15, %rdi
callq 0x32d0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq 0x6b8c(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0xec54
movq 0x68(%rsp), %r14
callq 0x3380
movq %rax, %r13
movq 0x6b59(%rip), %rdi      # 0x16fb8
leaq 0x17c8(%rip), %rsi      # 0x11c2e
movl $0x48, %edx
callq 0x32d0
movq %rbx, %rax
subq %r14, %rax
movabsq $0x20c49ba5e353f7cf, %r14 # imm = 0x20C49BA5E353F7CF
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6b20(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbp
leaq 0x1329(%rip), %rsi      # 0x117d0
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0x6ad5(%rip), %rdi      # 0x16fb8
leaq 0x178d(%rip), %rsi      # 0x11c77
movl $0x2e, %edx
callq 0x32d0
subq 0x60(%rsp), %rbx
movq %rbx, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6aa4(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x12ad(%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 0xe0(%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 0x118(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x109f2
leaq 0x120(%rsp), %rdi
callq 0x954a
movsd %xmm0, (%rsp)
leaq 0x120(%rsp), %rdi
callq 0x90a2
movq 0x69f6(%rip), %rdi      # 0x16fb8
leaq 0x16dd(%rip), %rsi      # 0x11ca6
movl $0x35, %edx
callq 0x32d0
movq 0x69de(%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 0x69a3(%rip), %rdi      # 0x16fb8
leaq 0x1523(%rip), %rsi      # 0x11b3f
movl $0x36, %edx
callq 0x32d0
movq %r13, %rax
subq %r12, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6974(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x117d(%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 0x692a(%rip), %rdi      # 0x16fb8
leaq 0x14e1(%rip), %rsi      # 0x11b76
movl $0x1c, %edx
callq 0x32d0
subq %r15, %r13
movq %r13, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x68fb(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1104(%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 0x40(%rsp), %rdi
leaq 0x30(%rsp), %r14
callq 0xe8f2
movsd %xmm0, (%rsp)
movq 0x689d(%rip), %rdi      # 0x16fb8
leaq 0x1471(%rip), %rsi      # 0x11b93
movl $0x21, %edx
callq 0x32d0
movq 0x6885(%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 0x40(%rsp), %rdi
callq 0xe760
leaq 0xa8(%rsp), %rdi
callq 0x9032
leaq 0xe0(%rsp), %rdi
callq 0x90a2
leaq 0x64f6(%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 0x107e4
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x107fb
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 0x969(%rip), %rdi       # 0x1118a
callq 0x33e0
leaq 0x1203(%rip), %rdi      # 0x11a30
leaq 0x1209(%rip), %rsi      # 0x11a3d
leaq 0x1391(%rip), %rcx      # 0x11bcc
movl $0x82, %edx
callq 0x3170
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x90a2
jmp 0x108f4
jmp 0x108f1
movq %rax, %rbx
jmp 0x108fe
jmp 0x10905
jmp 0x1086e
movq %rax, %rbx
jmp 0x10922
jmp 0x108e2
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x1089a
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
jmp 0x1089a
movq %rax, %rbx
movl $0xe8, %esi
movq %r12, %rdi
callq 0x3290
jmp 0x1092f
jmp 0x108e2
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x10946
movq 0x98(%rsp), %rsi
incq %rsi
jmp 0x10941
jmp 0x108d3
jmp 0x108f1
movq %rax, %rbx
jmp 0x10946
jmp 0x108f1
jmp 0x108f1
jmp 0x108f1
jmp 0x108f1
jmp 0x108f1
movq %rax, %rbx
jmp 0x1092f
jmp 0x108f1
jmp 0x10905
jmp 0x10905
jmp 0x108f1
jmp 0x10905
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xe760
leaq 0x30(%rsp), %r13
jmp 0x10908
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x9032
leaq 0xe0(%rsp), %rdi
callq 0x90a2
leaq 0x158(%rsp), %rdi
callq 0x8f38
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x10946
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x1095d
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x260(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x34a0