def simple_actions_lpg() -> SysML2LabeledPropertyGraph: new_lpg = SysML2LabeledPropertyGraph() client = simple_actions_model_loaded_client() new_lpg.model = client.model return new_lpg
def test_path_graph(kerbal_model): lpg = SysML2LabeledPropertyGraph(model=kerbal_model) source, target = [ id_ for id_, data in lpg.nodes.items() if data.get("name") in SEED_NODE_NAMES ] path_graph = lpg.get_path_graph( lpg.graph, source=source, target=target, enforce_directionality=False, ) for node in (target, source): assert node in path_graph assert len(path_graph.nodes) > 0 assert len(path_graph.nodes) < len(lpg.nodes) assert len(path_graph.edges) > 0 assert len(path_graph.edges) < len(lpg.edges) with pytest.warns(UserWarning, match="networkx.exception.NetworkXNoPath"): warnings.warn("networkx.exception.NetworkXNoPath", UserWarning) path_graph = lpg.get_path_graph( lpg.graph, source=source, target=target, enforce_directionality=True, ) assert len(path_graph.nodes) == 0
def test_spanning_graph(kerbal_model): lpg = SysML2LabeledPropertyGraph(model=kerbal_model) nodes = [ id_ for id_, data in lpg.nodes.items() if data.get("name") in SEED_NODE_NAMES ] small_directed = lpg.get_spanning_graph( graph=lpg.graph, seeds=nodes, max_distance=1, enforce_directionality=True, ) assert len(small_directed.nodes) > 0 assert len(small_directed.nodes) < len(lpg.nodes) assert len(small_directed.edges) > 0 assert len(small_directed.edges) < len(lpg.edges) small_undirected = lpg.get_spanning_graph( graph=lpg.graph, seeds=nodes, max_distance=1, enforce_directionality=False, ) assert len(small_undirected.nodes) > len(small_directed.nodes) assert len(small_undirected.nodes) < len(lpg.nodes) assert len(small_undirected.edges) > len(small_directed.edges) assert len(small_undirected.edges) < len(lpg.edges) large_directed = lpg.get_spanning_graph( graph=lpg.graph, seeds=nodes, max_distance=2, enforce_directionality=True, ) assert len(large_directed.nodes) > len(small_directed.nodes) assert len(large_directed.nodes) < len(lpg.nodes) assert len(large_directed.edges) > len(small_directed.edges) assert len(large_directed.edges) < len(lpg.edges) large_undirected = lpg.get_spanning_graph( graph=lpg.graph, seeds=nodes, max_distance=2, enforce_directionality=False, ) assert len(large_undirected.nodes) > len(small_undirected.nodes) assert len(large_undirected.nodes) < len(lpg.nodes) assert len(large_undirected.edges) > len(small_undirected.edges) assert len(large_undirected.edges) < len(lpg.edges) small_one_seed = lpg.get_spanning_graph( graph=lpg.graph, seeds=[nodes[0]], max_distance=1, enforce_directionality=True, ) assert len(small_one_seed.nodes) > 0 assert len(small_one_seed.nodes) < len(small_directed.nodes) assert len(small_one_seed.edges) > 0 assert len(small_one_seed.edges) < len(small_directed.edges)
def kerbal_lpg() -> SysML2LabeledPropertyGraph: new_lpg = SysML2LabeledPropertyGraph() client = kerbal_model_loaded_client() trt.link( (client, "model"), (new_lpg, "model"), ) return new_lpg
def kerbal_random_stage_5_complete( kerbal_lpg: SysML2LabeledPropertyGraph, kerbal_random_stage_4_complete: dict, ) -> dict: random_generator_playbook_phase_5(kerbal_lpg, kerbal_lpg.get_projection("Connection"), kerbal_random_stage_4_complete) return kerbal_random_stage_4_complete
def test_lpg(kerbal_model): lpg = SysML2LabeledPropertyGraph(model=kerbal_model) assert len(lpg.nodes) == len(kerbal_model.all_non_relationships) assert len(lpg.edges) == len(kerbal_model.all_relationships) banded = lpg.get_projection("Banded") assert len(banded.nodes) > 0 assert len(banded.nodes) < len(lpg.nodes) assert len(banded.edges) > 0 assert len(banded.edges) < len(lpg.edges)
def kerbal_stable_names(): client = kerbal_model_loaded_client() lpg = SysML2LabeledPropertyGraph() lpg.model = client.model return build_stable_id_lookups(lpg)
def simple_actions_stable_names(): client = simple_actions_model_loaded_client() lpg = SysML2LabeledPropertyGraph() lpg.model = client.model return build_stable_id_lookups(lpg)