Removes the edge between the two vertices. If any given vertex doesn't exist or the edge does not exist, a ValueError will be thrown.
(self, source_vertex: T, destination_vertex: T)
| 88 | self.adj_matrix[v][u] = 1 |
| 89 | |
| 90 | def remove_edge(self, source_vertex: T, destination_vertex: T) -> None: |
| 91 | """ |
| 92 | Removes the edge between the two vertices. If any given vertex |
| 93 | doesn't exist or the edge does not exist, a ValueError will be thrown. |
| 94 | """ |
| 95 | if not ( |
| 96 | self.contains_vertex(source_vertex) |
| 97 | and self.contains_vertex(destination_vertex) |
| 98 | ): |
| 99 | msg = ( |
| 100 | f"Incorrect input: Either {source_vertex} or " |
| 101 | f"{destination_vertex} does not exist" |
| 102 | ) |
| 103 | raise ValueError(msg) |
| 104 | if not self.contains_edge(source_vertex, destination_vertex): |
| 105 | msg = ( |
| 106 | "Incorrect input: The edge does NOT exist between " |
| 107 | f"{source_vertex} and {destination_vertex}" |
| 108 | ) |
| 109 | raise ValueError(msg) |
| 110 | |
| 111 | # Get the indices of the corresponding vertices and set their edge value to 0. |
| 112 | u: int = self.vertex_to_index[source_vertex] |
| 113 | v: int = self.vertex_to_index[destination_vertex] |
| 114 | self.adj_matrix[u][v] = 0 |
| 115 | if not self.directed: |
| 116 | self.adj_matrix[v][u] = 0 |
| 117 | |
| 118 | def add_vertex(self, vertex: T) -> None: |
| 119 | """ |