// File: 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:
subq $0x278, %rsp            # imm = 0x278
movq %rdi, 0xe8(%rsp)
movq %rdi, %rax
movq %rax, 0xf0(%rsp)
movq %rdi, 0x270(%rsp)
movq %rsi, 0x268(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0xf8(%rsp)
movslq (%rax), %rax
movq %rax, 0x100(%rsp)
leaq 0x24f(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0x9ee0
movq 0x100(%rsp), %rsi
movq 0x108(%rsp), %rdx
leaq 0x250(%rsp), %rdi
callq 0x9ef0
jmp 0x6ff9
leaq 0x24f(%rsp), %rdi
callq 0x9f70
movl $0x0, 0x238(%rsp)
movq 0xf8(%rsp), %rcx
movl 0x238(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x70dc
movq 0xf8(%rsp), %rdi
addq $0x60, %rdi
movslq 0x238(%rsp), %rsi
callq 0xf110
movq %rax, 0xe0(%rsp)
jmp 0x704c
movq 0xe0(%rsp), %rax
movslq (%rax), %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a6b0
movq %rax, 0xd8(%rsp)
jmp 0x706e
movq 0xd8(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x1a6f0
jmp 0x7085
jmp 0x7087
movl 0x238(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x238(%rsp)
jmp 0x7011
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x24f(%rsp), %rdi
callq 0x9f70
jmp 0x78bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x78af
movq 0xf8(%rsp), %rax
movslq (%rax), %rax
movq %rax, 0xc8(%rsp)
movq $0x0, 0x218(%rsp)
leaq 0x217(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x3730
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rcx
leaq 0x220(%rsp), %rdi
leaq 0x218(%rsp), %rdx
callq 0xadc0
jmp 0x7137
leaq 0x217(%rsp), %rdi
callq 0x4730
movq 0xf8(%rsp), %rax
movslq (%rax), %rax
movq %rax, 0xb8(%rsp)
movl $0x0, 0x1f4(%rsp)
leaq 0x1f3(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x83b0
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rcx
leaq 0x1f8(%rsp), %rdi
leaq 0x1f4(%rsp), %rdx
callq 0x83c0
jmp 0x719e
leaq 0x1f3(%rsp), %rdi
callq 0x8440
xorps %xmm0, %xmm0
movsd %xmm0, 0x1e8(%rsp)
movl $0x0, 0x1e4(%rsp)
movq 0xf8(%rsp), %rcx
movl 0x1e4(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x778c
movq 0xf8(%rsp), %rdi
addq $0x60, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0xf110
movq %rax, 0xb0(%rsp)
jmp 0x71fd
movq 0xf8(%rsp), %rdi
movq 0xb0(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1e0(%rsp)
addq $0x48, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0x6f30
movq %rax, 0xa8(%rsp)
jmp 0x7231
movq 0xa8(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x45a0
jmp 0x7248
movq 0xf8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x1a730
movl %eax, 0xa4(%rsp)
jmp 0x7266
leaq 0x1c0(%rsp), %rdi
callq 0x3550
movl 0xa4(%rsp), %eax
movl %eax, 0x1dc(%rsp)
movslq 0x1e0(%rsp), %rsi
leaq 0x1f8(%rsp), %rdi
callq 0xf110
movq %rax, 0x98(%rsp)
jmp 0x72a0
movq 0x98(%rsp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq $0x0, 0x1b8(%rsp)
movq $0x0, 0x1b0(%rsp)
movslq 0x1e0(%rsp), %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a6b0
movq %rax, 0x90(%rsp)
jmp 0x72e5
movq 0x90(%rsp), %rdi
callq 0xce20
movq %rax, 0x1a8(%rsp)
movslq 0x1e0(%rsp), %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a6b0
movq %rax, 0x88(%rsp)
jmp 0x7319
movq 0x88(%rsp), %rdi
callq 0xce50
movq %rax, 0x1a0(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xce80
testb $0x1, %al
jne 0x734c
jmp 0x7516
movq 0xf8(%rsp), %rdi
addq $0x48, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0x6f30
movq %rax, 0x80(%rsp)
jmp 0x736f
movq 0x80(%rsp), %rsi
leaq 0x188(%rsp), %rdi
callq 0x45a0
jmp 0x7386
movq 0xf8(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x70(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0xcef0
movq 0x70(%rsp), %rdi
movslq (%rax), %rsi
callq 0x6f30
movq %rax, 0x78(%rsp)
jmp 0x73b8
movq 0x78(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0x45a0
jmp 0x73cc
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x188(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x15af0
movsd %xmm0, 0x68(%rsp)
jmp 0x73f4
movsd 0x68(%rsp), %xmm0
addsd 0x1b8(%rsp), %xmm0
movsd %xmm0, 0x1b8(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x3550
leaq 0x188(%rsp), %rdi
callq 0x3550
leaq 0x1a8(%rsp), %rdi
xorl %esi, %esi
callq 0x17300
movq %rax, 0x168(%rsp)
jmp 0x72fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x217(%rsp), %rdi
callq 0x4730
jmp 0x78af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x1f3(%rsp), %rdi
callq 0x8440
jmp 0x78a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x7895
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x3550
jmp 0x7895
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x7504
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x3550
leaq 0x188(%rsp), %rdi
callq 0x3550
jmp 0x7895
movslq 0x1dc(%rsp), %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a6b0
movq %rax, 0x60(%rsp)
jmp 0x7532
movq 0x60(%rsp), %rdi
callq 0xce20
movq %rax, 0x160(%rsp)
movslq 0x1dc(%rsp), %rsi
leaq 0x250(%rsp), %rdi
callq 0x1a6b0
movq %rax, 0x58(%rsp)
jmp 0x7560
movq 0x58(%rsp), %rdi
callq 0xce50
movq %rax, 0x158(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0xce80
testb $0x1, %al
jne 0x7590
jmp 0x76c9
movq 0xf8(%rsp), %rdi
addq $0x48, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0x6f30
movq %rax, 0x50(%rsp)
jmp 0x75b0
movq 0x50(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x45a0
jmp 0x75c4
movq 0xf8(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x40(%rsp)
leaq 0x160(%rsp), %rdi
callq 0xcef0
movq 0x40(%rsp), %rdi
movslq (%rax), %rsi
callq 0x6f30
movq %rax, 0x48(%rsp)
jmp 0x75f6
movq 0x48(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0x45a0
jmp 0x760a
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x140(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x15af0
movsd %xmm0, 0x38(%rsp)
jmp 0x7632
movsd 0x38(%rsp), %xmm0
addsd 0x1b0(%rsp), %xmm0
movsd %xmm0, 0x1b0(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x3550
leaq 0x140(%rsp), %rdi
callq 0x3550
leaq 0x160(%rsp), %rdi
xorl %esi, %esi
callq 0x17300
movq %rax, 0x120(%rsp)
jmp 0x7544
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
jmp 0x76b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x240(%rsp)
movl %eax, 0x23c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x3550
leaq 0x140(%rsp), %rdi
callq 0x3550
jmp 0x7895
movsd 0x1b0(%rsp), %xmm0
movsd 0x1b8(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x1b8(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x1a930
movq %rax, 0x30(%rsp)
jmp 0x7701
movsd 0x28(%rsp), %xmm0
movq 0x30(%rsp), %rax
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x118(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movslq 0x1e0(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0xb000
movq %rax, 0x20(%rsp)
jmp 0x7748
movq 0x20(%rsp), %rax
movsd 0x18(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd 0x118(%rsp), %xmm0
addsd 0x1e8(%rsp), %xmm0
movsd %xmm0, 0x1e8(%rsp)
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x71c2
movl $0x0, 0x114(%rsp)
movq 0xf8(%rsp), %rcx
movl 0x114(%rsp), %eax
cmpl (%rcx), %eax
jge 0x781c
movslq 0x114(%rsp), %rsi
leaq 0x1f8(%rsp), %rdi
callq 0xf110
movq %rax, 0x10(%rsp)
jmp 0x77c6
movq 0x10(%rsp), %rax
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, (%rsp)
movslq 0x114(%rsp), %rsi
leaq 0x220(%rsp), %rdi
callq 0xb000
movq %rax, 0x8(%rsp)
jmp 0x77f0
movq 0x8(%rsp), %rax
movsd (%rsp), %xmm1
movsd (%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x7797
movq 0xe8(%rsp), %rdi
movq 0xf8(%rsp), %rax
cvtsi2sdl 0x4(%rax), %xmm1
movsd 0x1e8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x1e8(%rsp)
leaq 0x220(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
callq 0x1a970
jmp 0x785e
leaq 0x1f8(%rsp), %rdi
callq 0x7a50
leaq 0x220(%rsp), %rdi
callq 0x3550
leaq 0x250(%rsp), %rdi
callq 0xa090
movq 0xf0(%rsp), %rax
addq $0x278, %rsp            # imm = 0x278
retq
leaq 0x1f8(%rsp), %rdi
callq 0x7a50
leaq 0x220(%rsp), %rdi
callq 0x3550
leaq 0x250(%rsp), %rdi
callq 0xa090
movq 0x240(%rsp), %rdi
callq 0x2400
nopl (%rax)