コード例 #1
0
ファイル: main.py プロジェクト: lberzhitskaya/seminar5
for j in range(len(m)):
    x = None
    y = None
    cnt = 0
    for i in range(len(m[0]) - 1):
        if cnt == 0 and m[j][i] == 1:
            x = i
            cnt = 1
            continue
        if m[j][i] == 1 and cnt == 1:
            y = i
            cnt = 2
        if cnt == 2:
            g.add_edge(x, y, weight[j])
            break

g.print_graph()

print('Vertices:', g.vertices())
print('Edges: ', g.edges())
print('Number of edges:', g.num_edges())
print('Number of vertices:', g.num_vertices())
print('Get vertex: ', g.get_vertex(2))
print('Get edge: ', g.get_edge(3, 2))
print('Get adjacents: ', g.adj_vertices(1))

print(prims_algorithm(g.get_data()))


コード例 #2
0
ファイル: main.py プロジェクト: gulnaz8891/seminar5
for j in range(len(t)):
    x = None
    y = None
    cnt = 0
    for i in range(len(t[0]) - 1):
        if cnt == 0 and t[j][i] == 1:
            x = i
            cnt = 1
            continue
        if t[j][i] == 1 and cnt == 1:
            y = i
            cnt = 2
        if cnt == 2:
            g.add_edge(x, y, weight[j])
            break

g.print_graph()
print('Vertices:', g.vertices())
print('Edges: ', g.edges())
print('num_vertices:', g.num_vertices())
print('num_edges:', g.num_edges())
print('get_vertex: ', g.get_vertex(3))
print('get_edge: ', g.get_edge(2, 3))
print('adj_vertices: ', g.adj_vertices(1))
print('Minimum Spanning Tree:')
print(kruskalsalg(g.get_data(), g.num_vertices()))

#Yermagambet Gylnaz

コード例 #3
0
for j in range(len(m)):
    x = None
    y = None
    cnt = 0
    for i in range(len(m[0]) - 1):
        if cnt == 0 and m[j][i] == 1:
            x = i
            cnt = 1
            continue
        if m[j][i] == 1 and cnt == 1:
            y = i
            cnt = 2
        if cnt == 2:
            g.add_edge(x, y, weight[j])
            break

g.print_graph()

print('Vertices:', g.vertices())
print('Edges: ', g.edges())
print('Number of edges:', g.num_edges())
print('Number of vertices:', g.num_vertices())
print('Get vertex: ', g.get_vertex(2))
print('Get edge: ', g.get_edge(3, 2))
print('Get adjacents: ', g.adj_vertices(1))

print(prims_algorithm(g.get_data(), g.num_vertices()))


コード例 #4
0
ファイル: main.py プロジェクト: shaniyev/seminar5
for i in range(len(m[0]) - 1):
    g.add_vertex(i)

for j in range(len(m)):
    x = None
    y = None
    cnt = 0
    for i in range(len(m[0]) - 1):
        if cnt == 0 and m[j][i] == 1:
            x = i
            cnt = 1
            continue
        if m[j][i] == 1 and cnt == 1:
            y = i
            cnt = 2
        if cnt == 2:
            g.add_edge(x, y, weight[j])
            break

g.print_graph()
print('Vertices:', g.vertices())
print('Edges: ', g.edges())
print('Number of edges:', g.num_edges())
print('Number of vertices:', g.num_vertices())
print('Get vertex: ', g.get_vertex(2))
print('Get edge: ', g.get_edge(3, 2))
print('Get adjacents: ', g.adj_vertices(1))
print('Minimum Spanning Tree:')

print(kruskals_algorithm(g.get_data(), g.num_vertices()))