This applet illustrates a method that attempts to improve the layout of a graph. This applet is highly inspired from the demonstration applet called GraphLayout in Java 2 SDK of Sun Microsystems. The main idea of the algorithm is to start with random coordinates for the nodes of the graph and simulate forces between this nodes in order to reach a balance that is supposed to be a good layout for the graph. The result is quite good for small graphs, but the method is generally inefficient for large graphs. Briefly, each arc of the graph creates an attraction force between its two extremities that grows with its length. On the contrary, between every pair of nodes is a repulsion force that grows when the distance between the nodes decreases. If you are interested on this applet, look at the page .
To use this applet, you have to indicate the size of the layout and to describe the structure of the graph. The structure of the graph is specified by a string of characters in the parameter graph. It simply lists the arcs of the graph. For instance, the graph above will be specified as follows.
Be careful to number the nodes from 0 and to avoid jumps in the numbering. The applet can then attempt to find a good layout for the graph.
Here is the source code of the applet:
Click here to download the applet and its source code. |