def test_small_matrix(self):
     result = hungalg.minimize([[7, 53, 183, 439, 863],
                                [497, 383, 563, 79, 973],
                                [287, 63, 343, 169, 583],
                                [627, 343, 773, 959, 943],
                                [767, 473, 103, 699, 303]])
     self.assertEqual(result, [(0, 0), (1, 3), (2, 2), (3, 1), (4, 4)])
Ejemplo n.º 2
0
 def test_small_matrix(self):
     result = hungalg.minimize(
         [[  7,  53, 183, 439, 863],
          [497, 383, 563,  79, 973],
          [287,  63, 343, 169, 583],
          [627, 343, 773, 959, 943],
          [767, 473, 103, 699, 303]])
     self.assertEqual(result, [( 0, 0), (1, 3), (2, 2), (3, 1), (4, 4)])
Ejemplo n.º 3
0
            'vertex1': vertices[i],
            'vertex2': vertices[j],
            'weight': value
        })
        tour_matrix.append((i + 1, j + 1))

uneven_vertices = check_uneven_vertices(edges, vertices)
uneven_matrix = []

for i, vertex_i in enumerate(uneven_vertices):
    uneven_matrix.append([])
    for j, vertex_j in enumerate(uneven_vertices):
        uneven_matrix[i].append(matrix[ord(vertex_i) - 65][ord(vertex_j) - 65])

print('Отримауємо наступні пари')
for edge in hungalg.minimize(uneven_matrix):
    print('(', uneven_vertices[edge[0]], '->', uneven_vertices[edge[1]], ')')
    vertex_index_1 = ord(uneven_vertices[edge[0]]) - 65
    vertex_index_2 = ord(uneven_vertices[edge[1]]) - 65
    matrix[vertex_index_1][vertex_index_2] *= 2
    tour_matrix.append((vertex_index_1 + 1, vertex_index_2 + 1))

print('Отриманий шлях:')
tour = []
eulerian_tour = eulerian.find_eulerian_tour(sorted(list(set(tour_matrix))))
print('->'.join(map(str, eulerian_tour)))

print('Вага шляху: ', end='')
tour_weight = 0
for i in range(size - 1):
    for j in range(i + 1, size):
Ejemplo n.º 4
0
import hungalg

n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]

ans = hungalg.minimize(mat);
best = sum(mat[i][j] for i,j in ans)
print(best)