The Fruchterman-Reingold algorithm is a type of force-directed graph drawing algorithm designed to arrange the nodes of a graph in a two-dimensional or three-dimensional space in an aesthetically pleasing manner. It aims to ensure that the edges between nodes are of approximately equal length and that edge crossings are minimized. This is achieved by assigning attractive and repulsive forces to the edges and nodes based on their positions and then adjusting these positions to simulate motion or minimize the overall energy of the system (this is measured through system temperature and cooling factors), resulting in a more visually appealing graph layout.
The visualizer is fully programmed in C using SDL2 (Simple DirectMedia Layer) for interactivity and visuals.
Key(s) | Action |
---|---|
WASD | Grid panning, allows for moving the demo grid and nodes |
Mouse Scoll | Adjusts zoom level on demo grid |
LEFT/RIGHT Arrow Keys | One frame adjustments (rev or fwd) |
Space Bar | Play/Pause |
There will be auto-generated nodes and edges on the visualizer upon starting. To generate new randomized node locations, click the "Generate Nodes" button.
Make sure you have both SDL2 and SDL2_ttf installed on your system. You can usually install them via your package manager
i.e MacOS using brew install sdl2 sdl2_ttf
. Also ensure you have a C compiler and make installed or you may have to do some adjustments to the MakeFile.
Start by cloning and navigating to the project,
git clone https://github.com/OP-Patel/Fruchterman-Reingold_Visualizer.git
cd Fruchterman-Reingold_Visualizer
Then simply write,
make
./build/debug/play
Below are some examples of the Fruchterman-Reingold algorithm at play using different input graphs.
Fruchterman-Reingold | GraphViz |
---|---|
Large-scale Graph | |
K6 Graph |
|
Binary Tree |