Skip to content

Commit

Permalink
Get rid of HillClimbAsync.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyvan committed Jul 23, 2024
1 parent 9e83bdd commit 7f274ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 174 deletions.
30 changes: 18 additions & 12 deletions Sources/geometrize/GeometrizeModelHillClimb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,24 @@ class GeometrizeModelHillClimb: GeometrizeModelBase {
for _ in 0..<maxThreads {
let seed = UInt64(baseRandomSeed + randomSeedOffset) // TODO: fix
randomSeedOffset += 1
taskGroup.addTask {
let state = await bestHillClimbStateAsync(
shapeCreator: shapeCreator,
alpha: alpha,
n: shapeCount,
age: maxShapeMutations,
target: target,
current: current,
lastScore: lastScore,
energyFunction: energyFunction,
seed: seed
)
taskGroup.addTask { [current] in
var generator = SplitMix64(seed: seed)
let state = await withCheckedContinuation { continuation in
var buffer = current
let state = bestHillClimbState(
shapeCreator: shapeCreator,
alpha: alpha,
n: shapeCount,
age: maxShapeMutations,
target: target,
current: current,
buffer: &buffer,
lastScore: lastScore,
energyFunction: energyFunction,
using: &generator
)
continuation.resume(returning: state)
}
return state
}
}
Expand Down
162 changes: 0 additions & 162 deletions Sources/geometrize/HillClimbAsync.swift

This file was deleted.

17 changes: 17 additions & 0 deletions Sources/geometrize/SVGAsyncIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ public struct SVGAsyncIterator: AsyncIteratorProtocol {
if verbose {
print("Step \(stepCounter)", terminator: "")
}
let stepResult = await withCheckedContinuation { continuation in
var buffer = current
let state = bestHillClimbState(
shapeCreator: shapeCreator,
alpha: alpha,
n: shapeCount,
age: maxShapeMutations,
target: target,
current: current,
buffer: &buffer,
lastScore: lastScore,
energyFunction: energyFunction,
using: &generator
)
continuation.resume(returning: state)
}

let stepResult = await runner.stepAsync(
options: runnerOptions,
energyFunction: defaultEnergyFunction,
Expand Down

0 comments on commit 7f274ea

Please sign in to comment.