The problem is I have 10 nodes(say) and there are some connections between them. Now I want to draw a visual graph depicting the above with circles as nodes and lines as connections between them. My problem is what is the algorithm for placement of nodes on screen, say we have drawn one circle, then the other circle should be drawn as non-overlapping as possible. Please explain.
views:
554answers:
1There are quite a few ways of approaching this problem, because there are a number of goals in graph drawing which aren't mutually compatible. Things to avoid include
- the number of crossing edges
- the total surface area occupied and overall shape (compactness, aspect ratio)
- overly long edges
- small angles between edges (overlapping edges)
Here are a few approaches.
An easy one to code is to place your nodes on a circle, and space them evenly. Then add your edges as straight lines. This will 'mostly work'.
More general is to model your nodes as springs which mutually repel one another. This the idea behind the Kamada-Kawai algorithm, for example. It keeps the nodes apart while minimising edge length.
A third approach is radial layout, where nodes are placed on concentric rings that indicate their distance from a chosen root node.
I recommend you check out the Graphviz package to get an idea of what's possible. It's easy to use and fun to mess around with. There are bindings to the Graphviz libraries available in a number of languages, but unfortunately Visual Basic doesn't seem to be one of them.
Edit: This question is related.