Ejemplo n.º 1
0
def watt_strogatz_3d_plot(p, number_of_average):
	N = np.arange(5, 105, 5)
	K = np.arange(0, 10, 1)
	X = N
	Y = K
	X, Y = np.meshgrid(X, Y)
	Z = X/2

	for i in range(len(N)):
		n = N[i]
		print n
		for j in range(len(K)):
			k = K[j]
			if k>=n/2:
				Z[j][i] = 100
				continue
			average = 0
			for av in range(number_of_average):
				G = watts_strogatz_graph_directed(n, k, p)
				graph = Graph(G)
				graph.stats()
				average = average + graph.bow_tie[1]
			average = average / number_of_average
			Z[j][i] = average
	
	plot_3d(X, Y, Z, '3d_watt_strognatz.png', 'nodes', 'number of outgoing edges per node', 'scc [%]')
Ejemplo n.º 2
0
def erdoes_3d_plot(number_of_average):
	N = np.arange(5, 105, 5)
	X = N
	P = arange(0, 0.2, 0.005)
	Y = P
	X, Y = np.meshgrid(X, Y)
	Z = X/2

	for i in range(len(N)):
		n = N[i]
		print n
		p = 0
		for j in range(len(P)):
			if n > 50 and p > 0.1:
				Z[j][i] = 100
				continue
			average = 0
			for av in range(number_of_average):
				G = nx.gnp_random_graph(n, p, None, 1)
				graph = Graph(G)
				graph.stats()
				average = average + graph.bow_tie[1]
			average = average / number_of_average
			Z[j][i] = average
			p = p + 0.01

	plot_3d(X, Y, Z, '3d_erdoes.png', 'nodes', 'probability of edge creation', 'scc [%]')
Ejemplo n.º 3
0
def random_nm_with_preferential_attachment_plot(number_of_average):
	N = np.arange(5, 105, 5)
	M = np.arange(0, 10, 1)
	X = N
	Y = M
	X, Y = np.meshgrid(X, Y)
	Z = X/2

	for i in range (len(N)):
		n = N[i]
		print n
		for j in range(len(M)):
			m = M[j]
			if m >= n:
				Z[j][i] = 100
				continue
			average = 0
			for av in range(number_of_average):
				G = create_random_nm_graph_with_preferential_attachment(n, m) 
				graph = Graph(G)
				graph.stats()
				average = average + graph.bow_tie[1]
			average = average / number_of_average
			Z[j][i] = average

	plot_3d(X, Y, Z, '3d_random_nm_with_preferential_attachment.png', 'nodes', 'number of outgoing edges per node', 'scc [%]')
Ejemplo n.º 4
0
 def test_ancestors_with_crossing_paths(self):
     graph = Graph()
     graph.add_edges([
         Edge('a', 'b', 1),
         Edge('a', 'c', 1),
         Edge('c', 'd', 1),
         Edge('b', 'd', 1)])
     self.assertCountEqual(graph.ancestors('d'), ['a', 'b', 'c', 'd'])
