本文整理匯總了Golang中github.com/paulfchristiano/dwimmer/dynamics.Dwimmer.Continuations方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dwimmer.Continuations方法的具體用法?Golang Dwimmer.Continuations怎麽用?Golang Dwimmer.Continuations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/paulfchristiano/dwimmer/dynamics.Dwimmer
的用法示例。
在下文中一共展示了Dwimmer.Continuations方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: analogies
//TODO the algorithms part could be more efficient, but I don't really care
func analogies(d dynamics.Dwimmer, s *term.Setting, n int) ([]*term.Setting, []float32) {
if s.Size == 1 {
return contenders(d, s.Last, n)
}
previousSetting := s.Previous
lastLine := s.Last
previousAnalogies, previousPriorities := analogies(d, previousSetting, n+1)
possibilities, possiblePriorities := []*term.Setting{}, new(indexHeap)
i := 0
for j, priority := range previousPriorities {
analogy := previousAnalogies[j]
for _, setting := range d.Continuations(analogy) {
fit, canMatch := match(setting.Last, lastLine)
if canMatch {
possiblePriorities.Push(prioritized{
index: i,
priority: priority * fit,
})
i++
possibilities = append(possibilities, setting)
}
}
}
heap.Init(possiblePriorities)
result := make([]*term.Setting, 0)
priorities := make([]float32, 0)
for i := 0; i < n && possiblePriorities.Len() > 0; i++ {
next := heap.Pop(possiblePriorities).(prioritized)
priorities = append(priorities, next.priority)
result = append(result, possibilities[next.index])
}
return result, priorities
}
示例2: allSettings
func allSettings(d dynamics.Dwimmer, s *term.SettingT) term.T {
queue := []*term.Setting{term.Init()}
for k := 0; k < len(queue); k++ {
top := queue[k]
queue = append(queue, d.Continuations(top)...)
}
result := make([]term.T, len(queue))
for i, setting := range queue {
result[i] = represent.Setting(setting)
}
return core.Answer.T(represent.List(result))
}
示例3: getContinuations
func getContinuations(d dynamics.Dwimmer, s *term.SettingT, quotedSetting term.T) term.T {
setting, err := represent.ToSetting(d, quotedSetting)
if err != nil {
return term.Make("asked to return the continuations from a setting, " +
"but while converting to a setting received []").T(err)
}
continuations := d.Continuations(setting)
result := make([]term.T, len(continuations))
for i, c := range continuations {
result[i] = represent.Setting(c)
}
return core.Answer.T(represent.List(result))
}
示例4: contenders
func contenders(d dynamics.Dwimmer, l term.SettingLine, n int) ([]*term.Setting, []float32) {
allSettings := d.Continuations(term.Init())
result, priorities := Top(l, allSettings, n)
return result, priorities
}