Planarity
- This article is about the game; for the graph theory property, see Planar graph.
Planarity is a puzzle computer game based on a concept by Mary Radcliffe at Western Michigan University.[1] The name comes from the term planar graph. In graph theory, a planar graph is a graph that can be embedded in a plane so that no edges intersect. In the game, the player starts out with a tangled series of connected dots, and has to untangle the web until no edges intersect.
The game was written in Flash by John Tantalo at Case Western Reserve University.[2] Online popularity and the local notoriety he gained placed Tantalo as one of Cleveland's most interesting people for 2006.[3][4] It in turn has inspired the creation of a GTK+ version by Xiph.org's Chris Montgomery, which possesses additional level generation algorithms and the ability to manipulate multiple nodes at once.[5]
The problem of determining if a graph is planar can be solved in linear time with a simple algorithm, and any such graph is guaranteed to have a straight-line embedding by Fáry's theorem; this makes it easy to generate solvable puzzles. Puzzles can also be solved by a computer in linear time,[6] but are not as straightforward for human players to solve. In the field of computational geometry, the process of moving a subset of the vertices in a graph embedding to eliminate edge crossings has been studied by Pach and Tardos (2002), and others.
Contents |
[edit] Algorithm
- Generate a set of random lines in a plane such that no two lines are parallel.
- Calculate the intersections of every line pair.
- Create a graph with a vertex for each intersection and an edge for each line segment connecting two intersections.
If a graph is generated from n lines, then the graph will have n choose 2 = n(n-1)/2 vertices (each line has n-1 vertices, each vertex is shared with one other line) and n(n-2) edges (each line contains n-2 edges).
The first level of Planarity is built from n=4 lines, so it has n(n-1)/2=6 vertices and n(n-2)=8 edges. Each level after is generated by one more line than the last. If a level was generated with n lines, then the next level has n more vertices and 2n-1 more edges.
[edit] Pseudocode
Input: a list L of n 2-dimensional lines, and a labeling A from each p in L to {1...n}
- Let G be an empty graph.
- Add vertices {1...n(n-1)/2} to G.
- For each line p in L:
- Let M be the lines q in L ordered by the intersection points of p with q and p != q.
- For each consecutive pair Mi and Mi+1:
- Let u = PairIndex(A(p), A(Mi), n).
- Let v = PairIndex(A(p), A(Mi+1), n).
- Add an edge (u, v) to G.
- Return G.
This algorithm assumes lists index from 1.
[edit] Pair Index
In the graph, every pair of distinct lines (p, q) corresponds to exactly one vertex v, but it is much more convenient to address this vertex as a single value than a tuple. So, how do we most efficiently map (p, q) into v? The function PairIndex does this by mapping each (p, q) to some number between 1 and (n(n-1)/2) (inclusive), the range of vertices.
- Definition
- If 1 <= p < q <= n, then PairIndex(p, q) = (p(2n-p-1)/2)+p-q, where n is the number of lines.
- Claim
- PairIndex is a bijection (i.e., one-to-one and onto) between {(p, q) | 1 <= p < q <= n} and {1...n(n-1)/2} for a fixed n.
- Proof
- Observe that PairIndex is linear in q when p is fixed. When p=1, PairIndex takes on the values {1..n-1}. When p=n-1, PairIndex is n(n-1)/2. For a given p, the minimum value is PairIndex(p,n) and the maximum value is PairIndex(p,p+1). Basic algebraic manipulation is required to show that the maximum value of PairIndex for any p is exactly one less than the minimum value for p+1. Therefore every value in {1...n(n-1)/2} must correspond to exactly one pair (p, q). ∎
- This proof is due to Mary Radcliffe.
- Alternate definition
- If 0 <= p < q < n, then PairIndex(p, q) = (p(2n-p-1)/2)+q-p.
- This definition is practical when you index sequences from zero.
[edit] References
- ^ Krasean, Bill (August 10, 2005). "WMU student, partner create popular Web game". Kalamazoo Gazette (MI).
- ^ Massie, Laura (2005-06-20). "Case student develops booming on-line game". Case Western Reserve University News Center. http://www.case.edu/news/2005/7-05/planarity.htm. Retrieved 2007-09-30.
- ^ Castro, Laura (2005-11-18). "Case student one of Cleveland's "Most Interesting People"". The Observer. http://observer.case.edu/Archives/Volume_38/Issue_11/Story_379/. Retrieved 2007-09-30.[dead link]
- ^ "Most Interesting People 2006" (Press release). Cleveland Magazine. January, 2006. http://www.clevelandmagazine.com/ME2/dirmod.asp?sid=E73ABD6180B44874871A91F6BA5C249C&nm=Arts+%26+Entertainemnt&type=Publishing&mod=Publications%3A%3AArticle&mid=1578600D80804596A222593669321019&tier=4&id=5BE7EE32336E46ACA55FAE03A95E4E35. Retrieved 2007-09-30.
- ^ "gPlanarity home". http://web.mit.edu/xiphmont/Public/gPlanarity.html.
- ^ Kurt Mehlhorn and Petra Mutzel. On the embedding phase of the Hopcroft and Tarjan planarity testing algorithm. Algorithmica, vol. 16, issue 2, pp.233-242. [1] (Citeseer)
- Prosenjit Bose, Vida Dujmovic, Ferran Hurtado, Stefan Langerman, Pat Morin, David R. Wood (2008). "A polynomial bound for untangling geometric planar graphs". Discrete & Computational Geometry 42: 570. doi:10.1007/s00454-008-9125-3.
- Josef Cibulka (2009). "Untangling Polygons and Graphs". Discrete & Computational Geometry 43: 402. doi:10.1007/s00454-009-9150-x.
- Janos Pach and G. Tardos (2002). "Untangling a polygon". Discrete & Computational Geometry 28: 585–592. doi:10.1007/s00454-002-2889-y.
- Xavier Goaoc, Jan Kratochvíl, Yoshio Okamoto, Chan-Su Shin, Andreas Spillner and Alexander Wolff (2009). "Untangling a Planar Graph". Discrete & Computational Geometry 42: 542. doi:10.1007/s00454-008-9130-6.
[edit] External links
- Planarity.net — the original Flash game
- JPlanarity — a simple planarity Java version
- Canvas Planarity — Planarity implemented in HTML5
- NetLogo System — Included as sample program (game) in NetLogo system
- Planetary — Version using SVG and the d3 JavaScript library