Properly bubble up the max fitness because some calculations use it.
This commit is contained in:
parent
6e718eb3b0
commit
22b41082a7
4 changed files with 26 additions and 10 deletions
7
pool.lua
7
pool.lua
|
@ -732,7 +732,6 @@ local function mainLoop(currentSpecies, topGenome)
|
|||
table.insert(slice, pool.species[i])
|
||||
end
|
||||
end
|
||||
local finished = 0
|
||||
|
||||
return runner.run(
|
||||
slice,
|
||||
|
@ -741,7 +740,11 @@ local function mainLoop(currentSpecies, topGenome)
|
|||
-- Genome callback
|
||||
-- FIXME Should we do something here??? What was your plan, past me?
|
||||
end
|
||||
):next(function()
|
||||
):next(function(maxFitness)
|
||||
if maxFitness > pool.maxFitness then
|
||||
pool.maxFitness = maxFitness
|
||||
end
|
||||
|
||||
if hasThreads then
|
||||
currentSpecies = currentSpecies + #slice
|
||||
else
|
||||
|
|
|
@ -124,9 +124,10 @@ local function waitLoop(inputLine)
|
|||
speciesId = speciesId,
|
||||
})
|
||||
end
|
||||
):next(function()
|
||||
):next(function(maxFitness)
|
||||
writeResponse({
|
||||
type = 'onFinish',
|
||||
maxFitness = maxFitness,
|
||||
speciesId = speciesId,
|
||||
})
|
||||
end)
|
||||
|
|
|
@ -174,6 +174,7 @@ return function(promise)
|
|||
|
||||
message(_M, 'Waiting for child processes to finish')
|
||||
|
||||
local maxFitness = nil
|
||||
local function readLoop(outputPipe)
|
||||
return util.promiseWrap(function()
|
||||
return outputPipe:read("*l")
|
||||
|
@ -210,12 +211,15 @@ return function(promise)
|
|||
end
|
||||
genomeCallback(obj.genome, obj.index)
|
||||
elseif obj.type == 'onFinish' then
|
||||
if maxFitness == nil or obj.maxFitness > maxFitness then
|
||||
maxFitness = obj.maxFitness
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
end):next(function(finished)
|
||||
if finished then
|
||||
return
|
||||
return maxFitness
|
||||
end
|
||||
|
||||
return readLoop(outputPipe)
|
||||
|
@ -230,8 +234,16 @@ return function(promise)
|
|||
end
|
||||
|
||||
return Promise.all(table.unpack(waiters))
|
||||
end):next(function()
|
||||
end):next(function(maxFitnesses)
|
||||
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
|
||||
|
||||
|
|
|
@ -639,7 +639,7 @@ local function mainLoop(_M, genome)
|
|||
|
||||
-- Continue if we haven't timed out
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -686,7 +686,7 @@ local function mainLoop(_M, genome)
|
|||
end
|
||||
genome.fitness = fitness
|
||||
|
||||
if fitness > _M.maxFitness then
|
||||
if _M.maxFitness == nil or fitness > _M.maxFitness then
|
||||
_M.maxFitness = fitness
|
||||
end
|
||||
|
||||
|
@ -712,7 +712,7 @@ local function mainLoop(_M, genome)
|
|||
input.keyhook("9", false)
|
||||
input.keyhook("tab", false)
|
||||
|
||||
return
|
||||
return _M.maxFitness
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -910,7 +910,7 @@ return function(promise)
|
|||
currentGenomeIndex = 1,
|
||||
currentFrame = 0,
|
||||
drawFrame = 0,
|
||||
maxFitness = 0,
|
||||
maxFitness = nil,
|
||||
|
||||
dereg = {},
|
||||
inputmode = false,
|
||||
|
|
Loading…
Add table
Reference in a new issue