def add_edge(self, edge, wt=1, label="", attrs=[]): """ Add an directed edge to the graph connecting two nodes. An edge, here, is a pair of nodes like C{(n, m)}. @type edge: tuple @param edge: Edge. @type wt: number @param wt: Edge weight. @type label: string @param label: Edge label. @type attrs: list @param attrs: List of node attributes specified as (attribute, value) tuples. """ u, v = edge for n in [u, v]: if not n in self.node_neighbors: raise AdditionError( "%s is missing from the node_neighbors table" % n) if not n in self.node_incidence: raise AdditionError( "%s is missing from the node_incidence table" % n) if v in self.node_neighbors[u] and u in self.node_incidence[v]: raise AdditionError("Edge (%s, %s) already in digraph" % (u, v)) else: self.node_neighbors[u].append(v) self.node_incidence[v].append(u) self.set_edge_weight((u, v), wt) self.add_edge_attributes((u, v), attrs) self.set_edge_properties((u, v), label=label, weight=wt)
def add_edge(self, edge, wt=1, label='', attrs=[]): """ Add an edge to the graph connecting two nodes. An edge, here, is a pair of nodes like C{(n, m)}. @type edge: tuple @param edge: Edge. @type wt: number @param wt: Edge weight. @type label: string @param label: Edge label. @type attrs: list @param attrs: List of node attributes specified as (attribute, value) tuples. """ u, v = edge if (v not in self.node_neighbors[u] and u not in self.node_neighbors[v]): self.node_neighbors[u].append(v) if (u != v): self.node_neighbors[v].append(u) self.add_edge_attributes((u, v), attrs) # zwei # self.set_edge_properties((u, v), label=label, weight=wt) else: raise AdditionError("Edge (%s, %s) already in graph" % (u, v))
def link(self, node, hyperedge): """ Link given node and hyperedge. @type node: node @param node: Node. @type hyperedge: node @param hyperedge: Hyperedge. """ if (hyperedge not in self.node_links[node]): self.edge_links[hyperedge].append(node) self.node_links[node].append(hyperedge) self.graph.add_edge(((node,'n'), (hyperedge,'h'))) else: raise AdditionError("Link (%s, %s) already in graph" % (node, hyperedge))
def add_node(self, node): """ Add given node to the hypergraph. @attention: While nodes can be of any type, it's strongly recommended to use only numbers and single-line strings as node identifiers if you intend to use write(). @type node: node @param node: Node identifier. """ if (not node in self.node_links): self.node_links[node] = [] self.node_attr[node] = [] self.graph.add_node((node, 'n')) else: raise AdditionError("Node %s already in graph" % node)
def add_node(self, node, attrs=[]): """ Add given node to the graph. @attention: While nodes can be of any type, it's strongly recommended to use only numbers and single-line strings as node identifiers if you intend to use write(). @type node: node @param node: Node identifier. @type attrs: list @param attrs: List of node attributes specified as (attribute, value) tuples. """ if (not node in self.node_neighbors): self.node_neighbors[node] = [] self.node_attr[node] = attrs else: raise AdditionError("Node %s already in graph" % node)