def main(): """ Make it so. """ edges = None graph_name = setup_args() try: print(('Loading graph: {}'.format(graph_name))) edges = getattr(data.data, graph_name) except (AttributeError, TypeError): print(('\nInvalid graph name. Available graphs:\n\t{}\n'.format( '\n\t'.join([x for x in dir(data.data) if not x.startswith('__')])))) sys.exit() original_graph = network.Graph(edges) print(('{} edges'.format(len(original_graph)))) if not original_graph.is_eularian: print('Converting to Eularian path...') graph = eularian.make_eularian(original_graph) print('Conversion complete') print(('\tAdded {} edges'.format(len(graph) - len(original_graph)))) print(('\tTotal cost is {}'.format(graph.total_cost))) else: graph = original_graph print('Attempting to solve Eularian Circuit...') route, attempts = eularian.eularian_path(graph, start=1) if not route: print(('\tGave up after {} attempts.'.format(attempts))) else: print(('\tSolved in {} attempts'.format(attempts, route))) print(('Solution: ({} edges)'.format(len(route) - 1))) print(('\t{}'.format(route)))
def main(): edges = None graph_name = setup_args() try: edges = getattr(data.data, graph_name) except (AttributeError, TypeError): print('Invalid graph name. Available graphs:\n\t{}\n'.format( '\n\t'.join([x for x in dir(data.data) if not x.startswith('__')]))) sys.exit() original_graph = network.Graph(edges) print('Number of edges: {}'.format(len(original_graph))) if not original_graph.is_eularian: graph, num_dead_ends = eularian.make_eularian(original_graph) # print('\tAdded {} edges'.format(len(graph) - len(original_graph) + num_dead_ends)) print('Total cost: {}'.format(graph.total_cost)) else: graph = original_graph route, attempts = eularian.eularian_path(graph, start=1) if not route: print('Gave up after <{}> attempts.'.format(attempts)) else: print('Solution ({} edges):'.format(len(route) - 1)) print('{}'.format(route))
def main(): edges = None graph_name = setup_args() try: edges = getattr(data.data, graph_name) except (AttributeError, TypeError): print('Графа з такою назвою не існує. Доступні графи: \n\t{}\n'.format( '\n\t'.join([x for x in dir(data.data) if not x.startswith('__')]))) sys.exit() original_graph = network.Graph(edges) print('Кількість ребер: {}'.format(len(original_graph))) if not original_graph.is_eularian: graph, num_dead_ends = eularian.make_eularian(original_graph) #print('\tAdded {} edges'.format(len(graph) - len(original_graph) + num_dead_ends)) print('Загальна вартість: {}'.format(graph.total_cost)) else: graph = original_graph route, attempts = eularian.eularian_path(graph, start=1) if not route: print('Здався після <{}> спроб.'.format(attempts)) else: print('Відповідь ({} вершини):'.format(len(route) - 1)) print('{}'.format(route))
def test_find_cost_easy(self): graph = network.Graph([(1,2,1), (2,3,1), (3,4,5), (4,1,5)]) path = (1, 3) cost, route = di.find_cost(path, graph) expected = (2, [1, 2, 3]) self.assertEqual(expected, (cost, route))