Skip to content
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

add initial_population param #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

SuryaThiru
Copy link
Contributor

Allow initialization of the genetic algorithm with a custom population using the initial_population parameter. A list less than or equal to the size of the population can be passed, the remaining population is filled randomly.

Addresses issue #7

Example using the multi-dimensional knapsack

Refer the tutorial for the complete code snippets

# run the algorithm for 10 gens
ga = pyeasyga.GeneticAlgorithm(data, verbose=True, generations=10, population_size=200,
                              random_state=42)
ga.run()
best = ga.best_individual()[1]   # save the best individual (best fitness : 3472)

bests = [best for i in range(10)]  # duplicate the individual few times

# run with the best individual in the initial population (best fitness after 1st gen will be >= 3472)
ga = pyeasyga.GeneticAlgorithm(data, verbose=True, generations=10, population_size=200,
                              random_state=42, initial_population=bests)
ga.run()
ga.best_individual()  # best fitness : 3516

@SuryaThiru
Copy link
Contributor Author

Hey @remiomosowon ! Can you review the PR and let me know if it would be a useful addition to the library? Let me know if you like to see some updates as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant