From 1fc72a7c5cd3e31fec3de8c8ae1e13e39677c42d Mon Sep 17 00:00:00 2001 From: Sofia Faltenbacher Date: Sun, 15 Oct 2023 15:33:05 +0200 Subject: [PATCH] feat(graph.py): function only_directed_edge_exists --- causy/graph.py | 5 +++++ causy/orientation_tests.py | 28 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/causy/graph.py b/causy/graph.py index f38dad5..e8d1de4 100644 --- a/causy/graph.py +++ b/causy/graph.py @@ -189,6 +189,11 @@ def directed_edge_exists(self, u: Node, v: Node): return False return True + def only_directed_edge_exists(self, u: Node, v: Node): + if self.directed_edge_exists(u, v) and not self.directed_edge_exists(v, u): + return True + return False + def edge_value(self, u: Node, v: Node): return self.edges[u][v] diff --git a/causy/orientation_tests.py b/causy/orientation_tests.py index a460818..2e1bfe7 100644 --- a/causy/orientation_tests.py +++ b/causy/orientation_tests.py @@ -105,7 +105,7 @@ def test( # It cannot be a collider because we have already oriented all unshielded triples that contain colliders. results = [] for z in potential_zs: - if graph.directed_edge_exists(x, z): + if graph.only_directed_edge_exists(x, z): results.append( TestResult( x=y, @@ -114,7 +114,7 @@ def test( data={}, ) ) - if graph.directed_edge_exists(y, z): + if graph.only_directed_edge_exists(y, z): results.append( TestResult( x=x, @@ -151,8 +151,8 @@ def test( for z in potential_zs: if ( graph.edge_exists(x, y) - and graph.directed_edge_exists(x, z) - and graph.directed_edge_exists(z, y) + and graph.only_directed_edge_exists(x, z) + and graph.only_directed_edge_exists(z, y) ): results.append( TestResult( @@ -164,8 +164,8 @@ def test( ) if ( graph.edge_exists(x, y) - and graph.directed_edge_exists(y, z) - and graph.directed_edge_exists(z, x) + and graph.only_directed_edge_exists(y, z) + and graph.only_directed_edge_exists(z, x) ): results.append( TestResult( @@ -206,8 +206,8 @@ def test( w = zs[1] if ( not graph.edge_exists(x, y) - and graph.directed_edge_exists(x, z) - and graph.directed_edge_exists(y, z) + and graph.only_directed_edge_exists(x, z) + and graph.only_directed_edge_exists(y, z) and graph.edge_exists(x, w) and graph.edge_exists(y, w) and graph.edge_exists(z, w) @@ -222,8 +222,8 @@ def test( ) if ( not graph.edge_exists(x, y) - and graph.directed_edge_exists(x, w) - and graph.directed_edge_exists(y, w) + and graph.only_directed_edge_exists(x, w) + and graph.only_directed_edge_exists(y, w) and graph.edge_exists(x, z) and graph.edge_exists(y, z) and graph.edge_exists(z, w) @@ -267,8 +267,8 @@ def test( w = zs[1] if ( not graph.edge_exists(x, y) - and graph.directed_edge_exists(x, z) - and graph.directed_edge_exists(z, y) + and graph.only_directed_edge_exists(x, z) + and graph.only_directed_edge_exists(z, y) and graph.edge_exists(z, w) and graph.edge_exists(x, z) and graph.edge_exists(y, z) @@ -283,8 +283,8 @@ def test( ) if ( not graph.edge_exists(y, x) - and graph.directed_edge_exists(y, z) - and graph.directed_edge_exists(z, x) + and graph.only_directed_edge_exists(y, z) + and graph.only_directed_edge_exists(z, x) and graph.edge_exists(z, w) and graph.edge_exists(x, z) and graph.edge_exists(y, z)