FlexRiLoG -- A SageMath Package for Motions of Graphs
Georg Grasegger Jan Legerský
cs.MS cs.RO math.CO 52C25, 68R10










english




 

calc








theoremTheorem
lemmaLemma
definitiondefinition[theorem]Definition





and 

IsageVVerbatimgobble=2
OsageVerbatimgobble=2,formatcom=,fontsize=

Isage

 
 


IOsage

 
 












 
 

vertex=[circle, draw, fill=black, inner sep=0pt, minimum size=4pt]
smallvertex=[circle, draw, fill=black, inner sep=0pt, minimum size=2pt]
edge=[line width=1.5pt,black!50!white]
gridl=[black!50!white]
axes=[gridl,-latex]

lnode=[circle,white,draw=black!60!white,fill=black!60!white,inner sep=1pt]
lnodesmall=[circle,white,draw=black!60!white,fill=black!60!white,inner sep=1pt, font=]
redge=[edge,colR]
bedge=[edge,colB]


lnodeR=[circle,colvR,draw=colvR,fill=white,inner sep=1.2pt, font=]
vertexR=[circle,draw=colvR,fill=white,inner sep=0pt, minimum size=4.5pt]



arbitrarygraph=[dashed,black!70!white,thick]
labelsty=[font=]



































FlexRiLoG — A SageMath Package for Motions of Graphs
    Georg GraseggerJohann Radon Institute for Computational and Applied Mathematics (RICAM), Austrian Academy of Sciences
Jan LegerskýJohannes Kepler University Linz, Research Institute for Symbolic Computation (RISC)
Department of Applied Mathematics, Faculty of Information Technology, Czech Technical University in Prague
    
====================================================================================================================================================================================================================================================================================================================================


	In this paper we present the  package  (short for flexible and rigid labelings of graphs).
	Based on recent results the software generates motions of graphs
	using special edge colorings.
	The package computes and illustrates the colorings and the motions.
	We present the structure and usage of the package.




§ INTRODUCTION

A graph with a placement of its vertices in the plane is considered to be flexible if 
the placement 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 <cit.>).
Recently we provided a series of results <cit.> 
with a deeper analysis of the existence of flexible placements.
This is done via special edge colorings called
NAC-colorings (“No Almost Cycles”, see <cit.>).
These colorings classify the 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 →^2
is a placement of G in ^2.
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,

    p(u) - p(v)  =  q(u) - q(v) .

Two placements p,q of G are said to be congruent if (<ref>) holds for all pairs of vertices u,v ∈ V_G.
Equivalently, p and q are congruent if there exists a Euclidean isometry M of ^2 such that M q(v) = p(v) for all v ∈ V_G.

A flex of the framework (G,p) is a continuous path t ↦ p_t, t ∈ [0,1],
in the space of placements of G such that p_0= p and each (G,p_t) is equivalent to (G,p).
The flex is called trivial if p_t is congruent to p for all t ∈ [0,1].

