def add_edge(self, s, t, attrs=None, **attr):
# set up attribute dict (from Networkx to preserve the signature)
if attrs is None:
attrs = attr
else:
try:
attrs.update(attr)
except AttributeError:
raise ValueError(
"The attr_dict argument must be a dictionary."
)
if s not in self.nodes():
raise ValueError("Node %s is not defined!" % s)
if t not in self.nodes():
raise ValueError("Node %s is not defined!" % t)
source_type = self.node[s].type_
target_type = self.node[t].type_
if self.metamodel_ is not None:
if (source_type, target_type) not in self.metamodel_.edges():
raise ValueError(
"Edge from '%s' to '%s' is not allowed by metamodel" %
(source_type, target_type)
)
normalize_attrs(attrs)
nx.DiGraph.add_edge(self, s, t, attrs)
评论列表
文章目录