Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import graph as g
  2.  
  3.  
  4. def Revise(edge):
  5. revised = False
  6. first_node = edge.first_node
  7. last_node = edge.second_node
  8.  
  9. #print("First Node:")
  10. #print(first_node)
  11. #print("Last Node:")
  12. #print(last_node)
  13. # print("F_D:")
  14. # print(g.node_list[first_node])
  15. # print("L_D:")
  16. # print(g.node_list[last_node])
  17. i=0
  18. while True:
  19. cnt = 0
  20. if(len(g.node_list[first_node])==0):
  21. break
  22. for j in range(len(g.node_list[last_node])):
  23. constraint_index = g.edge_list.index(edge)
  24. constraint_no = g.edge_list[constraint_index].constraint_no
  25. #print("const No ",constraint_no)
  26. func = g.constraints_list(constraint_no)
  27. #print("hello ",i," ",g.node_list[first_node][i]," ",j," ",g.node_list[last_node][j])
  28. if func(g.node_list[first_node][i], g.node_list[last_node][j]) == True:
  29. cnt = cnt + 1
  30. i+=1
  31. break
  32. if cnt == 0:
  33. g.node_list[first_node].remove(g.node_list[first_node][i])
  34. revised = True
  35.  
  36.  
  37. if(i==len(g.node_list[first_node])):
  38. break
  39.  
  40. # print("Middle")
  41.  
  42.  
  43.  
  44. # print("F_D:")
  45. # print(g.node_list[first_node])
  46. # print("L_D:")
  47. # print(g.node_list[last_node])
  48.  
  49.  
  50. i=0
  51. while True:
  52. if(len(g.node_list[last_node])==0):
  53. break
  54. cnt = 0
  55. for j in range(len(g.node_list[first_node])):
  56. constraint_index = g.edge_list.index(edge)
  57. constraint_no = g.edge_list[constraint_index].constraint_no
  58. #print("const No R",constraint_no)
  59. func = g.constraints_list(constraint_no)
  60. #print("hello R",i," ",g.node_list[last_node][i]," ",j," ",g.node_list[first_node][j])
  61. if func(g.node_list[last_node][i], g.node_list[first_node][j]) == True:
  62. cnt = cnt + 1
  63. i+=1
  64. break
  65.  
  66. if cnt == 0:
  67. g.node_list[last_node].remove(g.node_list[last_node][i])
  68. revised = True
  69.  
  70.  
  71. if(i==len(g.node_list[last_node])):
  72. break
  73.  
  74.  
  75. return revised
  76.  
  77.  
  78. def AC_1():
  79. total_node = g.total_node
  80. total_edge = g.total_edge
  81.  
  82. change = False
  83.  
  84. while(not change):
  85. change = False
  86. for i in range(total_edge):
  87. if Revise(g.edge_list[i]) == True:
  88. change = True
  89.  
  90.  
  91. AC_1()
  92. print("After")
  93. for nodes in g.node_list:
  94. print(nodes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement