// File: /workspace/github_cpp_makefile_star2_O1/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, 0x80(%rsp)
movslq (%rsi), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x5f82
cmpl $0x0, 0x4(%r14)
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
jle 0x4e87
xorl %ebx, %ebx
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x5412
movslq (%rax,%rbx,4), %r15
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x540f
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 0x4e1d
movslq (%r14), %rsi
leaq 0x68(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x50(%rsp), %rdi
leaq 0x44(%rsp), %rcx
callq 0x643c
movslq (%r14), %rsi
leaq 0x44(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x68(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x578a
movl 0x4(%r14), %ebx
xorpd %xmm0, %xmm0
testl %ebx, %ebx
jle 0x52dc
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xc0(%rsp), %r15
leaq 0x90(%rsp), %rbp
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r12, %rdx
jbe 0x544a
movq 0x48(%r14), %rcx
movq 0x50(%r14), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x5439
movslq (%rax,%r12,4), %rbx
leaq (%r12,%r12,2), %rax
movq %rax, 0x48(%rsp)
leaq (%rcx,%rax,8), %rsi
movq %r15, %rdi
callq 0x3900
movq %r14, %rdi
movq %r15, %rsi
callq 0xa84e
movl %eax, %r15d
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x4f58
callq 0x2260
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbx, %rdx
jbe 0x5434
incl (%rax,%rbx,4)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbx, %rdx
jbe 0x53f0
movl %r15d, 0x38(%rsp)
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbx, %rdx
jbe 0x53dc
leaq (,%rbx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
movq (%rcx,%rsi), %r15
addq %rax, %rsi
xorpd %xmm0, %xmm0
cmpq %rsi, %r15
je 0x50ff
movsd %xmm0, 0x10(%rsp)
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r12, %rdx
jbe 0x53ed
movq 0x48(%rsp), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rbp, %rdi
callq 0x3900
movslq 0x10(%r15), %rsi
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rsi, %rdx
jbe 0x5401
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x3900
movslq 0x8(%r14), %rax
testq %rax, %rax
jle 0x5081
movq 0x90(%rsp), %rcx
xorpd %xmm2, %xmm2
movq 0xf0(%rsp), %rdx
xorl %esi, %esi
movapd 0x61ab(%rip), %xmm1     # 0xb210
movsd (%rcx,%rsi,8), %xmm0
subsd (%rdx,%rsi,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rsi
cmpq %rsi, %rax
jne 0x5065
jmp 0x5085
xorpd %xmm2, %xmm2
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
movsd %xmm2, 0x18(%rsp)
je 0x50a3
callq 0x2260
movsd 0x18(%rsp), %xmm2
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x50bb
callq 0x2260
movsd 0x18(%rsp), %xmm2
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbx, %rdx
jbe 0x53dc
movsd 0x10(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
movq (%r15), %r15
leaq (%rbx,%rbx,2), %rcx
leaq (%rax,%rcx,8), %rcx
cmpq %rcx, %r15
jne 0x4fdc
jmp 0x5105
movsd %xmm0, 0x10(%rsp)
movq %rbx, 0x88(%rsp)
movslq 0x38(%rsp), %r15
cmpq %r15, %rdx
jbe 0x53bd
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
jbe 0x53a9
movq %r12, %rbp
leaq (%r15,%r15,2), %r12
leaq (%rax,%r12,8), %rbx
xorpd %xmm2, %xmm2
movq (%rbx), %rbx
leaq (%rcx,%r12,8), %rax
cmpq %rax, %rbx
je 0x5265
movq 0x48(%r14), %rax
movq 0x50(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %rbp, %rdx
jbe 0x53ba
movsd %xmm2, 0x18(%rsp)
movq 0x48(%rsp), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x3900
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 0x53ce
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x3900
movslq 0x8(%r14), %rax
testq %rax, %rax
jle 0x5208
movq 0xa8(%rsp), %rcx
xorpd %xmm2, %xmm2
movq 0xd8(%rsp), %rdx
xorl %esi, %esi
movapd 0x6024(%rip), %xmm1     # 0xb210
movsd (%rcx,%rsi,8), %xmm0
subsd (%rdx,%rsi,8), %xmm0
andpd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rsi
cmpq %rsi, %rax
jne 0x51ec
jmp 0x520c
xorpd %xmm2, %xmm2
movsd %xmm2, 0x38(%rsp)
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x5224
callq 0x2260
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x5236
callq 0x2260
movsd 0x18(%rsp), %xmm2
addsd 0x38(%rsp), %xmm2
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r13, %rdx
cmpq %r15, %rdx
ja 0x5148
jmp 0x53a9
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq 0x88(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x545b
movapd %xmm2, %xmm0
movsd 0x10(%rsp), %xmm1
maxsd %xmm1, %xmm0
subsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x8(%rsp)
addsd (%rax,%rsi,8), %xmm2
movsd %xmm2, (%rax,%rsi,8)
movq %rbp, %r12
incq %r12
movslq 0x4(%r14), %rbx
cmpq %rbx, %r12
leaq 0xc0(%rsp), %r15
leaq 0x90(%rsp), %rbp
jl 0x4eeb
jmp 0x52e2
movsd %xmm0, 0x8(%rsp)
movslq (%r14), %rax
testq %rax, %rax
movq 0x80(%rsp), %r14
jle 0x5348
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq 0x50(%rsp), %r8
movq 0x58(%rsp), %rdi
subq %r8, %rdi
sarq $0x3, %rdi
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x5426
cmpq %rsi, %rdi
je 0x5423
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx,%rsi,4), %xmm0
movsd (%r8,%rsi,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r8,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x5316
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x3900
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%r14)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x537b
callq 0x2260
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x538a
callq 0x2260
leaq 0x20(%rsp), %rdi
callq 0x603a
movq %r14, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5f95(%rip), %rdi      # 0xb345
movq %r15, %rsi
xorl %eax, %eax
callq 0x2370
movq %rbp, %r15
leaq 0x5f81(%rip), %rdi      # 0xb345
movq %r15, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x5f70(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
leaq 0x5f62(%rip), %rdi      # 0xb345
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2370
movq %r12, %rbx
leaq 0x5f4e(%rip), %rdi      # 0xb345
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x5f3d(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
movq %r15, %rbx
leaq 0x5f2c(%rip), %rdi      # 0xb345
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2370
movq %rdi, %rdx
leaq 0x5f18(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
movq %rbx, %rsi
jmp 0x543c
movq %r12, %rsi
leaq 0x5f02(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
leaq 0x5ef4(%rip), %rdi      # 0xb345
movq %r12, %rsi
xorl %eax, %eax
callq 0x2370
leaq 0x5ee3(%rip), %rdi      # 0xb345
xorl %eax, %eax
callq 0x2370
jmp 0x54c2
movq %rax, %rbx
jmp 0x54d4
jmp 0x548b
jmp 0x54c2
jmp 0x54c2
jmp 0x54c2
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
jmp 0x54b4
jmp 0x548b
jmp 0x54c2
jmp 0x54c2
movq %rax, %rbx
jmp 0x54e3
jmp 0x5492
movq %rax, %rbx
movq 0x90(%rsp), %rdi
jmp 0x54b4
jmp 0x54c2
jmp 0x54c2
jmp 0x54c2
jmp 0x54c2
jmp 0x54a9
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x54c5
callq 0x2260
jmp 0x54c5
jmp 0x54c2
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x54d4
callq 0x2260
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x54e3
callq 0x2260
leaq 0x20(%rsp), %rdi
callq 0x603a
movq %rbx, %rdi
callq 0x2450
nop