Skip to content

Conversation

Anantbhardwaj2003
Copy link

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 13, 2024
@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 14, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

import numpy as np

class GeneticAlgorithm:
def __init__(self, func, bounds, pop_size=20, generations=100, mutation_rate=0.1, crossover_rate=0.8, selection_method='tournament'):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: func

Please provide type hint for the parameter: bounds

Please provide type hint for the parameter: pop_size

Please provide type hint for the parameter: generations

Please provide type hint for the parameter: mutation_rate

Please provide type hint for the parameter: crossover_rate

Please provide type hint for the parameter: selection_method

self.crossover_rate = crossover_rate
self.selection_method = selection_method

def initialize_population(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: initialize_population. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file genetic_algorithm/ga_optimisation.py, please provide doctest for the function initialize_population

dim = len(self.bounds)
return np.array([np.random.uniform(self.bounds[d][0], self.bounds[d][1], self.pop_size) for d in range(dim)]).T

def fitness(self, individual):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: fitness. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file genetic_algorithm/ga_optimisation.py, please provide doctest for the function fitness

Please provide type hint for the parameter: individual

# Calculate fitness (for minimization, return function value)
return self.func(*individual)

def selection(self, population, fitness_values):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: selection. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file genetic_algorithm/ga_optimisation.py, please provide doctest for the function selection

Please provide type hint for the parameter: population

Please provide type hint for the parameter: fitness_values

elif self.selection_method == 'roulette':
return self.roulette_wheel_selection(population, fitness_values)

def tournament_selection(self, population, fitness_values):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: tournament_selection. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file genetic_algorithm/ga_optimisation.py, please provide doctest for the function tournament_selection

Please provide type hint for the parameter: population

Please provide type hint for the parameter: fitness_values

@@ -0,0 +1,51 @@
class DisjointSet:
def __init__(self, n):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: n

Please provide descriptive name for the parameter: n

self.parent = list(range(n))
self.rank = [0] * n

def find(self, u):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: find. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file graphs/kruskal_algo.py, please provide doctest for the function find

Please provide type hint for the parameter: u

Please provide descriptive name for the parameter: u

self.parent[u] = self.find(self.parent[u])
return self.parent[u]

def union(self, u, v):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: union. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file graphs/kruskal_algo.py, please provide doctest for the function union

Please provide type hint for the parameter: u

Please provide descriptive name for the parameter: u

Please provide type hint for the parameter: v

Please provide descriptive name for the parameter: v

self.rank[root_u] += 1


def kruskal_algorithm(vertices, edges):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: kruskal_algorithm. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file graphs/kruskal_algo.py, please provide doctest for the function kruskal_algorithm

Please provide type hint for the parameter: vertices

Please provide type hint for the parameter: edges


def kruskal_algorithm(vertices, edges):
# Step 1: Sort edges based on weight
edges.sort(key=lambda x: x[2])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: x

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 14, 2024
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 14, 2024
@cclauss
Copy link
Member

cclauss commented Oct 22, 2024

Closing require_type_hints PRs to prepare for Hacktoberfest

@cclauss cclauss closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants