mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fix long line, tests (#2123)
* Fix long line * updating DIRECTORY.md * Add doctest * ... * ... * Update tabu_search.py * space * Fix doctest >>> find_neighborhood(['a','c','b','d','e','a']) # doctest: +NORMALIZE_WHITESPACE [['a','e','b','d','c','a',90], [['a','c','d','b','e','a',90], ['a','d','b','c','e','a',93], ['a','c','b','e','d','a',102], ['a','c','e','d','b','a',113], ['a','b','c','d','e','a',93]] Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
This commit is contained in:
parent
9316e7c014
commit
b9e5259aeb
|
@ -18,6 +18,7 @@
|
|||
* [Hamiltonian Cycle](https://github.com/TheAlgorithms/Python/blob/master/backtracking/hamiltonian_cycle.py)
|
||||
* [Minimax](https://github.com/TheAlgorithms/Python/blob/master/backtracking/minimax.py)
|
||||
* [N Queens](https://github.com/TheAlgorithms/Python/blob/master/backtracking/n_queens.py)
|
||||
* [Rat In Maze](https://github.com/TheAlgorithms/Python/blob/master/backtracking/rat_in_maze.py)
|
||||
* [Sudoku](https://github.com/TheAlgorithms/Python/blob/master/backtracking/sudoku.py)
|
||||
* [Sum Of Subsets](https://github.com/TheAlgorithms/Python/blob/master/backtracking/sum_of_subsets.py)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class NearestNeighbour:
|
|||
:param y: Destination X coordinate
|
||||
:return: Parent X coordinate based on `y ratio`
|
||||
>>> nn = NearestNeighbour(imread("digital_image_processing/image_data/lena.jpg",
|
||||
1), 100, 100)
|
||||
... 1), 100, 100)
|
||||
>>> nn.ratio_y = 0.5
|
||||
>>> nn.get_y(4)
|
||||
2
|
||||
|
|
|
@ -325,10 +325,10 @@ def convex_hull_recursive(points):
|
|||
>>> convex_hull_recursive([[0, 0], [1, 0], [10, 0]])
|
||||
[(0.0, 0.0), (10.0, 0.0)]
|
||||
>>> convex_hull_recursive([[-1, 1],[-1, -1], [0, 0], [0.5, 0.5], [1, -1], [1, 1],
|
||||
[-0.75, 1]])
|
||||
... [-0.75, 1]])
|
||||
[(-1.0, -1.0), (-1.0, 1.0), (1.0, -1.0), (1.0, 1.0)]
|
||||
>>> convex_hull_recursive([(0, 3), (2, 2), (1, 1), (2, 1), (3, 0), (0, 0), (3, 3),
|
||||
(2, -1), (2, -4), (1, -3)])
|
||||
... (2, -1), (2, -4), (1, -3)])
|
||||
[(0.0, 0.0), (0.0, 3.0), (1.0, -3.0), (2.0, -4.0), (3.0, 0.0), (3.0, 3.0)]
|
||||
|
||||
"""
|
||||
|
|
|
@ -29,7 +29,8 @@ def gamma(num: float) -> float:
|
|||
40320.0
|
||||
|
||||
>>> from math import gamma as math_gamma
|
||||
>>> all(gamma(i)/math_gamma(i) <= 1.000000001 and abs(gamma(i)/math_gamma(i)) > .99999999 for i in range(1, 50))
|
||||
>>> all(.99999999 < gamma(i) / math_gamma(i) <= 1.000000001
|
||||
... for i in range(1, 50))
|
||||
True
|
||||
|
||||
|
||||
|
|
|
@ -139,10 +139,19 @@ def find_neighborhood(solution, dict_of_neighbours):
|
|||
from the solution that the method took as an input
|
||||
|
||||
Example:
|
||||
>>> find_neighborhood(['a','c','b','d','e','a']) # doctest: +NORMALIZE_WHITESPACE
|
||||
[['a','e','b','d','c','a',90], [['a','c','d','b','e','a',90],
|
||||
['a','d','b','c','e','a',93], ['a','c','b','e','d','a',102],
|
||||
['a','c','e','d','b','a',113], ['a','b','c','d','e','a',93]]
|
||||
>>> find_neighborhood(['a', 'c', 'b', 'd', 'e', 'a'],
|
||||
... {'a': [['b', '20'], ['c', '18'], ['d', '22'], ['e', '26']],
|
||||
... 'c': [['a', '18'], ['b', '10'], ['d', '23'], ['e', '24']],
|
||||
... 'b': [['a', '20'], ['c', '10'], ['d', '11'], ['e', '12']],
|
||||
... 'e': [['a', '26'], ['b', '12'], ['c', '24'], ['d', '40']],
|
||||
... 'd': [['a', '22'], ['b', '11'], ['c', '23'], ['e', '40']]}
|
||||
... ) # doctest: +NORMALIZE_WHITESPACE
|
||||
[['a', 'e', 'b', 'd', 'c', 'a', 90],
|
||||
['a', 'c', 'd', 'b', 'e', 'a', 90],
|
||||
['a', 'd', 'b', 'c', 'e', 'a', 93],
|
||||
['a', 'c', 'b', 'e', 'd', 'a', 102],
|
||||
['a', 'c', 'e', 'd', 'b', 'a', 113],
|
||||
['a', 'b', 'c', 'd', 'e', 'a', 119]]
|
||||
"""
|
||||
|
||||
neighborhood_of_solution = []
|
||||
|
@ -209,7 +218,7 @@ def tabu_search(
|
|||
best_cost_index = len(best_solution) - 1
|
||||
|
||||
found = False
|
||||
while found is False:
|
||||
while not found:
|
||||
i = 0
|
||||
while i < len(best_solution):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user