import numpy as np from functions.reading_writing_function import get_graph from algorithms.prims_algorithm import prims from functions.graph_operations import * input_graph = get_graph('G1.txt') start_node = int(input(f'Choose a starting node, {input_graph[0]}:')) print('') prims_MST = prims(input_graph, start_node) total_tree_weight = total_tree_weight(input_graph, prims_MST) vertices, edges = prims_MST #[NODES],[(EDGES)] T = ([0], [()]) print('') print('Prim' 's algorithm - "minimum spanning tree"') print('') print(f'MST NODES: {vertices}') print(f'MST EDGES : {edges}') print('') print(f'MST WEIGHT (cost): {total_tree_weight}')
from algorithms.prims_algorithms import Prims import numpy as np import os from functions.reading_writing_function import get_graph from functions.graph_operations import * os.system("cls") # used to clear the console on windows machines File = input(' Input name of file that cotians the graph. :') Graph = get_graph('G' + File) starting_point = int(input(f' {Graph[0]} \n Pick a vertex. :')) minimum_spanning_tree = Prims(Graph, starting_point) cost_of_tree = total_cost_of_tree(Graph, minimum_spanning_tree) vertices, edges = minimum_spanning_tree T = ([0, 1, 4], [(0, 1), (1, 4)]) print(f'''\n The minimun spanining tree Vetices: {vertices}, {len(vertices)} Edges : {edges}, {len(edges)} and the total cost of the tree {total_cost_of_tree(Graph, minimum_spanning_tree)} ********* prims output ********** {minimum_spanning_tree}
from algorithms.prims_algorithms import Prims from functions.reading_writing_function import get_graph from functions.graph_operations import * import os os.system("cls") # used to clear the console on windows machines T = ([0, 2, 1, 9, 4, 5, 6, 3, 11, 7, 8, 10], [(0, 2), (1, 2), (2, 9), (1, 4), (4, 5), (2, 6), (4, 3), (3, 11), (5, 7), (7, 8), (7, 10)]) Graph = get_graph('FinalG') #starting_point = int( input(f' {Graph[0]} \n Pick a vertex. :')) starting_point = 3 minimum_spanning_tree = Prims(Graph, starting_point) cost_of_tree = total_cost_of_tree(Graph, minimum_spanning_tree) vertices, edges = minimum_spanning_tree print(f'''\n The minimun spanining tree Vetices: {vertices}, total: {len(vertices)} Edges : {edges}, total: {len(edges)} Total cost of the tree: {total_cost_of_tree(Graph, minimum_spanning_tree)} ''' )
import numpy as np import os from functions.reading_writing_function import get_graph from functions.graph_operations import inceident_edgees, cost def star (): print ('*******') G = get_graph('G1') os.system("cls") star() print (f'V(G) = {G[0]}') print (f'V(E) = {G[1]}') star() #tree T = ([3, 1, 4], [(1, 3), (1, 4)]) ''' star() for e in G[1]: print (e) star() ''' #print (inceident_edgees(G,T))
from algorithms.prims_algorithms import Prims from functions.reading_writing_function import get_graph from functions.graph_operations import * import os os.system("cls") # used to clear the console on windows machines File = str( input( ''' Input name of file that contians the graph, or use (G1, G2, G3, G4, G5 or FinalG). DO NOT add file extension. : ''')) Graph = get_graph(File) starting_point = int(input(f' {Graph[0]} \n Pick a vertex. :')) minimum_spanning_tree = Prims(Graph, starting_point) cost_of_tree = total_cost_of_tree(Graph, minimum_spanning_tree) vertices, edges = minimum_spanning_tree print(f'''\n The minimun spanining tree Vetices: {vertices}, total: {len(vertices)} Edges : {edges}, total: {len(edges)} Total cost of the tree: {total_cost_of_tree(Graph, minimum_spanning_tree)} ''' )