Ejemplo n.º 5
0
def get_values():
    wt = list()
    val = list()
    n = int(nombre_arc_entry.get())
    for i in range(1,n+1):
        wt.append(int(tab1.grid_slaves(i, 1)[0].get()))
        val.append(int(tab1.grid_slaves(i, 2)[0].get()))
    print(wt,val)    

    initial_graph = Graph(int(nombre_nodes_entry.get()))



    for i in range(n):
        initial_graph.addEdge(wt[i],val[i])
    
    
    initial_graph.DrawGraph()

    initial_graph.PrintGraph()
    
   
    
    initial_graph.Color()
    plt.show()


    newWindow = Toplevel(window) 
    newWindow.title("point d'articulation") 
    newWindow.geometry("200x200") 
    
    points = "les points d'articulation son : " + str(initial_graph.AP())
    point = Label(newWindow, text=points).pack()
    
    """
Ejemplo n.º 6
0
def watts_strogatz(n, k, p_start, p_end, p_step, number_of_average):
	x = []
	bow_tie = []
	legend = ["inc", "scc", "outc", "in_tendril", "out_tendril", "tube", "other"]

	p = p_start
	while p < p_end:
		average = np.array([0,0,0,0,0,0,0])
		for i in range(number_of_average):
			G = watts_strogatz_graph_directed(n, k, p)
			graph = Graph(G)
			graph.stats()
			average = average + graph.bow_tie
		average = average / number_of_average
		x.append(p)
		bow_tie.append(average)
		p = p + p_step
	
	plt.plot(x, bow_tie)
	plt.legend(legend, loc='right', shadow=True)
	plt.xlabel('probability for edge rewiring')
	plt.ylabel('percent')
	plt.savefig('test.png')
Ejemplo n.º 7
0
def erdoes(n, p_start, p_end, p_step, number_of_average):
	x = []
	bow_tie = []
	legend = ["inc", "scc", "outc", "in_tendril", "out_tendril", "tube", "other"]

	p = p_start
	while p < p_end:
		average = np.array([0,0,0,0,0,0,0])
		for i in range(number_of_average):
			G = nx.gnp_random_graph(n, p, None, 1)
			graph = Graph(G)
			graph.stats()
			average = average + graph.bow_tie
		average = average / number_of_average
		x.append(p)
		bow_tie.append(average)
		p = p + p_step

	plt.plot(x, bow_tie)
	plt.legend(legend, loc='right', shadow=True)
	plt.xlabel('probability for edge creation')
	plt.ylabel('percent') 
	plt.savefig('test.png')
Ejemplo n.º 8
0
def random_graph_3d_plot(number_of_average):
	N = np.arange(5, 55, 5)
	X = N
	M = np.arange(1, 101, 5)
	Y = M
	X, Y = np.meshgrid(X, Y)
	Z = X/2

	for i in range(len(N)):
		n = N[i]
		print n
		for j in range(len(M)):
			m = M[j]
			average = 0
			for av in range(number_of_average):
				G = nx.gnm_random_graph(n, m, None, 1)
				graph = Graph(G)
				graph.stats()
				average = average + graph.bow_tie[1]
			average = average / number_of_average
			Z[j][i] = average

	plot_3d(X, Y, Z, '3d_random_graph.png', 'nodes', 'edges', 'scc [%]')
Ejemplo n.º 9
0
def barabasi_albert(n, m_start, m_end, number_of_average):
	print("barabasi_albert called")
	x = []
	bow_tie = []
	legend = ["inc", "scc", "outc", "in_tendril", "out_tendril", "tube", "other"]

	m = m_start
	while m < m_end:
		average = np.array([0,0,0,0,0,0,0])
		for i in range(number_of_average):
			G = barabasi_albert_graph_directed(n, m)
			graph = Graph(G)
			graph.stats()
			average = average + graph.bow_tie
		average = average / number_of_average
		x.append(m)
		bow_tie.append(average)
		m = m + 1

	plt.plot(x, bow_tie)
	plt.legend(legend, loc='right', shadow=True)
	plt.xlabel('number of edges from new node')
	plt.ylabel('percent')
	plt.savefig('barabasi_albert_components.png')
Ejemplo n.º 10
0
 def test_ancestors(self):
     graph = Graph()
     graph.add_edges([
         Edge('a', 'b', 1),
         Edge('a', 'c', 1),
         Edge('c', 'd', 1)])
     self.assertCountEqual(graph.ancestors('a'), ['a'])
     self.assertCountEqual(graph.ancestors('b'), ['a', 'b'])
     self.assertCountEqual(graph.ancestors('c'), ['a', 'c'])
     self.assertCountEqual(graph.ancestors('d'), ['a', 'c', 'd'])
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    def test_big_out(self):
        print("Plotting Test Start:\tBig Out ")
        start_time = time.time()
        name = "big_out"
        graph = Graph()
        vList = graph.add_vertex(22)

        # IN-Layers
        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(0))
        graph.add_edge(graph.vertex(2), graph.vertex(3))

        graph.add_edge(graph.vertex(3), graph.vertex(4))
        graph.add_edge(graph.vertex(3), graph.vertex(5))
        graph.add_edge(graph.vertex(3), graph.vertex(6))

        graph.add_edge(graph.vertex(4), graph.vertex(7))
        graph.add_edge(graph.vertex(4), graph.vertex(8))
        graph.add_edge(graph.vertex(5), graph.vertex(9))
        graph.add_edge(graph.vertex(5), graph.vertex(10))
        graph.add_edge(graph.vertex(6), graph.vertex(11))
        graph.add_edge(graph.vertex(6), graph.vertex(12))

        graph.add_edge(graph.vertex(7), graph.vertex(13))
        graph.add_edge(graph.vertex(8), graph.vertex(13))
        graph.add_edge(graph.vertex(9), graph.vertex(13))
        graph.add_edge(graph.vertex(10), graph.vertex(14))
        graph.add_edge(graph.vertex(11), graph.vertex(14))
        graph.add_edge(graph.vertex(12), graph.vertex(14))

        graph.add_edge(graph.vertex(13), graph.vertex(15))
        graph.add_edge(graph.vertex(14), graph.vertex(16))
        graph.add_edge(graph.vertex(13), graph.vertex(17))
        graph.add_edge(graph.vertex(14), graph.vertex(18))
        graph.add_edge(graph.vertex(13), graph.vertex(19))
        graph.add_edge(graph.vertex(14), graph.vertex(20))
        graph.add_edge(graph.vertex(13), graph.vertex(21))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tBig Out \t(%.2fs)\n" % duration)
Ejemplo n.º 13
0
    def test_big_scc(self):
        print("Plotting Test Start:\tBig SCC")
        start_time = time.time()
        graph = Graph()
        graph.add_vertex(13)

        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(7))
        graph.add_edge(graph.vertex(7), graph.vertex(8))
        graph.add_edge(graph.vertex(8), graph.vertex(9))
        graph.add_edge(graph.vertex(9), graph.vertex(10))
        graph.add_edge(graph.vertex(10), graph.vertex(11))
        graph.add_edge(graph.vertex(11), graph.vertex(12))
        graph.add_edge(graph.vertex(12), graph.vertex(1))
        self.plot_graph(graph, "big_scc")
        duration = (time.time() - start_time)
        print("Plotting Test End:\tBig SCC\t\t(%.2fs)\n" % duration)
Ejemplo n.º 14
0
    def test_40nodes_in_scc_out(self):
        print("Plotting Test Start:\t40 Nodes ")
        start_time = time.time()
        name = "40_nodes"
        graph = Graph()
        vList = graph.add_vertex(40)

        # 1st and 2nd layer IN
        graph.add_edge(graph.vertex(0), graph.vertex(6))
        graph.add_edge(graph.vertex(1), graph.vertex(6))
        graph.add_edge(graph.vertex(2), graph.vertex(6))
        graph.add_edge(graph.vertex(3), graph.vertex(6))
        graph.add_edge(graph.vertex(4), graph.vertex(6))

        # 3rd layer IN
        graph.add_edge(graph.vertex(6), graph.vertex(7))
        graph.add_edge(graph.vertex(6), graph.vertex(8))
        graph.add_edge(graph.vertex(6), graph.vertex(9))
        graph.add_edge(graph.vertex(6), graph.vertex(10))
        graph.add_edge(graph.vertex(5), graph.vertex(7))

        # 4th layer IN
        graph.add_edge(graph.vertex(7), graph.vertex(11))
        graph.add_edge(graph.vertex(8), graph.vertex(11))
        graph.add_edge(graph.vertex(9), graph.vertex(12))
        graph.add_edge(graph.vertex(10), graph.vertex(12))

        # 5th layer IN (13, 14, 15, 16, 17)
        graph.add_edge(graph.vertex(11), graph.vertex(13))
        graph.add_edge(graph.vertex(11), graph.vertex(14))
        graph.add_edge(graph.vertex(11), graph.vertex(15))
        graph.add_edge(graph.vertex(12), graph.vertex(16))
        graph.add_edge(graph.vertex(12), graph.vertex(17))
        
        # build SCC
        # scc nodes from in (18, 19, 20)
        graph.add_edge(graph.vertex(13), graph.vertex(18))
        graph.add_edge(graph.vertex(14), graph.vertex(19))
        graph.add_edge(graph.vertex(15), graph.vertex(18))
        graph.add_edge(graph.vertex(16), graph.vertex(19))
        graph.add_edge(graph.vertex(17), graph.vertex(20))

        # scc nodes from in and to out (21, 22, 23, 24)
        graph.add_edge(graph.vertex(14), graph.vertex(21))
        graph.add_edge(graph.vertex(15), graph.vertex(22))
        graph.add_edge(graph.vertex(16), graph.vertex(23))
        graph.add_edge(graph.vertex(17), graph.vertex(24))
        graph.add_edge(graph.vertex(21), graph.vertex(31))
        graph.add_edge(graph.vertex(22), graph.vertex(31))
        graph.add_edge(graph.vertex(23), graph.vertex(30))
        graph.add_edge(graph.vertex(24), graph.vertex(29))

        # Internal SCC (25, 26)
        graph.add_edge(graph.vertex(18), graph.vertex(24))
        graph.add_edge(graph.vertex(18), graph.vertex(23))
        graph.add_edge(graph.vertex(19), graph.vertex(23))
        graph.add_edge(graph.vertex(19), graph.vertex(22))
        graph.add_edge(graph.vertex(18), graph.vertex(25))
        graph.add_edge(graph.vertex(20), graph.vertex(26))
        graph.add_edge(graph.vertex(21), graph.vertex(27))
        graph.add_edge(graph.vertex(22), graph.vertex(27))
        graph.add_edge(graph.vertex(24), graph.vertex(28))
        graph.add_edge(graph.vertex(25), graph.vertex(21))
        graph.add_edge(graph.vertex(27), graph.vertex(28))
        graph.add_edge(graph.vertex(28), graph.vertex(20))

        # back links (to ensure scc)
        graph.add_edge(graph.vertex(25), graph.vertex(19))
        graph.add_edge(graph.vertex(25), graph.vertex(20))
        graph.add_edge(graph.vertex(26), graph.vertex(18))
        graph.add_edge(graph.vertex(21), graph.vertex(22))
        graph.add_edge(graph.vertex(23), graph.vertex(24))

        # scc nodes to out (27, 28)
        graph.add_edge(graph.vertex(27), graph.vertex(29))
        graph.add_edge(graph.vertex(28), graph.vertex(29))
        graph.add_edge(graph.vertex(28), graph.vertex(30))
        graph.add_edge(graph.vertex(28), graph.vertex(31))

        # multiple out layers
        graph.add_edge(graph.vertex(31), graph.vertex(32))
        graph.add_edge(graph.vertex(32), graph.vertex(33))
        graph.add_edge(graph.vertex(32), graph.vertex(34))
        graph.add_edge(graph.vertex(32), graph.vertex(35))
        graph.add_edge(graph.vertex(34), graph.vertex(36))
        graph.add_edge(graph.vertex(35), graph.vertex(37))
        graph.add_edge(graph.vertex(37), graph.vertex(38))
        graph.add_edge(graph.vertex(37), graph.vertex(39))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\t40 Nodes \t(%.2fs)\n" % duration)
Ejemplo n.º 15
0
    def test_tiny(self):
        print("Plotting Test Start:\tTiny Graph")
        start_time = time.time()
        graph = Graph()
        vList = graph.add_vertex(8)

        # build scc
        graph.add_edge(graph.vertex(0), graph.vertex(1))
        graph.add_edge(graph.vertex(0), graph.vertex(2))
        graph.add_edge(graph.vertex(0), graph.vertex(3))
        
        graph.add_edge(graph.vertex(1), graph.vertex(0))
        graph.add_edge(graph.vertex(1), graph.vertex(2))
        graph.add_edge(graph.vertex(1), graph.vertex(3))
        
        graph.add_edge(graph.vertex(2), graph.vertex(0))
        graph.add_edge(graph.vertex(2), graph.vertex(1))
        graph.add_edge(graph.vertex(2), graph.vertex(3))
        
        graph.add_edge(graph.vertex(3), graph.vertex(0))
        graph.add_edge(graph.vertex(3), graph.vertex(1))
        graph.add_edge(graph.vertex(3), graph.vertex(2))

        # build in
        graph.add_edge(graph.vertex(4), graph.vertex(0))
        graph.add_edge(graph.vertex(5), graph.vertex(1))
        
        # build out
        graph.add_edge(graph.vertex(2), graph.vertex(6))
        graph.add_edge(graph.vertex(3), graph.vertex(7))

        self.plot_graph(graph, "tiny")
        duration = (time.time() - start_time)
        print("Plotting Test End:\tTiny Graph\t(%.2fs)\n" % duration)
Ejemplo n.º 16
0
    def test_30nodes_in_scc_out(self):
        print("Plotting Test Start:\t30 Nodes ")
        start_time = time.time()
        name = "30_nodes"
        graph = Graph()
        vList = graph.add_vertex(30)

        # IN-Layers
        graph.add_edge(graph.vertex(0), graph.vertex(3))
        graph.add_edge(graph.vertex(1), graph.vertex(3))
        graph.add_edge(graph.vertex(2), graph.vertex(4))
        graph.add_edge(graph.vertex(3), graph.vertex(5))
        graph.add_edge(graph.vertex(4), graph.vertex(3))
        graph.add_edge(graph.vertex(4), graph.vertex(6))
        graph.add_edge(graph.vertex(5), graph.vertex(6))
        graph.add_edge(graph.vertex(5), graph.vertex(7))
        graph.add_edge(graph.vertex(6), graph.vertex(7))
        graph.add_edge(graph.vertex(6), graph.vertex(8))

        # scc
        # in from scc (8,9,10,11)
        graph.add_edge(graph.vertex(7), graph.vertex(9))
        graph.add_edge(graph.vertex(7), graph.vertex(10))
        graph.add_edge(graph.vertex(7), graph.vertex(11))
        graph.add_edge(graph.vertex(8), graph.vertex(9))
        graph.add_edge(graph.vertex(9), graph.vertex(10))
        graph.add_edge(graph.vertex(9), graph.vertex(11))
        graph.add_edge(graph.vertex(10), graph.vertex(11)) 
        graph.add_edge(graph.vertex(10), graph.vertex(14))
        graph.add_edge(graph.vertex(11), graph.vertex(8))
        graph.add_edge(graph.vertex(11), graph.vertex(12))
        graph.add_edge(graph.vertex(12), graph.vertex(13))
        graph.add_edge(graph.vertex(13), graph.vertex(11))
        graph.add_edge(graph.vertex(13), graph.vertex(16))
        graph.add_edge(graph.vertex(14), graph.vertex(9))
        graph.add_edge(graph.vertex(14), graph.vertex(15))
        graph.add_edge(graph.vertex(14), graph.vertex(17))
        graph.add_edge(graph.vertex(15), graph.vertex(18))
        graph.add_edge(graph.vertex(15), graph.vertex(10))
        graph.add_edge(graph.vertex(16), graph.vertex(12))
        graph.add_edge(graph.vertex(16), graph.vertex(17))
        graph.add_edge(graph.vertex(11), graph.vertex(18))

        # OUT-Layers
        graph.add_edge(graph.vertex(18), graph.vertex(19))
        graph.add_edge(graph.vertex(18), graph.vertex(20))
        graph.add_edge(graph.vertex(18), graph.vertex(21))
        graph.add_edge(graph.vertex(17), graph.vertex(20))
        graph.add_edge(graph.vertex(17), graph.vertex(22))
        graph.add_edge(graph.vertex(17), graph.vertex(23))
        
        graph.add_edge(graph.vertex(19), graph.vertex(24))
        graph.add_edge(graph.vertex(20), graph.vertex(24))
        graph.add_edge(graph.vertex(20), graph.vertex(25))
        graph.add_edge(graph.vertex(20), graph.vertex(26))
        graph.add_edge(graph.vertex(21), graph.vertex(26))
        graph.add_edge(graph.vertex(22), graph.vertex(26))
        graph.add_edge(graph.vertex(22), graph.vertex(27))
        graph.add_edge(graph.vertex(23), graph.vertex(27))
        graph.add_edge(graph.vertex(24), graph.vertex(28))
        graph.add_edge(graph.vertex(27), graph.vertex(28))
        graph.add_edge(graph.vertex(27), graph.vertex(29))
        graph.add_edge(graph.vertex(28), graph.vertex(23))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\t30 Nodes \t(%.2fs)\n" % duration)
Ejemplo n.º 17
0
        pvg.add_edge(edge.v_from, edge.v_to)
    return pvg


def test(number, graph):
    pvg = convert_graph_to_pvg(graph)
    pvg.layout()
    pvg.draw('test results/test' + number + '.png')
    print('wrote test' + number + '.png')


test(
    '001',
    Graph({'a', 'b', 'c', 'd'},
          {Edge('a', 'b'),
           Edge('c', 'd'),
           Edge('d', 'b'),
           Edge('c', 'a')}))

test(
    '002',
    Graph.topological_sort(
        Graph({'a', 'b', 'c', 'd'},
              {Edge('a', 'b'), Edge('c', 'd'),
               Edge('d', 'b')},
              directed=True), 'a'))

test(
    '003',
    Graph({'a', 'b', 'c', 'd', 'e'},
          {Edge('a', 'b'),
Ejemplo n.º 18
0
print "graph created. start calculation..."

'''
x = []
y = set()
for i in range(1,60000):
	if i not in y:
		x.append(i)
		y.add(i)
	if i%100 == 0:
		print i



'''
t1 = time.time()

graph = Graph(G)
graph.stats()
print graph.bow_tie

t2 = time.time()

graph = BowTie(G)
graph.stats()
print graph.bow_tie

t3 = time.time()
print "Time for the first programm: %s" %(t2-t1)
print "Time for the second programm: %s" %(t3-t2)
Ejemplo n.º 19
0
    for vertex in graph.get_vertices():
        pvg.add_node(vertex)
    for edge in graph.get_edges():
        pvg.add_edge(edge.v_from, edge.v_to)
    return pvg


def test(number, graph):
    pvg = convert_graph_to_pvg(graph)
    pvg.layout()
    pvg.draw('test results/test' + number + '.png')
    print('wrote test' + number + '.png')


test('001', Graph({'a', 'b', 'c', 'd'}, {
                    Edge('a', 'b'),
                    Edge('c', 'd'),
                    Edge('d', 'b'),
                    Edge('c', 'a')}))

test('002', Graph.topological_sort(Graph({'a', 'b', 'c', 'd'}, {
                            Edge('a', 'b'),
                            Edge('c', 'd'),
                            Edge('d', 'b')}, directed=True), 'a'))

test('003', Graph({'a', 'b', 'c', 'd', 'e'}, {
                    Edge('a', 'b'),
                    Edge('c', 'd'),
                    Edge('d', 'b'),
                    Edge('c', 'a')}, True))
Ejemplo n.º 20
0
 def test_1(self):
     g = Graph(['A', 'B', 'C', 'D', 'E', 'F'], [(0, 1, 10), (0, 2, 8),
                                                (1, 2, 1), (1, 3, 30),
                                                (1, 4, 6), (2, 4, 20),
                                                (3, 4, 7), (4, 5, 15)])
     print(g.floyd())
Ejemplo n.º 21
0
    def test_success(self):

        gr = Graph(9, 0, 4, g)
        self.assertEqual(gr.retShortestPath(), 21)
Ejemplo n.º 22
0
import json

from flask import Flask, request, jsonify
from urllib.parse import urlparse, parse_qs

from main import Graph

app = Flask(__name__)

graph = Graph()


def create_command(command, data):
    try:
        if data[1].strip() != 'content-type : application/json':
            return jsonify({"msg": "Invalid command syntax"}), 400

        if command[1].strip() == '/devices':
            request_data = json.loads(data[2])
            status_code, msg = graph.add_node(request_data["name"], request_data["type"])
            return jsonify({"msg": msg}), status_code

        elif command[1].strip() == '/connections':
            request_data = json.loads(data[2])
            status_code, msg = graph.add_connection(request_data["source"], request_data["targets"])
            return jsonify({"msg": msg}), status_code
    except Exception as e:
        return jsonify({"msg": "Invalid command syntax"}), 400


def modify_command(command, data):
Ejemplo n.º 23
0
    def test_all_components(self):
        print("Plotting Test Start:\tAll Components")
        start_time = time.time()
        name = "all_components"
        graph = Graph()
        vList = graph.add_vertex(20)

        # build in
        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(1))
        graph.add_edge(graph.vertex(16), graph.vertex(1))

        graph.add_edge(graph.vertex(1), graph.vertex(0))

        # build scc
        graph.add_edge(graph.vertex(2), graph.vertex(5))
        graph.add_edge(graph.vertex(3), graph.vertex(4))
        graph.add_edge(graph.vertex(3), graph.vertex(6))
        graph.add_edge(graph.vertex(4), graph.vertex(5))
        graph.add_edge(graph.vertex(5), graph.vertex(6))
        graph.add_edge(graph.vertex(5), graph.vertex(7))
        graph.add_edge(graph.vertex(6), graph.vertex(4))
        graph.add_edge(graph.vertex(2), graph.vertex(13))
        graph.add_edge(graph.vertex(15), graph.vertex(6))
        graph.add_edge(graph.vertex(4), graph.vertex(15))
        graph.add_edge(graph.vertex(13), graph.vertex(15))
        graph.add_edge(graph.vertex(4), graph.vertex(13))

        # build out
        graph.add_edge(graph.vertex(6), graph.vertex(7))
        graph.add_edge(graph.vertex(13), graph.vertex(14))
        graph.add_edge(graph.vertex(14), graph.vertex(17))
        graph.add_edge(graph.vertex(14), graph.vertex(18))
        graph.add_edge(graph.vertex(17), graph.vertex(18))

        # build tube
        graph.add_edge(graph.vertex(3), graph.vertex(9))
        graph.add_edge(graph.vertex(9), graph.vertex(10))
        graph.add_edge(graph.vertex(10), graph.vertex(11))
        graph.add_edge(graph.vertex(11), graph.vertex(7))

        # Out-Tendril
        graph.add_edge(graph.vertex(8), graph.vertex(7))

        # Other
        graph.add_edge(graph.vertex(8), graph.vertex(12))

        # In-Tendril
        graph.add_edge(graph.vertex(16), graph.vertex(19))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tAll Components\t(%.2fs)\n" % duration)
Ejemplo n.º 24
0
import sys

# definindo cores
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
GRAY = (30, 30, 29)

pygame.init()
sair = True
    #fps
frame = pygame.time.Clock()

graph = Graph()
graph.create(5, 5)
bot = Game()


# PROCESSAMENTO DE ENTRADA
screen = pygame.display.set_mode((640, 480))
contador = 0
# carregando fonte
font = pygame.font.SysFont(None, 55)
#titulo da janela
pygame.display.set_caption('Dots & Boxes')

# preenchendo o fundo com preto
screen.fill(BLACK)
Ejemplo n.º 25
0
    def test_small(self):
        print("Plotting Test Start:\tSmall Graph")
        start_time = time.time()
        name = "small"
        graph = Graph()
        vList = graph.add_vertex(14)

        # build 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(0))

        # build in
        graph.add_edge(graph.vertex(9), graph.vertex(0))
        graph.add_edge(graph.vertex(9), graph.vertex(5))
        graph.add_edge(graph.vertex(11), graph.vertex(5))
        graph.add_edge(graph.vertex(10), graph.vertex(11))
        graph.add_edge(graph.vertex(11), graph.vertex(12))
        graph.add_edge(graph.vertex(12), graph.vertex(10))
        graph.add_edge(graph.vertex(13), graph.vertex(5))
        graph.add_edge(graph.vertex(13), graph.vertex(4))

        # build out
        graph.add_edge(graph.vertex(1), graph.vertex(6))
        graph.add_edge(graph.vertex(2), graph.vertex(7))
        graph.add_edge(graph.vertex(3), graph.vertex(8))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tSmall Graph\t(%.2fs)\n" % duration)
Ejemplo n.º 26
0
    def test_bowtie(self):
        graph = Graph()
        vList = graph.add_vertex(13)

        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(1))

        graph.add_edge(graph.vertex(1), graph.vertex(0))

        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(4))

        graph.add_edge(graph.vertex(6), graph.vertex(7))

        graph.add_edge(graph.vertex(3), graph.vertex(9))
        graph.add_edge(graph.vertex(9), graph.vertex(10))
        graph.add_edge(graph.vertex(10), graph.vertex(11))
        graph.add_edge(graph.vertex(11), graph.vertex(7))

        graph.add_edge(graph.vertex(8), graph.vertex(7))
        graph.add_edge(graph.vertex(8), graph.vertex(12))

        graph.stats()
        self.assertEqual(graph.bow_tie,
                [
                300/len(list(graph.vertices())),
                300/len(list(graph.vertices())),
                100/len(list(graph.vertices())),
                100/len(list(graph.vertices())),
                100/len(list(graph.vertices())),
                300/len(list(graph.vertices())),
                100/len(list(graph.vertices()))
                ]
                )
Ejemplo n.º 27
0
        exit(0)
    else:
        pass
    if ([{'z', 'a'}, {'b', 'y'}, {'c', 'x'}, {'d', 'w'}] == return_val):
        print(return_val)
        flag+=1
        exit(0)
    else:
        pass
    if ([{'q', 'p'}, {'w', 'o'}, {'e', 'i'}, {'r', 'u'}] == return_val):
        print(return_val)
        flag+=1
        exit(0)
    else:
        pass
    if ([{'a', 'l'}, {'s', 'k'}, {'j', 'd'}, {'f', 'h'}] == return_val):
        print(return_val)
        flag+=1
        exit(0)
    else:
        pass
    if(flag==0):
        print('0')
keys = list(map(str,input().split()))
values =list(map(str,input().split()))
g = {}
for key, value in zip(keys, values):
    g[key] = value
graph = Graph(g)
test_case1(graph.edges())
Ejemplo n.º 28
0
    def test_ultra_long_tube(self):
        print("Plotting Test Start:\tUltra Long Tube ")
        start_time = time.time()
        name = "ultra_long_tube"
        graph = Graph()
        vList = graph.add_vertex(26)

        # build in
        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(1))
        graph.add_edge(graph.vertex(4), graph.vertex(5))
        graph.add_edge(graph.vertex(6), graph.vertex(5))
        graph.add_edge(graph.vertex(5), graph.vertex(3))

        # build scc
        graph.add_edge(graph.vertex(3), graph.vertex(7))
        graph.add_edge(graph.vertex(2), graph.vertex(11))
        graph.add_edge(graph.vertex(7), graph.vertex(8))
        graph.add_edge(graph.vertex(8), graph.vertex(9))
        graph.add_edge(graph.vertex(9), graph.vertex(10))
        graph.add_edge(graph.vertex(10), graph.vertex(11))
        graph.add_edge(graph.vertex(11), graph.vertex(7))

        # build out
        graph.add_edge(graph.vertex(8), graph.vertex(12))
        graph.add_edge(graph.vertex(12), graph.vertex(13))
        graph.add_edge(graph.vertex(12), graph.vertex(14))
        graph.add_edge(graph.vertex(9), graph.vertex(15))
        graph.add_edge(graph.vertex(15), graph.vertex(16))

        # build tube
        graph.add_edge(graph.vertex(5), graph.vertex(17))
        graph.add_edge(graph.vertex(17), graph.vertex(18))
        graph.add_edge(graph.vertex(18), graph.vertex(19))
        graph.add_edge(graph.vertex(19), graph.vertex(20))
        graph.add_edge(graph.vertex(20), graph.vertex(21))
        graph.add_edge(graph.vertex(21), graph.vertex(22))
        graph.add_edge(graph.vertex(22), graph.vertex(23))
        graph.add_edge(graph.vertex(23), graph.vertex(24))
        graph.add_edge(graph.vertex(24), graph.vertex(25))
        graph.add_edge(graph.vertex(25), graph.vertex(16))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\tUltra Long Tube \t\t(%.2fs)\n" % duration)
Ejemplo n.º 29
0
    def test_failed(self):

        gr = Graph(9, 0, 4, g)
        self.assertEqual(gr.retShortestPath(), 20)
Ejemplo n.º 30
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)
Ejemplo n.º 31
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)
Ejemplo n.º 32
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)
    return 15

def func7():
    print("func7")
    return 17


a = Node("A", func1)
b = Node("B", func2)
c = Node("C", func3)
d = Node("D", func4)
e = Node("E", func5)
f = Node("F", func6)
h = Node("H", func7)

g = Graph()
g.add_node(c)
g.add_node(b)
g.add_node(d)
g.add_node(e)
g.add_node(a)
g.add_node(f)
g.add_node(h)

g.add_edge(a, b)
g.add_edge(a, c)
g.add_edge(b, d)
g.add_edge(b, e)
g.add_edge(e, f)
g.add_edge(c, d)
g.add_edge(f, h)
Ejemplo n.º 34
0
    def test_10nodes_in_scc_out(self):
        print("Plotting Test Start:\t10 Nodes ")
        start_time = time.time()
        name = "10_nodes"
        graph = Graph()
        vList = graph.add_vertex(10)

        # IN-Layers
        graph.add_edge(graph.vertex(0), graph.vertex(1))
        graph.add_edge(graph.vertex(1), graph.vertex(2))
        graph.add_edge(graph.vertex(1), graph.vertex(3))
        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(2))
        graph.add_edge(graph.vertex(2), graph.vertex(6))
        graph.add_edge(graph.vertex(6), graph.vertex(7))
        graph.add_edge(graph.vertex(7), graph.vertex(5))
        graph.add_edge(graph.vertex(7), graph.vertex(8))
        graph.add_edge(graph.vertex(7), graph.vertex(9))
        graph.add_edge(graph.vertex(8), graph.vertex(6))
        graph.add_edge(graph.vertex(8), graph.vertex(9))

        self.plot_graph(graph, name)
        duration = (time.time() - start_time)
        print("Plotting Test End:\t10 Nodes \t(%.2fs)\n" % duration)
Ejemplo n.º 35
0
    def test_bowtie(self):
        graph = Graph()
        graph.add_edge(1, 2)
        graph.add_edge(2, 3)
        graph.add_edge(3, 1)

        graph.add_edge(1, 0)

        graph.add_edge(3, 4)
        graph.add_edge(4, 5)
        graph.add_edge(5, 6)
        graph.add_edge(6, 4)

        graph.add_edge(6, 7)

        graph.add_edge(3, 9)
        graph.add_edge(9, 10)
        graph.add_edge(10, 11)
        graph.add_edge(11, 7)

        graph.add_edge(8, 7)
        graph.add_edge(8, 12)

        graph.stats()
        self.assertEqual(graph.bow_tie, [300/len(graph), 300/len(graph),
                                         100/len(graph), 100/len(graph),
                                         100/len(graph), 300/len(graph),
                                         100/len(graph)])
Ejemplo n.º 36
0
from rolling import roll
import classes
import monsters
from os import system, name


def clear_console():
    if name == 'nt':
        system('cls')
    else:
        system('clear')


char = classes.fighter

g = Graph.create_graph(10, 10)

game = Game()
game.place_monster(g, create_moster(monsters.GOBLIN.copy()))
char_place = game.place_char(g, char, 94)
lvl_up = classes.LvlUp(char)

lvl_up.show_hero()
Graphic.show_map(g)
while not game.game_over:
    go = input('your turn\n>>>')
    if not game.your_turn:
        clear_console()
    game.go_char(g, go, char)
    if game.win:
        game.win = False