Commit e3f7a2a1 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

implements closest word excursion

parent 490566bd
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -34,6 +34,27 @@ class Robustness:
			self.swap(i, r)
			yield self.l[i]

	def closest_word(self):
		"""
		excursion by choosing the closest word to w_n
		"""
		d = len(self.l)
		i0 = random.randint(0, d-1)
		w0 = self.l[i0]
		self.swap(0, i0)
		yield w0

		for i in range(1, d):
			lowest_distance = self.distance(w0, self.l[i])
			lowest_index = i
			for j in range(i+1, d):
				dist = self.distance(w0, self.l[j])
				if dist < lowest_distance:
					lowest_distance = dist
					lowest_index = j
			self.swap(i, j)
			yield self.l[i]

	def closest_among_m_permutation(self, m=10):
		"""
		generates a permutation where w_0 is randomly choosen and w_n+1
@@ -110,7 +131,7 @@ class Robustness:

if __name__ == '__main__':
	R = Robustness(sys.argv[1])
	R.algo = R.closest_among_m_permutation
	R.algo = R.closest_word
	# R.distance = jaro.jaro_winkler_metric
	R.k = int(len(R.l)/10)
	# R.k = int(len(R.l)/10)
	print(R.min_rperm(n=10))