Beispiel #1
0
func graph(t *testing.T) (*goiso.Graph, *goiso.SubGraph, *SubGraph, *Indices) {
	Graph := goiso.NewGraph(10, 10)
	G := &Graph
	n1 := G.AddVertex(1, "black")
	n2 := G.AddVertex(2, "black")
	n3 := G.AddVertex(3, "red")
	n4 := G.AddVertex(4, "red")
	n5 := G.AddVertex(5, "red")
	n6 := G.AddVertex(6, "red")
	G.AddEdge(n1, n3, "")
	G.AddEdge(n1, n4, "")
	G.AddEdge(n2, n5, "")
	G.AddEdge(n2, n6, "")
	G.AddEdge(n5, n3, "")
	G.AddEdge(n4, n6, "")
	sg, _ := G.SubGraph([]int{n1.Idx, n2.Idx, n3.Idx, n4.Idx, n5.Idx, n6.Idx}, nil)

	indices := &Indices{
		G:          G,
		ColorIndex: make(map[int][]int),
		SrcIndex:   make(map[IdColorColor][]int),
		TargIndex:  make(map[IdColorColor][]int),
		EdgeIndex:  make(map[Edge]*goiso.Edge),
		EdgeCounts: make(map[Colors]int),
	}

	indices.InitEdgeIndices(G)
	indices.InitColorMap(G)

	return G, sg, FromEmbedding(sg), indices
}
Beispiel #2
0
func LoadGraph(getInput func() (io.Reader, func()), supportAttr string, nodeAttrs *bptree.BpTree, supportAttrs map[int]string) (graph *goiso.Graph, err error) {
	var errors ParseErrors
	reader, closer := getInput()
	G := goiso.NewGraph(graphSize(reader))
	closer()
	graph = &G
	vids := hashtable.NewLinearHash() // int64 ==> *goiso.Vertex

	reader, closer = getInput()
	defer closer()
	ProcessLines(reader, func(line []byte) {
		if len(line) == 0 || !bytes.Contains(line, []byte("\t")) {
			return
		}
		line_type, data := parseLine(line)
		switch line_type {
		case "vertex":
			if err := LoadVertex(graph, supportAttr, vids, nodeAttrs, supportAttrs, data); err != nil {
				errors = append(errors, err)
			}
		case "edge":
			if err := LoadEdge(graph, vids, data); err != nil {
				errors = append(errors, err)
			}
		default:
			errors = append(errors, fmt.Errorf("Unknown line type %v", line_type))
			return
		}
	})
	if len(errors) == 0 {
		return graph, nil
	}
	return graph, errors
}
Beispiel #3
0
func randomGraph(t testing.TB, V, E int, vlabels, elabels []string) (*Digraph, *goiso.Graph, *goiso.SubGraph, *subgraph.SubGraph, *EmbListNode) {
	Graph := goiso.NewGraph(10, 10)
	G := &Graph

	vidxs := make([]int, 0, V)
	vertices := make([]*goiso.Vertex, 0, V)
	for i := 0; i < V; i++ {
		v := G.AddVertex(i, vlabels[rand.Intn(len(vlabels))])
		vertices = append(vertices, v)
		vidxs = append(vidxs, v.Idx)
	}
	for i := 0; i < E; i++ {
		src := rand.Intn(len(vertices))
		targ := rand.Intn(len(vertices))
		elabel := rand.Intn(len(elabels))
		if !G.HasEdge(vertices[src], vertices[targ], elabels[elabel]) {
			G.AddEdge(vertices[src], vertices[targ], elabels[elabel])
		}
	}

	sg, _ := G.SubGraph(vidxs, nil)

	// make config
	conf := &config.Config{
		Support:     2,
		Parallelism: -1,
	}

	// make the *Digraph
	dt, err := NewDigraph(conf, &Config{
		MinEdges:            0,
		MaxEdges:            len(G.E),
		MinVertices:         0,
		MaxVertices:         len(G.V),
		Mode:                Automorphs | Caching | ExtensionPruning | EmbeddingPruning | ExtFromFreqEdges,
		EmbSearchStartPoint: subgraph.RandomStart,
	})
	if err != nil {
		errors.Logf("ERROR", "%v", err)
		t.Fatal(err)
	}

	err = dt.Init(G)
	if err != nil {
		t.Fatal(err)
	}

	f, err := os.Create("/tmp/random-graph.dot")
	if err == nil {
		fmt.Fprintf(f, "%v", G)
		f.Close()
	}

	return dt, G, sg, subgraph.FromEmbedding(sg), RootEmbListNode(dt)
}
Beispiel #4
0
func graph(t *testing.T) (*Digraph, *goiso.Graph, *goiso.SubGraph, *subgraph.SubGraph, *EmbListNode) {
	Graph := goiso.NewGraph(10, 10)
	G := &Graph
	n1 := G.AddVertex(1, "black")
	n2 := G.AddVertex(2, "black")
	n3 := G.AddVertex(3, "red")
	n4 := G.AddVertex(4, "red")
	n5 := G.AddVertex(5, "red")
	n6 := G.AddVertex(6, "red")
	G.AddEdge(n1, n3, "")
	G.AddEdge(n1, n4, "")
	G.AddEdge(n2, n5, "")
	G.AddEdge(n2, n6, "")
	G.AddEdge(n5, n3, "")
	G.AddEdge(n4, n6, "")
	sg, _ := G.SubGraph([]int{n1.Idx, n2.Idx, n3.Idx, n4.Idx, n5.Idx, n6.Idx}, nil)

	// make config
	conf := &config.Config{
		Support: 2,
	}

	// make the *Digraph
	dt, err := NewDigraph(conf, &Config{
		MinEdges:            0,
		MaxEdges:            len(G.E),
		MinVertices:         0,
		MaxVertices:         len(G.V),
		Mode:                Automorphs | ExtFromEmb,
		EmbSearchStartPoint: subgraph.RandomStart,
	})
	if err != nil {
		t.Fatal(err)
	}

	err = dt.Init(G)
	if err != nil {
		t.Fatal(err)
	}

	return dt, G, sg, subgraph.FromEmbedding(sg), RootEmbListNode(dt)
}