darwinning
darwinning copied to clipboard
Any ability to seed the first generation?
Wonderful (and simple) tool that I've been using to try and solve a tricky problem with balancing work teams. I've been wondering if there is any way to seed the population with a few known "decent" solutions. It's taking hundreds of generations until the randomly generated solutions are anywhere near as good as the manually created solutions. So I'd like to feed in one or two of the manually created solutions.
Thanks for your great gem!
-Dave
Could it be as simple as adding an option to the Population class to take an array of seed members to the first generation? Here's a two line change to the code that seems like it might allow this (comments indicate the changed lines)
def initialize(options = {})
@organism = options.fetch(:organism)
@population_size = options.fetch(:population_size)
@fitness_goal = options.fetch(:fitness_goal)
@fitness_objective = options.fetch(:fitness_objective, :nullify) # :nullify, :maximize, :minimize
@generations_limit = options.fetch(:generations_limit, 0)
@evolution_types = options.fetch(:evolution_types, DEFAULT_EVOLUTION_TYPES)
@members = options.fetch(:seeds,[]) #<--- changed, used to set to empty array
@generation = 0 # initial population is generation 0
@history = []
build_population(@population_size)
end
def build_population(population_size)
([email protected]).times do |i| #<--- changed, allows for possible preloading of members
@members << build_member
end
end