Hello @MaxHalford ,
Thanks for making a cool open source project! It's been interesting to learn about genetic algorithms by working with it. I'm also new to golang, so I may be missing something, but I'm having issues getting my Crossover function to work. When I set a pointer receiver (indicated here as the way to modify variables https://tour.golang.org/methods/4 ), I get a build error like below:
func (r *Route) Crossover(s eaopt.Genome, rng *rand.Rand) {
cannot use nearestNeighborRoute (type Route) as type eaopt.Genome in return argument:
Route does not implement eaopt.Genome (Crossover method has pointer receiver)
.. When I change this to not being a pointer, it builds and executes
func (r Route) Crossover(s eaopt.Genome, rng *rand.Rand) {
at the end of the Crossover method, I'm assigning the new offspring to the r variable, but when I step thru the code from individual.go, the genome is unchanged
// bottom of my Crossover method:
r = offspring1
// in individual.go, indi.Genome is unchanged, it has the original r value, not the new crossover one.
func (indi *Individual) Crossover(mate Individual, rng *rand.Rand) {
indi.Genome.Crossover(mate.Genome, rng)
indi.Evaluated = false
mate.Evaluated = false
}
I saw the note about how slices work better, so I changed my code to use Route instead of RouteState, which is a slice of Deliveries, but still seeing the issue
old data structure:
type RouteState struct {
Deliveries []*Delivery
}
new data structure:
type Route []*Delivery
Hello @MaxHalford ,
Thanks for making a cool open source project! It's been interesting to learn about genetic algorithms by working with it. I'm also new to golang, so I may be missing something, but I'm having issues getting my Crossover function to work. When I set a pointer receiver (indicated here as the way to modify variables https://tour.golang.org/methods/4 ), I get a build error like below:
func (r *Route) Crossover(s eaopt.Genome, rng *rand.Rand) {.. When I change this to not being a pointer, it builds and executes
func (r Route) Crossover(s eaopt.Genome, rng *rand.Rand) {at the end of the Crossover method, I'm assigning the new offspring to the r variable, but when I step thru the code from individual.go, the genome is unchanged
I saw the note about how slices work better, so I changed my code to use Route instead of RouteState, which is a slice of Deliveries, but still seeing the issue
old data structure:
new data structure:
type Route []*Delivery