Пример #1
0
def print_dijkstra(G: Graph, s):
    old_representation = G.representation_type
    graph.change_graph_representation_to(
        GraphRepresentationType.ADJACENCY_MATRIX)

    p_s, d_s = dijkstra(G, s)
    w = G.graph_weights

    G.print_graph_representation()
    G.print_weights()

    print("\nSTART: s =", s)

    for v in range(len(p_s)):
        path = []
        print('d({}) = {:>4} ===> '.format(v, d_s[v]), end='')

        currNode = v
        path.append(currNode)

        while p_s[currNode] != None:
            currNode = p_s[currNode]
            path.append(currNode)

        path = path[::-1]  # reversing
        print(path)

    plot_graph(graph)

    G.change_graph_representation_to(old_representation)
Пример #2
0
def find_connected_components(G: Graph):
    old_representation = G.representation_type
    graph.change_graph_representation_to(
        GraphRepresentationType.ADJACENCY_LIST)

    comp = components(graph)
    number_of_connected_components = max(comp)
    connected_components_list = []
    for i in range(number_of_connected_components):
        connected_components_list.append([])
        for j in range(len(G.graph_representation)):
            if (i + 1 == comp[j]):
                connected_components_list[i].append(j)

    for i in range(len(connected_components_list)):
        temp_str = f"{i + 1}: "
        for c in connected_components_list[i]:
            temp_str = temp_str + f"{c} "
        print(temp_str)

    plot_graph(graph, comp)

    G.change_graph_representation_to(old_representation)
Пример #3
0
from utils.handleInput import check_type_of_input, BadInputException, parse_graph_input
from utils.graph import Graph
from utils.plot import plot_graph

if __name__ == "__main__":
    with open('input/input.txt', 'r') as graph_input:
        try:
            graph_input = graph_input.readlines()
            input_type = check_type_of_input(graph_input)
            parsed_graph_input = parse_graph_input(input_type, graph_input)

            graph = Graph(input_type, parsed_graph_input)
            plot_graph(graph)

        except BadInputException:
            print(BadInputException)
Пример #4
0
    clean = fuzz.trimf(cleanness, [5, 10, 10])

    cheap = fuzz.trimf(price, [0, 0, 2.5])
    reasonable = fuzz.trimf(price, [0, 2.5, 5])
    expensive = fuzz.trimf(price, [2.5, 5, 5])

    less = fuzz.trimf(frequency, [1, 1, 10])
    enough = fuzz.trapmf(frequency, [5, 10, 15, 20])
    many = fuzz.trapmf(frequency, [12, 20, 30, 30])

    low = fuzz.trimf(quality, [1, 1, 5])
    medium = fuzz.trimf(quality, [1, 5, 10])
    high = fuzz.trimf(quality, [5, 10, 10])

    # graph plotting
    plot.plot_graph(cleanness, dirty, normal, clean, 'cleanness',
                    'membership function')
    plot.plot_graph(price, cheap, reasonable, expensive, 'price',
                    'membership function')
    plot.plot_graph(frequency, less, enough, many, 'frequency',
                    'membership function')
    plot.plot_graph(quality, low, medium, high, 'quality',
                    'membership function')

    # user input for testing
    test_expensive = float(input('What are the price?'))
    test_frequency = 60 / int(input('How long is train schedule?'))
    test_cleanness = int(input('What are the cleanness?'))

    # Rule 1: If the frequency is less the quality is low
    rule_1_less = fuzz.interp_membership(frequency, less, test_frequency)
    fire_rule1 = rule_1_less
Пример #5
0
from utils.graph import Graph
from utils.plot import plot_graph
from utils.graphRandomizer import generate_Gnl_graph, generate_Gnp_graph

if __name__ == "__main__":
    G_nl = generate_Gnl_graph(6, 10)
    plot_graph(G_nl)

    G_np = generate_Gnp_graph(8, 0.3)
    plot_graph(G_np)