# Revision history [back]

### How do I get the external face of a planar embedded graph?

First of all I am new to Sage and Python.

I need to get the external face a planar embedding and I immagined that it is always the first element returned by the function faces().

But in this example it seems to change. See the first and the second run.

Is it something about the function faces() or an error in this program?

print ("--- Create a graph")
G = Graph(sparse=True)

print ("--- Embed on a plane")
void = G.layout(layout = "planar", save_pos = True)

G.plot()

# Kempe reduction: for each loop remove an edge from faces <= F5
#
while len(G.faces()) > 2:

print ("Number of faces: ", len(G.faces()))

# Remove the external face. Is it always faces[0]???
#
faces = G.faces()
externalFace = faces[0]
facesWithoutTheExternalFace = copy(faces)
facesWithoutTheExternalFace.remove(externalFace)
print ("faces: ", faces)
print ("externalFace: ", externalFace)
print ("facesWithoutTheExternalFace: ", facesWithoutTheExternalFace)

# Find the fist face [0] with len <= 5. It always exists: unavoidable set
#
faceToReduce = [x for x in facesWithoutTheExternalFace if len(x) <= 5][0]
print ("Face <= 5: ", faceToReduce)

# Find the first edge of the faceToReduce that is not on an edge on the external face
#
edgeToRemove = [x for x in faceToReduce if not x in externalFace][0]
print ("edgeToRemove: ", edgeToRemove)

verticesToRemove = G.get_vertices(edgeToRemove)
print ("verticesToRemove ", verticesToRemove)

G.delete_edge(edgeToRemove)
neighborsOfTheFirstVertex = G.neighbors(verticesToRemove.keys()[0])
neighborsOfTheSecondVertex = G.neighbors(verticesToRemove.keys()[1])
print ("neighborsOfTheFirstVertex = ", neighborsOfTheFirstVertex)
print ("neighborsOfTheSecondVertex = ", neighborsOfTheSecondVertex)
G.delete_vertices(verticesToRemove)
G.plot()

 2 retagged FrédéricC 2306 ●3 ●27 ●46

### How do I get the external face of a planar embedded graph?

First of all I am new to Sage and Python.

I need to get the external face a planar embedding and I immagined that it is always the first element returned by the function faces().

But in this example it seems to change. See the first and the second run.

Is it something about the function faces() or an error in this program?

print ("--- Create a graph")
G = Graph(sparse=True)

print ("--- Embed on a plane")
void = G.layout(layout = "planar", save_pos = True)

G.plot()

# Kempe reduction: for each loop remove an edge from faces <= F5
#
while len(G.faces()) > 2:

print ("Number of faces: ", len(G.faces()))

# Remove the external face. Is it always faces[0]???
#
faces = G.faces()
externalFace = faces[0]
facesWithoutTheExternalFace = copy(faces)
facesWithoutTheExternalFace.remove(externalFace)
print ("faces: ", faces)
print ("externalFace: ", externalFace)
print ("facesWithoutTheExternalFace: ", facesWithoutTheExternalFace)

# Find the fist face [0] with len <= 5. It always exists: unavoidable set
#
faceToReduce = [x for x in facesWithoutTheExternalFace if len(x) <= 5][0]
print ("Face <= 5: ", faceToReduce)

# Find the first edge of the faceToReduce that is not on an edge on the external face
#
edgeToRemove = [x for x in faceToReduce if not x in externalFace][0]
print ("edgeToRemove: ", edgeToRemove)

verticesToRemove = G.get_vertices(edgeToRemove)
print ("verticesToRemove ", verticesToRemove)

G.delete_edge(edgeToRemove)
neighborsOfTheFirstVertex = G.neighbors(verticesToRemove.keys()[0])
neighborsOfTheSecondVertex = G.neighbors(verticesToRemove.keys()[1])
print ("neighborsOfTheFirstVertex = ", neighborsOfTheFirstVertex)
print ("neighborsOfTheSecondVertex = ", neighborsOfTheSecondVertex)
G.delete_vertices(verticesToRemove)