Ni! Woudn't simply:

u.get_vertex_filter()[0][v]

work?

.~´


On Fri, Sep 25, 2015 at 12:20 PM, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 25.09.2015 15:51, Christopher Morris wrote:
> Hi,
>
> given a graph G and a subgraph S of G (computed using GraphView). What is the best way to check if a vertex v in V(G) is also in V(S).
>
> Is there are better way than iterating over all vertices in S?

Yes, if you try to obtain a vertex in filtered graph via its index, a
ValueError exception will be raised if this vertex is being filtered
out. For example:

    >>> g = Graph()
    >>> g.add_vertex(2)
    >>> u = GraphView(g, vfilt=lambda v: int(v) < 1)
    >>> u.vertex(1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/count0/.local/lib/python3.4/site-packages/graph_tool/__init__.py", line 1683, in vertex
        raise ValueError("Invalid vertex index: %d" % int(i))
    ValueError: Invalid vertex index: 1

Hence you could do:

    def vertex_belongs(v, g):
        try:
            g.vertex(int(v))
            return True
        except ValueError:
            return False

Best,
Tiago

--
Tiago de Paula Peixoto <tiago@skewed.de>


_______________________________________________
graph-tool mailing list
graph-tool@skewed.de
http://lists.skewed.de/mailman/listinfo/graph-tool