6 Ekim 2019 Pazar

MutableGraph Arayüzü

Giriş
Şu satırı dahil ederiz..
import com.google.common.graph.ElementOrder;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
Traverse Algoritmaları
Şunlar kullanılabilir
breadthFirst(Iterable<? extends N> startNodes)
Iterable over the nodes reachable from any of the startNodes, in the order of a breadth-first traversal

breadthFirst(N startNode)
Iterable over the nodes reachable from startNode, in the order of a breadth-first traversal

depthFirstPostOrder(Iterable<? extends N> startNodes)
Iterable over the nodes reachable from any of the startNodes, in the order of a depth-first post-order traversal
depthFirstPostOrder(N startNode)
Iterable over the nodes reachable from startNode, in the order of a depth-first post-order traversal

depthFirstPreOrder(Iterable<? extends N> startNodes)
Iterable over the nodes reachable from any of the startNodes, in the order of a depth-first pre-order traversal
forGraph(SuccessorsFunction<N> graph)
Creates a new traverser for the given general graph.
forTree(SuccessorsFunction<N> tree)
Creates a new traverser for a directed acyclic graph that has at most one path from the start node(s) to any node reachable from the start node(s), and has no paths from any start node to any other start node, such as a tree or forest

constructor
Şöyle yaparız.
MutableGraph<String> graph = GraphBuilder.undirected()
  .nodeOrder(ElementOrder.insertion()).build();
addEdge metodu
Eğe düğümler yoksa bile otomatik ekler. Şöyle yaparız
//adds nodes 'ul','um' and then edge between them
myGraph.putEdge("ul", "um");
addNode metodu
Şöyle yaparız
//graph of Strings
MutableGraph<String> myGraph= GraphBuilder.directed().build();
//add nodes 'ul','um'
myGraph.addNode("ul");
myGraph.addNode("um");

//add edge between 'ul','um'
myGraph.putEdge("ul", "um");
adjacentNodes metodu
Şöyle yaparız. Beliritlen düğümün tüm komşularını verir.
System.out.println(graph.adjacentNodes("A"));
Çıktı olarak şunu alırız.
[D, E, B, C]
nodes metodu
Şöyle yaparız. Tüm düğümleri verir.
System.out.println(graph.nodes());
Çıktı olarak şunu alırız.
Nodes: [A, C, D, B, E]
predecessors metodu
Şöyle yaparız.
System.out.println(graph.predecessors("A"));
Çıktı olarak şunu alırız.
[D, E, B, C]
putEdge metodu
Şöyle yaparız.
graph.addNode("A");
graph.addNode("C");
graph.addNode("D");
graph.addNode("B");
graph.addNode("E");

graph.putEdge("A", "B");
graph.putEdge("A", "C");
graph.putEdge("A", "D");
graph.putEdge("A", "E");
removeNode metodu
Şöyle yaparız
myGraph.removeNode("ul");
myGraph.removeNode("um");
myGraph.removeEdge("ul", "um");
successors metodu
Şöyle yaparız.
System.out.println(graph.successors("A"));
Çıktı olarak şunu alırız.
[D, E, B, C]

Hiç yorum yok:

Yorum Gönder