Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.96 KB | None | 0 0
  1. #NEED PYTHON 3.6
  2. import networkx as nx
  3. from networkx.algorithms import find_cliques
  4. from networkx.algorithms import is_connected
  5.  
  6. charOffset = 97
  7. table = [[0,0,0,1.118033988749895,0,1.0,0,0,1.4142135623730951,1.5,0,1.4142135623730951,0,0,0,0,1.0,1.224744871391589,1.4352700094407325,1.4352700094407325,0,0,0,0,0],[0,0,0,1.118033988749895,0.5,0,0,1.4142135623730951,0,0,1.118033988749895,1.0,0,1.1981652640600127,0,1.0530432089900206,0,0.7071067811865476,0,0,0,0.7348469228349535,0.6557438524302001,0.9110433579144298,0],[0,0,0,0.5,0,1.0,0.7071067811865476,0,1.4142135623730951,0,0,1.4142135623730951,1.7320508075688772,0,0,0,0,0,0.5099019513592785,0,0,0,0.6557438524302001,0.9110433579144298,0],[1.118033988749895,1.118033988749895,0.5,0,0,0,0.5,0,1.118033988749895,1.0,0,0,0,0,0,1.1657186624567697,0,0.8660254037844386,0,1.1445523142259597,0,0,0,0,0.5385164807134505],[0,0.5,0,0,0,1.118033988749895,0,0,0,1.4142135623730951,1.0,0,0,0.8280096617793781,0.5099019513592785,0,0,0,1.1445523142259597,0,0,0.5385164807134505,0.6164414002968976,0,0],[1.0,0,1.0,0,1.118033988749895,0,0,0,1.0,1.118033988749895,1.5,0,0,0,1.268857754044952,1.0530432089900206,0,0,0,0,0,0.7348469228349535,0.9110433579144298,0,0.7348469228349535],[0,0,0.7071067811865476,0.5,0,0,0,0,0,0,0,0,0,0,1.004987562112089,0,1.224744871391589,0.7071067811865476,0.5099019513592785,0,0,0,0,0,0.58309518948453],[0,1.4142135623730951,0,0,0,0,0,0,1.0,0,0,1.0,1.4142135623730951,0,1.1874342087037917,0,0,0,0.5099019513592785,0,0,0,0.9110433579144299,1.1090536506409416,1.0677078252031311],[1.4142135623730951,0,1.4142135623730951,1.118033988749895,0,1.0,0,1.0,0,0,0,1.4142135623730951,1.0,0,0,0,1.7320508075688772,0,0,1.1224972160321824,0,0,0,0,0],[1.5,0,0,1.0,1.4142135623730951,1.118033988749895,0,0,0,0,0,0,0,0,0,0,1.5,0,0.714142842854285,0.714142842854285,0.7071067811865476,0,0,0.8831760866327847,0],[0,1.118033988749895,0,0,1.0,1.5,0,0,0,0,0,0.5,0,0.604648658313239,0.5099019513592785,0.8360023923410745,1.118033988749895,0,0,0,0,0,0,0,0.9433981132056605],[1.4142135623730951,1.0,1.4142135623730951,0,0,0,0,1.0,1.4142135623730951,0,0.5,0,0,1.0562196741208714,0,0,1.0,0,0,0,0,0,0.9110433579144299,0,0],[0,0,1.7320508075688772,0,0,0,0,1.4142135623730951,1.0,0,0,0,0,0.33999999999999997,0,0,0,0,0,1.1224972160321824,0,1.0677078252031311,0,0,1.0677078252031311],[0,1.1981652640600127,0,0,0.8280096617793781,0,0,0,0,0,0.604648658313239,1.0562196741208714,0.33999999999999997,0,0.6209669878504009,0,0,0,1.354843164355196,0,0,0,0.9325234581499813,0,0],[0,0,0,0,0.5099019513592785,1.268857754044952,1.004987562112089,1.1874342087037917,0,0,0.5099019513592785,0,0,0.6209669878504009,0,0.6236184731067546,0,0.6403124237432849,0,0,0.5099019513592785,0,0,0,0],[0,1.0530432089900206,0,1.1657186624567697,0,1.0530432089900206,0,0,0,0,0.8360023923410745,0,0,0,0.6236184731067546,0,0,0,0,0,0.7272551134230683,0.7189575787207476,0,0.5838664230798,0],[1.0,0,0,0,0,0,1.224744871391589,0,1.7320508075688772,1.5,1.118033988749895,1.0,0,0,0,0,0,0,0,0,0,0,0,0,0.7348469228349535],[1.224744871391589,0.7071067811865476,0,0.8660254037844386,0,0,0.7071067811865476,0,0,0,0,0,0,0,0.6403124237432849,0,0,0,0,0.4,0.5,0,0,0,0],[1.4352700094407325,0,0.5099019513592785,0,1.1445523142259597,0,0.5099019513592785,0.5099019513592785,0,0.714142842854285,0,0,0,1.354843164355196,0,0,0,0,0,0.5656854249492381,0,0,0,0,0],[1.4352700094407325,0,0,1.1445523142259597,0,0,0,0,1.1224972160321824,0.714142842854285,0,0,1.1224972160321824,0,0,0,0,0.4,0.5656854249492381,0,0.6403124237432849,0,0,0,0],[0,0,0,0,0,0,0,0,0,0.7071067811865476,0,0,0,0,0.5099019513592785,0.7272551134230683,0,0.5,0,0.6403124237432849,0,0,0.282842712474619,0.28284271247461906,0],[0,0.7348469228349535,0,0,0.5385164807134505,0.7348469228349535,0,0,0,0,0,0,1.0677078252031311,0,0,0.7189575787207476,0,0,0,0,0,0,0,0.22360679774997896,0],[0,0.6557438524302001,0.6557438524302001,0,0.6164414002968976,0.9110433579144298,0,0.9110433579144299,0,0,0,0.9110433579144299,0,0.9325234581499813,0,0,0,0,0,0,0.282842712474619,0,0,0,0],[0,0.9110433579144298,0.9110433579144298,0,0,0,0,1.1090536506409416,0,0.8831760866327847,0,0,0,0,0,0.5838664230798,0,0,0,0,0.28284271247461906,0.22360679774997896,0,0,0],[0,0,0,0.5385164807134505,0,0.7348469228349535,0.58309518948453,1.0677078252031311,0,0,0.9433981132056605,0,1.0677078252031311,0,0,0,0.7348469228349535,0,0,0,0,0,0,0,0]]
  8.  
  9. G = nx.Graph()
  10. G.add_nodes_from(list(range(0,25)))
  11.  
  12. for i in range(0,25):
  13.     for j in range(i+1,25):
  14.         if table[i][j]:
  15.             G.add_edge(i,j, weight= table[i][j])           
  16.             #G.add_edge(i,j)
  17. listClique = list(find_cliques(G))
  18.  
  19. nb3clique = 0
  20. nbNonTriangle = 0
  21. nbTriangle = 0
  22. for clique in listClique:
  23.     if len(clique)==3:
  24.         nb3clique+=1
  25.         listClique = list(clique)
  26.         distList = []
  27.         for i in range (0,3):
  28.             dist = G[listClique[i]][listClique[(i+1)%3]]["weight"]
  29.             distList.append(dist)
  30.         C = max(distList)
  31.         distList.remove(C)
  32.         if C > distList[0] + distList[1]:
  33.             nbNonTriangle += 1
  34.         else:
  35.             nbTriangle += 1
  36. print(f'nb3clique: {nb3clique} nbNonTriangle: {nbNonTriangle} nbTriangle: {nbTriangle}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement