Extensions¶
This module provides algorithms related to k-extensions of graphs.
- pyrigi.graph._constructions.extensions.all_extensions(graph, dim=2, only_non_isomorphic=False, k_min=0, k_max=None)[source]¶
Return an iterator over all
dim-dimensional extensions.All possible
k-extensions forksuch thatk_min <= k <= k_maxare considered.Definitions
- Parameters:
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(3) >>> type(all_extensions(G)) <class 'generator'> >>> len(list(all_extensions(G))) 6 >>> len(list(all_extensions(G, only_non_isomorphic=True))) 1
>>> diamond_graph = graphs.Diamond() >>> result1 = list(all_extensions(diamond_graph, 2, only_non_isomorphic=True, k_min=1, k_max=1)) # noqa: E501 >>> result2 = list(all_k_extensions(diamond_graph, 1, 2, only_non_isomorphic=True)) >>> result1 == result2 True
Notes
It turns out that possible errors on bad input parameters are only raised, when the output iterator is actually used, not when it is created.
- pyrigi.graph._constructions.extensions.all_k_extensions(graph, k, dim=2, only_non_isomorphic=False)[source]¶
Return an iterator over all possible
dim-dimensionalk-extensions.Definitions
- Parameters:
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(3) >>> type(all_k_extensions(G, 0)) <class 'generator'> >>> len(list(all_k_extensions(G, 0))) 3 >>> len(list(all_k_extensions(G, 0, only_non_isomorphic=True))) 1
>>> diamond_graph = graphs.Diamond() >>> len(list(all_k_extensions(diamond_graph, 1, 2, only_non_isomorphic=True))) 2
Notes
It turns out that possible errors on bad input parameters are only raised, when the output iterator is actually used, not when it is created.
- pyrigi.graph._constructions.extensions.extension_sequence(graph, dim=2, return_type='extensions')[source]¶
Compute a sequence of
dim-dimensional extensions.The
k-extensions forkfrom 0 to2 * dim - 1are considered. The sequence then starts from a complete graph ondimvertices. If no such sequence exists,Noneis returned.The function returns either a sequence of graphs, data on the extension, or both.
Note that for dimensions larger than two, the extensions are not always preserving rigidity.
Definitions
- Parameters:
graph (
Graph)dim (
int) – The dimension in which the extensions are created.return_type (
str) –Can have values
"graphs","extensions"or"both".If
"graphs", then the sequence of graphs obtained from the extensions is returned.If
"extensions", then an initial graph and a sequence of extensions of the form[k, vertices, edges, new_vertex]as needed for the input ofk_extension()is returned.If
"both", then an initial graph and a sequence of pairs[graph, extension], where the latter has the form from above, is returned.
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(3) >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] >>> extension_sequence(G, return_type="graphs") [Graph.from_vertices_and_edges([1, 2], [(1, 2)]), Graph.from_vertices_and_edges([0, 1, 2], [(0, 1), (0, 2), (1, 2)])] >>> G = graphs.Diamond() >>> print(G) Graph with vertices [0, 1, 2, 3] and edges [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3]] >>> extension_sequence(G, return_type="graphs") [Graph.from_vertices_and_edges([2, 3], [(2, 3)]), Graph.from_vertices_and_edges([0, 2, 3], [(0, 2), (0, 3), (2, 3)]), Graph.from_vertices_and_edges([0, 1, 2, 3], [(0, 1), (0, 2), (0, 3), (1, 2), (2, 3)])] >>> extension_sequence(G, return_type="extensions") [Graph.from_vertices_and_edges([2, 3], [(2, 3)]), [0, [3, 2], [], 0], [0, [0, 2], [], 1]]
- pyrigi.graph._constructions.extensions.has_extension_sequence(graph, dim=2)[source]¶
Return if there exists a sequence of
dim-dimensional extensions.The function returns whether there exists a sequence of extensions as described in
extension_sequence().Definitions
- Parameters:
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.ThreePrism() >>> print(G) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 1], [0, 2], [0, 3], [1, 2], [1, 4], [2, 5], [3, 4], [3, 5], [4, 5]] >>> has_extension_sequence(G) True >>> G = graphs.CompleteBipartite(1, 2) >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2]] >>> has_extension_sequence(G) False
- pyrigi.graph._constructions.extensions.k_extension(graph, k, vertices, edges, new_vertex=None, dim=2, inplace=False)[source]¶
Return a
dim-dimensionalk-extension.See also
zero_extension()andone_extension().Definitions
- Parameters:
graph (
Graph)k (
int)vertices (
Sequence[Vertex]) – A new vertex is connected to these vertices. All the vertices must be contained in the graph and there must bedim + kof them.edges (
Sequence[Edge]) – A list of edges that are deleted. The endvertices of all the edges must be contained in the listvertices. The edges must be contained in the graph and there must bekof them.new_vertex (
Vertex) – Newly added vertex is named according to this parameter. IfNone, the name is set as the lowest possible integer value greater or equal than the number of nodes.dim (
int) – The dimension in which thek-extension is created.inplace (
bool) – IfTrue, the graph is modified, otherwise a new modified graph is created, while the original graph remains unchanged (default).
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(5) >>> print(G) Graph with vertices [0, 1, 2, 3, 4] and edges [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]] >>> H = k_extension(G, 2, [0, 1, 2, 3], [[0, 1], [0,2]]) >>> print(H) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 3], [0, 4], [0, 5], [1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5]] >>> G = graphs.Complete(5) >>> print(G) Graph with vertices [0, 1, 2, 3, 4] and edges [[0, 1], [0, 2], [0, 3], [0, 4], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]] >>> H = k_extension(G, 2, [0, 1, 2, 3, 4], [[0, 1], [0,2]], dim = 3) >>> print(H) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 3], [0, 4], [0, 5], [1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]] >>> G = graphs.Path(6) >>> print(G) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]] >>> H = k_extension(G, 2, [0, 1, 2], [[0, 1], [1,2]], dim = 1, inplace = True); >>> print(H) Graph with vertices [0, 1, 2, 3, 4, 5, 6] and edges [[0, 6], [1, 6], [2, 3], [2, 6], [3, 4], [4, 5]] >>> print(G) Graph with vertices [0, 1, 2, 3, 4, 5, 6] and edges [[0, 6], [1, 6], [2, 3], [2, 6], [3, 4], [4, 5]]
- pyrigi.graph._constructions.extensions.one_extension(graph, vertices, edge, new_vertex=None, dim=2, inplace=False)[source]¶
Return a
dim-dimensional 1-extension.Definitions
- Parameters:
graph (
Graph)vertices (
Sequence[Vertex]) – A new vertex is connected to these vertices. All the vertices must be contained in the graph and there must bedim + 1of them.edge (
Edge) – An edge with endvertices from the listverticesthat is deleted. The edge must be contained in the graph.new_vertex (
Vertex) – Newly added vertex is named according to this parameter. IfNone, the name is set as the lowest possible integer value greater or equal than the number of nodes.dim (
int) – The dimension in which the 1-extension is created.inplace (
bool) – IfTrue, the graph is modified, otherwise a new modified graph is created, while the original graph remains unchanged (default).
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(3) >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] >>> H = one_extension(G, [0, 1, 2], [0, 1]) >>> print(H) Graph with vertices [0, 1, 2, 3] and edges [[0, 2], [0, 3], [1, 2], [1, 3], [2, 3]] >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] >>> G = graphs.ThreePrism() >>> print(G) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 1], [0, 2], [0, 3], [1, 2], [1, 4], [2, 5], [3, 4], [3, 5], [4, 5]] >>> H = one_extension(G, [0, 1], [0, 1], dim=1) >>> print(H) Graph with vertices [0, 1, 2, 3, 4, 5, 6] and edges [[0, 2], [0, 3], [0, 6], [1, 2], [1, 4], [1, 6], [2, 5], [3, 4], [3, 5], [4, 5]] >>> G = graphs.CompleteBipartite(3, 2) >>> print(G) Graph with vertices [0, 1, 2, 3, 4] and edges [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4]] >>> H = one_extension(G, [0, 1, 2, 3, 4], [0, 3], dim=4, inplace = True) >>> print(H) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 4], [0, 5], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 5], [4, 5]] >>> print(G) Graph with vertices [0, 1, 2, 3, 4, 5] and edges [[0, 4], [0, 5], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 5], [4, 5]]
- pyrigi.graph._constructions.extensions.zero_extension(graph, vertices, new_vertex=None, dim=2, inplace=False)[source]¶
Return a
dim-dimensional 0-extension.Definitions
- Parameters:
graph (
Graph)vertices (
Sequence[Vertex]) – A new vertex is connected to these vertices. All the vertices must be contained in the graph and there must bedimof them.new_vertex (
Vertex) – Newly added vertex is named according to this parameter. IfNone, the name is set as the lowest possible integer value greater or equal than the number of nodes.dim (
int) – The dimension in which the 0-extension is created.inplace (
bool) – IfTrue, the graph is modified, otherwise a new modified graph is created, while the original graph remains unchanged (default).
- Return type:
Examples
>>> import pyrigi.graphDB as graphs >>> G = graphs.Complete(3) >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] >>> H = zero_extension(G, [0, 2]) >>> print(H) Graph with vertices [0, 1, 2, 3] and edges [[0, 1], [0, 2], [0, 3], [1, 2], [2, 3]] >>> H = zero_extension(G, [0, 2], 5) >>> print(H) Graph with vertices [0, 1, 2, 5] and edges [[0, 1], [0, 2], [0, 5], [1, 2], [2, 5]] >>> print(G) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] >>> H = zero_extension(G, [0, 1, 2], 5, dim=3, inplace=True) >>> print(H) Graph with vertices [0, 1, 2, 5] and edges [[0, 1], [0, 2], [0, 5], [1, 2], [1, 5], [2, 5]] >>> print(G) Graph with vertices [0, 1, 2, 5] and edges [[0, 1], [0, 2], [0, 5], [1, 2], [1, 5], [2, 5]]