Gerion E activity https://git.skewed.de/gerion 2020-11-06T10:25:14Z tag:git.skewed.de,2020-11-06:5516 Gerion E opened issue #686: [Feature Request] Output dominator tree as GraphV... 2020-11-06T10:25:14Z gerion Gerion E

I already requested this on the mailing list and was told to put it here, so I will copy it:

The dominator_tree function in `graph_tool.topology` outputs a vertex property map that codifies a graph. To use the other graph_tool algorithms, it would be beneficial to get the dominator_tree back as Graph (or better GraphView).

Is there already a way to do this? Otherwise, how do you like the idea to implement it?

A possible use case is it to check, if a dominates b. This would be the pseudo code, if dominator_tree returns a graph like object:

``````dom_tree = graph_tool.topology.dominator_tree(graph, start, as_graph=True)
try:
next(graph_tool.topology.all_paths(a, b))
return True
except StopIteration:
return False``````

This is without (the path search runs in Python, not that much LOCs but more difficult to understand in my opinion):

``````dom_tree = graph_tool.topology.dominator_tree(graph, start)
while b:
if a == b:
return True
b = dom_tree[b]
return False``````
tag:git.skewed.de,2020-11-06:5515 Gerion E opened issue #685: Iterator in conjunction with Python properties fa... 2020-11-06T10:19:41Z gerion Gerion E

2.35

## Do you observe the problem with the current git version?

I will give a minimal example. It would be nice, if you test it yourself, since compiling graph-tool costs me several hours.

No

## Did you compile `graph-tool` manually?

Part of, I use Gentoo with the distribution package.

Yes

## A minimal and self-contained example that shows the problem.

This code should print the same in all 3 for loops but does not.

``````#!/usr/bin/env python3

import graph_tool

class Foo:
def __init__(self):
self.g = graph_tool.Graph()
self.g.vp["foo"] = self.g.new_vp("bool")
for i in range(10):
if i % 2 == 0:
self.g.vp.foo[v] = True

@property
def a(self):
return graph_tool.GraphView(self.g, vfilt=self.g.vp.foo)

foo = Foo()

t1 = foo.a
for i in t1.vertices():
print("1.", i)

for i in foo.a.vertices():
print("2.", i)

t2 = foo.a.vertices()
for i in t2:
print("3.", i)``````

This prints only

``````1. 0
1. 2
1. 4
1. 6
1. 8``````

So basically it ignores the next 2 for loops.

Gentoo

## The Python version you are using.

Gentoo allows multiple. I tested with 3.6, 3.7 and 3.8 (always the same bug).

## If you compiled graph-tool manually: Your compiler version, as well as the version of Boost being used.

GCC 9.2.0, Boost 1.72.0

## If you are reporting a compilation error, please provide the entire`./configure` output, as well as the entire contents of the `config.log` file and the entire compilation output.

No.

see this minimal example for a pure Python working example that mimics the above script:

``````#!/usr/bin/env python3

class Iterator:
def __init__(self):
self.x = 0

def __iter__(self):
return self

def __next__(self):
if self.x > 3:
raise StopIteration
self.x += 1
return self.x

class Sub:
def it(self):
return Iterator()

class Foo:
@property
def a(self):
return Sub()

foo = Foo()

t1 = foo.a
for i in t1.it():
print("1:", i)

for i in foo.a.it():
print("2:", i)

t2 = foo.a.it()
for i in t2:
print("3:", i)``````