1 Introduction
Planarity [16] is a popular abstract puzzle game that is widely available. Besides being a smartphone app and having a Wikipedia page, it is also available as a “model” in Netlogo [17]. The idea is that a tangled graph is given with intersecting edges, and the objective is to untangle the graph by dragging vertices to other locations as to reach a plane drawing. If the graph is planar (meaning that it can be embedded in the plane without intersections), then the objective can always be realized, and we never need more vertex drags than there are vertices.
Algorithmically, planarity of a graph can be tested in linear time [6, 8, 15], and the algorithm returns an embedding of the graph in which it is drawn planar. So for an algorithm, an instance of Planarity is easily solvable in linear time. Minimizing the number of moves, however, is NPhard [9, 19], see also [3].
In this paper we propose several variations on the game Planarity. These variations essentially limit the freedom of the operations that can be done on the drawn graph. We investigate one of the new variations closely: Swap Planarity, where we can swap the locations of two vertices that are connected by an edge. Examples are shown in Fig. 1. We show that quadratically many swaps are sometimes necessary, even if the input has just one edge crossing. We also prove that, if a planar state can be reached, quadratically many swaps are always sufficient to reach it. We also show, however, that deciding whether such a planar state exists is NPcomplete for general graphs. Simple graphs like trees can always be made planar by swaps, but we show that minimizing the number of swaps needed is NPcomplete.
We also investigate the automated generation of good puzzle instances. We describe a fivestep process which yields a puzzle instance. Some of the considerations of a good instance are puzzle (complexity) based and some are geometry based. Our process guarantees that the puzzle and geometry criteria are met.
We implemented the generator and ran a number of experiments that uncover some properties of point set generation and puzzle diversity. The implementation includes a puzzle mode where the user can solve generated instances by hand.
2 Graph untangling puzzles
We will limit the operations that change the drawing of the graph to arrive at different puzzles. Since the puzzle type is abstract, it is necessary that the interaction and operations themselves are simple. The puzzle then becomes an elegant abstract puzzle of which there are many already (Move, Lines/Flow, Zengrams, Nintaii, Fling, and several more).
Besides interacting with a vertex like in Planarity, it is natural to interact with an edge. Clicking or selecting is arguably the easiest interaction. We list a number of ways in which the graph drawing can change when an edge is selected:
 Swap:

the two endpoints of the selected edge swap locations. Intuitively, the edge turns around while the endpoints drag all incident edges with them.
 Rotate:

like swap, but now the selected edge rotates over degrees around its center. Since a single edge can be selected consecutively three times, it does not matter whether we rotate clockwise or counterclockwise.
 Stretch:

the selected edge is scaled by a factor from its center, or by a factor .
 Collapse:

