Esempio n. 1
0
func main() {

	numThreads := 4
	runtime.GOMAXPROCS(numThreads)

	genAlgo := ga.NewGeneticAlgorithm()

	genAlgo.Simulator = &stringMaterSimulator{}
	genAlgo.BitsetCreate = &myBitsetCreate{}
	genAlgo.EliteConsumer = &myEliteConsumer{}
	genAlgo.Mater = ga.NewMater(
		[]ga.MaterFunctionProbability{
			{P: 1.0, F: ga.TwoPointCrossover},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.UniformCrossover, UseElite: true},
		},
	)
	genAlgo.Selector = ga.NewSelector(
		[]ga.SelectorFunctionProbability{
			{P: 1.0, F: ga.Roulette},
		},
	)

	genAlgo.Init(populationSize, numThreads)

	startTime := time.Now()
	genAlgo.Simulate()
	fmt.Println(time.Since(startTime))
}
Esempio n. 2
0
func main() {

	runtime.GOMAXPROCS(runtime.NumCPU())

	// Get the input image
	inputImage = getImageFromFile(os.Args[1])

	rectBitsetFormat = ga.CreateBitsetParse()
	rectBitsetFormat.SetFormat([]int{
		bitsPerCoordinateNumber, bitsPerCoordinateNumber, bitsPerCoordinateNumber, bitsPerCoordinateNumber,
		bitsPerColourChannel, bitsPerColourChannel, bitsPerColourChannel, bitsPerColourChannel,
	})

	circleBitsetFormat = ga.CreateBitsetParse()
	circleBitsetFormat.SetFormat([]int{
		bitsPerCoordinateNumber, bitsPerCoordinateNumber, bitsPerCoordinateNumber,
		bitsPerColourChannel, bitsPerColourChannel, bitsPerColourChannel, bitsPerColourChannel,
	})

	genAlgo := ga.NewGeneticAlgorithm()
	genAlgo.Simulator = &imageMatcherSimulator{}
	genAlgo.BitsetCreate = &myBitsetCreate{}
	genAlgo.EliteConsumer = &myEliteConsumer{}
	genAlgo.Mater = ga.NewMater(
		[]ga.MaterFunctionProbability{
			{P: 1.0, F: ga.UniformCrossover, UseElite: true},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
			{P: 1.0, F: ga.Mutate},
		},
	)
	genAlgo.Selector = ga.NewSelector(
		[]ga.SelectorFunctionProbability{
			{P: 1.0, F: ga.Roulette},
		},
	)

	genAlgo.Init(populationSize, parallelSimulations)

	startTime := time.Now()
	genAlgo.Simulate()
	fmt.Println(time.Since(startTime))
}