We define a framework to be flexible if there is a non-trivial flex in ^2.
Otherwise is is called rigid.
We say that a labeling λ: E_G→_>0 of a graph G is flexible
if there is a flexible framework (G,p) such that 
p induces λ, namely, p(u) - p(v)  = λ(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 placements being injective. 
We call a graph movable if it has a proper flexible labeling.

Outline of the paper.
We have given the necessary definitions.
Section <ref> describes the main functionality of the  dealing with colorings and motions.
In this paper we do not provide the algorithms themselves but refer to the respective theorems and literature.
In Section <ref> we describe how to use the package to ask for movable graphs.



§ THE PACKAGE

 <cit.>
is a package for  running in versions 8.9 and 9.0 <cit.>.
The latest release of the package can be installed by executing:

sage -pip install –upgrade flexrilog

The development version of  can be found in the repository <cit.>,
where also other options of installation are described.

A convenient way of using the package instead of the  console is a Jupyter notebook
(coming with , launch by ).
The Jupyter notebook  in <cit.>
provides an interactive version of this paper. 

The package allows to check whether a graph has a NAC-coloring, in particular to list all of them.
A motion or flex obtained from a NAC-coloring can be constructed and displayed.
Moreover, it implements the results of <cit.> regarding the existence of proper flexible labelings,
namely, the check of a necessary condition and construction of a proper flex from a pair of NAC-colorings.
There is also functionality providing tools for classification of all proper flexible labeling,
which is out of the scope of this paper (see <cit.> for details). 




 §.§ Data Types

The package provides data types in different classes for dealing with graphs, colorings and motions.
In order to use the data types provided by the package, they have to be loaded.

  from flexrilog import FlexRiGraph, GraphMotion

The main object will always be of type .
This class inherits properties of the standard  from  
and adds specific properties for investigations of flexibility and rigidity.
In this paper we focus on the flexibility part.
A  can be constructed by the following command.

  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 <cit.> and via objects of the standard  class.

  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 ().
We do not discuss the class itself here but rather show how to compute colorings of graphs (see Section <ref>).
Furthermore, motions are stored in a third class, . They are discussed in Section <ref>.
The  class stores the code for some important graphs from the area of rigidity and flexibility theory.
We do not go into detail but some of the graphs are used in the paper.




 §.§ NAC-Colorings

NAC-colorings are a special type of edge colorings using two colors.
Unlike proper edge colorings in Graph Theory we do not require incident edges to have different colors.

	Let G be a graph. A coloring of edges δ  E_G→{, } 
	is called a NAC-coloring,
	if it is surjective and for every cycle in G,
	either all edges have the same color, or
	there are at least 2 edges in each color.






 contains functionality for computing and showing NAC-col­or­ings of a given graph.
The standard output is a textual list but the colorings can be shown in figures as well.

  C4 = FlexRiGraph([[0,1],[1,2],[2,3],[0,3]])
  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]]]
  C4.show_all_NAC_colorings()

[0.6]screenshots/C4nacs.png
In order to compute all NAC-colorings, lists of edges that necessarily have the same color
due to being in 3-cycles (so called -connected components, see <cit.>)
are determined. So far, we then test all possible combinations
how to color them by  and  <cit.>.
The edges colored the same in the following picture must have the same color in any NAC-coloring,
but no combination satisfies the conditions of NAC-coloring.

  from flexrilog import GraphGenerator
  N = GraphGenerator.NoNACGraph()
  N.has_NAC_coloring()
  *False
  N.plot(show_triangle_components=True)

[0.3]screenshots/noNACgraph.png

For graphs with symmetries we get many similar colorings, in a sense that after applying the symmetry one NAC-coloring yields the other.
We call such NAC-colorings isomorphic.
In order to visualize this, NAC-colorings can be named so that isomorphic ones have the same Greek letter but differ by their index.

  C4.set_NAC_colorings_names()
  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]]]]






 §.§ Constructing Motions

Given a NAC-coloring we are able to construct a motion. The following result from <cit.> describes the relation.

	A connected non-trivial graph has a flexible labeling if and only if it has a NAC-coloring.

The main idea to construct a flex is to place the vertices on a grid in such a way that all the edges lie on grid lines.
This can be achieved by placing vertices according to the color component of the graph.
For color components we remove all edges of the other color and then take connected components of the remaining graph.
Then all vertices which lie in the same red component are placed in the same column of the grid and
all vertices from the same blue component are placed in the same row of the grid.
By this procedure each vertex is assigned a unique grid point and all edges of the graph lie on the grid lines.
In  this can be done with the classmethod .

  from flexrilog import GraphMotion, GraphGenerator
  P = GraphGenerator.ThreePrismGraph()
  delta = P.NAC_colorings()[0]
  motion_P = GraphMotion.GridConstruction(P, delta)
  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,
