예제 #1
0
 def add_edges_from(self, edge_list, 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."
             )
     for edge in edge_list:
         if not edge[0] in self.nodes():
             raise ValueError("Node %s is not defined!" % edge[0])
         if not edge[1] in self.nodes():
             raise ValueError("Node %s is not defined!" % edge[1])
         source_type = self.node[edge[0]].type_
         target_type = self.node[edge[1]].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_edges_from(self, edge_list, attrs)
예제 #2
0
 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():
             if (target_type, source_type) not in self.metamodel_.edges():
                 raise ValueError(
                     "Edge from '%s' to '%s' is not allowed by metamodel" %
                     (source_type, target_type)
                 )
     # There is some strange things with edge attributes in NetworkX
     # for undirected graphs: if I say graph.edge[1][2] = <some attributes>
     # it will not update value of graph.edge[2][1]
     normalize_attrs(attrs)
     nx.Graph.add_edge(self, s, t, attrs)
     nx.Graph.add_edge(self, t, s, attrs)
예제 #3
0
 def set_edge(self, u, v, attrs):
     if (not (u, v) in self.edges()) and (not (v,u) in self.edges()):
         raise ValueError(
             "Edge %s-%s does not exist" % (str(u), str(v)))
     normalize_attrs(attrs)
     self.edge[u][v] = attrs
     self.edge[v][u] = attrs
예제 #4
0
 def add_edges_from(self, edge_list, 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.")
     for edge in edge_list:
         if not edge[0] in self.nodes():
             raise ValueError("Node %s is not defined!" % edge[0])
         if not edge[1] in self.nodes():
             raise ValueError("Node %s is not defined!" % edge[1])
         source_type = self.node[edge[0]].type_
         target_type = self.node[edge[1]].type_
         if self.metamodel_ is not None:
             if (source_type, target_type) not in self.metamodel_.edges():
                 if (target_type,
                         source_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.Graph.add_edges_from(self, edge_list, attrs)
예제 #5
0
 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():
             if (target_type, source_type) not in self.metamodel_.edges():
                 raise ValueError(
                     "Edge from '%s' to '%s' is not allowed by metamodel" %
                     (source_type, target_type))
     # There is some strange things with edge attributes in NetworkX
     # for undirected graphs: if I say graph.edge[1][2] = <some attributes>
     # it will not update value of graph.edge[2][1]
     normalize_attrs(attrs)
     nx.Graph.add_edge(self, s, t, attrs)
     nx.Graph.add_edge(self, t, s, attrs)
예제 #6
0
 def set_attrs(self, attrs):
     normalize_attrs(attrs)
     self.attrs_ = attrs
예제 #7
0
 def __init__(self, n_type=None, attrs=None):
     self.type_ = n_type
     self.attrs_ = attrs
     normalize_attrs(self.attrs_)
     return
예제 #8
0
 def set_edge(self, source, target, attrs):
     if not (source, target) in self.edges():
         raise ValueError(
             "Edge %s-%s does not exist" % (str(source), str(target)))
     normalize_attrs(attrs)
     self.edge[source][target] = attrs
예제 #9
0
 def set_edge(self, u, v, attrs):
     if (not (u, v) in self.edges()) and (not (v, u) in self.edges()):
         raise ValueError("Edge %s-%s does not exist" % (str(u), str(v)))
     normalize_attrs(attrs)
     self.edge[u][v] = attrs
     self.edge[v][u] = attrs
예제 #10
0
 def set_attrs(self, attrs):
     normalize_attrs(attrs)
     self.attrs_ = attrs
예제 #11
0
 def __init__(self, n_type=None, attrs=None):
     self.type_ = n_type
     self.attrs_ = attrs
     normalize_attrs(self.attrs_)
     return
예제 #12
0
 def set_edge(self, source, target, attrs):
     if not (source, target) in self.edges():
         raise ValueError("Edge %s-%s does not exist" %
                          (str(source), str(target)))
     normalize_attrs(attrs)
     self.edge[source][target] = attrs