def test_fill_missing_time(): """simple chain graph test """ g = Graph(directed=False) g.add_vertex(4) g.add_edge_list([(0, 1), (1, 2), (2, 3)]) t = GraphView(g, directed=True) efilt = t.new_edge_property('bool') efilt.a = True efilt[t.edge(2, 3)] = False t.set_edge_filter(efilt) vfilt = t.new_vertex_property('bool') vfilt.a = True vfilt[3] = False t.set_vertex_filter(vfilt) root = 0 obs_nodes = {0, 2} infection_times = [0, 1.5, 3, -1] pt = fill_missing_time(g, t, root, obs_nodes, infection_times, debug=False) for i in range(4): assert pt[i] == infection_times[i]
def is_order_respected(tree, root, obs_nodes, infection_times): tree = GraphView(tree) obs_set = set(obs_nodes) vfilt = tree.new_vertex_property('bool') vfilt.a = True tree.set_vertex_filter(vfilt) leaves = [o for o in obs_nodes if tree.vertex(o).out_degree() == 0] vis = init_visitor(tree, root) pbfs_search(tree, root, terminals=leaves, visitor=vis, count_threshold=-1) for l in leaves: edges = extract_edges_from_pred(tree, root, l, vis.pred) edges = edges[::-1] path = list(edges[0]) + [u for _, u in edges[1:]] useful_nodes_on_path = [v for v in path if v in obs_set] for i in range(len(useful_nodes_on_path)-1): u, v = useful_nodes_on_path[i: i+2] if infection_times[u] > infection_times[v]: return False return True
def is_order_respected(tree, root, obs_nodes, infection_times): tree = GraphView(tree) obs_set = set(obs_nodes) vfilt = tree.new_vertex_property('bool') vfilt.a = True tree.set_vertex_filter(vfilt) leaves = [o for o in obs_nodes if tree.vertex(o).out_degree() == 0] vis = init_visitor(tree, root) pbfs_search(tree, root, terminals=leaves, visitor=vis, count_threshold=-1) for l in leaves: edges = extract_edges_from_pred(tree, root, l, vis.pred) edges = edges[::-1] path = list(edges[0]) + [u for _, u in edges[1:]] useful_nodes_on_path = [v for v in path if v in obs_set] for i in range(len(useful_nodes_on_path)-1): u, v = useful_nodes_on_path[i: i+2] if infection_times[u] > infection_times[v]: return False return True