Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. # schedule
  2.  
  3. schedule = "r1(x) r1(y) w2(x) w1(x) r2(y)".split(' ')
  4. final_schedule = {}
  5. cycles = {}
  6.  
  7. i_index = 0
  8.  
  9. for i in schedule:
  10. i_index += 1
  11. i_operation_type, i_transaction, i_operator = i[0], i[1], i[3]
  12. j_index = 0
  13. for j in schedule:
  14. j_index += 1
  15. j_operation_type, j_transaction, j_operator = j[0], j[1], j[3]
  16. if((i_transaction != j_transaction) and (i_operator == j_operator) and (i_operation_type+''+j_operation_type != 'rr') and j_index > i_index):
  17. if(i_transaction + '' + j_transaction not in final_schedule.values()):
  18. final_schedule[i + '-->' + j] = i_transaction + '' + j_transaction
  19.  
  20. # print(final_schedule)
  21.  
  22. for k,v in final_schedule.items():
  23. for k1,v1 in final_schedule.items():
  24. if(v == v1[::-1]):
  25. cycles[k] = v
  26.  
  27. print("Schedule: ")
  28. for k,v in final_schedule.items():
  29. print('T'+v[0]+' --> '+'T'+v[1])
  30.  
  31. if(len(cycles)):
  32. print("Cycles found: ")
  33. for k,v in cycles.items():
  34. print('T'+v[0]+' --> '+'T'+v[1], end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement