canReach checks if there is a path from the start vertex to the end vertex.
(start, end VertexType)
| 140 | |
| 141 | // canReach checks if there is a path from the start vertex to the end vertex. |
| 142 | func (g *Graph[EdgeType, VertexType]) canReach(start, end VertexType) bool { |
| 143 | if start == end { |
| 144 | return true |
| 145 | } |
| 146 | |
| 147 | startID, startExists := g.vertexToID[start] |
| 148 | endID, endExists := g.vertexToID[end] |
| 149 | |
| 150 | if !startExists || !endExists { |
| 151 | return false |
| 152 | } |
| 153 | |
| 154 | // Use gonum's built-in path existence check |
| 155 | return topo.PathExistsIn(g.gonumGraph, simple.Node(startID), simple.Node(endID)) |
| 156 | } |
| 157 | |
| 158 | // ToDOT exports the graph to DOT format for visualization |
| 159 | func (g *Graph[EdgeType, VertexType]) ToDOT(name string) (string, error) { |