func weight(u, v lattice.Node) (float64, error) { umax, err := u.Maximal() if err != nil { return 0, err } vmax, err := v.Maximal() if err != nil { return 0, err } udeg, err := u.AdjacentCount() if err != nil { return 0, err } vdeg, err := v.AdjacentCount() if err != nil { return 0, err } if umax && vmax { return 0, nil } else if !umax && vmax { return 1.0 / float64(vdeg), nil } else if umax && !vmax { return 1.0 / float64(udeg), nil } else { return 1.0, nil } }
func (w *Walker) weight(_, v lattice.Node) (float64, error) { vmax, err := v.Maximal() if err != nil { return 0, err } if vmax { indeg, err := v.ParentCount() if err != nil { return 0, err } level := float64(v.Pattern().Level()) return (level) / float64(indeg), nil // maxLevel := float64(w.Dt.LargestLevel()) // return (level) / (float64(indeg) * maxLevel), nil } else { // level approximates indeg level := float64(v.Pattern().Level()) // indeg, err := v.ParentCount() // if err != nil { // return 0, err // } odeg, err := v.ChildCount() if err != nil { return 0, err } // return float64(odeg) / float64(indeg), nil return float64(odeg) / (level), nil } }
func (r *Max) Report(n lattice.Node) error { if ismax, err := n.Maximal(); err != nil { return err } else if ismax { return r.Reporter.Report(n) } return nil }
func Next(ctx interface{}, cur lattice.Node) (lattice.Node, error) { w := ctx.(*Walker) if ismax, err := cur.Maximal(); err != nil { return nil, err } else if ismax && w.Dt.Acceptable(cur) { w.teleportAllowed = true errors.Logf("INFO", "ALLOWING TELEPORTS") } if w.teleportAllowed && rand.Float64() < w.TeleportProbability { w.teleportAllowed = false next := w.Teleports[rand.Intn(len(w.Teleports))] errors.Logf("INFO", "TELEPORT\n from %v\n to %v", cur, next) return next, nil } return musk.Next(ctx, cur) }
func (w *Walker) Next(cur lattice.Node) (lattice.Node, error) { kids, err := cur.CanonKids() if err != nil { return nil, err } errors.Logf("DEBUG", "cur %v kids %v", cur, len(kids)) pr, next, err := walker.Transition(cur, kids, w.weight, true) if err != nil { return nil, err } if next == nil && w.Max { if ismax, err := cur.Maximal(); err != nil { return nil, err } else if !ismax { return w.Dt.Root(), nil } } return next, w.transitionProbability(cur, next, pr) }