More working code generation
This commit is contained in:
20
grow/defs/mul_five.yaml
Normal file
20
grow/defs/mul_five.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
global_memory_size: 1
|
||||||
|
function_memory_size: 1
|
||||||
|
instruction_limit: 2
|
||||||
|
samples:
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 0
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 0
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 1
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 5
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 2
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 10
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 100
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 500
|
||||||
20
grow/defs/mul_four.yaml
Normal file
20
grow/defs/mul_four.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
global_memory_size: 1
|
||||||
|
function_memory_size: 1
|
||||||
|
instruction_limit: 2
|
||||||
|
samples:
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 0
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 0
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 1
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 4
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 2
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 8
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 100
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 400
|
||||||
20
grow/defs/mul_two.yaml
Normal file
20
grow/defs/mul_two.yaml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
global_memory_size: 1
|
||||||
|
function_memory_size: 1
|
||||||
|
instruction_limit: 2
|
||||||
|
samples:
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 0
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 0
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 1
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 2
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 2
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 4
|
||||||
|
- global_memory_inputs:
|
||||||
|
0: 100
|
||||||
|
global_memory_outputs:
|
||||||
|
0: 200
|
||||||
@@ -12,7 +12,8 @@ func (def *Definition) Grow() {
|
|||||||
log.Print("Starting grow run...")
|
log.Print("Starting grow run...")
|
||||||
|
|
||||||
// TODO: Score should be number of output criteria, not number of Samples
|
// TODO: Score should be number of output criteria, not number of Samples
|
||||||
for high_score < len(def.Samples) {
|
progs := 0
|
||||||
|
for ; high_score < len(def.Samples); progs++ {
|
||||||
prog := gen.RandProgram(def.GlobalMemorySize, def.FunctionMemorySize, def.InstructionLimit)
|
prog := gen.RandProgram(def.GlobalMemorySize, def.FunctionMemorySize, def.InstructionLimit)
|
||||||
|
|
||||||
score, err := def.Score(prog)
|
score, err := def.Score(prog)
|
||||||
@@ -31,6 +32,8 @@ func (def *Definition) Grow() {
|
|||||||
log.Printf("New high score %d / %d:\n%s", high_score, len(def.Samples), src)
|
log.Printf("New high score %d / %d:\n%s", high_score, len(def.Samples), src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("%d programs tested", progs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (def *Definition) Score(prog *vm.Program) (int, error) {
|
func (def *Definition) Score(prog *vm.Program) (int, error) {
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package main
|
|||||||
|
|
||||||
import "flag"
|
import "flag"
|
||||||
import "log"
|
import "log"
|
||||||
|
import "math/rand"
|
||||||
import "os"
|
import "os"
|
||||||
|
import "time"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defPath := flag.String("def-path", "", "path to definition YAML file")
|
defPath := flag.String("def-path", "", "path to definition YAML file")
|
||||||
@@ -12,6 +14,8 @@ func main() {
|
|||||||
log.Fatal("Please specify --def-path")
|
log.Fatal("Please specify --def-path")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
defFile, err := os.Open(*defPath)
|
defFile, err := os.Open(*defPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user