I am writing some code in Sage to do some calculations with Feynman graphs, which are just finite, un-oriented multigraphs with edge-labels. I need to implement methods such as edge-contraction, which are curiously missing from the class sage.graphs.graph.Graph
. But I also want to inherit all the existing graph methods, like e.g. is_tree
.
Here's the top of the module Feynman.sage that ought to attach the new class.
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.'
I'm not doing something right. Although an instantiation of the class yields the correct directory of methods, many of them don't work because
'FeynmanGraph' object has no attribute '_backend'
I think this has something to do with the way that Sage is just a Pythonic wrapper for some other graph theory package.
Please advise.
merge_vertices
which is (along withis_tree
) in generic_graph.py. There's also a trac aboutedge_contract
, so see the discussion there.SparseGraphBackend
orDenseGraphBackend
.