the endpoints of the selected edge are united. The united vertex is placed in the middle of the edge and gets all edges incident to the original vertices. The selected edge is removed.
Of these versions, the first one distinguishes itself from the others because no new vertex positions appear. The graph will always be drawn on the original positions. Furthermore, the last version distinguishes itself by the fact that the number of vertices is reduced. Eventually, the whole graph could be reduced to a single vertex, so the challenge must be to remove all intersections in a limited number of steps. In the first three versions, steps are reversible.
We can also stay closer to the original Planarity puzzle and drag vertices in more limited ways. For example, a set of points can be given along with the graph, and the vertices must be dragged to the given points. This version is related to a wellknown problem in the graph drawing research area, namely that of embedding a graph on a given set of points [5]. In essence, the initial drawing of the graph is irrelevant.
In this paper we concentrate on the swap version, named Swap Planarity. It is perhaps the most elegant version and the graphs appearing after operations can be controlled in their appearance, unlike with the other versions (where edges may get so short that they cannot be selected any more). All following results concern this version.
Before we go into the algorithmic complexity of solving such puzzles and the process of generating good puzzle instances, we give a few examples to understand the puzzle better. First, consider the puzzle instance in Fig. 2 with eight vertices and eight edges. The graph is a single cycle and it has only one intersection. To solve this puzzle, note that any swap will increase the number of intersections. The minimum number of swaps needed is six; the set of intermediate drawings is shown in the figure and the selected edge is shown. When we extend this example to a set of vertices and edges, we need swaps to solve the instance.
Lemma 1
There exist graphs with vertices that require swaps to obtain a plane drawing.
Proof. Consider the drawing of Fig. 2 generalized to vertices, with even. Name the vertices of the graph so that are clockwise and are counterclockwise. This implies that the edges and intersect. Let us name the positions for the vertices , where initially is at and the positions are numbered clockwise, see Fig. 3.
In total there are ways to place on without intersections: in cyclic order clockwise or counterclockwise, and starting anywhere. This means that either or must be reversed on the positions .
Listing the points in the order of the cycle , we initially
get the
cyclic sequence . A swap exchanges precisely
two adjacent elements (where the first and last are also adjacent). Thus, to sort this sequence
in one of the ways, at least swaps are needed.
The next lemma shows that quadratically many swaps are sufficient; the result has been proved before as node swapping [20].
Lemma 2
Every embedded graph with vertices that can reach a plane drawing using swaps has a sequence of swaps to obtain this drawing.
Proof. Assume first that the graph has a single connected component. Name the positions , and name the vertices of the graph in such a way that the graph is drawn plane if is at position . We prove by induction that any connected graph with vertices can place its vertices at at positions , respectively.
Choose any vertex such that its removal will leave the graph connected. Suppose
a vertex is currently at position . Use the path between and in
to get onto as follows. Suppose this path is ,
see Fig. 4 for an example.
We swap , then , and so on until . This
brings onto in swaps. We remove from the graph and
from the locations and continue inductively. It is clear that at most swaps are
needed in total.
If the graph has multiple connected components, we follow this procedure for each connected component.
Another puzzle variant of swapping to planarity is possible, namely where we swap any two vertices (so they need not be connected by an edge). The interaction with the puzzle consists of clicking on two different vertices consecutively. In this variation, any solvable puzzle instance with vertices is solvable in at most swaps, because we can directly bring any vertex to the correct position. The challenge of this variant reduces to recognizing where vertices need to be to get a planar embedding, and no longer how to get it there.
3 Complexity of Swap Planarity
Theorem 3
Given an embedded graph , it is NPcomplete to decide if the graph can be made planar using swaps.
Proof. A solution of the problem can be presented by the sequence in which vertices are swapped. This solution can be represented in space by Lemma 2. Swapping these vertices and checking if the resulting graph is plane can be done in polynomial time, hence the problem is in NP.
Cabello [5] showed that it is NPcomplete to decide if a given point set admits a planar drawing of a given graph where the vertices must be placed at the points. This is also true for connected graphs. Given an instance of this problem with a connected graph, we assign the vertices of to the points in arbitrarily.
We now solve the graph planarization using swaps on this embedding of the graph. If it has a solution, we can just output the final pointvertex relation, leading to a planar embedding of the given graph. If no solution exists, we also know that no planar embedding exists,
since by the proof of Lemma 2, we can realize any assignment of vertices
to points in a connected graph.
It is known that if is a tree, the embedding problem of onto is no longer NPcomplete because every tree can be embedded without intersections onto a planar point set [4, 13]. This does not imply that our puzzle game is easy to solve when the graph is a tree when we bound the number of swaps. In particular, we can show that deciding whether the vertices of an embedded tree can be swapped to become plane in at most swaps is NPcomplete.
Theorem 4
Given an integer and a embedded tree with vertices, it is NPcomplete to decide if swaps suffice to obtain a plane drawing.
Proof. A solution of the problem can be presented by the sequence of edges to be swapped. Swapping these edges and checking if the resulting tree is plane can be done in polynomial time, hence the problem is in NP.
For ease of explanation, the given reduction contains a number of collinear vertices. By perturbing the vertices slightly, however, the same construction works for points in general position. We reduce from positive planar 1in3SAT. This problem was shown to be NPcomplete by Mulzer and Rote [12].
Positive planar 1in3SAT. In the positive planar 1in3SAT problem we are given a collection of clauses, each consisting of exactly three variables. Each of these variables occurs positively in the clause. In addition, we are given a planar embedding of the clauses and variables such that a variable is connected to a clause if and only if the variable occurs in the clause. The positive planar 1in3SAT problem asks to decide if there exists a truth assignment to the variables such that for each clause exactly one variable is true.
For the reduction, we introduce gadgets for the variables, clauses and connections between these in the given embedding. We describe the construction and functioning of each gadget below, noting that an overview of the final construction is given at the end in Fig. 9.
Variable gadget. We construct a variable gadget as follows; see Fig. 5 for an illustration. The basic construction is a path of 7 vertices, such that the first two and the last two form the corners of a square (in convex position), such that the path order matches the vertex order around the square’s boundary. The remaining three vertices are placed inside the square such that their connecting edges do not intersect, but the edges and do intersect. In order to remove the created crossings using the minimum number of swaps, we need to swap the first or last edge of this path.
We now create a variable gadget, by repeating this basic construction into a longer path. The first two vertices are the last two vertices of the previous construction in the same order; effectively, we vertically mirror the basic path of every second repetition. We always use an odd number (at least 3) of repetitions. This ensures that we can remove all crossings by swapping the endpoints of all even or all odd vertical edges and this requires the same number of swaps. We designate swapping all the even vertical edges (
,, etc.) to indicate false; all odd vertical edges as true. Note that this same construction can be used to propagate the truth value over longer distances as well, and that there is flexibility in this construction to make bends.Split gadget. In order to connect the variable to clauses, we construct a split gadget to be attached to a variable gadget; see Fig. 6a for illustration. We take another basic construction path (indicated using the vertices) and rotate it clockwise by 90 degrees and place it below one of the even vertical edges in the variable (e.g. ). We shorten and lengthen such that we can place a helper vertex between and such that is inside triangle but outside triangle in the input. We then add edges and .
There are two minimal ways of removing the crossings, each costing one swap in the split gadget, plus two in the variable construction shown in the figure. In a false assignment, is swapped; swapping then resolves all intersections. In the true assignment, is not swapped and swapping untangles the gadget. Observe that swapping does not resolve the intersection between and in the true assignment.
Clause gadget. The construction of a clause gadget is shown in Fig. 7. We place a central vertex and we place three vertices , , and equidistant from it, connecting them to . Next, we place three layers of three vertices each equidistant from such that each layer forms a triangle containing the central vertex. We place these such that all its vertices are placed well within the triangle . We note that the only way to untangle this structure is to swap locations of the central vertex with one of , , and and orient the three layers in such a way that the edges missing in each layer line up towards the new location of . This takes three swaps in total.
We connect a variable to a clause by using the split gadget at the variable, and then building a connection of an odd number of repetitions of the basic construction path, including one inherent in the split gadget to the clause, using one of , or ) for the last repetition of the basic construction. When placing this last repetition, we ensure that regardless of which of the three clause vertices , , and swaps with , the edges connecting the variables to do not cross any of the other edges of the clause gadget. Furthermore, we ensure that the last crossing of the basic construction is untangled for free when is swapped with the vertex next to the clause (see Fig. 7).
In Fig. 7 we illustrated two of these repetitions for each variable. This may either directly connect to the split gadget as shown in Fig. 6, or use another even number of repetitions in between; we assume the former in our exposition here. But either case guarantees that the number of swaps required to untangle it is the same, regardless of whether the variable is true or false.
When exactly one of the three variables has the value true, we can untangle the clause gadget using five swaps. Note that we do not count the outermost swap of the true variable, as this is shared with the split gadget. In Fig. 7, assume that the lower left variable is true and the other two are false. We untangle the clause gadget by swapping the edge connected to the center vertex that belongs to the true variable (the horizontal edge in Fig. 7). We also swap two of the edges of the middle triangles to make that part plane. Finally, we swap the endpoints of the middle edge of the connecting gadget of the two false variables. The result is shown in Fig. 8. We note that the connection of the true variable is untangled because the split gadget passes on its truth assignment.
Now consider the case where the clause is not satisfied. This can be because either no variable is true or because at least two variables are true. In the first case, the number of swaps needed to untangle the gadget is at least six, since we have to perform the same swaps as in the case where the clause is satisfied and in addition we need to swap the first edge of the connection of the third variable. This last edge swap corresponds to swapping the endpoints of the last edge in Fig. 6c.
Next, consider the case where the clause is not satisfied because at least two variables are true. We first note that to untangle the clause, we need to swap one of the edges connected to the center as well as two edges of the triangles surrounding the center. One of the true variables does not require any additional swaps, so let us consider the other two connections. For each of these connections that represents a true variable, we note that we cannot swap the first edge of the connection, since it is fixed by the split gadget (see Fig. 6b). Hence, to untangle an additional true variable, we need to reverse its sequence of two horizontal middle edges; this reversal requires three swaps. If there are two true variables, this implies that we need six swaps for the clause gadget. If there are three true variables, seven swaps are needed.
It remains to argue that there is no globally different set of swaps that makes the graph plane with fewer operations. Intuitively, for any pair of crossing edges, at least one of the neighboring edges needs to be swapped in order to remove the crossing. This argument implies that for edges that cross only a single other edge, we perform the minimum number of swaps to remove the crossings. Hence, we need to consider only those edges that cross multiple edges. Such edges occur only in the clause gadgets. We observe that the central vertex is surrounded by red triangles, hence to remove the crossings of the central vertex and these red edges, we need to either align the triangles (as our method does in the minimum number of operations) or swap at least one vertex of each triangle layer with a vertex outside the triangles. In order to perform the latter swaps, we would need to swap the endpoints of at least two edges per layer, since we first need to swap the central vertex with some edge outside the triangles followed by one or more operations to swap the desired triangle vertex with the central vertex. Hence, this approach requires at least six swaps in order to remove these crossings from a single clause gadget, which is more than the five swaps our approach needs.
Hence, when a clause is not satisfied, untangling it takes more than five swaps. Finally, since the number of swaps required for the variable gadgets and split gadgets is the same regardless of whether the instance is satisfiable or not, an instance is satisfiable if and only if we need five swaps per clause to untangle all clauses.
Constructing a tree. Each of the gadgets above can be translated, scaled and rotated. We place the gadgets to adhere to the given embedding of the positive planar 1in3SAT instance, using basic constructions to connect clause gadgets with their split gadgets at each relevant variable gadget. This is schematically shown in Fig. 9. However, this construction is generally not a tree, as it can contain cycles. To construct a tree, we remove the middle edges from some basic constructions (see Fig. 10). Since the endpoints of these edges are never swapped in any satisfiable assignment, this does not influence the satisfiability of the instance.
This last step shows that we can solve an instance of positive planar 1in3SAT by constructing a tree and determining whether the clause gadgets can be untangled using five swaps per clause. Retrieving the variable assignment for positive planar 1in3SAT can be done by checking how the corresponding variable gadgets are untangled. Hence, the problem is NPcomplete.
4 Generating levels
In this section we describe how puzzle instances or levels can be generated for Swap Planarity. First we outline a fivestep procedure, and then we explain these steps in more detail. We pay attention to three properties: (i) the puzzle instance should look good, also in states to be reached later, (ii) every possible good puzzle instance should be a possible output, for diversity, and (iii) solutions should not have a particular structure that might be identified by a puzzler, which may upset the intended puzzle instance difficulty.
4.1 Process of level generation
We describe a fivestep procedure to generate a puzzle instance. We assume that a desired number of vertices is specified, and also a desired number of edges, and a desired minimal number of swaps to the solution.