which is automatically displayed when used in a Jupyter notebook (the picture below is a screenshot).
If the  is specified, the SVG animation is stored and a web browser can be used to view it.
Note that not all web browsers support SVG animations.
It can be chosen, whether the edges are colored according to the NAC-coloring in use.
The package also distinguishes the vertex layout depending on whether it is drawing a graph having no specific placement properties (dark vertices),
or drawing a motion, in which edge lengths are fixed (light vertices).

  motion_P.animation_SVG(edge_partition="NAC",
  .                       fileName="3-prism_grid")


[0.2]screenshots/3-prism_grid.png

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. The standard values consists of lists with points (i,0) and (0,i) respectively.
Using them we get a rectangular initial grid.
A zig-zag grid in general does not need to be initially rectangular.
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 visible from the output motion.

  motion_P = GraphMotion.GridConstruction(P, delta, 
  .  zigzag=[[[0,0], [3/4,1/2], [2,0]],
  .           [[0,0], [1,0]]])
  motion_P.animation_SVG(edge_partition="NAC")

[0.2]screenshots/3-prism_zigzag_grid.png



§ MOVABLE GRAPHS

Using the grid construction, non-adjacent vertices might overlap, i.e., the constructed framework is not proper.
Note, that this cannot be avoided by zig-zag constructions either but depends solely on the NAC-coloring in use.
For some graphs all NAC-colorings result in overlapping vertices.
In  it can be checked whether this is the case.

  P.has_injective_grid_construction()
  *True
  Q1 = GraphGenerator.Q1Graph()        # see the picture below
  Q1.has_injective_grid_construction()
  *False

For some graphs, a proper flexible labeling exists due to the following lemma <cit.>,
which relates movability to spatial embeddings.

	Let G be a graph with an injective embedding ω:V_G→^3 such that for every edge 
	uv∈ E_G, the vector ω(u)-ω(v) is parallel to one of the four vectors 
	(1,0,0), (0,1,0), (0,0,1), (-1,-1,-1), 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 the embedding ω
	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.

  inj, nacs = Q1.has_injective_spatial_embedding(
  .                      certificate=True); inj
  *True
  graphics_array([d.plot() for d in nacs])

[0.6]screenshots/Q1twoNACs.png

From the spatial embedding we can construct a motion of the graph.
The motion can be transformed in such a way that a particular edge is fixed.

  motion_Q1 = GraphMotion.SpatialEmbeddingConstruction(Q1, nacs)
  motion_Q1.fix_edge([5,6])
  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)
  motion_Q1.animation_SVG()

[0.3]screenshots/Q1_spatial_construction.png

Besides the sufficient condition on movability above, there is also a necessary condition given in <cit.>.
For this condition we consider all NAC-colorings and look for monochromatic paths.
Adding certain edges according to these paths we get a bigger graph with similar movability properties.

For a graph G, let G denote the set of all pairs {u,v}⊂ V_G such that uv∉ E_G and 
there exists a path from u to v which is monochromatic for all NAC-colorings δ of G.	
If there exists a sequence of graphs G_0, …, G_n such that
	G=G_0,
	G_i=(V_G_i-1,E_G_i-1∪G_i-1) for i∈{1,…,n}, and
	G_n=∅,
then the graph G_n is called the constant distance closure of G, denoted by G.


	A graph G is movable if and only if G is movable.
	Particularly, if G is the complete graph, then G is not movable.


We can see that the following graph G is not movable
(G_1 has no NAC-coloring since {3,4},{5,6}∈G, 
hence, G_1 are all non-edges of G_1). 

  G = GraphGenerator.MaxEmbeddingsLamanGraph(7)
  G.show_all_NAC_colorings()

screenshots/Gmax7nacs.png



  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 movable graphs is going on the package is further developed,
both regarding improvements as well as new functionality (for instance n-fold rotationally symmetric frameworks, see <cit.>).
The most current version of  can be found in <cit.>.



 §.§ Acknowledgments

This project was supported by the Austrian Science Fund (FWF): P31061, P31888 and W1214-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 from the European Union's Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No 675789.



