1

我正在 Sage 中编写一些代码来使用费曼图进行一些计算,这些图只是有限的、无向的带有边标签的多重图。我需要实现诸如边缘收缩之类的方法,这些方法奇怪地从类中消失了sage.graphs.graph.Graph。但我也想继承所有现有的图形方法,例如is_tree.

这是应该附加新类的模块 Feynman.sage 的顶部。

from sage.graphs.graph import Graph

class FeynmanGraph(Graph):
    """An unoriented multi-graph with labeled edges"""
    def __init__(self, E=[]):
        self._edges = len(E)

    def __repr__(self):
        return 'A Feynman graph with ' + str(self._edges) + ' edges.'

我做的不对。尽管类的实例化产生了正确的方法目录,但它们中的许多都不起作用,因为

'FeynmanGraph' object has no attribute '_backend'

我认为这与 Sage 只是其他一些图论包的 Pythonic 包装器的方式有关。

请指教。

4

1 回答 1

3

You might simply not be inheriting things correctly. Try inserting this at the beginning of __init__():

super().__init__()
于 2011-03-25T03:46:37.800 回答