MCPcopy
hub / github.com/fogleman/primitive / HillClimb

Function HillClimb

primitive/optimize.go:15–34  ·  view source on GitHub ↗
(state Annealable, maxAge int)

Source from the content-addressed store, hash-verified

13}
14
15func HillClimb(state Annealable, maxAge int) Annealable {
16 state = state.Copy()
17 bestState := state.Copy()
18 bestEnergy := state.Energy()
19 step := 0
20 for age := 0; age < maxAge; age++ {
21 undo := state.DoMove()
22 energy := state.Energy()
23 if energy >= bestEnergy {
24 state.UndoMove(undo)
25 } else {
26 // fmt.Printf("step: %d, energy: %.6f\n", step, energy)
27 bestEnergy = energy
28 bestState = state.Copy()
29 age = -1
30 }
31 step++
32 }
33 return bestState
34}
35
36func PreAnneal(state Annealable, iterations int) float64 {
37 state = state.Copy()

Callers 2

StepMethod · 0.85
BestHillClimbStateMethod · 0.85

Calls 4

CopyMethod · 0.65
EnergyMethod · 0.65
DoMoveMethod · 0.65
UndoMoveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…