Exemple #1
0
func extendNode(dt *Digraph, n Node, debug bool) (*hashtable.LinearHash, error) {
	if debug {
		errors.Logf("DEBUG", "n.SubGraph %v", n.SubGraph())
	}
	sg := n.SubGraph()
	b := subgraph.Build(len(sg.V), len(sg.E)).From(sg)
	extPoints, err := n.Extensions()
	if err != nil {
		return nil, err
	}
	patterns := hashtable.NewLinearHash()
	for _, ep := range extPoints {
		bc := b.Copy()
		bc.Extend(ep)
		if len(bc.V) > dt.MaxVertices {
			continue
		}
		vord, eord := bc.CanonicalPermutation()
		ext := bc.BuildFromPermutation(vord, eord)
		if !patterns.Has(ext) {
			patterns.Put(ext, &extInfo{ep, vord})
		}
	}

	return patterns, nil
}
Exemple #2
0
func isCanonicalExtension(cur *subgraph.SubGraph, ext *subgraph.SubGraph) (bool, error) {
	// errors.Logf("DEBUG", "is %v a canonical ext of %v", ext.Label(), n)
	parent, err := firstParent(subgraph.Build(len(ext.V), len(ext.E)).From(ext))
	if err != nil {
		return false, err
	} else if parent == nil {
		return false, errors.Errorf("ext %v of node %v has no parents", ext, cur)
	}
	if bytes.Equal(parent.Build().Label(), cur.Label()) {
		return true, nil
	}
	return false, nil
}
Exemple #3
0
func computeParent(b *subgraph.Builder, i int, parents []*subgraph.Builder) ([]*subgraph.Builder, error) {
	if len(b.V) == 1 && len(b.E) == 1 {
		parents = append(
			parents,
			subgraph.Build(1, 0).FromVertex(b.V[b.E[0].Src].Color),
		)
	} else if len(b.V) == 2 && len(b.E) == 1 {
		parents = append(
			parents,
			subgraph.Build(1, 0).FromVertex(b.V[b.E[0].Src].Color),
			subgraph.Build(1, 0).FromVertex(b.V[b.E[0].Targ].Color),
		)
	} else {
		nb := b.Copy()
		err := nb.RemoveEdge(i)
		if err != nil {
			return nil, err
		}
		if nb.Connected() {
			parents = append(parents, nb)
		}
	}
	return parents, nil
}
Exemple #4
0
func (dt *Digraph) Init(b *digraph.Builder, l *digraph.Labels) (err error) {
	dt.lock.Lock()
	// i := digraph.NewIndices(b, dt.config.Support, dt.Mode & ExtFromFreqEdges == ExtFromFreqEdges)
	i := digraph.NewIndices(b, dt.config.Support)
	errors.Logf("DEBUG", "done building indices")
	dt.G = i.G
	dt.Indices = i
	dt.Labels = l
	dt.lock.Unlock()

	errors.Logf("DEBUG", "computing starting points")
	for color, _ := range dt.Indices.ColorIndex {
		sg := subgraph.Build(1, 0).FromVertex(color).Build()
		_, exts, embs, _, _, err := ExtsAndEmbs(dt, sg, nil, nil, nil, dt.Mode, false)
		if err != nil {
			return err
		}
		n := NewEmbListNode(dt, sg, exts, embs, nil, nil)
		dt.lock.Lock()
		dt.FrequentVertices = append(dt.FrequentVertices, n)
		dt.lock.Unlock()
	}
	return nil
}