Package pygraph :: Package mixins :: Module common :: Class common

# Class common

Standard methods common to all graph classes.

Instance Methods

boolean

__eq__(self, other) Return whether this graph is equal to another one. |

iterator

__getitem__(self, node) Return a iterator passing through all neighbors of the given node. |

iterator

__iter__(self) Return a iterator passing through all nodes in the graph. |

number

__len__(self) Return the order of self when requested by len(). |

string

__repr__(self) Return a string representing the graph when requested by repr() |

string

__str__(self) Return a string representing the graph when requested by str() (or print). |

add_graph(self, other) Add other graph to this graph. |

add_nodes(self, nodelist) Add given nodes to the graph. |

add_spanning_tree(self, st) Add a spanning tree to the graph. |

complete(self) Make the graph a complete graph. |

graph

inverse(self) Return the inverse of the graph. |

number

order(self) Return the order of self, this is defined as the number of nodes in the graph. |

digraph

reverse(self) Generate the reverse of a directed graph, returns an identical graph if not directed. |

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__init__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __eq__(self, other)
(Equality operator)

Return whether this graph is equal to another one.

Parameters:
  - `other` (graph, digraph) - Other graph or digraph
Returns: boolean
  Whether this graph and the other are equal.

### __getitem__(self, node)
(Indexing operator)

Return a iterator passing through all neighbors of the given node.

Returns: iterator
  Iterator passing through all neighbors of the given node.

### __iter__(self)

Return a iterator passing through all nodes in the graph.

Returns: iterator
  Iterator passing through all nodes in the graph.

### __len__(self)
(Length operator)

Return the order of self when requested by len().

Returns: number
  Size of the graph.

### __repr__(self)
(Representation operator)

Return a string representing the graph when requested by repr()

Returns: string
  String representing the graph.
Overrides: object.__repr__

### __str__(self)
(Informal representation operator)

Return a string representing the graph when requested by str() (or print).

Returns: string
  String representing the graph.
Overrides: object.__str__

### add_graph(self, other)

Add other graph to this graph.

Parameters:
  - `other` (graph) - Graph

Attention: Attributes and labels are not preserved.

### add_nodes(self, nodelist)

Add given nodes to the graph.

Parameters:
  - `nodelist` (list) - List of nodes to be added 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(). Objects used to identify nodes absolutely must be hashable. If you need attach a mutable or non-hashable node, consider using the labeling feature.

### add_spanning_tree(self, st)

Add a spanning tree to the graph.

Parameters:
  - `st` (dictionary) - Spanning tree.

### complete(self)

Make the graph a complete graph.

Attention: This will modify the current graph.

### inverse(self)

Return the inverse of the graph.

Returns: graph
  Complement graph for the graph.

### order(self)

Return the order of self, this is defined as the number of nodes in the graph.

Returns: number
  Size of the graph.

### reverse(self)

Generate the reverse of a directed graph, returns an identical graph if not directed. Attributes & weights are preserved.

Returns: digraph
  The directed graph that should be reversed.