I have this straight-forward Graph structure using the Guava Graph library and I'd like to understand better if that is possible to sort the adjacents/edges
(not the node
order). For the sake of clarification:
import com.google.common.graph.ElementOrder;
import com.google.common.graph.GraphBuilder;
import com.google.common.graph.MutableGraph;
public class MyNodeTest {
public static void main(String[] args) {
MutableGraph<String> graph = GraphBuilder.undirected().nodeOrder(ElementOrder.insertion()).build();
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");
System.out.println("My default Insertion.order Nodes: " + graph.nodes());
System.out.println("Adj. Order that I couldn't understand: " + graph.adjacentNodes("A"));
System.out.println("Successor. Order that I couldn't understand: " + graph.successors("A"));
System.out.println("Pred. Order that I couldn't understand: " + graph.predecessors("A"));
}
}
My outcome is:
My default Insertion.order Nodes: [A, C, D, B, E]
Adj. Order that I couldn't understand: [D, E, B, C]
Successor. Order that I couldn't understand: [D, E, B, C]
Pred. Order that I couldn't understand: [D, E, B, C]
Without further ado, what I mean is:
Using .nodeOrder(ElementOrder.insertion())
it is possible to sort the nodes themselves. Nonetheless, I'm more interested in sorting the edges
associated with a given node
in a way that if I used the putEdge
respectively from A
with B, C, D, E
the outcome is precisely this instead of the above shown.
Any insight?
Thanks in advance.