Generate a set of points in a playing area, such that for no two points, an edge between them would visually conflict with any other point from (property (i)).

Generate a Delaunay triangulation on , leading to an edge set .

Perform a number of Lawson flips to make sure that the solution of the puzzle instance need not only have Delaunay edges (done for properties (ii) and (iii)). This makes out of .

Remove a number of edges at random from until edges remain. Make sure that no isolated vertices remain. This gives the edge set .

Perform swap operations at random, by picking edges at random from . Test if the resulting instance requires swaps to a planar state (and if not, swap more edges).
The whole process ensures property (ii): any puzzle instance that satisfies property (i) can be generated, provided that sufficiently many flips are performed in step 3.
4.2 Generating points
Given the shape of screens, it is natural to generate a point set in a square or rectangular region. There are two important issues to consider when generating point sets. First, collinearity or nearcollinearity of points means that potentially, an edge will partly overlap a vertex in the drawing. This is undesirable. Second, point sets are “combinatorially different”, which relates to the variation to be obtained in puzzle instances. We discuss these two issues next.
Let us assume that each vertex is drawn as a disc with radius . Then any two vertices (centers) should be separated more than in order for their discs to be disjoint. Every edge is drawn as a rectangle with its length matching the distance between its endpoints () and width . The center of each vertex should be further away than from the center line of any edge that it is not incident to [18]. To have a little more room around each vertex and edge we introduce a parameter that specifies for each point how far it must be from each other point and edge, when points are viewed as dimensional and edges as dimensional. We always choose .
Definition 5
Given , a set of points in the plane is in general position if and only if for any three distinct points , the distance from to the line through and is at least .
To generate a point set in
general position, we incrementally add points, uniformly distributed in a square. For each addition, we check if the
general position condition is violated, and if so, we discard the last added point. To test this condition, we consider every pair of accepted points with the newly added point. Using a bit of geometry we can identify a region bounded by six lines where the new point may not lie, see Fig. 11. Two of these lines are the outer tangents to two discs of radius centered on the two accepted points. The other four are tangents to one of these discs, passing through the other accepted point. Hence, this test can be done in quadratic time per new point.Note that a set of two points is always in general position, but any third point enforces all points in the set to be at least distance apart; hence, we do not need to check vertexvertex distances after adding the second point.
When we generate puzzles with a considerable number of points we may get many failures. It is possible to compute the whole region where new points can be placed by generating the quadratically many regions for the accepted points and computing their union. The complement of this union is where a new point can still lie. In particular, we can compute this union and sample the complement explicitly, which means we do not get failures. If the union covers the whole square, we cannot add points anymore. For accepted points so far, this union has complexity and can be computed in time [11].
We next discuss the issue of combinatorially different point sets. To understand what this means, imagine a set of points in convex position: they all lie on the convex hull. Whether points lie as the vertices of a regular gon, or spread on an ellipse, or more randomly placed (but still in convex position), these point sets are essentially the same from the perspective of intersecting edges between these points. Any graph on these points has the same intersecting edges regardless of where the points lie precisely. Moreover, any point set with points and on its convex hull () has at most edges that do not intersect (the fewer vertices on the convex hull, the more edges can be in a plane graph). Point sets with the same number of points but different numbers of points on the convex hull are combinatorially different. But there are still differences between point sets with the same numbers of points and the same number of points on the convex hull. In Section 6 we look more closely at the concept of puzzle equivalence. In our experiments we use the number of points inside the convex hull () as a simple indicator of how varied instances may be. If there are no points inside, then the point sets are effectively the same; more points inside allow for more combinatorial differences.
4.3 Generating a plane graph
Once we have generated a set of points without collinearity or closeness, we can generate edges. We generate a plane graph (a solution) to a puzzle instance in three steps (steps 2–4).
First, we compute the Delaunay triangulation of [7]. This is a specific triangulation of a point set that maximizes the smallest angle that is used in the triangulation. This triangulation is also characterized by the emptycircle property: for any two points and for which a circle exists that touches only and and which has no points of inside, there is an edge connecting and . This characterization (in general) completely specifies the triangulation. There are several known algorithms to compute the Delaunay triangulation of points in time. This gives the edge set .
Second, we perform a few Lawson flips (beware that flips and swaps are very different operations). A Lawson flip can be applied to a pair of edgeadjacent triangles in a triangulation if those triangles together form a convex quadrilateral. A Lawson flip removes the shared edge and retriangulates the resulting quadrilateral in the (only) other way. These flips make it harder for a puzzler to solve instances. Delaunay triangulations favor shorter edges, and Lawson flips can generate longer edges again. If a puzzler would know—or realize—that the solution to each puzzle instance uses only Delaunay edges, then (s)he can quickly see which edges must be avoided in the drawing by imagining the emptycircle test (let’s face it: these puzzles are going to be done by geometers). Edges to be flipped are selected randomly, and the flip is done only if the four involved vertices are in convex position (otherwise the resulting drawing would be nonplanar). The resulting edge set is denoted .
Third, we remove some edges from so that a puzzle instance solution is not always a triangulation. We ensure that no isolated vertices are created, by not removing edges with an endpoint of degree 1. These would not influence the puzzle or its solution in any way. Notice that an isolated edge does influence the puzzle. While a swap applied to such an edge does not change the drawing, swapping other edges may resolve edge intersections with the isolated edge.
By removing edges we can realize a desired number of edges in the solution. Removing many edges may cause the puzzle instance to have multiple solutions and become easy.
4.4 Generating an instance
We have now generated a graph with a specified number of vertices and edges, and in particular, a solution to this puzzle instance. To generate the puzzle instance itself we make some swaps such that undoing these (swapping the same edges in reverse order) solves the instance.
It appears that puzzle instances with just two or three swaps from a solution are already not so easy (Fig. 1). Once a player gets more experienced, instances with four swaps may become suitable. This means that testing the difficulty of a solution can be done by bruteforce. For example, a graph with edges that should be four swaps away from a solution can be tested by trying all possibilities (we exclude swapping the same edge twice in a row). This may lead to an instance with fewer necessary swaps to solve than we have used to generate it; in this case we perform extra swaps until the desired minimal number of swaps is obtained. We will also recognize if there are more ways to a solved state, making the instance a bit easier too. Finally, swaps that are independent and possibly even wellseparated also give rise to easier instances. Two swaps are independent if the four endpoints of the edges are disjoint and there is no other edge than the two that are swapped between these four vertices.
We have now realized the three properties we aimed for. The visual quality (i) of the instance and every intermediate state that can be reached is captured by the vertexvertex distance and vertexedge distance conditions. The puzzle diversity (ii) is realized by allowing any number of vertices, edges, and steps to the solution, every possible plane drawing as a solution, and every possible nonplane drawing as a puzzle instance. There is no puzzle instance that cannot be generated. Absence of unintended structure (iii) is accomplished by ensuring that for a point set, any edge between two points could be part of the solution.
5 Implementation and experiments
The Swap Planarity game is implemented using Unity. Besides trying the game to see how difficult and fun puzzle instances are, we are interested in the efficient generation of noncollinear point sets, the number of points on the convex hull, the noncollinearity parameter , and relations these.
Fig. 12 shows the interface. From the settings on the right we can see that the instance has points generated with to ensure noncollinearity, the initial triangulation is flips away from being Delaunay, then edges were removed and two swaps were performed to shuffle the planar graph. The solution is shown on the right.
When we try to generate a large point set with a large value of , we may fail because there may not be enough space on the screen (play area) to realize the separation. This also depends on the random generation itself. It can happen that a point set of points cannot be extended to points without violating collinearity, but sets of noncollinear points may still exist. This means that the point generation procedure may have to abort and restart. If aborting is done too early, generation may be inefficient because we start from scratch without having to. If aborting is done too late, generation may have spent a lot of time on a configuration that cannot be extended anymore. Fig. 13 illustrates this for a fixed value of ; data points we generated with intervals of between and and with intervals of after that. Note that the vertical axis has exponential scale. For the larger point set sizes we observe that we should make enough attempts to add a point, but not too many, to get the best efficiency.
We also determined the number of points inside the convex hull for different point set sizes and different values of . We noticed a surprising phenomenon: the larger , the fewer points are in the convex hull. This can be seen in Fig. 14, right: for increasing , fewer points tend to lie inside the convex hull. This happens especially when it gets difficult to generate larger point sets for a given , and hence we cannot observe the behavior for larger point set values in Fig. 14, left. It may be the case that a placement of points on the convex hull is a good placement if one wants to realize a large . This suggestion is supported by theory on bold graph drawings [14]. Fig. 15
shows the standard deviations over the
point set instances. It also shows that if is chosen relatively large, fewer points will be inside the convex hull.The experiments show the following tradeoff: puzzle instances with a good visual appearance (clear noncollinearity, large ) are harder to generate efficiently and show less diversity, indicated by the relatively large number of points on the convex hull.
6 Equivalence of instances
We now return our attention to puzzle diversity. To generate diverse sets of puzzle instances, we ideally need a good measure of puzzle instance similarity (or its converse, distance). We study this aspect in its weakest form, namely puzzle instance equivalence. The following definition essentially states that two puzzle instances should be considered swapequivalent if and only if any sequence of corresponding swaps in both drawings gives the same sets of intersecting edges in the drawings. With slight abuse of notation we use the same symbol for a vertex in a graph and the point in the plane where it is drawn.
To define swapequivalence we use a onetoone matching between the vertices of the two graphs and their drawings. We use the subscripts and to refer to the two graphs, their drawings and their vertices. Furthermore, we use the same letter for graph vertices or points that are matched. So, vertex in graph is matched with vertex in . We use as an invertible function . Thus, generally, we use and .
Definition 6
Drawings and of graphs and are swapequivalent if and only if there is a onetoone matching between their vertices such that:
 (i)