10

Burmester1893
L. Burmester.
Die Brennpunktmechanismen.
Zeitschrift für Mathematik und Physik, 38:193–223, 1893.

ZenodoAlg
J. Capco, M. Gallet, G. Grasegger, C. Koutschan, N. Lubbes, and J. Schicho.
An algorithm for computing the number of realizations of a Laman
  graph.
Zenodo, 2018.
https://doi.org/10.5281/zenodo.1245506
  doi:10.5281/zenodo.1245506.

RotSymmetry
S. Dewar, G. Grasegger, and J. Legerský.
Flexible placements of graphs with rotational symmetry, 2020.
https://arxiv.org/abs/2003.09328 arXiv:2003.09328.

Dixon
A. C. Dixon.
On certain deformable frameworks.
Messenger, 29(2):1–21, 1899.

flexrilog
G. Grasegger and J. Legerský.
FlexRiLoG —  package for Flexible and Rigid Labelings of
  Graphs.
Zenodo, March 2020.
https://doi.org/10.5281/zenodo.3078757
  doi:10.5281/zenodo.3078757.

flexrilogGitHub
G. Grasegger and J. Legerský.
FlexRiLoG —  package for Flexible and Rigid Labelings of
  Graphs, repository, 2020.
URL: <https://github.com/Legersky/flexrilog/>.

flexibleLabelings
G. Grasegger, J. Legerský, and J. Schicho.
Graphs with Flexible Labelings.
Discrete & Computational Geometry, 62(2):461–480, 2019.
https://doi.org/10.1007/s00454-018-0026-9
  doi:10.1007/s00454-018-0026-9.

movableGraphs
G. Grasegger, J. Legerský, and J. Schicho.
Graphs with Flexible Labelings allowing Injective Realizations.
Discrete Mathematics, in press, 2019.
https://doi.org/10.1016/j.disc.2019.111713
  doi:10.1016/j.disc.2019.111713.

ClassificationPaper
G. Grasegger, J. Legerský, and J. Schicho.
On the classification of motions of paradoxically movable graphs,
  2020.
https://arxiv.org/abs/2003.11416 arXiv:2003.11416.

Kempe1877
A. B. Kempe.
On Conjugate Four-piece Linkages.
Proceedings of the London Mathematical Society,
  s1-9(1):133–149, 11 1877.
https://doi.org/10.1112/plms/s1-9.1.133
  doi:10.1112/plms/s1-9.1.133.

Stachel
H. Stachel.
On the flexibility and symmetry of overconstrained mechanisms.
Philosophical Transactions of the Royal Society of London A:
  Mathematical, Physical and Engineering Sciences, 372, 2013.
https://doi.org/10.1098/rsta.2012.0040
  doi:10.1098/rsta.2012.0040.

sagemath
The Sage Developers.
SageMath, the Sage Mathematics Software System
  (Version 9.0), 2020.
URL: <https://www.sagemath.org>.

WalterHusty
D. Walter and M. L. Husty.
On a nine-bar linkage, its possible configurations and conditions for
  paradoxical mobility.
In 12th World Congress on Mechanism and Machine Science,
  IFToMM, 2007.

Wunderlich1954
W. Wunderlich.
Ein merkwürdiges Zwölfstabgetriebe.
Österreichisches Ingenieur-Archiv, 8:224–228, 1954.

Wunderlich1976
W. Wunderlich.
On deformable nine-bar linkages with six triple joints.
Indagationes Mathematicae (Proceedings), 79(3):257–262, 1976.
https://doi.org/10.1016/1385-7258(76)90052-4
  doi:10.1016/1385-7258(76)90052-4.

Wunderlich1981
W. Wunderlich.
Mechanisms related to Poncelet's closure theorem.
Mechanisms and Machine Theory, 16:611–620, 1981.
https://doi.org/10.1016/0094-114X(81)90067-7
  doi:10.1016/0094-114X(81)90067-7.




