PlanarDiagram#
- class PlanarDiagram(incoming_diagram_data=None, **attr)#
Bases:
ABC
The PlanarDiagram class provides the basic abstract class for all planar objects (planar graph, knots, knotted graphs, …). It is intended to be used only as the parent class for Knot, PlanarGraph, etc.
A PlanarDiagram class consists of: - the diagram class with optional attributes, - nodes (vertices), that are any hashable objects with optional attributes, - endpoints, that represent part of the edge/arc emanating from the node and is a tuple (node, node_position), with optional attributes
In addition, we use the following terminology: - arcs are tuples of endpoints, - regions are the faces of the planar graph and are represented as a sequence of endpoints.
- __init__(incoming_diagram_data=None, **attr)#
Initialize a planar diagram. :param incoming_diagram_data: not implemented :param attr: graph attributes (name, framing, …)
Methods
__init__
([incoming_diagram_data])Initialize a planar diagram.
add_node
(node_for_adding, create_using[, degree])Add a node of type create_using with optional degree and attributes.
add_nodes_from
(nodes_for_adding[, create_using])Add or update a bunch (iterable) of nodes and update attributes.
clear
()Remove/clear all diagram data.
copy
([copy_using])Return shallow copy of the diagram.
degree
(node)get_endpoint
(node, position)Return the endpoint Endpoint(node, position)
get_endpoint_from_pair
(endpoint_pair)Returns the Endpoint instance of the pair (node, position).
is_oriented
()jump_over_node
(endpoint)- param endpoint:
Endpoint instance or pair (node, position)
permute_node
(node, permutation)Permute the endpoints of the node of knot k.
py3_cmp
(other[, compare_attr])Compare diagrams.
relabel_nodes
(mapping)Relabels the nodes, can be a partial map
remove_arc
(arc_for_removing)remove_arcs_from
(arcs_for_removing)remove_endpoint
(endpoint_for_removal)remove_endpoints_from
(endpoints_for_removal)remove_node
(node_for_removing[, ...])Remove the node.
remove_nodes_from
(nodes_for_removal[, ...])rename_nodes
(mapping_dict)rotate_node_ccw
(node[, ccw_shift])Permute the positions of endpoints of the node and take care of adjacent nodes.
set_arc
(arc_for_setting, **attr)Set the arc (v_endpoint, u_endpoint), which equals setting the two endpoints adj(u_endpoint) = v_endpoint and vice-versa.
set_arcs_from
(arcs_for_adding, **attr)Set the list of arcs.
set_endpoint
(endpoint_for_setting, ...[, ...])Set the endpoint to the adjacent endpoint and update the endpoint attributes.
to_oriented_class
()to_unoriented_class
()twin
(endpoint)Return the opposite endpoint (twin) of an endpoint.
Attributes
Node object holding the adjacencies of each node.
Node object holding the adjacencies of each node.
Node object holding the adjacencies of each node.
Blackboard framing number of planar diagram.
Name identifier of planar diagram.
Node object holding the adjacencies of each node.
number_of_arcs
number_of_endpoints
number_of_nodes
- add_node(node_for_adding, create_using: type, degree=None, **attr)#
Add a node of type create_using with optional degree and attributes.
- Parameters:
node_for_adding – any hashable object
create_using – the node type
degree – optional degree of the node
attr –
- Returns:
None
- add_nodes_from(nodes_for_adding, create_using=None, **attr)#
Add or update a bunch (iterable) of nodes and update attributes.
- Parameters:
nodes_for_adding – an iterable of nodes, which can be any hashable object. If a dictionary of is given, where the values are Node classes, the newly added nodes will inherit the degree and attributes of nodes in the dict.
create_using – if nodes_for_adding does not consist of a dictionary of Node instances, the node type must be given in this parameter (e.g. Vertex, Crossing,…)
attr – the nodes attribute will be updated with these values.
- Returns:
None
- property arcs#
Node object holding the adjacencies of each node.
- clear()#
Remove/clear all diagram data.
- copy(copy_using=None)#
Return shallow copy of the diagram. :param copy_using: the planar diagram type of the new diagram :return: shallow copy
- property endpoints#
Node object holding the adjacencies of each node.
- property faces#
Node object holding the adjacencies of each node.
- property framing#
Blackboard framing number of planar diagram.
- get_endpoint(node, position)#
Return the endpoint Endpoint(node, position)
- get_endpoint_from_pair(endpoint_pair)#
Returns the Endpoint instance of the pair (node, position).
- Parameters:
endpoint_pair – a pair (node, position)
- Returns:
Endpoint instance
- jump_over_node(endpoint)#
- Parameters:
endpoint – Endpoint instance or pair (node, position)
- Returns:
endpoint or None
- property name#
Name identifier of planar diagram.
- property nodes#
Node object holding the adjacencies of each node.
- permute_node(node, permutation)#
Permute the endpoints of the node of knot k. For example, if p = {0: 0, 1: 2, 2: 3, 3: 1} (or p = [0,2,2,1]), and if node has endpoints [a, b, c, d] (ccw) then the new endpoints will be [a, d, b, c]. :param node: node of which we permute its endpoints :param permutation: permutation given as a dict or list/tuple :return: TODO: are there problems regarding endpoint attributes? TODO: check if it works for loops (probably does not)
- py3_cmp(other, compare_attr=False)#
Compare diagrams. Replaces obsolete __cmp__ method.
- Parameters:
other –
compare_attr – do we compare also the node attributes (name, color, …)
- Returns:
1 if self > other, -1 if self < other, and 0 otherwise.
- relabel_nodes(mapping)#
Relabels the nodes, can be a partial map
- remove_node(node_for_removing, remove_incident_endpoints=True)#
Remove the node. :param node_for_removing: :param remove_incident_endpoints: use with care, if False, it breaks the planar structure :return: planar diagram without node
- rotate_node_ccw(node, ccw_shift=1)#
Permute the positions of endpoints of the node and take care of adjacent nodes. For example, if we rotate a 4-valent node by 90 degrees, the positions change from (0, 1, 2, 3) to (3, 0, 1, 2), so the permutation should be {0: 3, 1: 0, 2: 1, 3: 2}.
- Parameters:
node – the node of which endpoints we permute
ccw_shift – a dict or list object
- Returns:
- set_arc(arc_for_setting, **attr)#
Set the arc (v_endpoint, u_endpoint), which equals setting the two endpoints adj(u_endpoint) = v_endpoint and vice-versa.
- set_arcs_from(arcs_for_adding, **attr)#
Set the list of arcs.
- Parameters:
arcs_for_adding – a iterable of tuples (v_endpoint, u_endpoint)
- Returns:
None
- set_endpoint(endpoint_for_setting, adjacent_endpoint, create_using=<class 'knotpy.classes.endpoint.Endpoint'>, **attr)#
Set the endpoint to the adjacent endpoint and update the endpoint attributes.
- Parameters:
endpoint_for_setting – Endpoint object or tuple (crossing name, position)
adjacent_endpoint – overwrite the endpoint with adjacent_endpoint (Endpoint object or tuple (crossing name, position))
create_using – if the type is not Endpoint (or IngoingEndpoint or OutgoingEndpoint), the class should be given, be default Endpoint is assumed if endpoint_for_setting is given as a tuple. If an Endpoint instance is given instead of a class, the instance type is used with attributes copied.
attr – additional attributes of the endpoint are added
- Returns:
None
- twin(endpoint)#
Return the opposite endpoint (twin) of an endpoint. Both endpoints form an arc.
- Parameters:
endpoint – Endpoint instance or pair (node, position)
- Returns:
twin endpoint instance