def present_k_regular_graphs() -> None: """ Finds k-regular graph for given k and vertices number. """ vertices = int(input('\nNumber of vertices: ')) k = int(input('Put k-parameter: ')) randomizations = int(input("Put number of randomizations: ")) G = Graph() G.create_k_regular_with_n_vertices(k, vertices) randomize(G, randomizations) GraphPlotter.plot_graph(G)
def present_graph_from_file(G: Graph) -> None: operations_choice = '' v = len(G.repr) while operations_choice != 'b': display_submenu() operations_choice = input("Pick the option:\n") try: if operations_choice == '1': cycle = hamilton(G) if cycle == '[]': print('Graph is not Hamiltonian') else: print('Graph is Hamiltonian') print(cycle) if operations_choice == '2': cycle = euler_cycle(G) if cycle == '[]': print('Graph is not Eulerian') else: print('Graph is Eulerian') print(euler_cycle(G)) if operations_choice == '3': G.to_adjacency_matrix() for k in range(1, v): if G.is_k_regular(k): print('Graph is ' + str(k) + '-regular') break if k == v - 1: print('Graph is not k-regular') if operations_choice == '4': G.to_adjacency_matrix() randomizations = int(input('Number of randomizations: ')) randomize(G, randomizations) if operations_choice == '5': G.to_adjacency_list() groups = get_components(G) print_sorted_components(G, groups) GraphPlotter.plot_graph(G, False, False, groups) if operations_choice == '6': GraphPlotter.plot_graph(G) except: print("Something went wrong. Try again!")
def present_graph_randomization() -> None: """ Presents graph randomization for graph using graphical sequence and randomizations parameter. """ print('\nLet\'s start with Your own graphical sequence.\n') sequence = present_graphical_sequence() if sequence != []: randomizations = int(input('Number of randomizations: ')) G = Graph() G.load_data(sequence, RepresentationType.GRAPH_SEQUENCE) G.to_adjacency_matrix() randomize(G, randomizations) GraphPlotter.plot_graph(G)
def present_eulerian_graphs() -> None: """ Generates Eulerian Graph sequence and finds Eulerian Cycle. """ randomizations = 100 v = int(input('\nNumber of vertices: ')) G = Graph() if generate_euler_graph_sequence(G, v): print('Graphical sequence of graph: ' + str(G)) G.to_adjacency_matrix() randomize(G, randomizations) print('Euler Cycle: ' + euler_cycle(G)) GraphPlotter.plot_graph(G) else: print("Error while generating euler graph sequence")
import os, sys import numpy as np currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) from utils.Graph import Graph, RepresentationType from utils.graph_plotter import GraphPlotter from utils.graph_generators import randomize if __name__ == "__main__": G = Graph() G.create_k_regular_with_n_vertices(k=2, vertices=7) randomize(G, 100) GraphPlotter.plot_graph(G)
import os, sys currentdir = os.path.dirname(os.path.realpath(__file__)) parentdir = os.path.dirname(currentdir) sys.path.append(parentdir) from utils.Graph import Graph, RepresentationType from utils.graph_plotter import GraphPlotter from utils.graph_generators import randomize from algorithms.euler import euler_cycle, generate_euler_graph_sequence if __name__ == "__main__": randomizations = 100 G = Graph() v = int(input('Number of vertices: ')) if generate_euler_graph_sequence(G, v): print(G.repr) else: print("Error while generating euler graph sequence") exit() G.to_adjacency_matrix() randomize(G, randomizations) print(euler_cycle(G)) GraphPlotter.plot_graph(G) # minimal input: 3 # maximal input: 100-500 ~up to 62500 edges (without drawing)