Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planar graph layout does not respect clockwise ordering of neighbors in combinatorial embedding #28152

Closed
rburing opened this issue Jul 10, 2019 · 27 comments

Comments

@rburing
Copy link
Contributor

rburing commented Jul 10, 2019

Consider the claw S3:

S3 = Graph([[0,1,2,3],[[0,1],[0,2],[0,3]]])

The following combinatorial embedding is respected in the planar layout (the neighbors are in the given clockwise order):

S3.set_embedding({0: [1,2,3], 1: [0], 2: [0], 3: [0]})
S3.layout('planar', save_pos=True)
S3.show()

While this one isn't:

S3.set_embedding({0: [3,2,1], 1: [0], 2: [0], 3: [0]})
S3.layout('planar', save_pos=True)
S3.show()

In the latter, the neighbors are in the counterclockwise order (in fact the picture is the same as the former).

Strictly speaking, layout_planar (which is called by layout) does not promise to use the combinatorial embedding. But it does provide an option on_embedding which I assume should allow this:

S3.set_pos(S3.layout_planar(on_embedding={0: [3,2,1], 1: [0], 2: [0], 3: [0]}))

Still, the combinatorial embedding is not respected. I think this is because in layout_planar the line G.is_planar(set_embedding=True) executed unconditionally (totally ignoring on_embedding).

Component: graph theory

Keywords: planar, clockwise, embedding

Author: Hendrik Schrezenmaier

Branch/Commit: b941f18

Reviewer: David Coudert

Issue created by migration from https://trac.sagemath.org/ticket/28152

@rburing rburing added this to the sage-8.9 milestone Jul 10, 2019
@hensc
Copy link
Mannequin

hensc mannequin commented Jul 15, 2019

@hensc
Copy link
Mannequin

hensc mannequin commented Jul 15, 2019

New commits:

13c4252Fixed bug concerning the combinatorial embedding of Schnyder drawings
dc57871Added doctest and fixed bugs to pass doctests

@hensc
Copy link
Mannequin

hensc mannequin commented Jul 15, 2019

Author: Hendrik Schrezenmaier

@hensc
Copy link
Mannequin

hensc mannequin commented Jul 15, 2019

Commit: dc57871

@hensc hensc mannequin added the s: needs review label Jul 15, 2019
@dcoudert
Copy link
Contributor

comment:3

A few stylistic comments. Recall that comments must be in 80 columns mode and that we do our best to follow the pep8 conventions.

-        TESTS::
-
-            Check the dependence of the computed position on the given
-            combinatorial embedding (:trac:`28152`).
+        TESTS:
+
+        Check the dependence of the computed position on the given
+        combinatorial embedding (:trac:`28152`)::
-    all triangles, and return the set of newly created edges. Also comb_emb
+    all triangles, and return the set of newly created edges. Also ``comb_emb``

pep8

-            comb_emb[w].insert(comb_emb[w].index(x),u)
-            comb_emb[u].insert(comb_emb[u].index(v),w)
+            comb_emb[w].insert(comb_emb[w].index(x), u)
+            comb_emb[u].insert(comb_emb[u].index(v), w)

80 columns mode

-    # Up to this point we did not take the order of the external face into account.
-    # Since the combinatorial embedding of a triangulated is only unique up to
-    # the choice of the outer face and reflection, this might lead to a reflection
-    # of the Schnyder drawing resulting from this labeling which is not conformal
-    # with comb_emb any longer. Therefore, we might have to swap the labels 1 and 2.
+    # Up to this point we did not take the order of the external face into
+    # account. Since the combinatorial embedding of a triangulation is unique
+    # up to the choice of the outer face and reflection, this might lead
+    # to a reflection of the Schnyder drawing resulting from this labeling which
+    # is not conformal with comb_emb any longer. Therefore, we might have to
+    # swap the labels 1 and 2.

I also did minor changes in above text. Please check.

Passes all tests with py3. I have not fully tested yet de functionality.

@fchapoton
Copy link
Contributor

comment:4

one failing doctest in src/sage/graphs/planarity.pyx, see patchbot report

@rburing
Copy link
Contributor Author

rburing commented Jul 15, 2019

comment:6

Thanks for the effort so far. I suggest also to add a line of documentation, at least in layout_planar, explaining which combinatorial embedding is used when, e.g. "If on_embedding is provided then that combinatorial embedding is used for the layout. Otherwise: if a combinatorial embedding is set (e.g. using set_embedding) then that one is used, and if no combinatorial embedding is set then one is computed." (modify it to make it a true statement).

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

2b7870dpep8
3c74ff6Removed special case of path of length 2

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Changed commit from dc57871 to 3c74ff6

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

b3f4308fixed typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Changed commit from 3c74ff6 to b3f4308

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

2248ce7fixed typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 15, 2019

Changed commit from b3f4308 to 2248ce7

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 18, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

ec8e7b5edited documentation

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 18, 2019

Changed commit from 2248ce7 to ec8e7b5

@hensc hensc mannequin added s: needs review and removed s: needs work labels Jul 18, 2019
@hensc
Copy link
Mannequin

hensc mannequin commented Jul 18, 2019

comment:12

I fixed the pep8 and also fixed the bug that made the doctest fail.
Now the patchbot passed all tests.

I also made the documentation more precise about which combinatorial embedding is used. But unfortunately it is not as rburing thought (and I think to be more intuitive, too) that on_embedding is always used if it is given. If set_embedding is set to True, then on_embedding is ignored. So the question is if we could/should/want to change this behavior.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 21, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

07c6624Merge branch 'develop' of git://github.com/sagemath/sage into t/28152/planar_graph_layout_does_not_respect_clockwise_ordering_of_neighbors_in_combinatorial_embedding

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 21, 2019

Changed commit from ec8e7b5 to 07c6624

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

da464d2Merge branch 'develop' of git://github.com/sagemath/sage into t/28152/planar_graph_layout_does_not_respect_clockwise_ordering_of_neighbors_in_combinatorial_embedding

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jul 30, 2019

Changed commit from 07c6624 to da464d2

@hensc
Copy link
Mannequin

hensc mannequin commented Aug 2, 2019

comment:15

please review

@dcoudert
Copy link
Contributor

dcoudert commented Aug 4, 2019

comment:16

I have only a minor comment. Otherwise seems ok.

-            for (v,w) in labels[u]:
-                if labels[u][(v,w)] == 1:
-                    labels[u][(v,w)] = 2
-                elif labels[u][(v,w)] == 2:
-                    labels[u][(v,w)] = 1
+            for v, w in labels[u]:
+                if labels[u][v, w] == 1:
+                    labels[u][v, w] = 2
+                elif labels[u][v, w] == 2:
+                    labels[u][v, w] = 1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Branch pushed to git repo; I updated commit sha1. New commits:

b828839minor improvement of code style
b941f18Merge branch 'develop'

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 5, 2019

Changed commit from da464d2 to b941f18

@dcoudert
Copy link
Contributor

dcoudert commented Aug 5, 2019

Reviewer: David Coudert

@dcoudert
Copy link
Contributor

dcoudert commented Aug 5, 2019

comment:18

OK, LGTM.

@vbraun
Copy link
Member

vbraun commented Aug 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants