diff --git a/grow/definition.go b/grow/definition.go index 7ac8974..fefca6f 100644 --- a/grow/definition.go +++ b/grow/definition.go @@ -1,6 +1,7 @@ package grow import "io" +import "math/rand" import "sort" import "gopkg.in/yaml.v2" @@ -15,6 +16,8 @@ type Definition struct { InstructionsPerFunctionMean uint64 `yaml:"instructions_per_function_mean"` InstructionsPerFunctionStdDev uint64 `yaml:"instructions_per_function_std_dev"` + ReturnToBestPeriodMean uint64 `yaml:"return_to_best_period_mean"` + Samples []*Sample `yaml:"samples"` // Sample indices ranked by each output dimension @@ -67,6 +70,10 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) { for { status.Attempts++ + if def.ReturnToBestPeriodMean != 0 && rand.Uint64()%def.ReturnToBestPeriodMean == 0 { + prog = status.BestProgram.Copy() + } + Mutate(def, prog) scores, err := def.score(prog) diff --git a/grow/defs/pythag.yaml b/grow/defs/pythag.yaml index 079f469..5b211fa 100644 --- a/grow/defs/pythag.yaml +++ b/grow/defs/pythag.yaml @@ -5,6 +5,8 @@ instruction_limit: 10 instructions_per_function_mean: 5 instructions_per_function_std_dev: 3 +return_to_best_period_mean: 10000 + samples: - in: [3,4] out: [5]