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
37
votes
5 answers

How can I serialize a jgrapht simple graph to json?

I have a simple directed graph from jgrapht and I am trying to serialize it into a JSON file using jackson as follows: ObjectMapper mapper = new ObjectMapper(); File output = new File("P:\\tree.json"); ObjectWriter objectWriter =…
yann89
  • 371
  • 2
  • 4
17
votes
1 answer

Is it possible to check for the winning condition of a game of TicTacToe using jGraphT?

I found this working solution: private int[] winningPatterns = { 0b111000000, 0b000111000, 0b000000111, // rows 0b100100100, 0b010010010, 0b001001001, // cols 0b100010001, 0b001010100 // diagonals }; /** Returns true if thePlayer…
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
17
votes
2 answers

Protected? getSource and getTarget methods on JGraphT DefaultEdge class

The methods getSource() and getTarget() of DefaultEdge on org.jgrapht.graph.DefaultEdge are protected. How should I access source and target vertices of each of the edges returned by the edgeSet() of org.jgrapht.graph.SimpleGraph ? The code below…
Jose Ospina
  • 2,097
  • 3
  • 26
  • 40
15
votes
3 answers

Running Neo4j purely in memory without any persistence

I don't want to persist any data but still want to use Neo4j for it's graph traversal and algorithm capabilities. In an embedded database, I've configured cache_type = strong and after all the writes I set the transaction to failure. But my write…
cprsd
  • 473
  • 4
  • 13
14
votes
1 answer

Finding all the paths between two vertices with weight limit in a directed graph

I'm trying to find all the paths between two vertices that have weight less than N in a directed weighted graph that may have loops but not self-loops. So far, I could do it only by using AllDirectedPaths and then filter out the paths that have…
ouid
  • 393
  • 1
  • 13
12
votes
1 answer

How to include weight in edge of graph?

I want to include weights or costs of the edge on my graph using this jgrapht interface-class: package org.jgrapht; public interface WeightedGraph extends Graph { public static final double…
user3025494
  • 119
  • 1
  • 2
  • 5
11
votes
1 answer

Automatic Layout for a Graph (JGraphX)

I have trouble to display a JGraphX with automatic layout. My program (code below) creates an output like this: A sufficiant result could be look like this (I moved them by hand): I do not have to stick with JGraphX. I also tested JUNG and…
froehli
  • 904
  • 1
  • 11
  • 35
8
votes
5 answers

Getting all edges going out from a node in jgrapht

I am trying to randomly traverse through the graph in jgrapht (until I find some target node). To do it, I need to start at the sourceNode, randomly pick any coming out edge and follow it. I know there there is a method getAllEdges(sourceVertex,…
TheMP
  • 8,257
  • 9
  • 44
  • 73
8
votes
2 answers

JGraphT examples

I would like to plot lines on a simple x,y graph to display in a JApplet using JGraphT. The examples I found were not very helpful. Could someone please point me to a few simple JGraphT examples?
Paul Lombardi
  • 131
  • 2
  • 2
  • 9
7
votes
1 answer

How to draw a SimpleWeightedGraph on a JPanel?

I have a SimpleWeightedGraph and I want to draw it on a JPanel in a JFrame. Unfortunately nothing is drawn. I read this article. They are using a ListenableDirectedGraph so I tried a ListenableUndirectedGraph with no success. public class…
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
7
votes
3 answers

Graph Theory: Find the Jordan center?

I'm trying to find the set of vertices that minimizes their distance to other vertices on a weighted graph. Based on a cursory wikipedia search, I think that this is called the Jordan Center. What are some good algorithms for finding it? Right now,…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
6
votes
1 answer

How to use the DepthFirstSearchIterator class to run a depth first search on a graph using JGraphT

I am experimenting with JGraphT and have hit a brick wall trying to implement a depth first search using the JGraphT API. I have created a simple graph with nodes and vertices's as follows: DirectedGraph graph = new …
kazuwal
  • 1,071
  • 17
  • 25
6
votes
2 answers

How represent edge weight via JGraphT visualization?

I tried create a Java JGraphT visualization with Weight, for example: Now I want to change the edge label (ex: (a:b) to its edge weight (ex: 2). I tried to search in Javadoc but didn't see anything. Please help me thank you!
Kyris
  • 61
  • 1
  • 3
5
votes
2 answers

How to do Topological Sort (Dependency Resolution) with Java

Description The purpose of the question is to implement an interface that will order a list of tasks according to the information about their dependencies. For example, if task A has a dependency on tasks B and C, this means that to start working on…
Dzikoŭski
  • 69
  • 1
  • 7
5
votes
2 answers

Cannot invoke method version() on null object

i'm trying to use the Jgrapht library but it needs lambdas... Here's my code: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { maven { url…
Piero Tozzi
  • 219
  • 2
  • 3
  • 4
1
2 3
20 21