def main():
    random.seed()
    num_nodes = 10
    x = [random.randint(-10000, 10000) for _ in range(num_nodes)]
    y = [random.randint(-10000, 10000) for _ in range(num_nodes)]
    nodes = [Node(i, j) for i, j in zip(x, y)]

    graph = AdjacencyMatrix(nodes)
    for elem in graph.mat:
        while True:
            i = random.randrange(0, len(graph.mat))
            j = random.randrange(0, len(graph.mat))
            if i != j and not graph.has_edge(i, j):
                break
        graph.add_edge(i, j)
        graph.add_edge(j, i)
    graph.depth_first_search(random.randrange(0, len(graph.mat)))
    graph.show_graph(draw_edges=False)
Exemple #2
0
    vertex_visited[i] = True
    print(graph.get_vertex_value(i))

    for j in range(graph.get_number()):
        if graph.has_arc(i, j) and not vertex_visited[j]:
            depth_first_search(graph, j)


def depth_first_search_traverse(graph):
    global vertex_visited
    for i in range(graph.get_number()):
        if not vertex_visited[i]:
            depth_first_search(graph, i)


test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I')
test.insert_arc('A', 'B', 1)
test.insert_arc('A', 'F', 1)
test.insert_arc('B', 'G', 1)
test.insert_arc('F', 'G', 1)
test.insert_arc('E', 'F', 1)
test.insert_arc('E', 'H', 1)
test.insert_arc('D', 'E', 1)
test.insert_arc('D', 'H', 1)
test.insert_arc('G', 'H', 1)
test.insert_arc('D', 'G', 1)
test.insert_arc('D', 'I', 1)
test.insert_arc('C', 'D', 1)
test.insert_arc('C', 'I', 1)
test.insert_arc('B', 'C', 1)
test.insert_arc('B', 'I', 1)
Exemple #3
0
        print(final)

        # if not has link between i, j or has short one
        for j in range(1, number):
            if not final[j] and min + \
                    graph.get_arc(k, j, 255) < short_path_weight[j]:
                short_path_weight[j] = min + graph.get_arc(k, j)
                short_vertexs[j] = k

    print(short_vertexs)
    print(short_path_weight)


if __name__ == '__main__':
    from adjacency_matrix import AdjacencyMatrix
    test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I')
    test.insert_arc('A', 'B', 1)
    test.insert_arc('A', 'C', 5)
    test.insert_arc('B', 'C', 3)
    test.insert_arc('B', 'D', 7)
    test.insert_arc('B', 'E', 5)
    test.insert_arc('C', 'E', 1)
    test.insert_arc('C', 'F', 7)
    test.insert_arc('D', 'G', 3)
    test.insert_arc('D', 'E', 2)
    test.insert_arc('E', 'F', 3)
    test.insert_arc('E', 'G', 6)
    test.insert_arc('E', 'H', 9)
    test.insert_arc('F', 'H', 5)
    test.insert_arc('G', 'H', 2)
    test.insert_arc('G', 'I', 7)
        while j < number:
            if lowcast[j] != 0 and lowcast[j] < min:
                min = lowcast[j]
                k = j
            j += 1

        print(adjvex[k], k)
        lowcast[k] = 0
        for j in range(1, number):
            if lowcast[j] != 0 and graph.get_arc(k, j, MAX) < lowcast[j]:
                lowcast[j] = graph.get_arc(k, j, MAX)
                adjvex[j] = k


test = AdjacencyMatrix(False, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I')
test.insert_arc('A', 'B', 10)
test.insert_arc('A', 'F', 11)
test.insert_arc('B', 'G', 16)
test.insert_arc('F', 'G', 17)
test.insert_arc('E', 'F', 26)
test.insert_arc('E', 'H', 7)
test.insert_arc('D', 'E', 20)
test.insert_arc('D', 'H', 16)
test.insert_arc('G', 'H', 19)
test.insert_arc('D', 'G', 24)
test.insert_arc('D', 'I', 21)
test.insert_arc('C', 'D', 22)
test.insert_arc('C', 'I', 8)
test.insert_arc('B', 'C', 18)
test.insert_arc('B', 'I', 12)
Exemple #5
0
 def A(self):
     if self.adjacency_matrix is None:
         self.adjacency_matrix = self.__compute_adjacency_matrix__()
     return AdjacencyMatrix(self.adjacency_matrix, self.vertex_list)
Exemple #6
0
def main(source_path, destination_path, mat_type, tensor_dimension):
    for root, dirs, files in os.walk(source_path, topdown=False):
        for name in tqdm(files):
            adj = AdjacencyMatrix(source_path, destination_path, name.split('_')[0], mat_type, tensor_dimension)
            if mat_type == 'fully_connected':
                adj.fully_connected()
                adj.pad()
                adj.save_file()
            elif mat_type == 'direct_neighbour':
                adj.direct_neighbour()
                adj.save_file()
            elif mat_type == 'nearest_neighbour':
                adj.nearest_neighbour(radius)
                adj.save_file_nearest(radius)
Exemple #7
0
    1: cipher.func1,
    2: cipher.func2,
    3: cipher.func3,
    4: cipher.func4,
    5: cipher.make_gamma
}
lookup_table_modified = {
    1: cipher.func1_new,
    2: cipher.func2_new,
    3: cipher.func3,
    4: cipher.func4,
    5: cipher.make_gamma
}

print('Start original method')
adjacency_matrix = AdjacencyMatrix(init_state=init_state)
exec_flag = True
cur_state = init_state
while exec_flag:
    for cnt in range(len(seq_of_application_of_func)):
        cur_func = seq_of_application_of_func[cnt]
        new_state = lookup_table[cur_func](cur_state)

        if adjacency_matrix.edge_exist(cur_state, new_state, cur_func):
            exec_flag = False
            continue
        adjacency_matrix.add_edge(cur_state, new_state, cur_func)
        cur_state = new_state

print('save_matrix')
adjacency_matrix.save_matrix()