Returns True if the graph contains the edge from the source_vertex to the destination_vertex, False otherwise. If any given vertex doesn't exist, a ValueError will be thrown.
(self, source_vertex: T, destination_vertex: T)
| 169 | return vertex in self.vertex_to_index |
| 170 | |
| 171 | def contains_edge(self, source_vertex: T, destination_vertex: T) -> bool: |
| 172 | """ |
| 173 | Returns True if the graph contains the edge from the source_vertex to the |
| 174 | destination_vertex, False otherwise. If any given vertex doesn't exist, a |
| 175 | ValueError will be thrown. |
| 176 | """ |
| 177 | if not ( |
| 178 | self.contains_vertex(source_vertex) |
| 179 | and self.contains_vertex(destination_vertex) |
| 180 | ): |
| 181 | msg = ( |
| 182 | f"Incorrect input: Either {source_vertex} " |
| 183 | f"or {destination_vertex} does not exist." |
| 184 | ) |
| 185 | raise ValueError(msg) |
| 186 | |
| 187 | u = self.vertex_to_index[source_vertex] |
| 188 | v = self.vertex_to_index[destination_vertex] |
| 189 | return self.adj_matrix[u][v] == 1 |
| 190 | |
| 191 | def clear_graph(self) -> None: |
| 192 | """ |