| 264 | |
| 265 | |
| 266 | class UndirectedGraph(Graph): |
| 267 | def __init__(self, V, E): |
| 268 | """ |
| 269 | A generic undirected graph object. |
| 270 | |
| 271 | Parameters |
| 272 | ---------- |
| 273 | V : list |
| 274 | A list of vertex IDs. |
| 275 | E : list of :class:`Edge <numpy_ml.utils.graphs.Edge>` objects |
| 276 | A list of edges connecting pairs of vertices in ``V``. For any edge |
| 277 | connecting vertex `u` to vertex `v`, :class:`UndirectedGraph |
| 278 | <numpy_ml.utils.graphs.UndirectedGraph>` will assume that there |
| 279 | exists a corresponding edge connecting `v` to `u`, even if this is |
| 280 | not present in `E`. |
| 281 | """ |
| 282 | super().__init__(V, E) |
| 283 | self.is_directed = False |
| 284 | |
| 285 | def _build_adjacency_list(self): |
| 286 | """Encode undirected, unweighted graph as an adjancency list""" |
| 287 | # assumes no parallel edges |
| 288 | # each edge appears twice as (u,v) and (v,u) |
| 289 | for e in self.edges: |
| 290 | fr_i = self._V2I[e.fr] |
| 291 | to_i = self._V2I[e.to] |
| 292 | |
| 293 | self._G[fr_i].add(e) |
| 294 | self._G[to_i].add(e.reverse()) |
| 295 | |
| 296 | |
| 297 | ####################################################################### |
no outgoing calls