Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

copying lists, embedded multigraphs

I am working with planar, embedded, labelled multigraphs. I am trying to define a function "face_modification()" that modifies the set of faces when an edge of the graph is deleted. I thought that when taking a copy of a list, and altering the copy, the original list would not change. However, when I evaluate the function face_modification() below, with Gf=F1, my original list (F1) is being altered, and I can't figure out why or how to prevent it.

Here, G1 is the labelled graph without double edges, Gd is the graph of double edges, Gt is the graph of triple edges, and Gf is a list, the ith entry of which is a list of labelled edges on the boundary of face i.

sage: def edge_on_faces(j, S, Gf, G1, Gd, Gt):

variables=[G1.edges()[i][2] for i in range(len(G1.edges()))]+[Gd.edges()[i][2] for i in range(len(Gd.edges()))]+[Gt.edges()[i][2] for i in range(len(Gt.edges()))]
if j in range(len(variables)):
    if [str(Gf[n][q][2])==str(variables[j]) for n in S for q in range(len(Gf[n]))].count(True)>0 :
        return 1 
    else:
        return 0
else:
    return 0

sage: def face_modification(i, Gf, G1, Gd, Gt):

variables=[G1.edges()[k][2] for k in range(len(G1.edges()))]+[Gd.edges()[k][2] for k in range(len(Gd.edges()))]+[Gt.edges()[k][2] for k in range(len(Gt.edges()))]
l=[m for m in range(len(Gf)) if edge_on_faces(i, [m], Gf, G1, Gd, Gt)==1]       
PF=[Gf.copy()[l[p]] for p in range(len(l))] # this is the list of two faces in Gf with the ith edge on the boundary
GGf=Gf.copy()
for m in range(len(PF)):
    GGf.remove(PF[m])
    for k in range(len(PF[m])):
        if str(PF[m][k][2])==str(variables[i]):
            PF[m].remove(PF[m][k])
        else:
            PF[m]=PF[m]
if len(PF)==2:
    B=GGf+[PF[0]+PF[1]]
    return B
else:
    return 'error'

Thanks a lot for your help!

copying lists, embedded multigraphs

I am working with planar, embedded, labelled multigraphs. multigraphs. I am trying to define a function "face_modification()" that face_modification that modifies the set of faces when an edge of the graph is deleted. deleted. I thought that when taking a copy of a list, and altering the copy, copy, the original list would not change. However, when I evaluate evaluate the function face_modification() face_modification below, with Gf=F1, Gf=F1, my original list (F1) (F1) is being altered, altered, and I can't figure out why or how to prevent it.

Here, G1 G1 is the labelled graph without double edges, Gd edges, Gd is the graph of double edges, Gt Gt is the graph graph of triple edges, and Gf Gf is a list, the ith entry i``-th entry of which is a list of labelled edges on the boundary of face i.facei`.

sage:

def edge_on_faces(j, S, Gf, G1, Gd, Gt):

variables=[G1.edges()[i][2] Gt):
    variables = ([G1.edges()[i][2] for i in range(len(G1.edges()))]+[Gd.edges()[i][2] range(len(G1.edges()))] +
                 [Gd.edges()[i][2] for i in range(len(Gd.edges()))]+[Gt.edges()[i][2] range(len(Gd.edges()))] +
                 [Gt.edges()[i][2] for i in range(len(Gt.edges()))]
range(len(Gt.edges()))])
    if j in range(len(variables)):
     if [str(Gf[n][q][2])==str(variables[j]) [str(Gf[n][q][2]) == str(variables[j])
            for n in S for q in range(len(Gf[n]))].count(True)>0 :
range(len(Gf[n]))].count(True) > 0:
            return 1 
     else:
         return 0
 else:
     return 0

sage: def face_modification(i, Gf, G1, Gd, Gt):

variables=[G1.edges()[k][2] Gt):
    variables = ([G1.edges()[k][2] for k in range(len(G1.edges()))]+[Gd.edges()[k][2] range(len(G1.edges()))] +
                 [Gd.edges()[k][2] for k in range(len(Gd.edges()))]+[Gt.edges()[k][2] range(len(Gd.edges()))] +
                 [Gt.edges()[k][2] for k in range(len(Gt.edges()))]
l=[m range(len(Gt.edges()))])
    l = [m for m in range(len(Gf)) if edge_on_faces(i, [m], Gf, G1, Gd, Gt)==1]       
PF=[Gf.copy()[l[p]] for p in range(len(l))] Gt)==1]
    # this is the PF: list of two faces in Gf with the ith edge on the boundary
GGf=Gf.copy()
    PF = [Gf.copy()[l[p]] for p in range(len(l))]
    GGf = Gf.copy()
    for m in range(len(PF)):
     GGf.remove(PF[m])
     for k in range(len(PF[m])):
         if str(PF[m][k][2])==str(variables[i]):
str(PF[m][k][2]) == str(variables[i]):
                PF[m].remove(PF[m][k])
         else:
            PF[m]=PF[m]
    PF[m] = PF[m]
    if len(PF)==2:
    B=GGf+[PF[0]+PF[1]]
len(PF) == 2:
        B = GGf + [PF[0] + PF[1]]
        return B
 else:
     return 'error'

Thanks a lot for your help!

copying lists, embedded multigraphs

I am working with planar, embedded, labelled multigraphs. I am trying to define a function face_modification that modifies the set of faces when an edge of the graph is deleted. I thought that when taking a copy of a list, and altering the copy, the original list would not change. However, when I evaluate the function face_modification below, with Gf=F1, my original list (F1) is being altered, and I can't figure out why or how to prevent it.

Here, G1 is the labelled graph without double edges, Gd is the graph of double edges, Gt is the graph of triple edges, and Gf is a list, the i``-th i-th entry of which is a list of labelled edges on the boundary of facei`.face i.

def edge_on_faces(j, S, Gf, G1, Gd, Gt):
    variables = ([G1.edges()[i][2] for i in range(len(G1.edges()))] +
                 [Gd.edges()[i][2] for i in range(len(Gd.edges()))] +
                 [Gt.edges()[i][2] for i in range(len(Gt.edges()))])
    if j in range(len(variables)):
        if [str(Gf[n][q][2]) == str(variables[j])
            for n in S for q in range(len(Gf[n]))].count(True) > 0:
            return 1 
        else:
            return 0
    else:
        return 0

def face_modification(i, Gf, G1, Gd, Gt):
    variables = ([G1.edges()[k][2] for k in range(len(G1.edges()))] +
                 [Gd.edges()[k][2] for k in range(len(Gd.edges()))] +
                 [Gt.edges()[k][2] for k in range(len(Gt.edges()))])
    l = [m for m in range(len(Gf)) if edge_on_faces(i, [m], Gf, G1, Gd, Gt)==1]
    # PF: list of two faces in Gf with the ith edge on the boundary
    PF = [Gf.copy()[l[p]] for p in range(len(l))]
    GGf = Gf.copy()
    for m in range(len(PF)):
        GGf.remove(PF[m])
        for k in range(len(PF[m])):
            if str(PF[m][k][2]) == str(variables[i]):
                PF[m].remove(PF[m][k])
            else:
                PF[m] = PF[m]
    if len(PF) == 2:
        B = GGf + [PF[0] + PF[1]]
        return B
    else:
        return 'error'

Thanks a lot for your help!