Package gPy :: Module Graphs :: Class _AbsGraph
[hide private]
[frames] | no frames]

Class _AbsGraph

source code


Abstract class with method suitable for all types of graph

Instance Methods [hide private]
 
__init__(self, vertices=(), arrows=(), lines=(), vertex_positions=None)
Graph initialisation
source code
Boolean
__eq__(self, other)
Graphs of different classes are considered equal if they have the same vertices, arrows and lines
source code
Boolean
__ne__(self, other)
Graphs of different classes are considered equal if they have the same vertices, arrows and lines
source code
 
__repr__(self)
Formal string representation of a graph
source code
String
__str__(self)
Pretty string representation of a graph
source code
 
add_vertex(self, vertex)
Adds a vertex to a graph
source code
 
add_vertices(self, vertices)
Add a collection of vertices to the graph
source code
Anything immutable
arbitrary_vertex(self)
Returns an arbitrary vertex in the graph
source code
List of (vertex,child) tuples
arrows(self)
Return a list of arrows
source code
An immutable type (typically a String)
child(self, vertex)
Return an arbitrary child of vertex
source code
Set
children(self, vertex)
Return the children of vertex
source code
Same class as self
copy(self)
Return a copy a graph
source code
 
delete_vertex(self, vertex)
Deletes a vertex from a graph
source code
 
diff(self, other) source code
 
discard_arrow(self, frm, to)
Discard any arrow between two existing vertices
source code
 
discard_line(self, frm, to)
Discard the line between two existing vertices (if it exists)
source code
List
edges(self)
Return a list of the edges in the graph
source code
Generator iterator
extend_paths(self, paths)
Iterates over paths which can be produced by adding one vertex to a path in paths
source code
 
get_gui_graph_kill(self, gui, win=None)
Set the graph to match the one displayed on a GUI, and perhaps kill the GUI
source code
 
gui_edit(self, parent, **config)
Edit a graph using a GUI
source code
GraphCanvas
gui_display(self, parent, scrollable=False, **config)
Display a graph using a GUI
source code
 
is_neighbour(self, vertex1, vertex2)
Return whether vertex1 is a neighbour of vertex2
source code
Boolean
is_parent(self, parent, child)
Return whether parent is a parent of child
source code
List
lines(self)
Returns an ordered list of lines in the graph
source code
UGraph object
moralise(self)
Return a moralised version of the graph
source code
Set
neighbours(self, vertex)
Return the set (not a copy) of neighbours of a vertex
source code
List
orphanlist(self)
Return a list containing all nodes with no parents
source code
An immutable type (typically a String)
parent(self, vertex)
Return an arbitrary parent of vertex
source code
Integer
num_parents(self, vertex)
Return the number of parents of vertex
source code
 
num_parentsets(self)
Iterate over the number of parents of vertices
source code
Set
parents(self, vertex)
Return (a copy of) the parents of vertex
source code
 
parentsets(self)
Iterate over (copies of) all parent sets
source code
Generator iterator
paths(self, vertex)
Iterates over paths starting with vertex
source code
 
put_vertex(self, vertex)
Adds a vertex to a graph or does nothing if it already exists
source code
 
reinit(self, vertices, arrows, lines, vertex_positions)
(Re-)initialise a graph
source code
 
remove_vertex(self, vertex)
Remove a vertex
source code
 
set_vertex_positions(self, coords)
Position each vertex according to the co-ordinates in coords
source code
Int
shd(self, b)
Structural Hamming distance to graph b from self
source code
Boolean
is_subset_of_parents(self, child, vertices)
Return whether vertices is a subset of the parents of child
source code
Boolean
is_superset_of_parents(self, child, vertices)
Return whether vertices is a superset of the parents of child
source code
Dictionary
vertex_positions(self)
Return a dictionary mapping each vertex to a co-ordinate for display
source code
List
vertexlist(self)
Returns a list of the vertices in the graph
source code
Set
vertices(self)
Returns the set of vertices in the graph
source code
 
_gui_help(self)
Display help for editing graphs in a top-level window
source code

Inherited from Hypergraphs.Incidence: reachable, separates

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables [hide private]
  _edit_help_msg = '\n Select an object with the left mouse b...
Instance Variables [hide private]
Dictionary _ch
Maps each vertex to its children
Dictionary _ne
Maps each vertex to its neighbours
Dictionary _pa
Maps each vertex to its parents
Dictionary _vertex_positions
Maps vertices to canvas co-ordinates
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, vertices=(), arrows=(), lines=(), vertex_positions=None)
(Constructor)

source code 

