-
-
Notifications
You must be signed in to change notification settings - Fork 48.7k
kruskal_algorithm problems #1 #12039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this 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.
genetic_algorithm/ga_optimisation.py
Outdated
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'): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
for more information, see https://pre-commit.ci
Closing require_type_hints PRs to prepare for Hacktoberfest |
Describe your change:
Checklist: