Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Components function #171

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

orzel7
Copy link

@orzel7 orzel7 commented Apr 7, 2024

Resolves #163

@bodgit
Copy link

bodgit commented Dec 6, 2024

This doesn't appear to be working fully, unless I'm misunderstanding something. Consider this example:

g := graph.New(graph.StringHash)

_ = g.AddVertex("A")
_ = g.AddVertex("B")
_ = g.AddVertex("C")
_ = g.AddVertex("D")
_ = g.AddVertex("E")
_ = g.AddVertex("F")
_ = g.AddVertex("G")
_ = g.AddVertex("H")

_ = g.AddEdge("A", "B")
_ = g.AddEdge("A", "C")
_ = g.AddEdge("A", "D")
_ = g.AddEdge("B", "C")
_ = g.AddEdge("C", "D")
_ = g.AddEdge("D", "E")
_ = g.AddEdge("E", "F")
_ = g.AddEdge("E", "G")
_ = g.AddEdge("E", "H")
_ = g.AddEdge("F", "G")
_ = g.AddEdge("G", "H")

file, _ := os.Create("graph.dot")
_ = draw.DOT(g, file)

_ = g.RemoveEdge("D", "E")

components, _ := Components(g)

for i, component := range components {
	file, _ := os.Create(fmt.Sprintf("component%d.dot", i))
	_ = draw.DOT(component, file)
}

This creates a graph like so:
graphviz

I then remove edge D-E which should split this into two separate graphs while still retaining every other edge, but I end up with these:
graphviz-2
graphviz-3

Many of the edges are now missing; A-C, A-D & C-D from one graph, and F-G & G-H from the other. It varies slightly depending on which vertex is used as a starting point but it always loses some edges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to split graph into disconnected subgraphs
3 participants