Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: grafos
Path: 01.sagews
Views: 76
def bip_dist(X): if X.is_bipartite(): M = X.distance_matrix() L = []; R = [] n = len(X) k = X.vertices() for j in range(n): if M[1][j] % 2 == 0: L.append(k[j]) else: R.append(k[j]) print L,R else: print "O grafo não é bipartido!"
G = Graph({0:[5,6], 1:[4,5], 2:[4,6], 3:[4,5,6]}) bip_dist(G) print "__________________________" print "" B = BipartiteGraph(G) B.left; B.right
[0, 1, 2, 3] [4, 5, 6] __________________________ set([0, 1, 2, 3]) set([4, 5, 6])
H = Graph({'A':['F','D'], 'C':['D','B'], 'E':['F', 'B'], 'G':['B','F','D']}) bip_dist(H) print "__________________________" print "" B = BipartiteGraph(H) B.left; B.right
['B', 'D', 'F'] ['A', 'C', 'E', 'G'] __________________________ set(['A', 'C', 'E', 'G']) set(['B', 'D', 'F'])
V = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] E = [['A', 'E'],['A', 'F'],['B', 'C'], ['B', 'D'],['B','E'],['B','G'],['C','F'],['C','G'],['D','G'],['F','G']] P = Graph([V,E],format='vertices_and_edges') bip_dist(P) print "__________________________" print "" B = BipartiteGraph(P) B.left; B.right
O grafo não é bipartido! __________________________
Error in lines 7-7 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1044, in execute exec compile(block+'\n', '', 'single', flags=compile_flags) in namespace, locals File "", line 1, in <module> File "/ext/sage/sage-8.1/local/lib/python2.7/site-packages/sage/graphs/bipartite_graph.py", line 390, in __init__ raise TypeError("Input graph is not bipartite!") TypeError: Input graph is not bipartite!
def bip_dist(X): M = X.distance_matrix() L = []; R = [] n = len(X) k = X.vertices() for j in range(n): if M[1][j] % 2 == 0: L.append(k[j]) else: R.append(k[j]) print L,R bip_dist(G)
[0, 1, 2, 3] [4, 5, 6]
G = Graph(5);G
Graph on 5 vertices
G.add_edges([(0,2),(1,2)])
G.adjacency_matrix()
[0 0 1 0 0] [0 0 1 0 0] [1 1 0 0 0] [0 0 0 0 0] [0 0 0 0 0]
show(G)
d3-based renderer not yet implemented
plot(G)
G.has_loops()
False
H=Graph(5).adjacency_matrix(vertices=[2,4,1,3,0]) show(H)
(0000000000000000000000000)\displaystyle \left(\begin{array}{rrrrr} 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \end{array}\right)
G.add_path([1,3,0])
G.add_edge([0,1])
show(G)
d3-based renderer not yet implemented
plot(G)
plot(G)
Mg = matrix([[1,1],[1,1]])
G = Graph(Mg); plot(G)
Mg2 = matrix([[0,1,1,1],[1,0,1,0],[1,1,0,1],[1,0,1,0]]); show(Mg2)
(0111101011011010)\displaystyle \left(\begin{array}{rrrr} 0 & 1 & 1 & 1 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \end{array}\right)
G = Graph(Mg2); plot(G)
72 [[(0, 1), (1, 2), (2, 3), (3, 0)], [(2, 0), (0, 3), (3, 2)], [(1, 0), (0, 2), (2, 1)]]
show(G)
d3-based renderer not yet implemented
G.is_eulerian()
False
G.triangles_count()
2
G.faces()
[[(0, 1), (1, 2), (2, 3), (3, 0)], [(2, 0), (0, 3), (3, 2)], [(1, 0), (0, 2), (2, 1)]]
G.to_dictionary()
{0: [1, 2, 3], 1: [0, 2], 2: [0, 1, 3], 3: [0, 2]}
G.incidence_matrix()
[1 1 1 0 0] [1 0 0 1 0] [0 1 0 1 1] [0 0 1 0 1]
G=Graph({0:[4,5,6], 1:[4,5], 2:[4,6], 3:[4,5,6]})
plot(G)
Mg2 = matrix([[0,0,0,0,0,1,1],[0,0,0,0,1,1,0],[0,0,0,0,1,0,1],[0,0,0,0,1,1,1],[0,1,1,1,0,0,0],[1,1,0,1,0,0,0], [1,0,1,1,0,0,0]]); show(Mg2) G = Graph(Mg2); plot(G)
(0000011000011000001010000111011100011010001011000)\displaystyle \left(\begin{array}{rrrrrrr} 0 & 0 & 0 & 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 & 1 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 \\ 1 & 0 & 1 & 1 & 0 & 0 & 0 \end{array}\right)
H = Graph(Mg2^2); plot(H)
A = matrix.random(ZZ, 3); A
[5550 -2 24] [ 0 59 -3] [ 0 -2 3]
type(A.row(1))
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
To bypass auto-detection, prefer the more explicit "Graph([V,E],format='vertices_and_edges')". 4. "Graph(list_of_edges)" -- return a graph with a given list of edges (see documentation of "add_edges()"). To bypass auto-detection, prefer the more explicit "Graph(L, format='list_of_edges')".
V = ['A', 'B', 'C', 'D', 'E', 'F', 'G'] E = [['A', 'E'],['A', 'F'],['B', 'C'], ['B', 'D'],['B','E'],['B','G'],['C','F'],['C','G'],['D','G'],['F','G'], ['C', 'C']]
G=Graph([V,E],format='vertices_and_edges'); plot(G)
G.vertices()
['A', 'B', 'C', 'D', 'E', 'F', 'G']
len(G.neighbors('A'))
2
G.edges()
[('A', 'E', None), ('A', 'F', None), ('B', 'C', None), ('B', 'D', None), ('B', 'E', None), ('B', 'G', None), ('C', 'F', None), ('C', 'G', None), ('D', 'G', None), ('F', 'G', None)]
g=1 v='X' for i in G.vertices(): if len(G.neighbors(i))>g: g = len(G.neighbors(i)) v=i v, g
('B', 4)
H.has_loops()
True
v = { 'A': ['A','B','D','O'], 'B': ['C', 'M', 'N'], 'C': ['C','D','P'], 'D': ['M', 'O'], 'E': ['N','P'], 'M': ['P','N'] } H = Graph(v) H.has_loops() H.loops() # L=[] # for i in H.edges(): # print i # if i[0]==i[1]: # L.append(i[0]) # L
True [('A', 'A', None), ('C', 'C', None)]
H = Graph(E,format='list_of_edges'); plot(H)
<string>:1: DeprecationWarning: You created a graph with loops from a list. Please set 'loops' to 'True' when you do so, as in the future the default behaviour will be to ignore those edges See http://trac.sagemath.org/15706 for details.
v = { 'A': ['B','D','O'], 'B': ['C', 'M', 'N'], 'C': ['D','P'], 'D': ['M', 'O'], 'E': ['N','P'], 'M': ['P','N'] } G = Graph(v)
plot(G)
G.chromatic_number()
3
H = G.coloring(hex_colors=True) G.plot(vertex_colors=H)
def soma(n,m): for i in range(10): n = n+i m = m*n return [n,m]
matrix.random(ZZ, 1, 6, x=1, y=6)
[2 2 4 4 5 3]
Permutations(6).list()
[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 6, 5], [1, 2, 3, 5, 4, 6], [1, 2, 3, 5, 6, 4], [1, 2, 3, 6, 4, 5], [1, 2, 3, 6, 5, 4], [1, 2, 4, 3, 5, 6], [1, 2, 4, 3, 6, 5], [1, 2, 4, 5, 3, 6], [1, 2, 4, 5, 6, 3], [1, 2, 4, 6, 3, 5], [1, 2, 4, 6, 5, 3], [1, 2, 5, 3, 4, 6], [1, 2, 5, 3, 6, 4], [1, 2, 5, 4, 3, 6], [1, 2, 5, 4, 6, 3], [1, 2, 5, 6, 3, 4], [1, 2, 5, 6, 4, 3], [1, 2, 6, 3, 4, 5], [1, 2, 6, 3, 5, 4], [1, 2, 6, 4, 3, 5], [1, 2, 6, 4, 5, 3], [1, 2, 6, 5, 3, 4], [1, 2, 6, 5, 4, 3], [1, 3, 2, 4, 5, 6], [1, 3, 2, 4, 6, 5], [1, 3, 2, 5, 4, 6], [1, 3, 2, 5, 6, 4], [1, 3, 2, 6, 4, 5], [1, 3, 2, 6, 5, 4], [1, 3, 4, 2, 5, 6], [1, 3, 4, 2, 6, 5], [1, 3, 4, 5, 2, 6], [1, 3, 4, 5, 6, 2], [1, 3, 4, 6, 2, 5], [1, 3, 4, 6, 5, 2], [1, 3, 5, 2, 4, 6], [1, 3, 5, 2, 6, 4], [1, 3, 5, 4, 2, 6], [1, 3, 5, 4, 6, 2], [1, 3, 5, 6, 2, 4], [1, 3, 5, 6, 4, 2], [1, 3, 6, 2, 4, 5], [1, 3, 6, 2, 5, 4], [1, 3, 6, 4, 2, 5], [1, 3, 6, 4, 5, 2], [1, 3, 6, 5, 2, 4], [1, 3, 6, 5, 4, 2], [1, 4, 2, 3, 5, 6], [1, 4, 2, 3, 6, 5], [1, 4, 2, 5, 3, 6], [1, 4, 2, 5, 6, 3], [1, 4, 2, 6, 3, 5], [1, 4, 2, 6, 5, 3], [1, 4, 3, 2, 5, 6], [1, 4, 3, 2, 6, 5], [1, 4, 3, 5, 2, 6], [1, 4, 3, 5, 6, 2], [1, 4, 3, 6, 2, 5], [1, 4, 3, 6, 5, 2], [1, 4, 5, 2, 3, 6], [1, 4, 5, 2, 6, 3], [1, 4, 5, 3, 2, 6], [1, 4, 5, 3, 6, 2], [1, 4, 5, 6, 2, 3], [1, 4, 5, 6, 3, 2], [1, 4, 6, 2, 3, 5], [1, 4, 6, 2, 5, 3], [1, 4, 6, 3, 2, 5], [1, 4, 6, 3, 5, 2], [1, 4, 6, 5, 2, 3], [1, 4, 6, 5, 3, 2], [1, 5, 2, 3, 4, 6], [1, 5, 2, 3, 6, 4], [1, 5, 2, 4, 3, 6], [1, 5, 2, 4, 6, 3], [1, 5, 2, 6, 3, 4], [1, 5, 2, 6, 4, 3], [1, 5, 3, 2, 4, 6], [1, 5, 3, 2, 6, 4], [1, 5, 3, 4, 2, 6], [1, 5, 3, 4, 6, 2], [1, 5, 3, 6, 2, 4], [1, 5, 3, 6, 4, 2], [1, 5, 4, 2, 3, 6], [1, 5, 4, 2, 6, 3], [1, 5, 4, 3, 2, 6], [1, 5, 4, 3, 6, 2], [1, 5, 4, 6, 2, 3], [1, 5, 4, 6, 3, 2], [1, 5, 6, 2, 3, 4], [1, 5, 6, 2, 4, 3], [1, 5, 6, 3, 2, 4], [1, 5, 6, 3, 4, 2], [1, 5, 6, 4, 2, 3], [1, 5, 6, 4, 3, 2], [1, 6, 2, 3, 4, 5], [1, 6, 2, 3, 5, 4], [1, 6, 2, 4, 3, 5], [1, 6, 2, 4, 5, 3], [1, 6, 2, 5, 3, 4], [1, 6, 2, 5, 4, 3], [1, 6, 3, 2, 4, 5], [1, 6, 3, 2, 5, 4], [1, 6, 3, 4, 2, 5], [1, 6, 3, 4, 5, 2], [1, 6, 3, 5, 2, 4], [1, 6, 3, 5, 4, 2], [1, 6, 4, 2, 3, 5], [1, 6, 4, 2, 5, 3], [1, 6, 4, 3, 2, 5], [1, 6, 4, 3, 5, 2], [1, 6, 4, 5, 2, 3], [1, 6, 4, 5, 3, 2], [1, 6, 5, 2, 3, 4], [1, 6, 5, 2, 4, 3], [1, 6, 5, 3, 2, 4], [1, 6, 5, 3, 4, 2], [1, 6, 5, 4, 2, 3], [1, 6, 5, 4, 3, 2], [2, 1, 3, 4, 5, 6], [2, 1, 3, 4, 6, 5], [2, 1, 3, 5, 4, 6], [2, 1, 3, 5, 6, 4], [2, 1, 3, 6, 4, 5], [2, 1, 3, 6, 5, 4], [2, 1, 4, 3, 5, 6], [2, 1, 4, 3, 6, 5], [2, 1, 4, 5, 3, 6], [2, 1, 4, 5, 6, 3], [2, 1, 4, 6, 3, 5], [2, 1, 4, 6, 5, 3], [2, 1, 5, 3, 4, 6], [2, 1, 5, 3, 6, 4], [2, 1, 5, 4, 3, 6], [2, 1, 5, 4, 6, 3], [2, 1, 5, 6, 3, 4], [2, 1, 5, 6, 4, 3], [2, 1, 6, 3, 4, 5], [2, 1, 6, 3, 5, 4], [2, 1, 6, 4, 3, 5], [2, 1, 6, 4, 5, 3], [2, 1, 6, 5, 3, 4], [2, 1, 6, 5, 4, 3], [2, 3, 1, 4, 5, 6], [2, 3, 1, 4, 6, 5], [2, 3, 1, 5, 4, 6], [2, 3, 1, 5, 6, 4], [2, 3, 1, 6, 4, 5], [2, 3, 1, 6, 5, 4], [2, 3, 4, 1, 5, 6], [2, 3, 4, 1, 6, 5], [2, 3, 4, 5, 1, 6], [2, 3, 4, 5, 6, 1], [2, 3, 4, 6, 1, 5], [2, 3, 4, 6, 5, 1], [2, 3, 5, 1, 4, 6], [2, 3, 5, 1, 6, 4], [2, 3, 5, 4, 1, 6], [2, 3, 5, 4, 6, 1], [2, 3, 5, 6, 1, 4], [2, 3, 5, 6, 4, 1], [2, 3, 6, 1, 4, 5], [2, 3, 6, 1, 5, 4], [2, 3, 6, 4, 1, 5], [2, 3, 6, 4, 5, 1], [2, 3, 6, 5, 1, 4], [2, 3, 6, 5, 4, 1], [2, 4, 1, 3, 5, 6], [2, 4, 1, 3, 6, 5], [2, 4, 1, 5, 3, 6], [2, 4, 1, 5, 6, 3], [2, 4, 1, 6, 3, 5], [2, 4, 1, 6, 5, 3], [2, 4, 3, 1, 5, 6], [2, 4, 3, 1, 6, 5], [2, 4, 3, 5, 1, 6], [2, 4, 3, 5, 6, 1], [2, 4, 3, 6, 1, 5], [2, 4, 3, 6, 5, 1], [2, 4, 5, 1, 3, 6], [2, 4, 5, 1, 6, 3], [2, 4, 5, 3, 1, 6], [2, 4, 5, 3, 6, 1], [2, 4, 5, 6, 1, 3], [2, 4, 5, 6, 3, 1], [2, 4, 6, 1, 3, 5], [2, 4, 6, 1, 5, 3], [2, 4, 6, 3, 1, 5], [2, 4, 6, 3, 5, 1], [2, 4, 6, 5, 1, 3], [2, 4, 6, 5, 3, 1], [2, 5, 1, 3, 4, 6], [2, 5, 1, 3, 6, 4], [2, 5, 1, 4, 3, 6], [2, 5, 1, 4, 6, 3], [2, 5, 1, 6, 3, 4], [2, 5, 1, 6, 4, 3], [2, 5, 3, 1, 4, 6], [2, 5, 3, 1, 6, 4], [2, 5, 3, 4, 1, 6], [2, 5, 3, 4, 6, 1], [2, 5, 3, 6, 1, 4], [2, 5, 3, 6, 4, 1], [2, 5, 4, 1, 3, 6], [2, 5, 4, 1, 6, 3], [2, 5, 4, 3, 1, 6], [2, 5, 4, 3, 6, 1], [2, 5, 4, 6, 1, 3], [2, 5, 4, 6, 3, 1], [2, 5, 6, 1, 3, 4], [2, 5, 6, 1, 4, 3], [2, 5, 6, 3, 1, 4], [2, 5, 6, 3, 4, 1], [2, 5, 6, 4, 1, 3], [2, 5, 6, 4, 3, 1], [2, 6, 1, 3, 4, 5], [2, 6, 1, 3, 5, 4], [2, 6, 1, 4, 3, 5], [2, 6, 1, 4, 5, 3], [2, 6, 1, 5, 3, 4], [2, 6, 1, 5, 4, 3], [2, 6, 3, 1, 4, 5], [2, 6, 3, 1, 5, 4], [2, 6, 3, 4, 1, 5], [2, 6, 3, 4, 5, 1], [2, 6, 3, 5, 1, 4], [2, 6, 3, 5, 4, 1], [2, 6, 4, 1, 3, 5], [2, 6, 4, 1, 5, 3], [2, 6, 4, 3, 1, 5], [2, 6, 4, 3, 5, 1], [2, 6, 4, 5, 1, 3], [2, 6, 4, 5, 3, 1], [2, 6, 5, 1, 3, 4], [2, 6, 5, 1, 4, 3], [2, 6, 5, 3, 1, 4], [2, 6, 5, 3, 4, 1], [2, 6, 5, 4, 1, 3], [2, 6, 5, 4, 3, 1], [3, 1, 2, 4, 5, 6], [3, 1, 2, 4, 6, 5], [3, 1, 2, 5, 4, 6], [3, 1, 2, 5, 6, 4], [3, 1, 2, 6, 4, 5], [3, 1, 2, 6, 5, 4], [3, 1, 4, 2, 5, 6], [3, 1, 4, 2, 6, 5], [3, 1, 4, 5, 2, 6], [3, 1, 4, 5, 6, 2], [3, 1, 4, 6, 2, 5], [3, 1, 4, 6, 5, 2], [3, 1, 5, 2, 4, 6], [3, 1, 5, 2, 6, 4], [3, 1, 5, 4, 2, 6], [3, 1, 5, 4, 6, 2], [3, 1, 5, 6, 2, 4], [3, 1, 5, 6, 4, 2], [3, 1, 6, 2, 4, 5], [3, 1, 6, 2, 5, 4], [3, 1, 6, 4, 2, 5], [3, 1, 6, 4, 5, 2], [3, 1, 6, 5, 2, 4], [3, 1, 6, 5, 4, 2], [3, 2, 1, 4, 5, 6], [3, 2, 1, 4, 6, 5], [3, 2, 1, 5, 4, 6], [3, 2, 1, 5, 6, 4], [3, 2, 1, 6, 4, 5], [3, 2, 1, 6, 5, 4], [3, 2, 4, 1, 5, 6], [3, 2, 4, 1, 6, 5], [3, 2, 4, 5, 1, 6], [3, 2, 4, 5, 6, 1], [3, 2, 4, 6, 1, 5], [3, 2, 4, 6, 5, 1], [3, 2, 5, 1, 4, 6], [3, 2, 5, 1, 6, 4], [3, 2, 5, 4, 1, 6], [3, 2, 5, 4, 6, 1], [3, 2, 5, 6, 1, 4], [3, 2, 5, 6, 4, 1], [3, 2, 6, 1, 4, 5], [3, 2, 6, 1, 5, 4], [3, 2, 6, 4, 1, 5], [3, 2, 6, 4, 5, 1], [3, 2, 6, 5, 1, 4], [3, 2, 6, 5, 4, 1], [3, 4, 1, 2, 5, 6], [3, 4, 1, 2, 6, 5], [3, 4, 1, 5, 2, 6], [3, 4, 1, 5, 6, 2], [3, 4, 1, 6, 2, 5], [3, 4, 1, 6, 5, 2], [3, 4, 2, 1, 5, 6], [3, 4, 2, 1, 6, 5], [3, 4, 2, 5, 1, 6], [3, 4, 2, 5, 6, 1], [3, 4, 2, 6, 1, 5], [3, 4, 2, 6, 5, 1], [3, 4, 5, 1, 2, 6], [3, 4, 5, 1, 6, 2], [3, 4, 5, 2, 1, 6], [3, 4, 5, 2, 6, 1], [3, 4, 5, 6, 1, 2], [3, 4, 5, 6, 2, 1], [3, 4, 6, 1, 2, 5], [3, 4, 6, 1, 5, 2], [3, 4, 6, 2, 1, 5], [3, 4, 6, 2, 5, 1], [3, 4, 6, 5, 1, 2], [3, 4, 6, 5, 2, 1], [3, 5, 1, 2, 4, 6], [3, 5, 1, 2, 6, 4], [3, 5, 1, 4, 2, 6], [3, 5, 1, 4, 6, 2], [3, 5, 1, 6, 2, 4], [3, 5, 1, 6, 4, 2], [3, 5, 2, 1, 4, 6], [3, 5, 2, 1, 6, 4], [3, 5, 2, 4, 1, 6], [3, 5, 2, 4, 6, 1], [3, 5, 2, 6, 1, 4], [3, 5, 2, 6, 4, 1], [3, 5, 4, 1, 2, 6], [3, 5, 4, 1, 6, 2], [3, 5, 4, 2, 1, 6], [3, 5, 4, 2, 6, 1], [3, 5, 4, 6, 1, 2], [3, 5, 4, 6, 2, 1], [3, 5, 6, 1, 2, 4], [3, 5, 6, 1, 4, 2], [3, 5, 6, 2, 1, 4], [3, 5, 6, 2, 4, 1], [3, 5, 6, 4, 1, 2], [3, 5, 6, 4, 2, 1], [3, 6, 1, 2, 4, 5], [3, 6, 1, 2, 5, 4], [3, 6, 1, 4, 2, 5], [3, 6, 1, 4, 5, 2], [3, 6, 1, 5, 2, 4], [3, 6, 1, 5, 4, 2], [3, 6, 2, 1, 4, 5], [3, 6, 2, 1, 5, 4], [3, 6, 2, 4, 1, 5], [3, 6, 2, 4, 5, 1], [3, 6, 2, 5, 1, 4], [3, 6, 2, 5, 4, 1], [3, 6, 4, 1, 2, 5], [3, 6, 4, 1, 5, 2], [3, 6, 4, 2, 1, 5], [3, 6, 4, 2, 5, 1], [3, 6, 4, 5, 1, 2], [3, 6, 4, 5, 2, 1], [3, 6, 5, 1, 2, 4], [3, 6, 5, 1, 4, 2], [3, 6, 5, 2, 1, 4], [3, 6, 5, 2, 4, 1], [3, 6, 5, 4, 1, 2], [3, 6, 5, 4, 2, 1], [4, 1, 2, 3, 5, 6], [4, 1, 2, 3, 6, 5], [4, 1, 2, 5, 3, 6], [4, 1, 2, 5, 6, 3], [4, 1, 2, 6, 3, 5], [4, 1, 2, 6, 5, 3], [4, 1, 3, 2, 5, 6], [4, 1, 3, 2, 6, 5], [4, 1, 3, 5, 2, 6], [4, 1, 3, 5, 6, 2], [4, 1, 3, 6, 2, 5], [4, 1, 3, 6, 5, 2], [4, 1, 5, 2, 3, 6], [4, 1, 5, 2, 6, 3], [4, 1, 5, 3, 2, 6], [4, 1, 5, 3, 6, 2], [4, 1, 5, 6, 2, 3], [4, 1, 5, 6, 3, 2], [4, 1, 6, 2, 3, 5], [4, 1, 6, 2, 5, 3], [4, 1, 6, 3, 2, 5], [4, 1, 6, 3, 5, 2], [4, 1, 6, 5, 2, 3], [4, 1, 6, 5, 3, 2], [4, 2, 1, 3, 5, 6], [4, 2, 1, 3, 6, 5], [4, 2, 1, 5, 3, 6], [4, 2, 1, 5, 6, 3], [4, 2, 1, 6, 3, 5], [4, 2, 1, 6, 5, 3], [4, 2, 3, 1, 5, 6], [4, 2, 3, 1, 6, 5], [4, 2, 3, 5, 1, 6], [4, 2, 3, 5, 6, 1], [4, 2, 3, 6, 1, 5], [4, 2, 3, 6, 5, 1], [4, 2, 5, 1, 3, 6], [4, 2, 5, 1, 6, 3], [4, 2, 5, 3, 1, 6], [4, 2, 5, 3, 6, 1], [4, 2, 5, 6, 1, 3], [4, 2, 5, 6, 3, 1], [4, 2, 6, 1, 3, 5], [4, 2, 6, 1, 5, 3], [4, 2, 6, 3, 1, 5], [4, 2, 6, 3, 5, 1], [4, 2, 6, 5, 1, 3], [4, 2, 6, 5, 3, 1], [4, 3, 1, 2, 5, 6], [4, 3, 1, 2, 6, 5], [4, 3, 1, 5, 2, 6], [4, 3, 1, 5, 6, 2], [4, 3, 1, 6, 2, 5], [4, 3, 1, 6, 5, 2], [4, 3, 2, 1, 5, 6], [4, 3, 2, 1, 6, 5], [4, 3, 2, 5, 1, 6], [4, 3, 2, 5, 6, 1], [4, 3, 2, 6, 1, 5], [4, 3, 2, 6, 5, 1], [4, 3, 5, 1, 2, 6], [4, 3, 5, 1, 6, 2], [4, 3, 5, 2, 1, 6], [4, 3, 5, 2, 6, 1], [4, 3, 5, 6, 1, 2], [4, 3, 5, 6, 2, 1], [4, 3, 6, 1, 2, 5], [4, 3, 6, 1, 5, 2], [4, 3, 6, 2, 1, 5], [4, 3, 6, 2, 5, 1], [4, 3, 6, 5, 1, 2], [4, 3, 6, 5, 2, 1], [4, 5, 1, 2, 3, 6], [4, 5, 1, 2, 6, 3], [4, 5, 1, 3, 2, 6], [4, 5, 1, 3, 6, 2], [4, 5, 1, 6, 2, 3], [4, 5, 1, 6, 3, 2], [4, 5, 2, 1, 3, 6], [4, 5, 2, 1, 6, 3], [4, 5, 2, 3, 1, 6], [4, 5, 2, 3, 6, 1], [4, 5, 2, 6, 1, 3], [4, 5, 2, 6, 3, 1], [4, 5, 3, 1, 2, 6], [4, 5, 3, 1, 6, 2], [4, 5, 3, 2, 1, 6], [4, 5, 3, 2, 6, 1], [4, 5, 3, 6, 1, 2], [4, 5, 3, 6, 2, 1], [4, 5, 6, 1, 2, 3], [4, 5, 6, 1, 3, 2], [4, 5, 6, 2, 1, 3], [4, 5, 6, 2, 3, 1], [4, 5, 6, 3, 1, 2], [4, 5, 6, 3, 2, 1], [4, 6, 1, 2, 3, 5], [4, 6, 1, 2, 5, 3], [4, 6, 1, 3, 2, 5], [4, 6, 1, 3, 5, 2], [4, 6, 1, 5, 2, 3], [4, 6, 1, 5, 3, 2], [4, 6, 2, 1, 3, 5], [4, 6, 2, 1, 5, 3], [4, 6, 2, 3, 1, 5], [4, 6, 2, 3, 5, 1], [4, 6, 2, 5, 1, 3], [4, 6, 2, 5, 3, 1], [4, 6, 3, 1, 2, 5], [4, 6, 3, 1, 5, 2], [4, 6, 3, 2, 1, 5], [4, 6, 3, 2, 5, 1], [4, 6, 3, 5, 1, 2], [4, 6, 3, 5, 2, 1], [4, 6, 5, 1, 2, 3], [4, 6, 5, 1, 3, 2], [4, 6, 5, 2, 1, 3], [4, 6, 5, 2, 3, 1], [4, 6, 5, 3, 1, 2], [4, 6, 5, 3, 2, 1], [5, 1, 2, 3, 4, 6], [5, 1, 2, 3, 6, 4], [5, 1, 2, 4, 3, 6], [5, 1, 2, 4, 6, 3], [5, 1, 2, 6, 3, 4], [5, 1, 2, 6, 4, 3], [5, 1, 3, 2, 4, 6], [5, 1, 3, 2, 6, 4], [5, 1, 3, 4, 2, 6], [5, 1, 3, 4, 6, 2], [5, 1, 3, 6, 2, 4], [5, 1, 3, 6, 4, 2], [5, 1, 4, 2, 3, 6], [5, 1, 4, 2, 6, 3], [5, 1, 4, 3, 2, 6], [5, 1, 4, 3, 6, 2], [5, 1, 4, 6, 2, 3], [5, 1, 4, 6, 3, 2], [5, 1, 6, 2, 3, 4], [5, 1, 6, 2, 4, 3], [5, 1, 6, 3, 2, 4], [5, 1, 6, 3, 4, 2], [5, 1, 6, 4, 2, 3], [5, 1, 6, 4, 3, 2], [5, 2, 1, 3, 4, 6], [5, 2, 1, 3, 6, 4], [5, 2, 1, 4, 3, 6], [5, 2, 1, 4, 6, 3], [5, 2, 1, 6, 3, 4], [5, 2, 1, 6, 4, 3], [5, 2, 3, 1, 4, 6], [5, 2, 3, 1, 6, 4], [5, 2, 3, 4, 1, 6], [5, 2, 3, 4, 6, 1], [5, 2, 3, 6, 1, 4], [5, 2, 3, 6, 4, 1], [5, 2, 4, 1, 3, 6], [5, 2, 4, 1, 6, 3], [5, 2, 4, 3, 1, 6], [5, 2, 4, 3, 6, 1], [5, 2, 4, 6, 1, 3], [5, 2, 4, 6, 3, 1], [5, 2, 6, 1, 3, 4], [5, 2, 6, 1, 4, 3], [5, 2, 6, 3, 1, 4], [5, 2, 6, 3, 4, 1], [5, 2, 6, 4, 1, 3], [5, 2, 6, 4, 3, 1], [5, 3, 1, 2, 4, 6], [5, 3, 1, 2, 6, 4], [5, 3, 1, 4, 2, 6], [5, 3, 1, 4, 6, 2], [5, 3, 1, 6, 2, 4], [5, 3, 1, 6, 4, 2], [5, 3, 2, 1, 4, 6], [5, 3, 2, 1, 6, 4], [5, 3, 2, 4, 1, 6], [5, 3, 2, 4, 6, 1], [5, 3, 2, 6, 1, 4], [5, 3, 2, 6, 4, 1], [5, 3, 4, 1, 2, 6], [5, 3, 4, 1, 6, 2], [5, 3, 4, 2, 1, 6], [5, 3, 4, 2, 6, 1], [5, 3, 4, 6, 1, 2], [5, 3, 4, 6, 2, 1], [5, 3, 6, 1, 2, 4], [5, 3, 6, 1, 4, 2], [5, 3, 6, 2, 1, 4], [5, 3, 6, 2, 4, 1], [5, 3, 6, 4, 1, 2], [5, 3, 6, 4, 2, 1], [5, 4, 1, 2, 3, 6], [5, 4, 1, 2, 6, 3], [5, 4, 1, 3, 2, 6], [5, 4, 1, 3, 6, 2], [5, 4, 1, 6, 2, 3], [5, 4, 1, 6, 3, 2], [5, 4, 2, 1, 3, 6], [5, 4, 2, 1, 6, 3], [5, 4, 2, 3, 1, 6], [5, 4, 2, 3, 6, 1], [5, 4, 2, 6, 1, 3], [5, 4, 2, 6, 3, 1], [5, 4, 3, 1, 2, 6], [5, 4, 3, 1, 6, 2], [5, 4, 3, 2, 1, 6], [5, 4, 3, 2, 6, 1], [5, 4, 3, 6, 1, 2], [5, 4, 3, 6, 2, 1], [5, 4, 6, 1, 2, 3], [5, 4, 6, 1, 3, 2], [5, 4, 6, 2, 1, 3], [5, 4, 6, 2, 3, 1], [5, 4, 6, 3, 1, 2], [5, 4, 6, 3, 2, 1], [5, 6, 1, 2, 3, 4], [5, 6, 1, 2, 4, 3], [5, 6, 1, 3, 2, 4], [5, 6, 1, 3, 4, 2], [5, 6, 1, 4, 2, 3], [5, 6, 1, 4, 3, 2], [5, 6, 2, 1, 3, 4], [5, 6, 2, 1, 4, 3], [5, 6, 2, 3, 1, 4], [5, 6, 2, 3, 4, 1], [5, 6, 2, 4, 1, 3], [5, 6, 2, 4, 3, 1], [5, 6, 3, 1, 2, 4], [5, 6, 3, 1, 4, 2], [5, 6, 3, 2, 1, 4], [5, 6, 3, 2, 4, 1], [5, 6, 3, 4, 1, 2], [5, 6, 3, 4, 2, 1], [5, 6, 4, 1, 2, 3], [5, 6, 4, 1, 3, 2], [5, 6, 4, 2, 1, 3], [5, 6, 4, 2, 3, 1], [5, 6, 4, 3, 1, 2], [5, 6, 4, 3, 2, 1], [6, 1, 2, 3, 4, 5], [6, 1, 2, 3, 5, 4], [6, 1, 2, 4, 3, 5], [6, 1, 2, 4, 5, 3], [6, 1, 2, 5, 3, 4], [6, 1, 2, 5, 4, 3], [6, 1, 3, 2, 4, 5], [6, 1, 3, 2, 5, 4], [6, 1, 3, 4, 2, 5], [6, 1, 3, 4, 5, 2], [6, 1, 3, 5, 2, 4], [6, 1, 3, 5, 4, 2], [6, 1, 4, 2, 3, 5], [6, 1, 4, 2, 5, 3], [6, 1, 4, 3, 2, 5], [6, 1, 4, 3, 5, 2], [6, 1, 4, 5, 2, 3], [6, 1, 4, 5, 3, 2], [6, 1, 5, 2, 3, 4], [6, 1, 5, 2, 4, 3], [6, 1, 5, 3, 2, 4], [6, 1, 5, 3, 4, 2], [6, 1, 5, 4, 2, 3], [6, 1, 5, 4, 3, 2], [6, 2, 1, 3, 4, 5], [6, 2, 1, 3, 5, 4], [6, 2, 1, 4, 3, 5], [6, 2, 1, 4, 5, 3], [6, 2, 1, 5, 3, 4], [6, 2, 1, 5, 4, 3], [6, 2, 3, 1, 4, 5], [6, 2, 3, 1, 5, 4], [6, 2, 3, 4, 1, 5], [6, 2, 3, 4, 5, 1], [6, 2, 3, 5, 1, 4], [6, 2, 3, 5, 4, 1], [6, 2, 4, 1, 3, 5], [6, 2, 4, 1, 5, 3], [6, 2, 4, 3, 1, 5], [6, 2, 4, 3, 5, 1], [6, 2, 4, 5, 1, 3], [6, 2, 4, 5, 3, 1], [6, 2, 5, 1, 3, 4], [6, 2, 5, 1, 4, 3], [6, 2, 5, 3, 1, 4], [6, 2, 5, 3, 4, 1], [6, 2, 5, 4, 1, 3], [6, 2, 5, 4, 3, 1], [6, 3, 1, 2, 4, 5], [6, 3, 1, 2, 5, 4], [6, 3, 1, 4, 2, 5], [6, 3, 1, 4, 5, 2], [6, 3, 1, 5, 2, 4], [6, 3, 1, 5, 4, 2], [6, 3, 2, 1, 4, 5], [6, 3, 2, 1, 5, 4], [6, 3, 2, 4, 1, 5], [6, 3, 2, 4, 5, 1], [6, 3, 2, 5, 1, 4], [6, 3, 2, 5, 4, 1], [6, 3, 4, 1, 2, 5], [6, 3, 4, 1, 5, 2], [6, 3, 4, 2, 1, 5], [6, 3, 4, 2, 5, 1], [6, 3, 4, 5, 1, 2], [6, 3, 4, 5, 2, 1], [6, 3, 5, 1, 2, 4], [6, 3, 5, 1, 4, 2], [6, 3, 5, 2, 1, 4], [6, 3, 5, 2, 4, 1], [6, 3, 5, 4, 1, 2], [6, 3, 5, 4, 2, 1], [6, 4, 1, 2, 3, 5], [6, 4, 1, 2, 5, 3], [6, 4, 1, 3, 2, 5], [6, 4, 1, 3, 5, 2], [6, 4, 1, 5, 2, 3], [6, 4, 1, 5, 3, 2], [6, 4, 2, 1, 3, 5], [6, 4, 2, 1, 5, 3], [6, 4, 2, 3, 1, 5], [6, 4, 2, 3, 5, 1], [6, 4, 2, 5, 1, 3], [6, 4, 2, 5, 3, 1], [6, 4, 3, 1, 2, 5], [6, 4, 3, 1, 5, 2], [6, 4, 3, 2, 1, 5], [6, 4, 3, 2, 5, 1], [6, 4, 3, 5, 1, 2], [6, 4, 3, 5, 2, 1], [6, 4, 5, 1, 2, 3], [6, 4, 5, 1, 3, 2], [6, 4, 5, 2, 1, 3], [6, 4, 5, 2, 3, 1], [6, 4, 5, 3, 1, 2], [6, 4, 5, 3, 2, 1], [6, 5, 1, 2, 3, 4], [6, 5, 1, 2, 4, 3], [6, 5, 1, 3, 2, 4], [6, 5, 1, 3, 4, 2], [6, 5, 1, 4, 2, 3], [6, 5, 1, 4, 3, 2], [6, 5, 2, 1, 3, 4], [6, 5, 2, 1, 4, 3], [6, 5, 2, 3, 1, 4], [6, 5, 2, 3, 4, 1], [6, 5, 2, 4, 1, 3], [6, 5, 2, 4, 3, 1], [6, 5, 3, 1, 2, 4], [6, 5, 3, 1, 4, 2], [6, 5, 3, 2, 1, 4], [6, 5, 3, 2, 4, 1], [6, 5, 3, 4, 1, 2], [6, 5, 3, 4, 2, 1], [6, 5, 4, 1, 2, 3], [6, 5, 4, 1, 3, 2], [6, 5, 4, 2, 1, 3], [6, 5, 4, 2, 3, 1], [6, 5, 4, 3, 1, 2], [6, 5, 4, 3, 2, 1]]
final int n = 3;//aqui vai o numero de elementos do seu sudoku(3 vai ser um sudoku 3x3 final int[][] field = new int[n*n][n*n];//matriz onde será armazenado o sudoku int x = rand()%10;//semente aleatória para não gerar o mesmo sudoku for(int i = 0; i < n; i++, x++) for(int j = 0; j < n; j++, x+=n) for(int k = 0; k < n*n; k++, x++) field[n*i+j][k] = (x % (n*n)) + 1;
[1]
def gera_sudoku(num): mat = [] inteiro = ZZ.random_element(x = 1, y = num)
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.6/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> AttributeError: 'list' object has no attribute 'permut'
ZZ.random_element(x = 1, y = 6)
3
matrix
[46, 21404787712]
sage: G = Graph({0: {1: 1}, 1: {2: 1}, 2: {3: 1}, 3: {4: 2}, 4: {0: 2}}, sparse = True) G.plot(edge_labels=True).show() # long time sage: G.shortest_path(0, 3)
[0, 4, 3]
sage: G.shortest_path(0, 3, by_weight=True)
[0, 1, 2, 3]
plot(G)
G = Graph (weighted = True, sparse=True) G.add_edges([('A','B',13),('A','J',5),('J','P',6),('J','Q',10),('Q','P',3),('Q','C',4),('Q','B',6),('P','C',6),('C','E',8),('P','B',11),('B','E',3)]) #show(G, weighted=True, sparse=True, edges_weighted=True) G.shortest_path('J','E', by_weight=True)
['J', 'P', 'Q', 'B', 'E']
G.shortest_path('J', 'E', algorithm='Dijkstra_NetworkX')
['J', 'A', 'B', 'E']
G.shortest_paths()
{'A': ['J', 'A'], 'C': ['J', 'P', 'C'], 'B': ['J', 'A', 'B'], 'E': ['J', 'P', 'C', 'E'], 'J': ['J'], 'Q': ['J', 'Q'], 'P': ['J', 'P']}
G.all_graphs_coloring()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.6/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> AttributeError: 'Graph' object has no attribute 'all_graphs_coloring'
plot(G, edge_labels=True)
G.eulerian_circuit()
False
def gera_grafo(nv): G = Graph (weighted = True, sparse=True) G.add_edges([('A','B',13),('A','J',5),('J','P',6),('J','Q',10),('Q','P',3),('Q','C',4),('Q','B',6),('P','C',6),('C','E',8),('P','B',11),('B','E',3)]) return
A = matrix.random(ZZ, 5, 5); A
[-1 0 -4 3 -4] [-8 0 -7 -4 1] [ 0 -1 -1 5 -5] [ 0 -2 2 1 1] [-1 -1 0 -1 -1]
show(A)
(1043480741011550221111011)\displaystyle \left(\begin{array}{rrrrr} -1 & 0 & -4 & 3 & -4 \\ -8 & 0 & -7 & -4 & 1 \\ 0 & -1 & -1 & 5 & -5 \\ 0 & -2 & 2 & 1 & 1 \\ -1 & -1 & 0 & -1 & -1 \end{array}\right)
B = matrix([[1,2,3],[9,8,7]]) show(B)
(123987)\displaystyle \left(\begin{array}{rrr} 1 & 2 & 3 \\ 9 & 8 & 7 \end{array}\right)
(123987)\displaystyle \left(\begin{array}{rrr} 1 & 2 & 3 \\ 9 & 8 & 7 \end{array}\right)
show(A^4)
(291155439339760196592752181924735461056343863413722224515189923330436250619)\displaystyle \left(\begin{array}{rrrrr} 291 & 155 & 439 & -339 & 760 \\ 196 & 592 & 752 & -1819 & 2473 \\ 546 & -105 & 634 & 386 & 341 \\ 372 & -222 & 451 & 518 & 99 \\ 233 & 30 & 436 & -250 & 619 \end{array}\right)
A
[-1 0 -4 3 -4] [-8 0 -7 -4 1] [ 0 -1 -1 5 -5] [ 0 -2 2 1 1] [-1 -1 0 -1 -1]
A.submatrix(1,2, 3, 3)
[-7 -4 1] [-1 5 -5] [ 2 1 1]
A.matrix_from_rows_and_columns([0,2,3],[0,2,3])
[-1 -4 3] [ 0 -1 5] [ 0 2 1]
v = {'A': ['B','F'],'B': ['C', 'F'],'C': ['E'],'D': ['E'],'E': ['F']} G = Graph(v)
M = G.adjacency_matrix(); M
[0 1 0 0 0 1] [1 0 1 0 0 1] [0 1 0 0 1 0] [0 0 0 0 1 0] [0 0 1 1 0 1] [1 1 0 0 1 0]
H=Graph(M) plot(G)
H.show()
G.vertices()
['A', 'B', 'C', 'D', 'E', 'F']
H.vertices()
[0, 1, 2, 3, 4, 5]
G.is_isomorphic(H)
True
N = G.incidence_matrix(); N
[1 1 0 0 0 0 0] [1 0 1 0 1 0 0] [0 0 1 1 0 0 0] [0 0 0 0 0 1 0] [0 0 0 1 0 1 1] [0 1 0 0 1 0 1]
H2 = Graph(N)
H
Graph on 6 vertices
H2
Graph on 6 vertices
H2.is_isomorphic(H)
True
M
[0 1 0 0 0 1] [1 0 1 0 0 1] [0 1 0 0 1 0] [0 0 0 0 1 0] [0 0 1 1 0 1] [1 1 0 0 1 0]
G2 = G.subgraph(['A', 'B', 'C', 'F']) G3 = G.subgraph(['A', 'B', 'F', 'C'])
G2.adjacency_matrix()
[0 1 0 1] [1 0 1 1] [0 1 0 0] [1 1 0 0]
G3.adjacency_matrix()
[0 1 0 1] [1 0 1 1] [0 1 0 0] [1 1 0 0]
G2.vertices()
['A', 'B', 'C', 'F']
G3.vertices()
['A', 'B', 'C', 'F']
H.edges(labels=False)
[(0, 1), (0, 5), (1, 2), (1, 5), (2, 4), (3, 4), (4, 5)]
G.add_vertex('G')
G.add_edges([('A', 'G'), ('G', 'H')])
plot(G)
H2 = Graph((G.adjacency_matrix())^2)
plot(H2)
v = { 'A': ['E','F'],'B': ['C','D','E','G'],'C': ['F','G'],'D': ['G'],'F': ['G']} # Nomeando os vértices de forma Simplificada
G = Graph(v) #Grafo G formado pelos vértices e arestas de v A = G.adjacency_matrix() #Nomeando A como Matriz de Adjacência G.vertices() #Identificando a ordenação dos vértices show(A) #Mostrar a Matriz de Adjacência A show(A^2) #Calcular e Mostrar a Potência 2 de A show(A^3) #Calcular e Mostrar a Potência 3 de A
['A', 'B', 'C', 'D', 'E', 'F', 'G']
(0000110001110101000110100001110000010100010111010)\displaystyle \left(\begin{array}{rrrrrrr} 0 & 0 & 0 & 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 & 1 & 0 & 1 \\ 0 & 1 & 0 & 0 & 0 & 1 & 1 \\ 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ 1 & 1 & 0 & 0 & 0 & 0 & 0 \\ 1 & 0 & 1 & 0 & 0 & 0 & 1 \\ 0 & 1 & 1 & 1 & 0 & 1 & 0 \end{array}\right)
(2110001141102211321120122111001121102111311221114)\displaystyle \left(\begin{array}{rrrrrrr} 2 & 1 & 1 & 0 & 0 & 0 & 1 \\ 1 & 4 & 1 & 1 & 0 & 2 & 2 \\ 1 & 1 & 3 & 2 & 1 & 1 & 2 \\ 0 & 1 & 2 & 2 & 1 & 1 & 1 \\ 0 & 0 & 1 & 1 & 2 & 1 & 1 \\ 0 & 2 & 1 & 1 & 1 & 3 & 1 \\ 1 & 2 & 2 & 1 & 1 & 1 & 4 \end{array}\right)
(0222342248654828432672632136352102344632272876376)\displaystyle \left(\begin{array}{rrrrrrr} 0 & 2 & 2 & 2 & 3 & 4 & 2 \\ 2 & 4 & 8 & 6 & 5 & 4 & 8 \\ 2 & 8 & 4 & 3 & 2 & 6 & 7 \\ 2 & 6 & 3 & 2 & 1 & 3 & 6 \\ 3 & 5 & 2 & 1 & 0 & 2 & 3 \\ 4 & 4 & 6 & 3 & 2 & 2 & 7 \\ 2 & 8 & 7 & 6 & 3 & 7 & 6 \end{array}\right)
G2 = Graph(A^2)
plot(G)
G.vertices()
['A', 'B', 'C', 'D', 'E', 'F', 'G']
G.degree(labels=True)
{'A': 2, 'C': 3, 'B': 4, 'E': 2, 'D': 2, 'G': 4, 'F': 3}
G.degree()
[2, 3, 4, 2, 2, 4, 3]
G.degree(vertices=G.vertices())
[2, 4, 3, 2, 2, 3, 4]
( .adjacency_matrix()^2).diagonal()
[2, 4, 3, 2, 2, 3, 4]