func main() { // Instantiate a GA with 3 variables and the fitness function var ga = presets.Float64(3, leastSquares) ga.Initialize() // Enhancement for i := 0; i < 1000; i++ { fmt.Println(ga.Best.Fitness) ga.Enhance() } }
func main() { // Instantiate a GA with 2 variables and the fitness function var ga = presets.Float64(2, styblinskiTang) ga.Initialize() // Enhancement for i := 0; i < 50; i++ { ga.Enhance() } // Display the best obtained solution fmt.Printf("The best obtained solution is %f\n", ga.Best.Fitness) }
func main() { // Instantiate a GA with 2 variables and the fitness function var ga = presets.Float64(2, styblinskiTang) ga.Initialize() // Number of generations var generations = 10 // Containers for fitnesses var best = make(plotter.XYs, generations) // Enhancement for i := 0; i < generations; i++ { ga.Enhance() // Store the best fitness for plotting best[i].X = float64(i) best[i].Y = ga.Best.Fitness } // Graph the fitnesses graph(best) }