// File: /workspace/github_cpp_makefile_star2_O3/nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/Clustering/../../algorithms/Clustering/clustering.h
// Function: Clustering<double>::compute_silhouette()
std::pair<std::vector<double>, double> compute_silhouette(void) {

			// create a temporary map to store the vectors that belong to each centroid
			std::vector<std::list<int>> centroids_map(k);

			for (int i = 0; i < n_points; i++) {
				centroids_map.at(assigned_centroid.at(i)).push_back(i);
			}

			// declare a vector of each cluster's silhouette
			vector<double> silhouettes(k, 0);

			// declare a vector that holds how many vectors are assinged to each centroid
			vector<int> assigned(k, 0);
			// declare the total silhouette
			double total_sil = 0;

			// compute the silhouette of each point
			for (int i = 0; i < n_points; i++) {
				// find the nearest and the second nearest 
				int nearest = assigned_centroid.at(i);
				int second_nearest = second_nearest_centroid(feature_vectors.at(i));
				assigned.at(nearest)++;
				double a_i = 0, b_i = 0;
				// compute a and b values for this vector
				for (std::list<int>::iterator it = centroids_map.at(nearest).begin(); it != centroids_map.at(nearest).end(); it++) {
					a_i += (double)metrics::ManhatanDistance(feature_vectors.at(i), feature_vectors.at(*it), space_dim);
				}	

				for (std::list<int>::iterator it = centroids_map.at(second_nearest).begin(); it != centroids_map.at(second_nearest).end(); it++) {
					b_i += (double)metrics::ManhatanDistance(feature_vectors.at(i), feature_vectors.at(*it), space_dim);
				}	

				// compute the vecor's silhouette
				double sil = (b_i - a_i) / std::max(a_i, b_i);

				// add it to the cluster's silhouette
				silhouettes.at(nearest) += sil;

				// add it to the total silhouette
				total_sil += sil;
			}

			// compute the final value of the silhouette for each cluster
			for (int i = 0; i < k; i++) {
				silhouettes.at(i) /= assigned.at(i);
			}

			// compute the final value of the total silhouette
			total_sil /= n_points;

			// return a pair of the vector of the silhouettes for each cluster and the total silhouette
			return make_pair(silhouettes, total_sil);
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %r14
movq %rdi, 0x88(%rsp)
movslq (%rsi), %rsi
leaq 0x38(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x5f58
cmpl $0x0, 0x4(%r14)
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
jle 0x4ea7
xorl %ebx, %ebx
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x53db
movslq (%rax,%rbx,4), %r15
movq 0x38(%rsp), %r12
movq 0x40(%rsp), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x53d8
movl $0x18, %edi
callq 0x2290
leaq (%r15,%r15,2), %rcx
leaq (%r12,%rcx,8), %r15
movl %ebx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2060
incq 0x10(%r15)
incq %rbx
movslq 0x4(%r14), %rax
cmpq %rax, %rbx
jl 0x4e3d
movslq (%r14), %rsi
leaq 0x70(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x58(%rsp), %rdi
leaq 0x34(%rsp), %rcx
callq 0x6432
movslq (%r14), %rsi
leaq 0x34(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x5762
movl 0x4(%r14), %ebx
xorpd %xmm0, %xmm0
testl %ebx, %ebx
jle 0x529e
movsd %xmm0, 0x18(%rsp)
xorl %ebp, %ebp
leaq 0xc0(%rsp), %r15
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbp, %rdx
movq %rbp, %rbx
jbe 0x5405
movq 0x48(%r14), %rcx
movq 0x50(%r14), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbx, %rdx
leaq 0xa8(%rsp), %rbp
jbe 0x5400
movslq (%rax,%rbx,4), %r12
leaq (%rbx,%rbx,2), %rax
movq %rax, 0x50(%rsp)
leaq (%rcx,%rax,8), %rsi
movq %r15, %rdi
callq 0x393a
movq %r14, %rdi
movq %r15, %rsi
callq 0xa81a
movl %eax, %r15d
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x4f7a
callq 0x2260
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r12, %rdx
jbe 0x5416
movl %r15d, 0x10(%rsp)
incl (%rax,%r12,4)
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x53c7
movq %r12, 0x28(%rsp)
leaq (%r12,%r12,2), %r15
leaq (%rcx,%r15,8), %rsi
movq (%rsi), %r12
xorpd %xmm0, %xmm0
cmpq %rsi, %r12
je 0x50e9
movsd %xmm0, 0x20(%rsp)
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbx, %rdx
jbe 0x53c4
movq 0x50(%rsp), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rbp, %rdi
callq 0x393a
movslq 0x10(%r12), %rsi
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x53a3
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x393a
movslq 0x8(%r14), %rax
movq 0xf0(%rsp), %rdi
testq %rax, %rax
jle 0x5097
xorpd %xmm0, %xmm0
movq 0xa8(%rsp), %rcx
xorl %edx, %edx
movapd 0x6185(%rip), %xmm2     # 0xb1f0
movsd (%rcx,%rdx,8), %xmm1
subsd (%rdi,%rdx,8), %xmm1
andpd %xmm2, %xmm1
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rax
jne 0x506b
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
jmp 0x509c
testq %rdi, %rdi
je 0x50a1
callq 0x2260
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x50b3
callq 0x2260
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq 0x28(%rsp), %rdx
jbe 0x53b1
movq (%r12), %r12
leaq (%rcx,%r15,8), %rsi
cmpq %rsi, %r12
jne 0x4fe1
jmp 0x50ef
movsd %xmm0, 0x20(%rsp)
movslq 0x10(%rsp), %r15
cmpq %r15, %rdx
jbe 0x5384
subq %rcx, %rax
sarq $0x3, %rax
imulq %r13, %rax
cmpq %r15, %rax
jbe 0x536d
movq %rbx, %rbp
leaq (%r15,%r15,2), %r12
leaq (%rcx,%r12,8), %rbx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq (%rbx), %rbx
leaq (%rcx,%r12,8), %rax
cmpq %rax, %rbx
je 0x522f
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbp, %rdx
jbe 0x5381
movq 0x50(%rsp), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x90(%rsp), %rdi
callq 0x393a
movslq 0x10(%rbx), %rsi
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x5395
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x393a
movslq 0x8(%r14), %rax
movq 0xd8(%rsp), %rdi
testq %rax, %rax
jle 0x51f0
xorpd %xmm0, %xmm0
movq 0x90(%rsp), %rcx
xorl %edx, %edx
movapd 0x602c(%rip), %xmm2     # 0xb1f0
movsd (%rcx,%rdx,8), %xmm1
subsd (%rdi,%rdx,8), %xmm1
andpd %xmm2, %xmm1
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rax
jne 0x51c4
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
jmp 0x51f5
testq %rdi, %rdi
je 0x51fa
callq 0x2260
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x520c
callq 0x2260
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
subq %rcx, %rax
sarq $0x3, %rax
imulq %r13, %rax
cmpq %r15, %rax
ja 0x5126
jmp 0x536d
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq 0x28(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x5427
movsd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm0
movsd 0x20(%rsp), %xmm1
maxsd %xmm1, %xmm0
subsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rsp)
addsd (%rax,%rsi,8), %xmm2
movsd %xmm2, (%rax,%rsi,8)
incq %rbp
movslq 0x4(%r14), %rbx
cmpq %rbx, %rbp
leaq 0xc0(%rsp), %r15
jl 0x4f02
jmp 0x52a4
movsd %xmm0, 0x18(%rsp)
movslq (%r14), %rax
testq %rax, %rax
movq 0x88(%rsp), %r14
jle 0x530c
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
sarq $0x3, %rsi
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x53ef
cmpq %r8, %rsi
je 0x53ec
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx,%r8,4), %xmm0
movsd (%rdi,%r8,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rax
jne 0x52d9
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x393a
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%r14)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x533f
callq 0x2260
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x534e
callq 0x2260
leaq 0x38(%rsp), %rdi
callq 0x600c
movq %r14, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5fb1(%rip), %rdi      # 0xb325
movq %r15, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2370
movq %rbp, %r15
leaq 0x5f9a(%rip), %rdi      # 0xb325
movq %r15, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x5f89(%rip), %rdi      # 0xb325
xorl %eax, %eax
callq 0x2370
leaq 0x5f7b(%rip), %rdi      # 0xb325
xorl %eax, %eax
callq 0x2370
leaq 0x5f6d(%rip), %rdi      # 0xb325
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x2370
movq %rbx, %r12
leaq 0x5f57(%rip), %rdi      # 0xb325
movq %r12, %rsi
xorl %eax, %eax
callq 0x2370
movq %r15, %rbx
leaq 0x5f43(%rip), %rdi      # 0xb325
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2370
movq %rsi, %rdx
leaq 0x5f2f(%rip), %rdi      # 0xb325
movq %rdx, %rsi
xorl %eax, %eax
callq 0x2370
movq %rbx, %rsi
jmp 0x5419
leaq 0x5f19(%rip), %rdi      # 0xb325
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2370
movq %r12, %rsi
leaq 0x5f05(%rip), %rdi      # 0xb325
xorl %eax, %eax
callq 0x2370
leaq 0x5ef7(%rip), %rdi      # 0xb325
xorl %eax, %eax
callq 0x2370
jmp 0x548e
movq %rax, %rbx
jmp 0x54a0
jmp 0x5457
jmp 0x548e
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
jmp 0x5480
jmp 0x548e
jmp 0x548e
jmp 0x5457
jmp 0x548e
jmp 0x548e
movq %rax, %rbx
jmp 0x54af
jmp 0x548e
jmp 0x548e
jmp 0x5462
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
jmp 0x5480
jmp 0x548e
jmp 0x548e
jmp 0x5475
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x5491
callq 0x2260
jmp 0x5491
jmp 0x548e
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x54a0
callq 0x2260
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x54af
callq 0x2260
leaq 0x38(%rsp), %rdi
callq 0x600c
movq %rbx, %rdi
callq 0x2450
nop