Ejemplo n.º 1
0
Archivo: main.go Proyecto: timtadh/sfp
func fastmaxMode(argv []string, conf *config.Config) (miners.Miner, []string) {
	args, optargs, err := getopt.GetOpt(
		argv,
		"h",
		[]string{
			"help",
		},
	)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		cmd.Usage(cmd.ErrorCodes["opts"])
	}
	for _, oa := range optargs {
		switch oa.Opt() {
		case "-h", "--help":
			cmd.Usage(0)
		default:
			fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
			cmd.Usage(cmd.ErrorCodes["opts"])
		}
	}
	return fastmax.NewWalker(conf), args
}
Ejemplo n.º 2
0
func digraphCommonAncestor(patterns []lattice.Pattern) (lattice.Pattern, error) {

	// construct a in memory configuration for finding common subdigraphs of all patterns
	conf := &config.Config{
		Cache:   "",
		Output:  "",
		Support: len(patterns),
		Samples: 5,
		Unique:  false,
	}
	wlkr := fastmax.NewWalker(conf)
	wlkr.Reject = false

	// closing the walker releases the memory
	defer func() {
		err := wlkr.Close()
		if err != nil {
			log.Panic(err)
		}
	}()

	maxE := int(math.MaxInt32)
	maxV := int(math.MaxInt32)
	for _, pat := range patterns {
		sg := pat.(*digraph.SubgraphPattern).Pat
		if len(sg.E) < maxE {
			maxE = len(sg.E)
		}
		if len(sg.V) < maxV {
			maxV = len(sg.V)
		}
	}

	// init the datatype (we are now ready to mine)
	dt, err := digraph.NewDigraph(conf, &digraph.Config{
		MinEdges:    0,
		MaxEdges:    maxE,
		MinVertices: 0,
		MaxVertices: maxV,
		Mode:        digraph.GIS | digraph.OverlapPruning | digraph.ExtFromEmb,
	})
	if err != nil {
		return nil, err
	}

	var labels *dg.Labels = patterns[0].(*digraph.SubgraphPattern).Dt.Labels
	// construct the digraph from the patterns
	b := dg.Build(10, 10)
	offset := 0
	for gid, pat := range patterns {
		sn := pat.(*digraph.SubgraphPattern)
		for i := range sn.Pat.V {
			vid := offset + i
			b.AddVertex(sn.Pat.V[i].Color)
			err := dt.NodeAttrs.Add(int32(vid), map[string]interface{}{"gid": gid})
			if err != nil {
				return nil, err
			}
		}
		for i := range sn.Pat.E {
			b.AddEdge(&b.V[offset+sn.Pat.E[i].Src], &b.V[offset+sn.Pat.E[i].Targ], sn.Pat.E[i].Color)
		}
		offset += len(sn.Pat.V)
	}

	// Initialize the *Digraph with the graph G being used.
	err = dt.Init(b, labels)
	if err != nil {
		return nil, err
	}

	// errors.Logf("DEBUG", "patterns %v %v", len(patterns), G)

	// create the reporter
	fmtr := digraph.NewFormatter(dt, nil)
	collector := &reporters.Collector{make([]lattice.Node, 0, 10)}
	uniq, err := reporters.NewUnique(conf, fmtr, collector, "")
	if err != nil {
		return nil, err
	}
	// rptr := &reporters.Chain{[]miners.Reporter{reporters.NewLog(fmtr, false, "DEBUG", "common-ancestor"), uniq}}
	rptr := uniq

	// mine
	err = wlkr.Mine(dt, rptr, fmtr)
	if err != nil {
		return nil, err
	}

	// extract the largest common subdigraph
	maxLevel := collector.Nodes[0].Pattern().Level()
	maxPattern := collector.Nodes[0].Pattern()
	for _, n := range collector.Nodes {
		p := n.Pattern()
		if p.Level() > maxLevel {
			maxLevel = p.Level()
			maxPattern = p
		}
	}
	errors.Logf("DEBUG", "ancestor %v", maxPattern)

	return maxPattern, nil
}