Graph initialisation

Parameters:
  • vertices (An iterator/sequence over immutable types) - The vertices of the graph
  • arrows (An iterator/sequence over pairs (of vertices). Each pair is a sequence of length 2.) - The arrows of the graph
  • lines (An iterator/sequence over pairs (of vertices). Each pair is a sequence of length 2.) - The lines of the graph
  • vertex_positions (Dictionary) - A mapping from vertices to canvas co-ordinates
Raises:
  • KeyError - If arrows or lines contains a vertex not included in vertices
  • ExistingVertexError - If vertices repeats a vertex.
Overrides: object.__init__

__eq__(self, other)
(Equality operator)

source code 

Graphs of different classes are considered equal if they have the same vertices, arrows and lines

Returns: Boolean
Whether the graphs are equal

__ne__(self, other)

source code 

Graphs of different classes are considered equal if they have the same vertices, arrows and lines

Returns: Boolean
Whether the graphs are not equal

__repr__(self)
(Representation operator)

source code 

Formal string representation of a graph

Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 

Pretty string representation of a graph

Vertices, arrows and edges are presented in sorted order

Returns: String
Pretty string representation of a graph
Overrides: object.__str__

add_vertex(self, vertex)

source code 

Adds a vertex to a graph

Parameters:
  • vertex (Anything immutable) - The vertex to add
Raises:

add_vertices(self, vertices)

source code 

Add a collection of vertices to the graph

Parameters:
  • vertices (An iterator/sequence over immutable types) - The vertices to add

arbitrary_vertex(self)

source code 

Returns an arbitrary vertex in the graph

Returns: Anything immutable
A vertex in the graph

arrows(self)

source code 

Return a list of arrows

Returns: List of (vertex,child) tuples
A list of arrows

child(self, vertex)

source code 

Return an arbitrary child of vertex

Returns: An immutable type (typically a String)
A vertex which is a child of vertex or None if it has no children

children(self, vertex)

source code 

Return the children of vertex

Returns: Set
The children of vertex

copy(self)

source code 

Return a copy a graph

Returns: Same class as self
A copy of the graph

delete_vertex(self, vertex)

source code 

Deletes a vertex from a graph

Parameters:
  • vertex (Immutable type) - The vertex to delete
Raises:
  • KeyError - If the vertex does not exist

discard_arrow(self, frm, to)

source code 

Discard any arrow between two existing vertices

If there is no such arrow nothing happens

Parameters:
  • frm (Immutable type) - One of the vertices connected by the possible arrow
  • to (Immutable type) - The other vertex connected by the possible arrow
Raises:
  • KeyError - If either vertex does not exist

discard_line(self, frm, to)

source code 

Discard the line between two existing vertices (if it exists)

If there is no such line nothing happens

Parameters:
  • frm (Immutable type) - One of the vertices connected by the possible arrow
  • to (Immutable type) - The other vertex connected by the possible arrow
Raises:
  • KeyError - If either vertex does not exist

edges(self)

source code 

Return a list of the edges in the graph

Returns: List
A list of edges

extend_paths(self, paths)

source code 

Iterates over paths which can be produced by adding one vertex to a path in paths

Each path is actually a tuple path_set,path where path_set is the set of all vertices in the path, and path is a list representing the path itself

Parameters:
  • paths (List) - Paths to extend
Returns: Generator iterator
Generator of paths

get_gui_graph_kill(self, gui, win=None)

source code 

Set the graph to match the one displayed on a GUI, and perhaps kill the GUI

Parameters:
  • gui (GraphCanvas object) - The GUI
  • win (Tkinter object) - Window to kill

gui_edit(self, parent, **config)

source code 

Edit a graph using a GUI

Parameters:
  • parent (Suitable Tkinter widget) - Parent window for GUI
  • config (Various) - Configuration options for the GUI

gui_display(self, parent, scrollable=False, **config)

source code 

Display a graph using a GUI

Parameters:
  • parent (Suitable Tkinter widget) - Parent window for GUI
  • config (Various) - Configuration options for the GUI
Returns: GraphCanvas
The GUI

is_neighbour(self, vertex1, vertex2)

source code 

Return whether vertex1 is a neighbour of vertex2

Parameters:
  • vertex1 (Immutable) - Vertex
  • vertex2 (Immutable) - Vertex
Raises:
  • KeyError - If vertex1 is not a vertex

is_parent(self, parent, child)

source code 

Return whether parent is a parent of child

Parameters:
  • parent (Immutable) - Potential parent vertex
  • child (Immutable) - Potential child vertex
