Esempio n. 1
0
    def test_grow_in(self):
        print("Plotting Test Start:\tGrow IN")
        start_time = time.time()
        name = "growIn"
        graph = Graph()

        graphs = []
        # create graphs collection instance 
        # is needed to create plotting instance
        gc = GraphCollection(name)
        vList = graph.add_vertex(7)

        # SCC
        graph.add_edge(graph.vertex(0),graph.vertex(1))
        graph.add_edge(graph.vertex(1),graph.vertex(2))
        graph.add_edge(graph.vertex(2),graph.vertex(3))
        graph.add_edge(graph.vertex(3),graph.vertex(4))
        graph.add_edge(graph.vertex(4),graph.vertex(5))
        graph.add_edge(graph.vertex(5),graph.vertex(6))
        graph.add_edge(graph.vertex(6),graph.vertex(0))
        gc.append(copy.deepcopy(graph))

        print("Growing IN")
        for x in range (7, 17):
            new_vertex = graph.add_vertex()
            graph.add_edge(new_vertex, graph.vertex(1))
            gc.append(copy.deepcopy(graph))

        graphs.append(gc)
        print("Graphs Created! Starting the plotting")
        self.plot_graph_collection(graphs, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tGrow IN\t\t(%.2fs)\n" % duration)
Esempio n. 2
0
    def plot_graph(self, graph, testcase):
        """
        Helper Method: Create the GC, Plotting object and call plot_bowtie
        Arguments:
        - testcase: the name of the TestCase
        - iteration: the iteration of the TestCase
        """

        graphs = []
        # create graphs collection instance 
        # is needed to create plotting instance
        gc = GraphCollection(testcase)
        gc.append(graph)
        graphs.append(gc)
        
        self.plot_graph_collection(graphs, testcase)
Esempio n. 3
0
def barabasi_albert_graph_directed(n, m):
	if m < 1 or m >=n:
		raise nx.NetworkXError("Barabasi-Albert network must have m>=1 and m<n, m=%d,n=%d"%(m,n))
	graphlist = []
	graph = Graph()
	gc = GraphCollection(barabasi_albert_graph_directed)
	graph.add_nodes_from(range(n))
	graph.name="barabasi_albert_graph(%s,%s)"%(n,m)
	targets=list(range(n))
	for i in range(0, n, 1):
		rand = random.sample(targets, m)
		while i in rand:
			rand = random.sample(targets, m)
		graph.add_edges_from(zip([i]*m, rand))
		gc.append(graph)
		graphlist.append(graph)

		#testP = TestPlotting('test_bowtie_plot_generator')
		#testP.call_plot_graph_with(graph, 'test_bowtie_plot_generator', i)

	return graphlist
Esempio n. 4
0
	graph = BowTie()
	set_of_nodes = set()
	for line in txtfile:
		edge = line.split('\t')
		edge[1] = edge[1].rstrip('\n')
		set_of_nodes.add(int(edge[0]))
		set_of_nodes.add(int(edge[1]))
		graph.set_edges(int(edge[0]), int(edge[1]))

	graph.set_nodes(set_of_nodes)
	txtfile.close()
	return graph



print "start"
language = "mn"
index = [1, 5, 10, 15]
gc = GraphCollection(language)
for i in index:    
	print "read..."
	graph = readSource("wiki_source/" + language + "/" + language +"-" + str(i) + ".txt")
	print "Graph constructed"
	gc.append(graph)
graphs = []
graphs.append(gc)
for g in graphs:
	print "calculate..."
	g.compute()
	P = Plotting(graphs)
Esempio n. 5
0
    def test_grow_shrink(self):
        print("Plotting Test Start:\tGrow & Shrink (GC)")
        start_time = time.time()
        name = "grow_shrink"
        graph = Graph()
        
        graphs = []
        # create graphs collection instance 
        gc = GraphCollection(name)

        graph.add_vertex(7)
        # SCC
        graph.add_edge(graph.vertex(0),graph.vertex(1))
        graph.add_edge(graph.vertex(1),graph.vertex(2))
        graph.add_edge(graph.vertex(2),graph.vertex(3))
        graph.add_edge(graph.vertex(3),graph.vertex(4))
        graph.add_edge(graph.vertex(4),graph.vertex(5))
        graph.add_edge(graph.vertex(5),graph.vertex(6))
        graph.add_edge(graph.vertex(6),graph.vertex(0))
        gc.append(copy.deepcopy(graph))

        in_edges = []
        out_edges = []
        scc_edges = []

        print("Growing IN")
        for x in range (7, 27):
            new_vertex = graph.add_vertex()
            in_edge = graph.add_edge(new_vertex, graph.vertex(1))
            in_edges.append(in_edge)
            gc.append(copy.deepcopy(graph))
        
        print("Growing OUT")
        for x in range (27, 47):
            new_vertex = graph.add_vertex()
            out_edge = graph.add_edge(graph.vertex(2), new_vertex)
            out_edges.append(out_edge)
            gc.append(copy.deepcopy(graph))
        
        print("Growing SCC")
        for x in range (7, 27):
            scc_edge = graph.add_edge(graph.vertex(1), graph.vertex(x))
            scc_edges.append(scc_edge)
            gc.append(copy.deepcopy(graph))
        
            scc_edge = graph.add_edge(graph.vertex(20+x), graph.vertex(2))
            scc_edges.append(scc_edge)
            gc.append(copy.deepcopy(graph))

        print("Shrinking SCC")
        for edge in scc_edges:
            graph.remove_edge(edge)
            gc.append(copy.deepcopy(graph))

        print("Shrinking OUT")
        for edge in out_edges:
            graph.remove_edge(edge)
            gc.append(copy.deepcopy(graph))

        print("Shrinking IN")
        for edge in in_edges:
            graph.remove_edge(edge)
            gc.append(copy.deepcopy(graph))

        graphs.append(gc)
        print("Plotting Graphs")
        self.plot_graph_collection(graphs, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tGrow & Shrink (deep copy)\t(%.2fs)\n" % duration)
Esempio n. 6
0
    def test_grow_in_scc_out(self):
        print("Plotting Test Start:\tGrow")
        start_time = time.time()
        name = "grow_in_scc_out"
        graph = Graph()

        graphs = []
        # create graphs collection instance 
        gc = GraphCollection(name)

        graph.add_vertex(7)
        # SCC
        graph.add_edge(graph.vertex(0),graph.vertex(1))
        graph.add_edge(graph.vertex(1),graph.vertex(2))
        graph.add_edge(graph.vertex(2),graph.vertex(3))
        graph.add_edge(graph.vertex(3),graph.vertex(4))
        graph.add_edge(graph.vertex(4),graph.vertex(5))
        graph.add_edge(graph.vertex(5),graph.vertex(6))
        graph.add_edge(graph.vertex(6),graph.vertex(0))
        gc.append(copy.deepcopy(graph))

        print("Growing IN")
        for x in range (7, 27):
            new_vertex = graph.add_vertex()
            graph.add_edge(new_vertex, graph.vertex(1))
            gc.append(copy.deepcopy(graph))
        
        print("Growing OUT")
        for x in range (27, 47):
            new_vertex = graph.add_vertex()
            graph.add_edge(graph.vertex(2), new_vertex)
            gc.append(copy.deepcopy(graph))
        
        print("Growing SCC")
        for x in range (7, 27):
            graph.add_edge(graph.vertex(1), graph.vertex(x))
            gc.append(copy.deepcopy(graph))
        
            graph.add_edge(graph.vertex(20+x), graph.vertex(2))
            gc.append(copy.deepcopy(graph))

        graphs.append(gc)
        print("Graphs Created! Starting the plotting")
        self.plot_graph_collection(graphs, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tGrow\t\t(%.2fs)\n" % duration)