is an edge in if and only if is an edge in , where and ;
 (ii)

after any sequence of zero or more swaps of matched edges in both graphs, and intersect if and only if matched edges and intersect.
It is clear that the drawings and need to have the same number of vertices and edges, otherwise onetoone matchings cannot exist.
Lemma 7
If two drawings and of graphs and are swapequivalent, then their graphs are isomorphic.
Proof.
This follows directly from Definition 6(i).
Beyond the topological equivalence of the graph indicated by the lemma above, we also need a form of geometric equivalence for the point set of the two puzzle instances. As it turns out, this corresponds to the order type, as formalized in the lemma below. Consider two point sets and of points each. These point sets are combinatorially equivalent if a onetoone mapping exists such that for any three points , the sequence is a left turn if and only if the sequence of points from is a left turn. The equivalence class thus obtained is called an order type [1, 2].
Lemma 8
If two drawings and of connected, nonstar graphs and are swapequivalent, then their point sets have the same order type.
Proof.
Let and denote the point sets of the two graphs.
Suppose these point sets have a different order type. Then
there is a quadruple of points in
with matching points in such
that are in convex position and
are not. Assume without loss of
generality that intersects .
Since is connected, we can realize any mapping
of graph vertices to points by Lemma 2.
Since is connected and not a star graph, it has two edges with four distinct vertices. Consider a sequence of swaps that places these two edges on and .
Then these edges intersect. However, since are not in convex position in , the corresponding edges in do not intersect.
This contradicts Definition 6(ii).
Theorem 9
Two drawings and of connected, nonstar graphs and using point sets and are swapequivalent if and only if there is a onetoone matching between and such that:

