def test_less_linear(self): dag = retworkx.PyDAG() node_a = dag.add_node('a') node_b = dag.add_child(node_a, 'b', {}) node_c = dag.add_child(node_b, 'c', {}) node_d = dag.add_child(node_c, 'd', {}) node_e = dag.add_child(node_d, 'e', {}) dag.add_edge(node_a, node_c, {}) dag.add_edge(node_a, node_e, {}) dag.add_edge(node_c, node_e, {}) self.assertEqual(4, retworkx.dag_longest_path_length(dag)) self.assertEqual([node_a, node_b, node_c, node_d, node_e], retworkx.dag_longest_path(dag))
def test_parallel_edges_with_weights(self): dag = retworkx.PyDiGraph() dag.extend_from_weighted_edge_list([ (0, 1, 1), (0, 3, 1), (3, 4, 1), (4, 5, 1), (1, 2, 1), (0, 1, 3), ]) self.assertEqual( [0, 1, 2], retworkx.dag_longest_path(dag, lambda _, __, weight: weight), ) self.assertEqual( 4, retworkx.dag_longest_path_length( dag, weight_fn=lambda _, __, weight: weight), )
def test_linear(self): """Longest depth for a simple dag. a | b |\ c d |\ e | | | f g """ dag = retworkx.PyDAG() node_a = dag.add_node('a') node_b = dag.add_child(node_a, 'b', {}) node_c = dag.add_child(node_b, 'c', {}) dag.add_child(node_b, 'd', {}) node_e = dag.add_child(node_c, 'e', {}) node_f = dag.add_child(node_e, 'f', {}) dag.add_child(node_c, 'g', {}) self.assertEqual(4, retworkx.dag_longest_path_length(dag)) self.assertEqual([node_a, node_b, node_c, node_e, node_f], retworkx.dag_longest_path(dag))
def time_dag_longest_path(self, _, __): retworkx.dag_longest_path(self.graph)