Search in sources :

Example 1 with ClosestFirstIterator

use of org.jgrapht.traverse.ClosestFirstIterator in project polyGembler by c-zhou.

the class JGraphTraverse method main.

public static void main(String[] args) {
    for (int i = 0; i != 5; i++) assembly_graph.addVertex((char) ('A' + i));
    DefaultWeightedEdge e;
    e = assembly_graph.addEdge('A', 'B');
    assembly_graph.setEdgeWeight(e, 1);
    e = assembly_graph.addEdge('A', 'C');
    assembly_graph.setEdgeWeight(e, 2);
    e = assembly_graph.addEdge('C', 'D');
    assembly_graph.setEdgeWeight(e, 7);
    e = assembly_graph.addEdge('C', 'E');
    assembly_graph.setEdgeWeight(e, 3);
    e = assembly_graph.addEdge('D', 'B');
    assembly_graph.setEdgeWeight(e, 3);
    final Set<Character> visited = new HashSet<Character>();
    char v = 'A';
    int r = 8;
    ClosestFirstIterator<Character, DefaultWeightedEdge> radius_search = new ClosestFirstIterator<Character, DefaultWeightedEdge>(assembly_graph, v, r);
    visited.clear();
    while (radius_search.hasNext()) visited.add(radius_search.next());
    System.out.print("radius search from vtex " + v + ", " + visited.size() + " vtex within " + r + " radius: ");
    for (Character vv : visited) System.out.print(vv + ";");
    System.out.println();
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) ClosestFirstIterator(org.jgrapht.traverse.ClosestFirstIterator) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)1 ClosestFirstIterator (org.jgrapht.traverse.ClosestFirstIterator)1