point sets and have the same order type which respects the onetoone matching;

the graphs and are isomorphic with the given onetoone matching of the points in and applied to the corresponding vertices in and .
Proof. Assume two drawings and are swapequivalent. Then Lemma 7 shows that their graphs are isomorphic. Furthermore, Lemma 8 shows that their point sets must have the same order type. Now assume that the order types are the same and the graphs are isomorphic, but there is no onetoone matching that simultaneously witnesses the same order type and graph isomorphy. Consider any onetoone matching for graph isomorphy. Then there is a quadruple of points that are in convex position in whose matched points are not in convex position in , or vice versa. The same argument as the one used to prove Lemma 8 shows that the intersections of edges are not the same in the two drawings after some sequence of swaps, contradicting swapequivalence.
Next, assume that two drawings satisfy the two conditions of the theorem.
Then there is a onetoone matching between
the vertices that respects the order types and that
is a witness for graph isomorphism at the same time.
Graph isomorphism implies (i) of Definition 6, and having the same
order type implies that the same pairs of edges intersect
in the complete graph. Hence this is also true in any subgraph.
The theorem above implies an efficient way to test whether two puzzle instances are equivalent. We first identify the at most onetoone matchings for the order type, and then check whether this matching also realizes graph isomorphism. Generating and testing the up to matchings takes time [10], and testing isomorphism for a given matching takes time linear in the size of the graph. Hence, swapequivalence of two drawings with vertices can be tested in time.
7 Conclusions
We introduced a new graph planarity puzzle game called Swap Planarity and analyzed various properties, including the algorithmic complexity of solving instances. Any instance that can be solved, is solved in swaps. However, deciding if an instance can be solved is NPcomplete. When the graph is a tree, the instance can always be solved, but deciding if swaps are sufficient is again NPcomplete. We presented a method to generate instances effectively while paying attention to visual clarity, diversity, and absence of accidental structure. Our implementation shows that generation works well, but has a tradeoff between a good visual clarity on the one hand and diversity and efficient generation on the other.
Visual clarity was defined using a new, simple condition on point sets called general position. The experiments showed an interesting phenomenon, namely that if is fairly large for the available space and the number of points, the solution tends to be a set of points in convex position (and no points in the interior of the convex hull). It would be interesting to explore this relationship further.
We think that the new, swapbased graph planarity puzzle game is a nice, elegant addition to the collection of abstract puzzle games. The puzzle is NPhard, the number of crossings may need to be increased to reach a solution, and even small instances are not so easy to solve. User studies are needed to analyze the fun and difficulty of the game for players.
Acknowledgments
Part of this work was performed at the DutchJapanese Bilateral Seminar on Kinetic Geometric Networks. We thank the organizers and participants of the workshop for providing a fun and stimulating research environment. A.v.R. was supported by JST ERATO Grant Number JPMJER1201, Japan. M.v.K. was supported by the Netherlands Organisation for Scientific Research on grant no. 612.001.651. W.M. was supported by Netherlands eScience Center (NLeSC) on grant no. 027.015.G02.
References
 [1] (2002) Enumerating order types for small point sets with applications. Order 19 (3), pp. 265–281. Cited by: §6.
 [2] (2007) On the number of plane geometric graphs. Graphs and Combinatorics 23 (1), pp. 67–84. Cited by: §6.
 [3] (2009) A polynomial bound for untangling geometric planar graphs. Discrete & Computational Geometry 42 (4), pp. 570–585. Cited by: §1.
 [4] (2002) On embedding an outerplanar graph in a point set. Computational Geometry 23 (3), pp. 303–312. Cited by: §3.
 [5] (2006) Planar embeddability of the vertices of a graph using a fixed point set is NPhard.. Journal of Graph Algorithms and Applications 10 (2), pp. 353–363. Cited by: §2, §3.
 [6] (1985) A linear algorithm for embedding planar graphs using PQtrees. Journal of Computer and System Sciences 30 (1), pp. 54–76. Cited by: §1.
 [7] (2008) Computational geometry – algorithms and applications. 3rd edition, Springer, Berlin. Cited by: §4.3.
 [8] (1990) How to draw a planar graph on a grid. Combinatorica 10 (1), pp. 41–51. Cited by: §1.
 [9] (2009) Untangling a planar graph. Discrete & Computational Geometry 42 (4), pp. 542–569. Cited by: §1.
 [10] (1984) Semispaces of configurations, cell complexes of arrangements. Journal of Combinatorial Theory, Series A 37 (3), pp. 257–293. Cited by: §6.
 [11] (2018) Arrangements. In Handbook of Discrete and Computational Geometry, J. E. Goodman, J. O’Rourke, and C. D. Tóth (Eds.), CRC Press, pp. 723–762. Cited by: §4.2.
 [12] (2008) Minimumweight triangulation is NPhard. Journal of the ACM 55 (2), pp. 11:1–11:29. Cited by: §3.
 [13] (1991) Embedding a planar triangulation with vertices at specified points. The American Mathematical Monthly 98 (2), pp. 165–166. Cited by: §3.
 [14] (2011) Every graph admits an unambiguous bold drawing. In International Symposium on Graph Drawing, pp. 332–342. Cited by: §5.
 [15] (2013) Handbook of graph drawing and visualization. CRC Press. Cited by: §1.
 [16] (2007) Planarity. Note: http://planarity.net/Accessed: 20180525 Cited by: §1.
 [17] (2004) NetLogo: a simple environment for modeling complexity. In International Conference on Complex Systems, Vol. 21, pp. 16–21. Cited by: §1.
 [18] (2011) Bold graph drawings. Computational Geometry 44 (9), pp. 499–506. Cited by: §4.2.
 [19] (2008) On the obfuscation complexity of planar graphs. Theoretical Compututer Science 396 (13), pp. 294–300. Cited by: §1.
 [20] (2015) Swapping labeled tokens on graphs. Theoretical Computer Science 586, pp. 81–94. Cited by: §2.