For Boruvks's algorithm the weights should be distinct Converts the weights to be distinct
(self)
| 33 | self.adjacency[tail][head] = weight |
| 34 | |
| 35 | def distinct_weight(self): |
| 36 | """ |
| 37 | For Boruvks's algorithm the weights should be distinct |
| 38 | Converts the weights to be distinct |
| 39 | |
| 40 | """ |
| 41 | edges = self.get_edges() |
| 42 | for edge in edges: |
| 43 | head, tail, weight = edge |
| 44 | edges.remove((tail, head, weight)) |
| 45 | for i in range(len(edges)): |
| 46 | edges[i] = list(edges[i]) |
| 47 | |
| 48 | edges.sort(key=lambda e: e[2]) |
| 49 | for i in range(len(edges) - 1): |
| 50 | if edges[i][2] >= edges[i + 1][2]: |
| 51 | edges[i + 1][2] = edges[i][2] + 1 |
| 52 | for edge in edges: |
| 53 | head, tail, weight = edge |
| 54 | self.adjacency[head][tail] = weight |
| 55 | self.adjacency[tail][head] = weight |
| 56 | |
| 57 | def __str__(self): |
| 58 | """ |