Example #1
0
func main() {
	// Get the names of the points
	var names []string
	for name := range points {
		names = append(names, name)
	}
	// Create the GA
	var ga = presets.TSP(names, distance)
	ga.Initialize()
	// Enhance
	for i := 0; i < 1000; i++ {
		ga.Enhance()
	}
	fmt.Println(ga.Best.Fitness)
	// Extract the genome of the best individual
	var points = make([]string, len(names))
	for i, gene := range ga.Best.Genome {
		points[i] = gene.(string)
	}
	graph(points)
}
Example #2
0
func main() {
	// Get the names of the points
	var names []string
	for name := range points {
		names = append(names, name)
	}
	// Create the GA
	var ga = presets.TSP(names, distance)
	ga.Initialize()
	// Enhance
	for i := 0; i < 1000; i++ {
		ga.Enhance()
	}
	var optimal = float64((size + 1) * (size - 1))
	fmt.Printf("Obtained %f\n", ga.Best.Fitness)
	fmt.Printf("Optimal is %d\n", int(optimal))
	fmt.Printf("Off by %f percent\n", 100*(ga.Best.Fitness-optimal)/optimal)
	// Extract the genome of the best individual
	var points = make([]string, len(names))
	for i, gene := range ga.Best.Genome {
		points[i] = gene.(string)
	}
	graph(points)
}