ã°ã©ãçè«ã©ã¤ãã©ãªã®JGraphTã使ã£ã¦ã¿ã
JGraphTã¯ãJavaã®ã°ã©ãã©ã¤ãã©ãªã§ããã°ã©ãã®æç»ã§ã¯ãªããã°ã©ãçè«ã®ã¢ãã«ã¨ã¢ã«ã´ãªãºã ã®æ¹ã«ãã©ã¼ã«ã¹ãã¦ãã¾ããã¨ã¦ã使ããããã£ãã®ã§ãç´¹ä»ãã¦ã¿ã¾ãã
ç¡åã°ã©ã
UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>( DefaultEdge.class); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); g.addEdge("a", "b"); g.addEdge("b", "c"); System.out.println(g.vertexSet()); System.out.println(g.edgeSet()); System.out.println(g.edgesOf("c"));
[a, b, c] [(a : b), (b : c)] [(b : c)]
æåã°ã©ã
DirectedGraph<String, DefaultEdge> g = new SimpleDirectedGraph<String, DefaultEdge>( DefaultEdge.class); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); g.addEdge("a", "b"); g.addEdge("b", "c"); System.out.println(g.incomingEdgesOf("b")); System.out.println(g.outgoingEdgesOf("b"));
[(a : b)] [(b : c)]
ãã¤ã¯ã¹ãã©æ³ã«ããæççµè·¯è¨ç®
WeightedGraph<String, DefaultWeightedEdge> g = new SimpleWeightedGraph<String, DefaultWeightedEdge>( DefaultWeightedEdge.class); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); g.setEdgeWeight(g.addEdge("a", "b"), 4); g.setEdgeWeight(g.addEdge("a", "c"), 1); g.setEdgeWeight(g.addEdge("c", "b"), 2); System.out.println(DijkstraShortestPath.findPathBetween(g, "a", "b"));
[(a : c), (c : b)]
ãã¼ãã®æ¢ç´¢
WeightedGraph<String, DefaultWeightedEdge> g = new SimpleWeightedGraph<String, DefaultWeightedEdge>( DefaultWeightedEdge.class); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); g.setEdgeWeight(g.addEdge("a", "b"), 4); g.setEdgeWeight(g.addEdge("a", "c"), 1); g.setEdgeWeight(g.addEdge("c", "b"), 2); // 以ä¸ã¯æçè·é¢åªå ãä»ã«ãå¹ åªå ãæ·±ãåªå ãªã©é¸æå¯ ClosestFirstIterator<String, DefaultWeightedEdge> it = new ClosestFirstIterator<String, DefaultWeightedEdge>(g, "a"); while (it.hasNext()) { System.out.println(it.next()); }
a c b
é£çµæ§ã®å¤å®
UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>( DefaultEdge.class); g.addVertex("a"); g.addVertex("b"); g.addVertex("c"); g.addEdge("a", "b"); ConnectivityInspector<String, DefaultEdge> inspector = new ConnectivityInspector<String, DefaultEdge>(g); System.out.println(inspector.connectedSets());
[[b, a], [c]]
ä»ã«ããbiconnectivity(二重連結性)ã®å¤å®ãvertex cover(頂点被覆)ã®è¨ç®ãªã©ãã§ãã¾ãã
ã°ã©ãçè«ã®ã¢ã«ã´ãªãºã ãèªåã§å®è£ ããã®ã¯çµæ§å¤§å¤ãªã®ã§ãJGraphTã¯ã¨ã¦ã便å©ã ã¨æãã¾ãããã²è©¦ãã¦ã¿ã¦ãã ããã