def _build_undirected_graph(self, graph: PertGraph): for key in graph.get_graph().keys(): self._adjacency_list[key] = [] for key, node in graph.get_graph().items(): for neighbour in node.dependencies: self._adjacency_list[key].append(neighbour) self._adjacency_list[neighbour].append(key)
def main(): print('jira_pert is running...\n') options = parse_arguments() epic_key = options.key jira_api = JiraAPIv2() features = jira_api.get_issues_in_epic(epic_key) graph = PertGraph(features) graph.print() diagram = PertDiagram(graph) diagram.plot()
def test_non_cyclic_graph(self): graph = PertGraph() graph._add_node(key='A', dependencies=[]) graph._add_node(key='B', dependencies=['A']) graph._add_node(key='C', dependencies=['A']) graph._add_node(key='D', dependencies=['B', 'C']) engine = CycleDetectorDFS(graph) self.assertEqual(False, engine.is_cyclic())
def test_not_connected_graph(self): graph = PertGraph() graph._add_node(key='A', dependencies=[]) graph._add_node(key='B', dependencies=['A']) graph._add_node(key='C', dependencies=[]) graph_connectivity = GraphConnectivityDFS(graph) self.assertEqual(False, graph_connectivity.is_connected()) self.assertEqual(['C'], graph_connectivity.get_not_connected_nodes())
def __init__(self, model: PertGraph): self._graph: Dict[str, PertNode] = model.get_graph() self._gates: [[str]] = [] self._positions: Dict[str, List[float]] = dict() detect_cycle = CycleDetectorDFS(model) if detect_cycle.is_cyclic(): raise ValueError('Graph has cycle', detect_cycle.get_cycle())
def test_graph_with_cycle(self): graph = PertGraph() graph._add_node(key='A', dependencies=['C']) graph._add_node(key='B', dependencies=['A']) graph._add_node(key='C', dependencies=['B']) self.assertRaises(ValueError, ChronologicalLayout, graph)
def test_cyclic_graph_1(self): graph = PertGraph() graph._add_node(key='A', dependencies=['C']) graph._add_node(key='B', dependencies=['A']) graph._add_node(key='C', dependencies=['B']) engine = CycleDetectorDFS(graph) self.assertEqual(True, engine.is_cyclic()) self.assertEqual(['A', 'B', 'C', 'A'], engine.get_cycle())
def test_three_nodes_in_order(self): graph = PertGraph() graph._add_node(key='A', dependencies=[]) graph._add_node(key='B', dependencies=['A']) graph._add_node(key='C', dependencies=['B']) engine = ChronologicalLayout(graph) engine.get_layout() self.assertEqual(['A'], engine._gates[0]) self.assertEqual(['B'], engine._gates[1]) self.assertEqual(['C'], engine._gates[2])