Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is as follows:

a=3 N=6 b=3 G=Graph(multiedges=False); for i in range(N): G.add_vertex(); plot(G); counter=0; #a counter that when reaches to N stops the while and the graph should already be semi-regular pointer=0; #the pointer to the vertex which we try to set its a or b neighbours

visited=[]

for i in range(N):

visited.append(False);

while counter<n: ds="list(G.degree_sequence());" if(pointer<n="" 2):="" checker="a" else:="" checker="b;" checked="False;" while(len(g[pointer])<checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" v="randint(0,N-1);" print="" 'new="" neighbor:',v;="" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" temp="len(G[v]);" g.add_edge(pointer,v);="" print="" 'processing="" vertex:',pointer,'with="" neighbours:',g[pointer];="" if="" len(g[v])="=checker2:" if="" len(g[v])="=temp+1:" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" if="" len(g[v])="=checker2+1:" if="" len(g[v])="=temp+1:" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" while(len(g[pointer])&gt;checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" rand="randint(0,len(G[pointer])-1);" v="G[pointer][rand];" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" print="" 'processing="" vertex:',pointer,'with="" degree:',g[pointer];="" print="" 'neighbor:',v;="" if(len(g[v])="=checker2):" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" if(len(g[v])="=checker2+1):" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" g.delete_edge([pointer,v]);="" plot(g);="" if="" checked="=True:" counter="counter+1;" pointer="mod(pointer+1,N);" print="" 'counter:',counter;<="" p="">

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is as follows:

a=3;

a=3 N=6 b=3 N=6; b=3; G=Graph(multiedges=False); for i in range(N): G.add_vertex(); plot(G); counter=0; #a counter that when reaches to N stops the while and the graph should already be semi-regular pointer=0; #the pointer to the vertex which we try to set its a or b neighbours

visited=[]

for i in range(N):

visited.append(False);

neighbours while counter<n: ds="list(G.degree_sequence());" if(pointer<n="" 2):="" checker="a" else:="" checker="b;" checked="False;" while(len(g[pointer])<checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" v="randint(0,N-1);" print="" 'new="" neighbor:',v;="" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" temp="len(G[v]);" g.add_edge(pointer,v);="" print="" 'processing="" vertex:',pointer,'with="" neighbours:',g[pointer];="" if="" len(g[v])="=checker2:" if="" len(g[v])="=temp+1:" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" if="" len(g[v])="=checker2+1:" if="" len(g[v])="=temp+1:" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" while(len(g[pointer])&gt;checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" rand="randint(0,len(G[pointer])-1);" v="G[pointer][rand];" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" print="" 'processing="" vertex:',pointer,'with="" degree:',g[pointer];="" print="" 'neighbor:',v;="" if(len(g[v])="=checker2):" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" more!';="" counter="counter-1;" if(len(g[v])="=checker2+1):" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" g.delete_edge([pointer,v]);="" plot(g);="" if="" checked="=True:" counter="counter+1;" pointer="mod(pointer+1,N);" print="" 'counter:',counter;<="" p="">

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is as follows:

a=3;

`a=3; N=6; b=3; G=Graph(multiedges=False); for i in range(N): G.add_vertex(); plot(G); counter=0; #a counter that when reaches to N stops the while and the graph should already be semi-regular pointer=0; #the pointer to the vertex which we try to set its a or b neighbours while counter<n: ds="list(G.degree_sequence());" if(pointer<n="" 2):="" checker="a" else:="" checker="b;" checked="False;" while(len(g[pointer])<checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" v="randint(0,N-1);" print="" 'new="" neighbor:',v;="" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" temp="len(G[v]);" g.add_edge(pointer,v);="" print="" 'processing="" vertex:',pointer,'with="" neighbours:',g[pointer];="" if="" len(g[v])="=checker2:" if="" len(g[v])="=temp+1:" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" if="" len(g[v])="=checker2+1:" if="" len(g[v])="=temp+1:" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" while(len(g[pointer])&gt;checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" rand="randint(0,len(G[pointer])-1);" v="G[pointer][rand];" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" print="" 'processing="" vertex:',pointer,'with="" degree:',g[pointer];="" print="" 'neighbor:',v;="" if(len(g[v])="=checker2):" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!';="" counter="counter-1;" if(len(g[v])="=checker2+1):" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" g.delete_edge([pointer,v]);="" plot(g);="" if="" checked="=True:" counter="counter+1;" pointer="mod(pointer+1,N);" print="" 'counter:',counter;<="" 'counter:',counter;'<="" p="">

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is as follows:

`a=3;

Blockquote

a=3; N=6; b=3; G=Graph(multiedges=False); for i in range(N): G.add_vertex(); plot(G); counter=0; #a counter that when reaches to N stops the while and the graph should already be semi-regular pointer=0; #the pointer to the vertex which we try to set its a or b neighbours while counter<n: ds="list(G.degree_sequence());" if(pointer<n="" 2):="" checker="a" else:="" checker="b;" checked="False;" while(len(g[pointer])<checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" v="randint(0,N-1);" print="" 'new="" neighbor:',v;="" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" temp="len(G[v]);" g.add_edge(pointer,v);="" print="" 'processing="" vertex:',pointer,'with="" neighbours:',g[pointer];="" if="" len(g[v])="=checker2:" if="" len(g[v])="=temp+1:" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" if="" len(g[v])="=checker2+1:" if="" len(g[v])="=temp+1:" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" while(len(g[pointer])&gt;checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" rand="randint(0,len(G[pointer])-1);" v="G[pointer][rand];" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" print="" 'processing="" vertex:',pointer,'with="" degree:',g[pointer];="" print="" 'neighbor:',v;="" if(len(g[v])="=checker2):" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!';="" counter="counter-1;" if(len(g[v])="=checker2+1):" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" g.delete_edge([pointer,v]);="" plot(g);="" if="" checked="=True:" counter="counter+1;" pointer="mod(pointer+1,N);" print="" 'counter:',counter;'<="" 'counter:',counter;<="" p="">

Blockquote

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is as follows:at: http://www.4shared.com/file/ZKT9x0W2/Generating_Regular_Graphs.html

Blockquote

a=3; N=6; b=3; G=Graph(multiedges=False); for i in range(N): G.add_vertex(); plot(G); counter=0; #a counter that when reaches to N stops the while and the graph should already be semi-regular pointer=0; #the pointer to the vertex which we try to set its a or b neighbours while counter<n: ds="list(G.degree_sequence());" if(pointer<n="" 2):="" checker="a" else:="" checker="b;" checked="False;" while(len(g[pointer])<checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" v="randint(0,N-1);" print="" 'new="" neighbor:',v;="" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" temp="len(G[v]);" g.add_edge(pointer,v);="" print="" 'processing="" vertex:',pointer,'with="" neighbours:',g[pointer];="" if="" len(g[v])="=checker2:" if="" len(g[v])="=temp+1:" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" if="" len(g[v])="=checker2+1:" if="" len(g[v])="=temp+1:" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!'="" counter="counter-1;" while(len(g[pointer])&gt;checker):="" checked="True;" v="randint(0,N-1);" while="" (pointer="=v):" rand="randint(0,len(G[pointer])-1);" v="G[pointer][rand];" if(v<n="" 2):="" checker2="a;" else:="" checker2="b;" print="" 'processing="" vertex:',pointer,'with="" degree:',g[pointer];="" print="" 'neighbor:',v;="" if(len(g[v])="=checker2):" print="" v,'was="" a="" good="" vertex!="" bot="" no="" more!';="" counter="counter-1;" if(len(g[v])="=checker2+1):" print="" v,'is="" now="" a="" good="" vertex!'="" counter="counter+1;" g.delete_edge([pointer,v]);="" plot(g);="" if="" checked="=True:" counter="counter+1;" pointer="mod(pointer+1,N);" print="" 'counter:',counter;<="" p="">

Blockquote

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code the to generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is at: http://www.4shared.com/file/ZKT9x0W2/Generating_Regular_Graphs.html

Show function for graphs is not working!

Hi everyone,

Yesterday I wrote a code to generate a random semi-regular graph. The algorithm works in this way: 1)It chooses vertices in numerical order 2)in each step it looks to see if the degree of the vertex is larger or smaller than the specified value for that vertex(which is a for first N/2 and b for second N/2 vertices) 3)it randomly adds an edge or remove one until the degree of vertex become acceptable 4)switches to the next vertex. However when I use show() function to see what is happening in each step, the result is frustrating, the Show() function shows a graph like what it should but the degrees are not associated with the correct vertices! for example most of the time even in the first cycle of the while loop, it should assign 3 edges to the '0' vertex. When I print the neighbours of '0' with "print G[0]" I get '[1,3,4]' but then in the plotted graph neighbours of '0' are '1' and '2' and '5'. I don't understand what is wrong with this Sage?! I am really exhausted of trying! My code is at: http://www.4shared.com/file/ZKT9x0W2/Generating_Regular_Graphs.html

Thanks a lot for the helps...