Class AbstractSpanningTree

java.lang.Object
org.graphstream.algorithm.AbstractSpanningTree
All Implemented Interfaces:
Algorithm, SpanningTree
Direct Known Subclasses:
Dijkstra, Kruskal

public abstract class AbstractSpanningTree
extends Object
implements SpanningTree
Base for spanning tree algorithms.

The result is stored in an edge attribute which name is defined by flagAttribute and value is flagOn if the edge is in the tree or flagOff if not. If flagAttribute is null nothing is stored in the edges. If flagOn is null edges in the tree are not tagged. If flagOff is null edges out of the tree are not tagged.

Creating a spanning tree algorithm

Spanning tree algorithms have to extend this class and to implements the makeTree() and getTreeEdgesStream() methods. edgeOn(Edge) and edgeOff(Edge) methods have to be used to properly tag edges.

A call to compute reset the values of edges attribute. Then a call to makeTree() is made.

Highlight the spanning tree in viewer

Using the CSS, it is possible to highlight the spanning tree result using classes. Considering two css edge classes have been defined in the CSS, for example :

 edge .in {
         size: 3px;
   fill-color: black;
 }
 
 edge .notin {
   size: 2px;
   fill-color: gray;
 }
 

You can tell the algorithm to set up the value of the "ui.class" attribute of edges to "in" when the edge is in the tree or "notin" when edge is not in the tree.

This can be done by setting the flagAttribute of the algorithm using the setter setFlagAttribute(String) and the flag values flagOn and flagOff with setFlagOn(Object) and setFlagOff(Object) setters.

 Graph graph = ...;
 AbstractSpanningTree sp = ...;
 
 ...
 
 sp.setFlagAttribute("ui.class");
 sp.setFlagOn("in");
 sp.setFlagOff("notin");
 
 sp.init(graph);
 sp.compute();
 
 graph.display();
 
 ..
 
  • Constructor Details

    • AbstractSpanningTree

      public AbstractSpanningTree()
      Create a new SpanningTree algorithm. By default edges are not tagged.
    • AbstractSpanningTree

      public AbstractSpanningTree​(String flagAttribute)
      Create a new SpanningTree algorithm. Default flag attribute values are true for edges in the tree and false for the remaining edges.
      Parameters:
      flagAttribute - attribute used to compare edges
    • AbstractSpanningTree

      public AbstractSpanningTree​(String flagAttribute, Object flagOn, Object flagOff)
      Create a new SpanningTree algorithm.
      Parameters:
      flagAttribute - attribute used to set if an edge is in the spanning tree
      flagOn - value of the flagAttribute if edge is in the spanning tree
      flagOff - value of the flagAttribute if edge is not in the spanning tree
  • Method Details