Minify only at new best program time
This commit is contained in:
@@ -57,6 +57,15 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if score > status.BestScore {
|
if score > status.BestScore {
|
||||||
|
err = def.minifyProgram(prog)
|
||||||
|
if err != nil {
|
||||||
|
if statusChan != nil {
|
||||||
|
close(statusChan)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
status.BestScore = score
|
status.BestScore = score
|
||||||
status.BestProgram = prog.Copy()
|
status.BestProgram = prog.Copy()
|
||||||
|
|
||||||
@@ -65,20 +74,6 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if status.BestScore == status.TargetScore {
|
if status.BestScore == status.TargetScore {
|
||||||
err = def.minifyProgram(prog)
|
|
||||||
if err != nil {
|
|
||||||
if statusChan != nil {
|
|
||||||
close(statusChan)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
status.BestProgram = prog.Copy()
|
|
||||||
|
|
||||||
if statusChan != nil {
|
|
||||||
statusChan <- status
|
|
||||||
}
|
|
||||||
|
|
||||||
if statusChan != nil {
|
if statusChan != nil {
|
||||||
close(statusChan)
|
close(statusChan)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,3 +19,12 @@ samples:
|
|||||||
|
|
||||||
- in: [12,35]
|
- in: [12,35]
|
||||||
out: [37]
|
out: [37]
|
||||||
|
|
||||||
|
- in: [9, 40]
|
||||||
|
out: [41]
|
||||||
|
|
||||||
|
- in: [88, 105]
|
||||||
|
out: [137]
|
||||||
|
|
||||||
|
- in: [161, 240]
|
||||||
|
out: [289]
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ const instrucitonsPerFunctionStdDev = 10
|
|||||||
|
|
||||||
const minifyPeriodMean = 10000
|
const minifyPeriodMean = 10000
|
||||||
|
|
||||||
func Mutate(def *Definition, prog *vm.Program) {
|
func Mutate(_ *Definition, prog *vm.Program) {
|
||||||
if rand.Intn(minifyPeriodMean) == 0 {
|
|
||||||
def.minifyProgram(prog) // ignore error
|
|
||||||
}
|
|
||||||
|
|
||||||
target := int(rand.NormFloat64()*instrucitonsPerFunctionStdDev + instructionsPerFunctionMean)
|
target := int(rand.NormFloat64()*instrucitonsPerFunctionStdDev + instructionsPerFunctionMean)
|
||||||
|
|
||||||
if len(prog.Functions[0].Instructions) < target {
|
if len(prog.Functions[0].Instructions) < target {
|
||||||
|
|||||||
Reference in New Issue
Block a user