Inserting a vertex in a GraphPath in Jgrapht

How can I create a new path by expanding an existing one in a graph with JgraphT e.g. after I get the shortest path between two vertices, how can I expand it by inserting an adjacent node in between the vertices that make up the path? Assume I have a path that looks like that specified below: Before Insertion VertexList:-> [1, 29, 191, 189, 126, 243, 197] EdgeList:-> [((1) : (29)), ((29) : (191)), ((191) : (189)), ((189) : (126)), ((126) : (243)), ((243) : (197))] Adjacent vertex to vertex 191 -> 44After Insertion VertexList:...Read more

Do the function “GetDiameter” in JGraphT cost much internal memory?

Here is the problem:Recently I would like to use JGraphT to get the diameter from a graph with 5 million vertices.But it shows that "out of memory java heap space" even I add -Xmx 500000m.How could I solve this issue? Thanks a lot!Here is the part of my code:public static void main(String[] args) throws URISyntaxException,ExportException,Exception { Graph<Integer, DefaultEdge> subGraph = createSubGraph(); System.out.println(GetDiameter(subGraph));}private static Graph<Integer, DefaultEdge> createSubGraph() throws Exception{ ...Read more

Graph Layout Algorithms for JGraphT

I'm using JGraphT to create a graph and I want to be able to visualise and manipulate it. There are some examples that show how to visualise the graph, but it seems that it involves quite a lot of manual code to layout the vertices, etc.I was wondering if there was any graph layout algorithm that could automate this process already in JGraph with a small example. Mostly the graphs I'm drawing are Directed Acyclic Graphs.I have already drawn the graphs by exporting them to .dot format and display it using dot, but I need a little interaction now...Read more

Using JGraphT to Manage Ordering of Dependent Tasks

I have a list of tasks that have dependencies between them and I was considering how I could use JGraphT to manage the ordering of the tasks. I would set up the graph as a directed graph and remove vertices as I processed them (or should I mask them?). I could use TopologicalOrderIterator if I were only going to execute one task at a time but I'm hoping to parallelize the tasks. I could get TopologicalOrderIterator and check Graphs.vertexHasPredecessors until I find as many as I want to execute as once but ideally, there would be something like...Read more

jgrapht - Selection event listener on graph

I would like to implement a selection event listener on a graph to change the style of the selected vertices.I have tried the following: String[] events = {mxEvent.ADD, mxEvent.ADD_CELLS, mxEvent.ADD_OVERLAY, mxEvent.AFTER_PAINT, mxEvent.ALIGN_CELLS, mxEvent.BEFORE_PAINT, mxEvent.BEFORE_UNDO, mxEvent.BEGIN_UPDATE, mxEvent.CELL_CONNECTED, mxEvent.CELLS_ADDED, mxEvent.CELLS_FOLDED, mxEvent.CELLS_MOVED, mxEvent.CELLS_ORDERED, mxEvent.CELLS_REMOVED, mxEvent.CELLS_RESIZED, mxEvent.CELLS_TOGGLED, mxEvent.CHANGE, mxEvent.CLEAR, mxEvent.CONNECT, mx...Read more

jgrapht - Equals betwen two graphs come?

I tried to simply equals two jgraphT instances and it returns false, even though they are identical.I then tried to override the equals with an implementation of mine:public boolean equals(MyGraph<CustomV, CustomE> otherGraph){ boolean result = true; Iterator<CustomV> vertexes = otherGraph.vertexSet().iterator(); while(result && vertexes.hasNext()){ result = this.containsVertex((V); } Iterator<CustomE> edges = otherGraph.edgeSet().iterator(); while(result && edges.has...Read more

creating a cost function in jgrapht

jgrapht supports the idea of putting a wehight(a cost) on an edge/vertex between two nodes. This can be achieved using the class DefaultWeightedEdge.In my graph I do have the requirement to not find the shortest path but the cheapest one. The cheapest path might be longer/have more hops nodes to travel then the shortest path.Therefor, one can use the DijkstraShortestPath algorithm to achieve this.However, my use case is a bit more complex: It needs to also evaluate costs on actions that need to be executed when arriving at a node. Let's say, yo...Read more

JGraphT cannot be cast to org.jgrapht.graph.DefaultWeightedEdge

I'm new Java and am using jGraphT to create a SimpleDirectedWeightedGraph. I'm getting this error when trying to set weights on my edges after creating and adding them to the graph:Exception in thread "main" java.lang.ClassCastException: ObservationsDAG$ObservationsDAGEdge cannot be cast to org.jgrapht.graph.DefaultWeightedEdgeat org.jgrapht.graph.AbstractBaseGraph.setEdgeWeight(Unknown Source)I am assuming I need to do something in my ObservationsDAGEdge class here, but from looking at the JGraphT docs, I am stuck as to what that is. Does my e...Read more

JGraphT: Stack overflow error with Liao Wong longest path algorithm?

I'm trying to implement a longest path algorithm in Java with jGraphT, but i get an java.lang.StackOverflowError when i compile. The error message point to the line where i copy the graph and to the line where the method calls itself inside the algorithm. The algorithm description i use is here Liao Wong longest path at page 11.Where and what have i done wrong?import org.jgrapht.*;import org.jgrapht.graph.*;import java.util.*;public class LongestPath { private DirectedWeightedMultigraph<Vertice, DefaultWeightedEdge> graph; private d...Read more

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 shows what is happening.import java.util.Set;import org.jgrapht.UndirectedGraph;import org.jgrapht.graph.DefaultEdge;import org.jgrapht.graph.SimpleGraph;public class TestEdges{ public static void main(String [] args) { UndirectedGraph<String, DefaultEdge> g = new SimpleGra...Read more

jgrapht - How to determine if two vertices are connected in a graph

SimpleWeightedGraph<String, DefaultWeightedEdge> g = new SimpleWeightedGraph<>(DefaultWeightedEdge.class); String v1 = "v1"; String v2 = "v2"; String v3 = "v3"; // add the vertices g.addVertex(v1); g.addVertex(v2); g.addVertex(v3); // add edges to create a path g.addEdge(v1, v2); g.addEdge(v2, v3);I use the JGraphT library to create a graph containing a path from v1 to v3 via v2. How can I check if v1 is connected with v3?...Read more