Score on criteria count, not sample count
This commit is contained in:
@@ -30,22 +30,24 @@ func NewDefinition(r io.Reader) (*Definition, error) {
|
||||
|
||||
func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
||||
status := Status{
|
||||
TargetScore: uint64(len(def.Samples)),
|
||||
TargetScore: def.sumOuts(),
|
||||
}
|
||||
|
||||
if statusChan != nil {
|
||||
statusChan <- status
|
||||
}
|
||||
|
||||
// TODO: Score should be number of output criteria, not number of Samples
|
||||
for {
|
||||
status.Attempts++
|
||||
|
||||
prog := gen.RandProgram(def.GlobalMemorySize, def.FunctionMemorySize, def.InstructionLimit)
|
||||
|
||||
score, err := def.Score(prog)
|
||||
score, err := def.score(prog)
|
||||
if err != nil {
|
||||
close(statusChan)
|
||||
if statusChan != nil {
|
||||
close(statusChan)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -58,14 +60,17 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
||||
}
|
||||
|
||||
if status.BestScore == status.TargetScore {
|
||||
close(statusChan)
|
||||
if statusChan != nil {
|
||||
close(statusChan)
|
||||
}
|
||||
|
||||
return prog, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (def *Definition) Score(prog *vm.Program) (uint64, error) {
|
||||
func (def *Definition) score(prog *vm.Program) (uint64, error) {
|
||||
score := uint64(0)
|
||||
|
||||
for _, sample := range def.Samples {
|
||||
@@ -78,10 +83,18 @@ func (def *Definition) Score(prog *vm.Program) (uint64, error) {
|
||||
|
||||
state.Execute() // ignore error
|
||||
|
||||
if sample.OutputsMatch(state) {
|
||||
score += 1
|
||||
}
|
||||
score += sample.matchingOuts(state)
|
||||
}
|
||||
|
||||
return score, nil
|
||||
}
|
||||
|
||||
func (def *Definition) sumOuts() uint64 {
|
||||
sum := uint64(0)
|
||||
|
||||
for _, sample := range def.Samples {
|
||||
sum += uint64(len(sample.Out))
|
||||
}
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user