I'm looking for where best to start on the following problem.
I have a graph of N nodes and each node as a weight. I need to group all nodes into X groups such that the sum of weights in each group are approximately even and that each group is a connected component of the original graph.
After some simple searching I came across the lukes partitioning algorithm implemented in python.
This is approximately what I am looking for but performance feels slow for the size of the graph I am working with.
Do you have any potentially better ideas that worked for you?
Thank so much for the pastebin link, I managed to write my own code as well. Its not nearly as neat and efficient as Stevens.
https://pastebin.com/a21v2Nxz
I still think you are miss understanding my problems with the algorithm
I entirely believe it will colour each node without stopping
My main issue is its not guaranteed or even likely the colouring will be balanced.
Imagine a line graph with uniform weightage, and your random choice of starting classes is the first k nodes on the line graph.
Hopefully I am correct in saying that the only colour capable of growing in size in that situation is the which ever colour is the final colour (i.e. the kth colour on the line graph)
A situation like the simple graph below, where there are 4 coulours and n nodes in the line graph.
red - blue - green - yellow - null - null - ... - null
The solution to this problem I figured was a montecarlo like approach. The algorithm runs fast enough that you can do it many times, and choose which one is the best of all the attempts. That's the main addition to my code