Returns: Boolean
Whether parent is a parent of child
Raises:
  • KeyError - If child is not a vertex

lines(self)

source code 

Returns an ordered list of lines in the graph

Returns: List
An ordered list of lines in the graph

moralise(self)

source code 

Return a moralised version of the graph

All parents are married, and directions are dropped. The moral graph will share its vertex co-ordinates, if any, with self

Returns: UGraph object
The moralised graph

neighbours(self, vertex)

source code 

Return the set (not a copy) of neighbours of a vertex

Neighbours are connected by undirected edges (lines)

Returns: Set
Neighbours of vertex

orphanlist(self)

source code 

Return a list containing all nodes with no parents

Returns: List
Nodes with no parents

parent(self, vertex)

source code 

Return an arbitrary parent of vertex

Returns: An immutable type (typically a String)
A vertex which is a parent of vertex or None if it has no parents

num_parents(self, vertex)

source code 

Return the number of parents of vertex

Returns: Integer
The number of parents of vertex
Raises:
  • KeyError - If vertex is not in the graph.

num_parentsets(self)

source code 

Iterate over the number of parents of vertices

(In no particular order)

parents(self, vertex)

source code 

Return (a copy of) the parents of vertex

Returns: Set
The parents of vertex
Raises:
  • KeyError - If vertex is not in the graph.

paths(self, vertex)

source code 

Iterates over paths starting with vertex

Each path is actually a tuple path_set,path where path_set is the set of all vertices in the path, and path is a list representing the path itself

Parameters:
  • vertex (Immutable) - Vertex from which all paths start
Returns: Generator iterator
Generator of paths

put_vertex(self, vertex)

source code 

Adds a vertex to a graph or does nothing if it already exists

Parameters:
  • vertex (Immutable type) - The vertex to add

reinit(self, vertices, arrows, lines, vertex_positions)

source code 

(Re-)initialise a graph

Pre-existing state will be deleted.

Parameters:
  • vertices (An iterator/sequence over immutable types) - The vertices of the graph
  • arrows (An iterator/sequence over pairs (of vertices). Each pair is a sequence of length 2.) - The arrows of the graph
  • lines (An iterator/sequence over pairs (of vertices). Each pair is a sequence of length 2.) - The lines of the graph
  • vertex_positions (Dictionary) - A mapping from vertices to canvas co-ordinates
Raises:
  • KeyError - If arrows or lines contains a vertex not included in vertices

remove_vertex(self, vertex)

source code 

Remove a vertex

Parameters:
  • vertex (Immutable) - Vertex to be removed
Raises:
  • KeyError - If vertex is not in the graph

set_vertex_positions(self, coords)

source code 

Position each vertex according to the co-ordinates in coords

Parameters:
  • coords (Dictionary) - A dictionary mapping some (maybe all) vertices to a co-ordinate for display

shd(self, b)

source code 

Structural Hamming distance to graph b from self

+1 for a missing edge (directed or not) +1 for an incorrectly oriented edge +1 for an extra edge (directed or not)

Only works on simple graphs (those without multiple connections between vertices)

Parameters:
  • b (Graph) - Graph to compare to self
Returns: Int
Structural Hamming distance to graph b from self

is_subset_of_parents(self, child, vertices)

source code 

Return whether vertices is a subset of the parents of child

Parameters:
  • child (Immutable) - Child vertex
  • vertices (Iterable) - Set of vertices
Returns: Boolean
Whether vertices is a subset of child's parents
Raises:
  • KeyError - If child is not a vertex

is_superset_of_parents(self, child, vertices)

source code 

Return whether vertices is a superset of the parents of child

Parameters:
  • child (Immutable) - Child vertex
  • vertices (Iterable) - Set of vertices
Returns: Boolean
Whether vertices is a superset of child's parents
Raises:
  • KeyError - If child is not a vertex

vertex_positions(self)

source code 

Return a dictionary mapping each vertex to a co-ordinate for display

Returns: Dictionary
A dictionary mapping some (maybe all) vertices to a co-ordinate for display

vertexlist(self)

source code 

Returns a list of the vertices in the graph

Returns: List
A list of the vertices in the graph

vertices(self)

source code 

Returns the set of vertices in the graph

Can be altered without affecting self

Returns: Set
The set of vertices in the graph

Class Variable Details [hide private]

_edit_help_msg

Value:
'''
    Select an object with the left mouse button.
    Clicking on a node with the right button will draw a
    line to the selected node (if any).
    Clicking on a node with the middle button will draw an
    arrow to the selected node (if any).

    You will be prevented from saving a graph with an illegal edge
...