// File: /workspace/github_cpp_makefile_star2_O1/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 $0x478, %rsp            # imm = 0x478
movsd %xmm0, (%rsp)
movq %rdi, %rbx
leaq 0x270(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x3430
leaq 0x2e8(%rsp), %rdi
callq 0x3080
testb %al, %al
je 0x103bd
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x270(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3270
movsbl %al, %edx
leaq 0x270(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x34c0
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0xfbad
movq 0x20(%rsp), %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movzbl (%r12,%r13), %edi
callq 0x3060
cmpl $0x1, %eax
sbbq $-0x1, %r15
incq %r13
cmpq %r13, %r14
jne 0xfb8f
incl %r15d
jmp 0xfbb3
movl $0x1, %r15d
leaq 0x76ee(%rip), %rax      # 0x172a8
movl %r15d, (%rax)
leaq 0xb0(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x5628
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movl %r15d, %edx
callq 0x3b80
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0xfc12
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %r12
subq 0x8(%rsp), %r12
callq 0x3380
movq %rax, %r14
movq 0x738d(%rip), %rdi      # 0x16fb8
leaq 0x1dd0(%rip), %rsi      # 0x11a02
movl $0x12, %edx
callq 0x32d0
movl $0xe8, %edi
callq 0x3280
movq %rax, %r13
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10502
leaq 0x88(%rsp), %rsi
movq %r13, %rdi
callq 0x4998
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0xfc88
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x7329(%rip), %rbx      # 0x16fb8
leaq 0x1abd(%rip), %rsi      # 0x11753
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 0x72f7(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
movq %r13, %rsi
callq 0xcb58
leaq 0x168(%rsp), %rdi
callq 0xcb6e
movq %rbx, 0x68(%rsp)
movq %r14, 0x70(%rsp)
callq 0x3380
leaq 0xf8(%rsp), %rdi
leaq 0x168(%rsp), %rsi
movsd (%rsp), %xmm0
callq 0xab18
leaq 0xf0(%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 0x108(%rsp), %r14
testq %r14, %r14
je 0xfe17
leaq 0x48(%rsp), %r13
leaq 0xc0(%rsp), %rbp
leaq 0x78(%rsp), %rbx
movups 0x8(%r14), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x48(%rsp), %rcx
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rsi
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0xfdd6
movq (%rdx), %r9
movq %rdx, %rax
cmpq 0x8(%r9), %rcx
je 0xfdd6
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0xfdd4
movq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0xfdd6
movq %r10, %rax
cmpq %rdi, %rcx
jne 0xfda9
jmp 0xfdd6
xorl %eax, %eax
testq %rax, %rax
je 0xfdf0
cmpq $0x0, (%rax)
je 0xfdf0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x93cc
incl (%rax)
jmp 0xfe0b
movq %rcx, 0x78(%rsp)
movl $0x1, 0x80(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x940e
movq (%r14), %r14
testq %r14, %r14
jne 0xfd65
movq 0x719a(%rip), %rdi      # 0x16fb8
leaq 0x1d57(%rip), %rsi      # 0x11b7c
movl $0x14, %edx
callq 0x32d0
movq 0xd8(%rsp), %rsi
movq 0x717a(%rip), %rdi      # 0x16fb8
callq 0x3190
movq %rax, %rbx
leaq 0x1539(%rip), %rsi      # 0x11386
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 0xd0(%rsp), %rax
xorl %ebx, %ebx
testq %rax, %rax
je 0xfeb0
xorl %ecx, %ecx
cmpl $0x2, 0x10(%rax)
setge %cl
addl %ecx, %ebx
movq (%rax), %rax
jmp 0xfe9b
movq 0x7101(%rip), %rdi      # 0x16fb8
leaq 0x1510(%rip), %rsi      # 0x113ce
movl $0xa, %edx
callq 0x32d0
movq 0x70e9(%rip), %rdi      # 0x16fb8
movl %ebx, %esi
callq 0x3490
movq %rax, %rbx
leaq 0x1cb1(%rip), %rsi      # 0x11b91
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, %rbp
callq 0x3380
movq %rax, %r13
movq 0x708d(%rip), %rdi      # 0x16fb8
leaq 0x1ae3(%rip), %rsi      # 0x11a15
movl $0x12, %edx
callq 0x32d0
shrq $0x3, %r12
movl 0x110(%rsp), %ecx
leaq 0x40(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xe29c
testl %r12d, %r12d
jle 0xff9d
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r14d, %r14d
leaq 0x40(%rsp), %rbx
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
movl %r15d, %edx
callq 0xe480
incl %r15d
movslq %r15d, %rax
xorl %edx, %edx
divq 0x110(%rsp)
incq %r14
movq %rdx, %r15
cmpq %r14, %r12
jne 0xff6e
movq 0x7014(%rip), %rbx      # 0x16fb8
leaq 0x17a8(%rip), %rsi      # 0x11753
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 0x6fe2(%rip), %rdi      # 0x16fb8
callq 0x3040
movq %rax, %rdi
callq 0x31a0
callq 0x3380
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0xe8d2
callq 0x3380
movq %rax, %r12
movq 0x6fb4(%rip), %rdi      # 0x16fb8
leaq 0x1ba3(%rip), %rsi      # 0x11bae
movl $0x48, %edx
callq 0x32d0
movq %rbp, %rax
subq 0x70(%rsp), %rax
movabsq $0x20c49ba5e353f7cf, %r14 # imm = 0x20C49BA5E353F7CF
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6f79(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1742(%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 0x6f2f(%rip), %rdi      # 0x16fb8
leaq 0x1b67(%rip), %rsi      # 0x11bf7
movl $0x2e, %edx
callq 0x32d0
subq 0x68(%rsp), %rbp
movq %rbp, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6efe(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x16c7(%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 0x130(%rsp), %rdi
movq %rax, (%rdi)
leaq 0xf8(%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 0x78(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x10582
leaq 0x130(%rsp), %rdi
callq 0x9722
movsd %xmm0, (%rsp)
leaq 0x130(%rsp), %rdi
callq 0x91c8
movq 0x6e53(%rip), %rdi      # 0x16fb8
leaq 0x1aba(%rip), %rsi      # 0x11c26
movl $0x35, %edx
callq 0x32d0
movq 0x6e3b(%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 0x6e00(%rip), %rdi      # 0x16fb8
leaq 0x1900(%rip), %rsi      # 0x11abf
movl $0x36, %edx
callq 0x32d0
movq %r12, %rax
subq %r13, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6dd1(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x159a(%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 0x6d87(%rip), %rdi      # 0x16fb8
leaq 0x18be(%rip), %rsi      # 0x11af6
movl $0x1c, %edx
callq 0x32d0
subq %r15, %r12
movq %r12, %rax
imulq %r14
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x7, %rdx
addq %rdx, %rsi
movq 0x6d58(%rip), %rdi      # 0x16fb8
callq 0x3260
movq %rax, %rbx
leaq 0x1521(%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 0x40(%rsp), %rdi
callq 0xe568
movsd %xmm0, (%rsp)
movq 0x6cff(%rip), %rdi      # 0x16fb8
leaq 0x1853(%rip), %rsi      # 0x11b13
movl $0x21, %edx
callq 0x32d0
movq 0x6ce7(%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 0xe3d8
leaq 0xc0(%rsp), %rdi
callq 0x9158
leaq 0xf8(%rsp), %rdi
callq 0x91c8
leaq 0x6958(%rip), %rax      # 0x16c88
leaq 0x178(%rsp), %rbx
movq %rax, -0x10(%rbx)
leaq 0x220(%rsp), %rdi
callq 0x5246
leaq 0x1e8(%rsp), %rdi
callq 0x51d6
leaq 0x1b0(%rsp), %rdi
callq 0x52b6
movq %rbx, %rdi
callq 0x5326
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x10382
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x1039e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x270(%rsp), %rdi
callq 0x3090
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15ec(%rip), %rdi      # 0x119b0
leaq 0x15f2(%rip), %rsi      # 0x119bd
leaq 0x177a(%rip), %rcx      # 0x11b4c
movl $0x82, %edx
callq 0x3170
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x91c8
jmp 0x10489
jmp 0x10486
jmp 0x10481
jmp 0x10481
jmp 0x10402
movq %rax, %rbx
jmp 0x104ad
jmp 0x10472
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x10431
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
jmp 0x10431
movq %rax, %rbx
movl $0xe8, %esi
movq %r13, %rdi
callq 0x3290
jmp 0x104ba
jmp 0x10472
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x104d1
movq 0xb0(%rsp), %rsi
incq %rsi
jmp 0x104cc
jmp 0x10463
jmp 0x10486
movq %rax, %rbx
jmp 0x104d1
jmp 0x10486
jmp 0x10486
jmp 0x10486
jmp 0x10486
jmp 0x10486
movq %rax, %rbx
jmp 0x104ba
jmp 0x10486
jmp 0x10481
jmp 0x10481
jmp 0x10481
jmp 0x10486
movq %rax, %rbx
jmp 0x10493
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xe3d8
leaq 0xc0(%rsp), %rdi
callq 0x9158
leaq 0xf8(%rsp), %rdi
callq 0x91c8
leaq 0x168(%rsp), %rdi
callq 0x905e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x104d1
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x104ed
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x270(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x34a0