-
Notifications
You must be signed in to change notification settings - Fork 2
/
ga_type.go
57 lines (43 loc) · 1.17 KB
/
ga_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package goga
import (
"sync"
"time"
)
type ga struct {
sync.Mutex
// generator generate random Models
generator func() Model
// weightFunc is weight of each model to be selected for the Mutation for the next generation.
weightFunc WeightFunc
// population calculate the next generation population based on the step, and best cost value.
population PopulationFunc
config struct {
// initialPopulation is the population of the first generation.
initialPopulation int
//maxNumOfSteps maximum number of steps
// -1 for infinity run
maxNumOfSteps int64
// zero for infinity run.
//
// ga stops when error < targetCost
targetCost float64
// the interval between two step
// useful for infinity mood.
stepsInterval time.Duration
// selection is the property for distribution to the next generation.
//
// top + mutation + random = 1
selection struct {
top float64
mutation float64
random float64
}
// numberOfThreads the number of thread in Cost calculation step.
numberOfThreads int
}
curetGeneration modelSortedList
step int64
result chan Model
runtimeError chan error
runtimeResult chan RunTimeResult
}