简体   繁体   中英

Java - Possible to draw a basic force-directed undirected Graph (Vertices, Edges)?

I am trying to create a class in Java that will extend another class called Graph.

The outline of the graph class is as follows:

  • Graph constructor
  • adjacent(int i, int j)
  • addEdge, removeEdge methods
  • addVertex, removeVertex methods
  • neighbors method
  • numOfEdges method
  • averageDegree method
  • girth method

I want to know if it possible to draw a very very basic force-directed undirected graph in Java using the graph class that I have made. I want my graph to be visually pleasing!

If so, can anyone point me in the right direction?

What is your question, exactly? If you ask whether your class contains enough information to allow applying a force-based layout, then obviously, the answer is no: you at least need to represent the position of the nodes ^^ (eg using additional x and y nodal attributes).

Regarding the algorithm itself, are you interested in the process of implementing it yourself, or just in the result: displaying your graph in a nice way? In the former case, you could start by having a look at seminal papers such as ( Fruchterman & Reingold '91 ) or ( Kamada & Kawai '89 ). Both articles explicitly give the proposed algorithm. In the latter case, you could have a look at existing implementations, there're so many of them. Maybe the most convenient for you would be Gephi 's layout-related class, since this open source software ( available on GitHub ) is itself written in Java.

In any case, you can also have a look at the other SO posts related to this topic, such as Kamada & Kawai graph layout algorithm? or Force-directed graphing .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM