Skip to content

Instantly share code, notes, and snippets.

@glyg
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glyg/2005df62820d35e7efe4 to your computer and use it in GitHub Desktop.
Save glyg/2005df62820d35e7efe4 to your computer and use it in GitHub Desktop.
Bug in graph_tool with list of edges property map
import graph_tool.all as gt
import numpy as np
import sys
print('*********************************')
print('gt version:\n {}\n'.format(gt.__version__))
print('sytem info:\n {}'.format(sys.version))
print('*********************************')
## Creating an hexagonal mesh
x_ax = np.linspace(0, 10, 20)
y_ax = np.linspace(0, 10, 20)
xs, ys = np.meshgrid(x_ax, y_ax)
xs[::2] += 0.25
pos = np.vstack([xs.ravel(), ys.ravel()]).T
graph, pos = gt.geometric_graph(pos, radius=0.6)
graph.set_directed(False)
print('A simple graph:\n')
print(graph)
### List of out edges pointing upward for each vertex
up_edges = graph.new_vertex_property('object')
def get_up_edges(v, up_edges):
ue = []
for e in v.out_edges():
if pos[e.target()][1] - pos[e.source()][1] > 0:
ue.append(e)
up_edges[v] = ue
### A bool propertymap to filter with
p1 = graph.new_vertex_property('bool')
p1.a[:] = 0
for v_ in graph.vertices():
if pos[v_][0] > 5:
p1[v_] = 1
### Updating the neighbours list for the first time:
for v_ in graph.vertices():
get_up_edges(v_, up_edges)
### Filtering and unfiltering
graph.set_vertex_filter(p1)
print('Filtered graph has {} vertices'.format(graph.num_vertices()))
graph.set_vertex_filter(None)
v = graph.vertex(0)
### Get the list for vertex v
print('vertex {} neighbours: {}'.format(v, [str(e) for e in up_edges[v]]))
e = graph.edge(0, 21)
print('Looking for {} in the neighbours:\n {}'.format(e, e in up_edges[v]))
### Updating the neighbours list once more:
for v_ in graph.vertices():
get_up_edges(v_, up_edges)
print('Looking for {} in the neighbours:\n {}'.format(e, e in up_edges[v]))
@glyg
Copy link
Author

glyg commented Oct 16, 2014

Here is the output on my machine:


gt version:
2.2.35 (commit c32ffd6c, Thu Sep 11 16:39:47 2014 +0200)

sytem info:
3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 10 2014, 17:10:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]


A simple graph:

<Graph object, undirected, with 400 vertices and 1121 edges at 0x7fe8ad1b15c0>
Filtered graph has 200 vertices
vertex 0 neighbours: ['(0, 21)', '(0, 20)']
Looking for (0, 21) in the neighbours:
False
Looking for (0, 21) in the neighbours:
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment