org.graphstream.algorithm
Class AbstractSpanningTree

java.lang.Object
  extended by org.graphstream.algorithm.AbstractSpanningTree
All Implemented Interfaces:
Algorithm
Direct Known Subclasses:
Edmonds, Kruskal, Prim

public abstract class AbstractSpanningTree
extends Object
implements Algorithm

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.

Creating a spanning tree algorithm

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

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

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 Summary
AbstractSpanningTree()
          Create a new SpanningTree algorithm.
AbstractSpanningTree(String flagAttribute)
          Create a new SpanningTree algorithm.
AbstractSpanningTree(String flagAttribute, Object flagOn, Object flagOff)
          Create a new SpanningTree algorithm.
 
Method Summary
 void compute()
          Run the algorithm.
 String getFlagAttribute()
          Get key attribute which will be used to set if edges are in the spanning tree, or not.
 Object getFlagOff()
          Get value used to set that an edge is not in the spanning tree.
 Object getFlagOn()
          Get value used to set that an edge is in the spanning tree.
 void init(org.graphstream.graph.Graph graph)
          Initialization of the algorithm.
 void setFlagAttribute(String newFlagAttribute)
          Set the flag attribute.
 void setFlagOff(Object newFlagOff)
          Set value used to set that an edge is not in the spanning tree.
 void setFlagOn(Object newFlagOn)
          Set value used to set that an edge is in the spanning tree.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSpanningTree

public AbstractSpanningTree()
Create a new SpanningTree algorithm.


AbstractSpanningTree

public AbstractSpanningTree(String flagAttribute)
Create a new SpanningTree algorithm.

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 Detail

getFlagAttribute

public String getFlagAttribute()
Get key attribute which will be used to set if edges are in the spanning tree, or not.

Returns:
flag attribute

setFlagAttribute

public void setFlagAttribute(String newFlagAttribute)
Set the flag attribute.

Parameters:
newFlagAttribute - new attribute used

getFlagOn

public Object getFlagOn()
Get value used to set that an edge is in the spanning tree.

Returns:
on value

setFlagOn

public void setFlagOn(Object newFlagOn)
Set value used to set that an edge is in the spanning tree.

Parameters:
newFlagOn - on value

getFlagOff

public Object getFlagOff()
Get value used to set that an edge is not in the spanning tree.

Returns:
off value

setFlagOff

public void setFlagOff(Object newFlagOff)
Set value used to set that an edge is not in the spanning tree.

Parameters:
newFlagOff - off value

init

public void init(org.graphstream.graph.Graph graph)
Description copied from interface: Algorithm
Initialization of the algorithm. This method has to be called before the Algorithm.compute() method to initialize or reset the algorithm according to the new given graph.

Specified by:
init in interface Algorithm
Parameters:
graph - The graph this algorithm is using.

compute

public void compute()
Description copied from interface: Algorithm
Run the algorithm. The Algorithm.init(Graph) method has to be called before computing.

Specified by:
compute in interface Algorithm
See Also:
Algorithm.init(Graph)


Copyright © 2011. All Rights Reserved.