// File: /workspace/github_cpp_makefile_star2_O2/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movq %rdi, 0x68(%rsp)
movslq (%rsi), %rsi
leaq 0x50(%rsp), %rbx
leaq 0x38(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x4eaa
leaq 0x60(%r15), %r12
xorl %eax, %eax
movl %eax, 0x38(%rsp)
cmpl 0x4(%r15), %eax
jge 0x4288
movslq %eax, %rsi
movq %r12, %rdi
callq 0x606e
movslq (%rax), %rsi
movq %rbx, %rdi
callq 0x91cc
movq %rax, %rdi
movq %r14, %rsi
callq 0x91ea
movl 0x38(%rsp), %eax
incl %eax
jmp 0x4255
movslq (%r15), %rsi
leaq 0x88(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x38(%rsp), %rdi
leaq 0x34(%rsp), %rcx
callq 0x530e
movq %r12, 0x70(%rsp)
movslq (%r15), %rsi
leaq 0x34(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x88(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x48a0
movq %r15, 0x8(%rsp)
leaq 0x48(%r15), %r12
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r14d, %r14d
leaq 0x100(%rsp), %rbx
leaq 0xe8(%rsp), %rbp
movq 0x8(%rsp), %rax
movslq 0x4(%rax), %rax
cmpq %rax, %r14
jge 0x4521
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x606e
movslq (%rax), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4200
leaq 0xb8(%rsp), %rdi
movq %rax, %rsi
callq 0x31d2
movq 0x8(%rsp), %rdi
leaq 0xb8(%rsp), %r15
movq %r15, %rsi
callq 0x91f6
movl %eax, %r13d
movq %r15, %rdi
callq 0x2f86
leaq 0x88(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x606e
incl (%rax)
leaq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x91cc
movq %rax, %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
movq (%r15), %r15
leaq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x91cc
cmpq %rax, %r15
je 0x43f9
movq %r12, %rdi
movq %r14, %rsi
callq 0x4200
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31d2
movslq 0x10(%r15), %rsi
movq %r12, %rdi
callq 0x4200
movq %rbp, %rdi
movq %rax, %rsi
callq 0x31d2
movq 0x8(%rsp), %rax
movl 0x8(%rax), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7f34
movsd 0x28(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movq %rbp, %rdi
callq 0x2f86
movq %rbx, %rdi
callq 0x2f86
jmp 0x4380
movslq %r13d, %rsi
leaq 0x50(%rsp), %rdi
movq %rsi, 0x80(%rsp)
callq 0x91cc
movq %rax, %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, 0x78(%rsp)
movq (%r15), %r15
leaq 0x50(%rsp), %rdi
movq 0x80(%rsp), %rsi
callq 0x91cc
cmpq %rax, %r15
je 0x44d2
movq %r12, %rdi
movq %r14, %rsi
callq 0x4200
leaq 0xd0(%rsp), %r14
leaq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0x31d2
movslq 0x10(%r15), %rsi
movq %r12, %rdi
callq 0x4200
movq %r14, %rdi
movq %rax, %rsi
callq 0x31d2
movq %r12, %r13
movq %rbp, %r12
movq %rbx, %rbp
movq 0x8(%rsp), %rax
movl 0x8(%rax), %edx
movq %r14, %rbx
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7f34
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x2f86
movq %r14, %rdi
callq 0x2f86
movq 0x78(%rsp), %r14
movq %rbp, %rbx
movq %r12, %rbp
movq %r13, %r12
jmp 0x4420
leaq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x5414
movsd 0x20(%rsp), %xmm2
movapd %xmm2, %xmm0
movsd 0x28(%rsp), %xmm1
maxsd %xmm1, %xmm0
subsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd (%rax), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rax)
movsd 0x18(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x18(%rsp)
incq %r14
jmp 0x42ee
xorl %r12d, %r12d
leaq 0x88(%rsp), %r14
leaq 0x38(%rsp), %r15
movq 0x8(%rsp), %rbx
movslq (%rbx), %rax
cmpq %rax, %r12
jge 0x456b
movq %r14, %rdi
movq %r12, %rsi
callq 0x606e
movl (%rax), %ebp
movq %r15, %rdi
movq %r12, %rsi
callq 0x5414
cvtsi2sd %ebp, %xmm0
movsd (%rax), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax)
incq %r12
jmp 0x4536
movl 0x4(%rbx), %ebx
leaq 0x38(%rsp), %rsi
movq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x31d2
cvtsi2sd %ebx, %xmm0
movsd 0x18(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%r14)
leaq 0x88(%rsp), %rdi
callq 0x4888
leaq 0x38(%rsp), %rdi
callq 0x2f86
leaq 0x50(%rsp), %rdi
callq 0x4f44
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4628
movq %rax, %rbx
jmp 0x464a
jmp 0x45ec
jmp 0x4628
jmp 0x4628
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x4638
jmp 0x4628
jmp 0x4628
jmp 0x4628
jmp 0x4628
movq %rax, %rbx
jmp 0x4654
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x2f86
jmp 0x461e
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x2f86
jmp 0x4630
jmp 0x4628
jmp 0x4628
jmp 0x4628
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x4638
movq %rax, %rbx
jmp 0x463d
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x2f86
leaq 0x88(%rsp), %rdi
callq 0x4888
leaq 0x38(%rsp), %rdi
callq 0x2f86
leaq 0x50(%rsp), %rdi
callq 0x4f44
movq %rbx, %rdi
callq 0x23b0