Esempio n. 1
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)
}
Esempio n. 2
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)
}