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. If graph is empty, and hence also the realization, 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

dim

Return the dimension of the framework.

graph

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 return dict[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:

FrameworkBase

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:

MutableDenseMatrix

Examples

>>> F = Framework(Graph([[0,1]]), {0:[1,2], 1:[0,5]})
>>> F[0]
Matrix([
[1],
[2]])
__repr__()[source]

Return a representation of the framework.

Return type:

str

__str__()[source]

Return the string representation.

Return type:

str

_input_check_point_dimension(point)[source]

Check whether a point has the right dimension and raise an error otherwise.

Parameters:

point (Point)

Return type:

None

_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:

None

_input_check_vertex_key(vertex, realization=None)[source]

Check whether a vertex appears as key in a realization and raise an error otherwise.

Parameters:
  • vertex (Vertex) – The vertex to check.

  • realization (dict[Vertex, Point]) – The realization to check.

Return type:

None

add_edge(edge)[source]

Add an edge to the framework.

Parameters:

edge (Edge)

Return type:

None

Notes

This method only alters the graph attribute.

add_edges(edges)[source]

Add a list of edges to the framework.

Parameters:

edges (Sequence[Edge])

Return type:

None

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:
  • point (Point) – The realization of the new vertex.

  • vertex (Vertex) – The label of the new vertex.

Return type:

None

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 method add_vertex(). Otherwise, the list of vertices needs to have the same length as the list of points.

Return type:

None

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.

delete_edge(edge)[source]

Delete an edge from the framework.

Parameters:

edge (Edge)

Return type:

None

delete_edges(edges)[source]

Delete a list of edges from the framework.

Parameters:

edges (Sequence[Edge])

Return type:

None

delete_vertex(vertex)[source]

Delete a vertex from the framework.

Parameters:

vertex (Vertex)

Return type:

None

delete_vertices(vertices)[source]

Delete a list of vertices from the framework.

Parameters:

vertices (Sequence[Vertex])

Return type:

None

property dim: int

Return the dimension of the framework.

edge_lengths(numerical=False)[source]

Return the dictionary of the edge lengths.

Parameters:

numerical (bool) – If True, numerical positions are used for the computation of the edge lengths.

Return type:

dict[Edge, Number]

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) – If True, then the vertex positions type is pyrigi.data_type.Point, otherwise Matrix (default).

  • numerical (bool) – If True, the vertex positions are converted to floats.

Return type:

dict[Vertex, Point] | dict[Vertex, MutableDenseMatrix]

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

Realization

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:

None

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:
  • vertex (Vertex) – A vertex whose position is changed.

  • point (Point) – A new position of the vertex.

Return type:

None

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.

Parameters:

subset_of_realization (dict[Vertex, Point])

Return type:

None

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 method set_vertex_positions() to the corresponding pairs of vertices and points.

Parameters:
Return type:

None

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]}