Properly bubble up the max fitness because some calculations use it.

This commit is contained in:
Empathic Qubit 2021-05-08 09:31:11 -04:00
parent 6e718eb3b0
commit 22b41082a7
4 changed files with 26 additions and 10 deletions

View file

@ -732,7 +732,6 @@ local function mainLoop(currentSpecies, topGenome)
table.insert(slice, pool.species[i]) table.insert(slice, pool.species[i])
end end
end end
local finished = 0
return runner.run( return runner.run(
slice, slice,
@ -741,7 +740,11 @@ local function mainLoop(currentSpecies, topGenome)
-- Genome callback -- Genome callback
-- FIXME Should we do something here??? What was your plan, past me? -- FIXME Should we do something here??? What was your plan, past me?
end end
):next(function() ):next(function(maxFitness)
if maxFitness > pool.maxFitness then
pool.maxFitness = maxFitness
end
if hasThreads then if hasThreads then
currentSpecies = currentSpecies + #slice currentSpecies = currentSpecies + #slice
else else

View file

@ -124,9 +124,10 @@ local function waitLoop(inputLine)
speciesId = speciesId, speciesId = speciesId,
}) })
end end
):next(function() ):next(function(maxFitness)
writeResponse({ writeResponse({
type = 'onFinish', type = 'onFinish',
maxFitness = maxFitness,
speciesId = speciesId, speciesId = speciesId,
}) })
end) end)

View file

@ -174,6 +174,7 @@ return function(promise)
message(_M, 'Waiting for child processes to finish') message(_M, 'Waiting for child processes to finish')
local maxFitness = nil
local function readLoop(outputPipe) local function readLoop(outputPipe)
return util.promiseWrap(function() return util.promiseWrap(function()
return outputPipe:read("*l") return outputPipe:read("*l")
@ -210,12 +211,15 @@ return function(promise)
end end
genomeCallback(obj.genome, obj.index) genomeCallback(obj.genome, obj.index)
elseif obj.type == 'onFinish' then elseif obj.type == 'onFinish' then
if maxFitness == nil or obj.maxFitness > maxFitness then
maxFitness = obj.maxFitness
end
return true return true
end end
end):next(function(finished) end):next(function(finished)
if finished then if finished then
return return maxFitness
end end
return readLoop(outputPipe) return readLoop(outputPipe)
@ -230,8 +234,16 @@ return function(promise)
end end
return Promise.all(table.unpack(waiters)) return Promise.all(table.unpack(waiters))
end):next(function() end):next(function(maxFitnesses)
message(_M, 'Child processes finished') message(_M, 'Child processes finished')
local maxestFitness = maxFitnesses[1]
for i=1,#maxFitnesses,1 do
local maxFitness = maxFitnesses[i]
if maxFitness > maxestFitness then
maxestFitness = maxFitness
end
end
return maxestFitness
end) end)
end end

View file

@ -639,7 +639,7 @@ local function mainLoop(_M, genome)
-- Continue if we haven't timed out -- Continue if we haven't timed out
local timeoutBonus = _M.currentFrame / 4 local timeoutBonus = _M.currentFrame / 4
if _M.timeout + timeoutBonus > 0 then if _M.timeout + timeoutBonus > 0 or _M.currentFrame % 5 ~= 0 then
return mainLoop(_M, genome) return mainLoop(_M, genome)
end end
@ -686,7 +686,7 @@ local function mainLoop(_M, genome)
end end
genome.fitness = fitness genome.fitness = fitness
if fitness > _M.maxFitness then if _M.maxFitness == nil or fitness > _M.maxFitness then
_M.maxFitness = fitness _M.maxFitness = fitness
end end
@ -712,7 +712,7 @@ local function mainLoop(_M, genome)
input.keyhook("9", false) input.keyhook("9", false)
input.keyhook("tab", false) input.keyhook("tab", false)
return return _M.maxFitness
end end
end end
@ -910,7 +910,7 @@ return function(promise)
currentGenomeIndex = 1, currentGenomeIndex = 1,
currentFrame = 0, currentFrame = 0,
drawFrame = 0, drawFrame = 0,
maxFitness = 0, maxFitness = nil,
dereg = {}, dereg = {},
inputmode = false, inputmode = false,