FrameworkBase¶
Base module for the functionality concerning frameworks.
- class pyrigi.framework.base.FrameworkBase(graph, realization)[source]¶
Bases:
object
This class is a base class for
Framework
.Definitions
- Parameters:
graph (
Graph
) – A graph without loops.realization (
dict
[Vertex
,Point
]) – A dictionary mapping the vertices of the graph to points in \(\RR^d\). The dimension \(d\) is retrieved from the points in realization. Ifgraph
is empty, and hence also therealization
, the dimension is set to 0 (Empty()
can be used to construct an empty framework with different dimension).
Examples
>>> F = FrameworkBase(Graph([[0,1]]), {0:[1,2], 1:[0,5]}) >>> print(F) FrameworkBase in 2-dimensional space consisting of: Graph with vertices [0, 1] and edges [[0, 1]] Realization {0:(1, 2), 1:(0, 5)}
Notice that the realization of a vertex can be accessed using
[ ]
:>>> F[0] Matrix([ [1], [2]])
This the base class for
Framework
.>>> from pyrigi import Framework >>> issubclass(Framework, FrameworkBase) True
Methods
Attribute getters
Return the dimension of the framework.
Return a copy of the underlying graph.
realization
([as_points, numerical])Return a copy of the realization.
Class methods
Empty
([dim])Generate an empty framework.
Framework manipulation
add_edge
(edge)Add an edge to the framework.
add_edges
(edges)Add a list of edges to the framework.
add_vertex
(point[, vertex])Add a vertex to the framework with the corresponding coordinates.
add_vertices
(points[, vertices])Add a list of vertices to the framework.
delete_edge
(edge)Delete an edge from the framework.
delete_edges
(edges)Delete a list of edges from the framework.
delete_vertex
(vertex)Delete a vertex from the framework.
delete_vertices
(vertices)Delete a list of vertices from the framework.
set_realization
(realization)Change the realization of the framework.
set_vertex_pos
(vertex, point)Change the coordinates of a single given vertex.
set_vertex_positions
(subset_of_realization)Change the coordinates of vertices given by a dictionary.
set_vertex_positions_from_lists
(vertices, points)Change the coordinates of a given list of vertices.
Other
edge_lengths
([numerical])Return the dictionary of the edge lengths.
Notes
Internally, the realization is represented as
dict[Vertex,Matrix]
. However,realization()
can also returndict[Vertex,Point]
.- classmethod Empty(dim=2)[source]¶
Generate an empty framework.
- Parameters:
dim (
int
) – A natural number that determines the dimension in which the framework is realized.- Return type:
Examples
>>> F = Framework.Empty(dim=1); print(F) Framework in 1-dimensional space consisting of: Graph with vertices [] and edges [] Realization {}
- __getitem__(vertex)[source]¶
Return the coordinates of a given vertex in the realization.
- Parameters:
vertex (
Vertex
)- Return type:
Examples
>>> F = Framework(Graph([[0,1]]), {0:[1,2], 1:[0,5]}) >>> F[0] Matrix([ [1], [2]])
- _input_check_point_dimension(point)[source]¶
Check whether a point has the right dimension and raise an error otherwise.
- _input_check_underlying_graphs(other_framework)[source]¶
Check whether the underlying graphs of two frameworks are the same and raise an error otherwise.
- Return type:
- _input_check_vertex_key(vertex, realization=None)[source]¶
Check whether a vertex appears as key in a realization and raise an error otherwise.
- add_edge(edge)[source]¶
Add an edge to the framework.
Notes
This method only alters the graph attribute.
- add_edges(edges)[source]¶
Add a list of edges to the framework.
Notes
For each edge that has to be added,
add_edge()
is called.
- add_vertex(point, vertex=None)[source]¶
Add a vertex to the framework with the corresponding coordinates.
If no vertex is provided (
None
), then an integer is chosen instead.- Parameters:
- Return type:
Examples
>>> F = Framework.Empty(dim=2) >>> F.add_vertex((1.5,2), 'a') >>> F.add_vertex((3,1)) >>> print(F) Framework in 2-dimensional space consisting of: Graph with vertices ['a', 1] and edges [] Realization {a:(1.50000000000000, 2), 1:(3, 1)}
- add_vertices(points, vertices=None)[source]¶
Add a list of vertices to the framework.
- Parameters:
points (
Sequence
[Point
]) – List of points consisting of coordinates in \(\RR^d\). It is checked that all points lie in the same ambient space.vertices (
Sequence
[Vertex
]) – List of vertices. If the list of vertices is empty, we generate vertices with the methodadd_vertex()
. Otherwise, the list of vertices needs to have the same length as the list of points.
- Return type:
Examples
>>> F = Framework.Empty(dim=2) >>> F.add_vertices([(1.5,2), (3,1)], ['a',0]) >>> print(F) Framework in 2-dimensional space consisting of: Graph with vertices ['a', 0] and edges [] Realization {a:(1.50000000000000, 2), 0:(3, 1)}
Notes
For each vertex that has to be added,
add_vertex()
is called.
- edge_lengths(numerical=False)[source]¶
Return the dictionary of the edge lengths.
- Parameters:
numerical (
bool
) – IfTrue
, numerical positions are used for the computation of the edge lengths.- Return type:
Examples
>>> G = Graph([(0,1), (1,2), (2,3), (0,3)]) >>> F = Framework(G, {0:[0,0], 1:[1,0], 2:[1,'1/2 * sqrt(5)'], 3:['1/2','4/3']}) >>> F.edge_lengths(numerical=False) {(0, 1): 1, (0, 3): sqrt(73)/6, (1, 2): sqrt(5)/2, (2, 3): sqrt((-4/3 + sqrt(5)/2)**2 + 1/4)} >>> F.edge_lengths(numerical=True) {(0, 1): 1.0, (0, 3): 1.4240006242195884, (1, 2): 1.118033988749895, (2, 3): 0.5443838790578374}
- property graph: Graph¶
Return a copy of the underlying graph.
Examples
>>> F = Framework.Random(Graph([(0,1), (1,2), (0,2)])) >>> print(F.graph) Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]]
- realization(as_points=False, numerical=False)[source]¶
Return a copy of the realization.
- Parameters:
as_points (
bool
) – IfTrue
, then the vertex positions type ispyrigi.data_type.Point
, otherwiseMatrix
(default).numerical (
bool
) – IfTrue
, the vertex positions are converted to floats.
- Return type:
Examples
>>> F = Framework.Complete([(0,0), (1,0), (1,1)]) >>> F.realization(as_points=True) {0: [0, 0], 1: [1, 0], 2: [1, 1]} >>> F.realization() {0: Matrix([ [0], [0]]), 1: Matrix([ [1], [0]]), 2: Matrix([ [1], [1]])}
- set_realization(realization)[source]¶
Change the realization of the framework.
Definitions
- Parameters:
realization (
dict
[Vertex
,Point
]) – A realization of the underlying graph of the framework. It must contain all vertices from the underlying graph. Furthermore, all points in the realization need to be contained in \(\RR^d\) for \(d\) being the current dimension of the framework.- Return type:
Examples
>>> F = Framework.Complete([(0,0), (1,0), (1,1)]) >>> F.set_realization( ... {vertex: (vertex, vertex + 1) for vertex in F.graph.vertex_list()} ... ) >>> print(F) Framework in 2-dimensional space consisting of: Graph with vertices [0, 1, 2] and edges [[0, 1], [0, 2], [1, 2]] Realization {0:(0, 1), 1:(1, 2), 2:(2, 3)}
- set_vertex_pos(vertex, point)[source]¶
Change the coordinates of a single given vertex.
- Parameters:
- Return type:
Examples
>>> F = Framework.from_points([(0,0)]) >>> F.set_vertex_pos(0, (6,2)) >>> print(F) Framework in 2-dimensional space consisting of: Graph with vertices [0] and edges [] Realization {0:(6, 2)}
- set_vertex_positions(subset_of_realization)[source]¶
Change the coordinates of vertices given by a dictionary.
Examples
>>> F = Framework.Complete([(0,0),(0,0),(1,0),(1,0)]) >>> F.realization(as_points=True) {0: [0, 0], 1: [0, 0], 2: [1, 0], 3: [1, 0]} >>> F.set_vertex_positions({1:(0,1),3:(1,1)}) >>> F.realization(as_points=True) {0: [0, 0], 1: [0, 1], 2: [1, 0], 3: [1, 1]}
- set_vertex_positions_from_lists(vertices, points)[source]¶
Change the coordinates of a given list of vertices.
It is necessary that both lists have the same length. No vertex from
vertices
can be contained multiple times. We apply the methodset_vertex_positions()
to the corresponding pairs ofvertices
andpoints
.Examples
>>> F = Framework.Complete([(0,0),(0,0),(1,0),(1,0)]) >>> F.realization(as_points=True) {0: [0, 0], 1: [0, 0], 2: [1, 0], 3: [1, 0]} >>> F.set_vertex_positions_from_lists([1,3], [(0,1),(1,1)]) >>> F.realization(as_points=True) {0: [0, 0], 1: [0, 1], 2: [1, 0], 3: [1, 1]}