Questions tagged [jgrapht]

JGraphT is a free Java graph library that provides mathematical graph-theory objects and algorithms.

JGraphT supports various types of graphs including:

  • directed and undirected graphs.
  • graphs with weighted / unweighted / labeled or any user-defined edges.
  • various edge multiplicity options, including: simple-graphs, multigraphs, pseudographs.
  • unmodifiable graphs - allow modules to provide "read-only" access to internal graphs.
  • listenable graphs - allow external listeners to track modification events.
  • subgraphs graphs that are auto-updating subgraph views on other graphs.
  • all compositions of above graphs. Although powerful, JGraphT is designed to be simple and type-safe (via Java generics). For example, graph vertices can be of any objects. You can create graphs based on: Strings, URLs, XML documents, etc; you can even create graphs of graphs! This code example shows how.

Other features offered by JGraphT:

  • graph visualization using the JGraph library
  • complete source code included, under the terms of the GNU Lesser General Public License.
  • comprehensive Javadocs.
  • easy extensibility.

Official website: http://jgrapht.org/

303 questions
5
votes
1 answer

Computing nearest vertex neighbors in a DAG completed by transitive-closure

Consider a directed graph, like this: Where, (A) initially, the solid black edges are asserted: 0 → {1,3} 1 → {2} 3 → {4} 4 → {2} Then (B) the transitive closure has then been computed to add the…
user206428
5
votes
2 answers

How to copy a graph in JGraphT?

I need make a copy of a simple graph. I don't see a graph duplicator among graph generators and UndirectedGraph doesn't implement a clone method. Year, I can copy a graph by hands. But I want to do this in one line.
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
5
votes
1 answer

Show weights in JgraphT

I have implemented this Graph: ListenableDirectedWeightedGraph g = new ListenableDirectedWeightedGraph(MyWeightedEdge.class); In order to show what the class name says; a simple listenable…
user5915
  • 253
  • 2
  • 5
  • 8
4
votes
1 answer

Determine edges belonging to triads in networks

I have edges of a network: var links = [ {source: "A", target: "D", type: "high"}, {source: "A", target: "K", type: "high"}, {source: "B", target: "G", type: "high"}, {source: "H", target: "B", type: "high"}, {source: "C", target: "A",…
jalapic
  • 13,792
  • 8
  • 57
  • 87
4
votes
2 answers

Avoid creation of duplicate vertices in digraph (using jgrapht)

I am looking for a way to avoid creating duplicates in my digraph (I use the jgrapht library). I read some topics which said to use: directedGraph.setCloneable(false); But it doesn't seem to be right, can't find it in the library's documentation…
Graham Slick
  • 6,692
  • 9
  • 51
  • 87
4
votes
2 answers

Custom Edge with jgrapht

I want to define a custom edge public class Connection extends DefaultWeightedEdge But when I try to use the super()is that possible? What should I use for EdgeFactory when creating a graph? new SimpleWeightedGraph
padawan
  • 1,295
  • 1
  • 17
  • 45
4
votes
0 answers

Route planning in public transport application

I'm making a journey planner (or a general timetable application) for all the public transport in my country (bus/train/air). The state of the project is at midpoint, now I'm having a bit of a hard time getting the more difficult part of the…
ekstrakt
  • 900
  • 1
  • 12
  • 28
4
votes
1 answer

Merge graphs in JGraphT

I'm using JGraphT and I have two DirectedGraph : g1 and g2. How can I merge g1 and g2 to a third graph g3? I need g3 be a normal graph and has the ability to add new edges and vertices.
masoud
  • 55,379
  • 16
  • 141
  • 208
3
votes
0 answers

JGraphT: Inconsistent graph size for same dataset

Version: 1.3.0 Graph Requirement: Child will have many parents or none. Data Node: Id + List [Parent ids] class Node { String id; List parents; } Total dataset: 3500 nodes. GraphType is selected using : Directed + No Multiple Edges…
Amit Gupta
  • 41
  • 2
3
votes
1 answer

JGraphT: Finding shortest path regardless of Edge Direction

I build the following graph A->B<-C using JGraphT as seen below: DirectedPseudograph graph = new DirectedPseudograph<>(Edge.class); DijkstraShortestPath shortestPath = new DijkstraShortestPath(graph); …
p192
  • 518
  • 1
  • 6
  • 19
3
votes
1 answer

Java:JGraphT add edges using a loop

Is it possible to add edges to a graph through the use of a loop? I am parsing a String to determine the appropriate edges and labels. For some reason it will only add the edge for the first round of the while loop used to iterate through the…
user663584
  • 31
  • 1
  • 2
3
votes
2 answers

Longest path in directed acyclic graph in jgrapht library

I want to find the longest path in directed (acyclic) graph. Let's say that I know starting node - sink. The path should begin from this point. I was thinking that I can set weights of edges to -1. There is many methods of finding all shortest path…
3
votes
1 answer

How to determine if two vertices are connected in a graph

SimpleWeightedGraph g = new SimpleWeightedGraph<>(DefaultWeightedEdge.class); String v1 = "v1"; String v2 = "v2"; String v3 = "v3"; // add the vertices g.addVertex(v1); g.addVertex(v2); …
Jason Z
  • 265
  • 1
  • 6
  • 12
3
votes
1 answer

Changing the color of an edge using JGraphXAdapter

I'm using the JGraphT library, in particular JGraphXAdapter to display graphs using JGraphX. I would like to change the color of a few edges (not all of them). My question is, how can that be accomplished? (I know how to change the default style for…
Edward Doolittle
  • 4,002
  • 2
  • 14
  • 27
3
votes
3 answers

How to label or color a vertex using jgrapht libraries?

I am interested in writing a graph coloring algorithm using various types of directed and undirected graph classes provided by jgrapht. None of them seem to have an easy ability to do this within the graph class itself (e.g. DirectedSimpleGraph). …
Steven Barkin
  • 99
  • 1
  • 2
  • 8
1
2
3
20 21