FlexRiLoG -- A SageMath Package for Motions of Graphs
FFlexRiLoG — A SageMath Package forMotions of Graphs
Georg Grasegger ∗ Jan Legerský †‡ In this paper we present the
SageMath package
FlexRiLoG (short forflexible and rigid labelings of graphs). Based on recent results the softwaregenerates motions of graphs using special edge colorings. The package com-putes and illustrates the colorings and the motions. We present the structureand usage of the package.
A graph with a placement of its vertices in the plane is considered to be flexible if theplacement can be continuously deformed by an edge length preserving motion into a non-congruent placement. The study of such graphs and their motions has a long history(see for instance [1, 4, 10, 11, 13–16]). Recently we provided a series of results [7, 8] witha deeper analysis of the existence of flexible placements. This is done via special edgecolorings called NAC-colorings (“No Almost Cycles”, see [7]). These colorings classifythe existence of a flexible placement in the plane and give a construction of the motion.
Basic definitions.
We briefly give a more precise definition of flexibility of a graph.A framework is a pair (
G, p ) where G = ( V G , E G ) is a graph and p : V G → R is a placement of G in R . The placement might be possibly non-injective but for all edges uv ∈ E G we require p ( u ) = p ( v ).Two frameworks ( G, p ) and (
G, q ) are equivalent if for all uv ∈ E G , k p ( u ) − p ( v ) k = k q ( u ) − q ( v ) k . (1)Two placements p, q of G are said to be congruent if (1) holds for all pairs of vertices u, v ∈ V G . Equivalently, p and q are congruent if there exists a Euclidean isometry M of R such that M q ( v ) = p ( v ) for all v ∈ V G . ∗ Johann Radon Institute for Computational and Applied Mathematics (RICAM), Austrian Academyof Sciences † Johannes Kepler University Linz, Research Institute for Symbolic Computation (RISC) ‡ Department of Applied Mathematics, Faculty of Information Technology, Czech Technical Universityin Prague a r X i v : . [ c s . M S ] M a r flex of the framework ( G, p ) is a continuous path t p t , t ∈ [0 , G such that p = p and each ( G, p t ) is equivalent to ( G, p ). The flex iscalled trivial if p t is congruent to p for all t ∈ [0 , flexible if there is a non-trivial flex in R . Otherwise isis called rigid . We say that a labeling λ : E G → R > of a graph G is flexible if thereis a flexible framework ( G, p ) such that p induces λ , namely, k p ( u ) − p ( v ) k = λ ( uv )for all uv ∈ E G . On the other hand, λ is rigid if ( G, p ) is rigid for all placements p inducing λ . A flexible labeling λ of a graph is proper if there exists a framework ( G, p )such that p induces λ and it has a non-trivial flex with all but finitely many placementsbeing injective. We call a graph movable if it has a proper flexible labeling. Outline of the paper.
We have given the necessary definitions. Section 2 describesthe main functionality of the
FlexRiLoG dealing with colorings and motions. In thispaper we do not provide the algorithms themselves but refer to the respective theoremsand literature. In Section 3 we describe how to use the package to ask for movablegraphs.
FlexRiLoG [5] is a package for
SageMath running in versions 8.9 and 9.0 [12]. Thelatest release of the package can be installed by executing: sage -pip install --upgrade flexrilog
The development version of
FlexRiLoG can be found in the repository [6], where alsoother options of installation are described.A convenient way of using the package instead of the sage console is a Jupyter note-book (coming with
SageMath , launch by sage -n jupyter ). The Jupyter notebook examples/flexrilog_Motions_of_Graphs.ipynb in [6] provides an interactive versionof this paper.The package allows to check whether a graph has a NAC-coloring, in particular tolist all of them. A motion or flex obtained from a NAC-coloring can be constructedand displayed. Moreover, it implements the results of [8] regarding the existence ofproper flexible labelings, namely, the check of a necessary condition and construction ofa proper flex from a pair of NAC-colorings. There is also functionality providing toolsfor classification of all proper flexible labeling, which is out of the scope of this paper(see [9] for details).
The package provides data types in different classes for dealing with graphs, coloringsand motions. In order to use the data types provided by the package, they have to beloaded. sage: from flexrilog import FlexRiGraph, GraphMotion
FlexRiGraph . This class inherits properties ofthe standard
Graph from
SageMath and adds specific properties for investigations offlexibility and rigidity. In this paper we focus on the flexibility part. A
FlexRiGraph can be constructed by the following command. sage: FlexRiGraph([[0,1],[1,2],[0,2]])
FlexRiGraph with the vertices [0, 1, 2] and edges [(0, 1), (0, 2), (1, 2)]
Further constructions can be made via integer encoding described in [2] and via objectsof the standard
Graph class. sage: FlexRiGraph(graphs.CompleteBipartiteGraph(2,3))
Complete bipartite graph of order 2+3: FlexRiGraph with the vertices [0, 1, 2, 3, 4]and edges [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4)]
Besides the class for graphs there is a class for colorings (
NACcoloring ). We do notdiscuss the class itself here but rather show how to compute colorings of graphs (seeSection 2.2). Furthermore, motions are stored in a third class,
GraphMotion . They arediscussed in Section 2.3. The
GraphGenerator class stores the code for some importantgraphs from the area of rigidity and flexibility theory. We do not go into detail but someof the graphs are used in the paper.
NAC-colorings are a special type of edge colorings using two colors. Unlike proper edgecolorings in Graph Theory we do not require incident edges to have different colors.
Definition 1.
Let G be a graph. A coloring of edges δ : E G → { blue, red } is called a NAC-coloring , if it is surjective and for every cycle in G , either all edges have the samecolor, or there are at least 2 edges in each color. FlexRiLoG contains functionality for computing and showing NAC-colorings of agiven graph. The standard output is a textual list but the colorings can be shown infigures as well. sage: C4 = FlexRiGraph([[0,1],[1,2],[2,3],[0,3]])sage: C4.NAC_colorings() [NAC-coloring with red edges [[0, 1], [0, 3]] and blue edges [[1, 2], [2, 3]],NAC-coloring with red edges [[0, 1], [1, 2]] and blue edges [[0, 3], [2, 3]],NAC-coloring with red edges [[0, 1], [2, 3]] and blue edges [[0, 3], [1, 2]]] sage: C4.show_all_NAC_colorings()
In order to compute all NAC-colorings, lists of edges that necessarily have the same color3ue to being in 3-cycles (so called -connected components , see [7]) are determined.So far, we then test all possible combinations how to color them by red and blue [7,Lemma 2.4]. The edges colored the same in the following picture must have the samecolor in any NAC-coloring, but no combination satisfies the conditions of NAC-coloring. sage: from flexrilog import GraphGeneratorsage: N = GraphGenerator.NoNACGraph()sage: N.has_NAC_coloring() False sage: N.plot(show_triangle_components=True)
For graphs with symmetries we get many similar colorings, in a sense that after ap-plying the symmetry one NAC-coloring yields the other. We call such NAC-coloringsisomorphic. In order to visualize this, NAC-colorings can be named so that isomorphicones have the same Greek letter but differ by their index. sage: C4.set_NAC_colorings_names()sage: C4.NAC_colorings_isomorphism_classes() [[alpha1: NAC-coloring with red edges [[0, 1], [0, 3]] and blue edges [[1, 2], [2, 3]],alpha2: NAC-coloring with red edges [[0, 1], [1, 2]] and blue edges [[0, 3], [2, 3]]],[beta: NAC-coloring with red edges [[0, 1], [2, 3]] and blue edges [[0, 3], [1, 2]]]]
Given a NAC-coloring we are able to construct a motion. The following result from [7]describes the relation.
Theorem 2.
A connected non-trivial graph has a flexible labeling if and only if it has aNAC-coloring.
The main idea to construct a flex is to place the vertices on a grid in such a way that allthe edges lie on grid lines. This can be achieved by placing vertices according to the colorcomponent of the graph. For color components we remove all edges of the other color andthen take connected components of the remaining graph. Then all vertices which lie inthe same red component are placed in the same column of the grid and all vertices fromthe same blue component are placed in the same row of the grid. By this procedure eachvertex is assigned a unique grid point and all edges of the graph lie on the grid lines. In
FlexRiLoG this can be done with the classmethod
GraphMotion.GridConstruction .4 age: from flexrilog import GraphMotion, GraphGeneratorsage: P = GraphGenerator.ThreePrismGraph()sage: delta = P.NAC_colorings()[0]sage: motion_P = GraphMotion.GridConstruction(P, delta)sage: motion_P.parametrization() {0: (0, 0),1: (sin(alpha) + 1, cos(alpha)),2: (2*sin(alpha) + 1, 2*cos(alpha)),3: (2*sin(alpha), 2*cos(alpha)),4: (sin(alpha), cos(alpha)),5: (1, 0)} There is also the option to generate an animated SVG showing the NAC-coloring, whichis automatically displayed when used in a Jupyter notebook (the picture below is ascreenshot). If the fileName is specified, the SVG animation is stored and a web browsercan be used to view it. Note that not all web browsers support SVG animations. It canbe chosen, whether the edges are colored according to the NAC-coloring in use. Thepackage also distinguishes the vertex layout depending on whether it is drawing a graphhaving no specific placement properties (dark vertices), or drawing a motion, in whichedge lengths are fixed (light vertices). sage: motion_P.animation_SVG(edge_partition="NAC",....: fileName="3-prism_grid")
More generally the base points of the grid can be chosen arbitrarily to get a zig-zag grid.This can be used to avoid degenerate subgraphs. Base points consist of two lists. Thestandard values consists of lists with points ( i,
0) and (0 , i ) respectively. Using themwe get a rectangular initial grid. A zig-zag grid in general does not need to be initiallyrectangular. It is uniquely determined by the base points and drawing parallel lines.Doing so the grid consists of parallelograms. Usually the grid itself is not easily visiblefrom the output motion. sage: motion_P = GraphMotion.GridConstruction(P, delta,....: zigzag=[[[0,0], [3/4,1/2], [2,0]],....: [[0,0], [1,0]]])sage: motion_P.animation_SVG(edge_partition="NAC") Movable graphs
Using the grid construction, non-adjacent vertices might overlap, i.e., the constructedframework is not proper. Note, that this cannot be avoided by zig-zag constructionseither but depends solely on the NAC-coloring in use. For some graphs all NAC-coloringsresult in overlapping vertices. In
FlexRiLoG it can be checked whether this is the case. sage: P.has_injective_grid_construction()
True sage: Q1 = GraphGenerator.Q1Graph()
False
For some graphs, a proper flexible labeling exists due to the following lemma [8], whichrelates movability to spatial embeddings.
Lemma 1.
Let G be a graph with an injective embedding ω : V G → R such that forevery edge uv ∈ E G , the vector ω ( u ) − ω ( v ) is parallel to one of the four vectors (1 , , , (0 , , , (0 , , , ( − , − , − , and all four directions are present. Then G is movable.Moreover, there exist two NAC-colorings of G such that two edges are parallel in theembedding ω if and only if they receive the same pair of colors. The package tries to construct such a spatial embedding for all pairs of NAC-colorings. sage: inj, nacs = Q1.has_injective_spatial_embedding(....: certificate=True); inj
True sage: graphics_array([d.plot() for d in nacs]) sage: motion_Q1 = GraphMotion.SpatialEmbeddingConstruction(Q1, nacs)sage: motion_Q1.fix_edge([5,6])sage: motion_Q1.parametrization() {1: ((3*t^2 - 3)/(t^2 + 1), -6*t/(t^2 + 1)),2: ((t^4 + 23*t^2 + 4)/(t^4 + 5*t^2 + 4), (6*t^3 - 12*t)/(t^4 + 5*t^2 + 4)),3: ((4*t^2 - 2)/(t^2 + 1), -6*t/(t^2 + 1)),4: (18*t^2/(t^4 + 5*t^2 + 4), (6*t^3 - 12*t)/(t^4 + 5*t^2 + 4)),5: (0, 0),6: (2, 0),7: (1, 0)} sage: motion_Q1.animation_SVG()
Besides the sufficient condition on movability above, there is also a necessary conditiongiven in [8]. For this condition we consider all NAC-colorings and look for monochromaticpaths. Adding certain edges according to these paths we get a bigger graph with similarmovability properties.For a graph G , let U( G ) denote the set of all pairs { u, v } ⊂ V G such that uv / ∈ E G andthere exists a path from u to v which is monochromatic for all NAC-colorings δ of G .If there exists a sequence of graphs G , . . . , G n such that G = G , G i = ( V G i − , E G i − ∪ U( G i − )) for i ∈ { , . . . , n } , and U( G n ) = ∅ , then the graph G n is called the constantdistance closure of G , denoted by CDC( G ). Theorem 3.
A graph G is movable if and only if CDC( G ) is movable. Particularly, if CDC( G ) is the complete graph, then G is not movable. We can see that the following graph G is not movable ( G has no NAC-coloring since { , } , { , } ∈ U( G ), hence, U( G ) are all non-edges of G ). sage: G = GraphGenerator.MaxEmbeddingsLamanGraph(7)sage: G.show_all_NAC_colorings() age: G.constant_distance_closure().is_complete() True
Conclusion
We gave a brief overview of the package and therefore did not cover all functionality.The package contains a documentation. As research in the field of flexible and movablegraphs is going on the package is further developed, both regarding improvements aswell as new functionality (for instance n -fold rotationally symmetric frameworks, see [3]).The most current version of FlexRiLoG can be found in [6].
Acknowledgments
This project was supported by the Austrian Science Fund (FWF): P31061, P31888 andW1214-N15, and by the Ministry of Education, Youth and Sports of the Czech Republic,project no. CZ.02.1.01/0.0/0.0/16_019/0000778. The project has received funding fromthe European Union’s Horizon 2020 research and innovation programme under the MarieSkłodowska-Curie grant agreement No 675789.
References [1] L. Burmester. Die Brennpunktmechanismen.
Zeitschrift für Mathematik und Physik ,38:193–223, 1893.[2] J. Capco, M. Gallet, G. Grasegger, C. Koutschan, N. Lubbes, and J. Schicho. Analgorithm for computing the number of realizations of a Laman graph. Zenodo,2018. doi:10.5281/zenodo.1245506 .[3] S. Dewar, G. Grasegger, and J. Legerský. Flexible placements of graphs with rota-tional symmetry, 2020. arXiv:2003.09328 .[4] A. C. Dixon. On certain deformable frameworks.
Messenger , 29(2):1–21, 1899.[5] G. Grasegger and J. Legerský. FlexRiLoG —
SageMath package for Flexible andRigid Labelings of Graphs. Zenodo, March 2020. doi:10.5281/zenodo.3078757 .[6] G. Grasegger and J. Legerský. FlexRiLoG —
SageMath package for Flexible andRigid Labelings of Graphs, repository, 2020. URL: https://github.com/Legersky/flexrilog/. 87] G. Grasegger, J. Legerský, and J. Schicho. Graphs with Flexible Label-ings.
Discrete & Computational Geometry , 62(2):461–480, 2019. doi:10.1007/s00454-018-0026-9 .[8] G. Grasegger, J. Legerský, and J. Schicho. Graphs with Flexible Labelings allowingInjective Realizations.
Discrete Mathematics , in press, 2019. doi:10.1016/j.disc.2019.111713 .[9] G. Grasegger, J. Legerský, and J. Schicho. On the classification of motions ofparadoxically movable graphs, 2020. arXiv:2003.11416 .[10] A. B. Kempe. On Conjugate Four-piece Linkages.
Proceedings of the London Math-ematical Society , s1-9(1):133–149, 11 1877. doi:10.1112/plms/s1-9.1.133 .[11] H. Stachel. On the flexibility and symmetry of overconstrained mechanisms.
Philo-sophical Transactions of the Royal Society of London A: Mathematical, Physicaland Engineering Sciences , 372, 2013. doi:10.1098/rsta.2012.0040 .[12] The Sage Developers.
SageMath, the Sage Mathematics Software System (Version9.0) , 2007.[14] W. Wunderlich. Ein merkwürdiges Zwölfstabgetriebe.
Österreichisches Ingenieur-Archiv , 8:224–228, 1954.[15] W. Wunderlich. On deformable nine-bar linkages with six triple joints.
IndagationesMathematicae (Proceedings) , 79(3):257–262, 1976. doi:10.1016/1385-7258(76)90052-4 .[16] W. Wunderlich. Mechanisms related to Poncelet’s closure theorem.
Mechanismsand Machine Theory , 16:611–620, 1981. doi:10.1016/0094-114X(81)90067-7doi:10.1016/0094-114X(81)90067-7