Class AbstractSpanningTree
- All Implemented Interfaces:
Algorithm,SpanningTree
public abstract class AbstractSpanningTree extends Object implements SpanningTree
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 Summary
Constructors Constructor Description 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
Modifier and Type Method Description voidclear()Removes the tags of all edges.voidcompute()Run the algorithm.StringgetFlagAttribute()Get key attribute which will be used to set if edges are in the spanning tree, or not.ObjectgetFlagOff()Get value used to set that an edge is not in the spanning tree.ObjectgetFlagOn()Get value used to set that an edge is in the spanning tree.Iterable<org.graphstream.graph.Edge>getTreeEdges()Iterable view of the spanning tree edges.abstract Stream<org.graphstream.graph.Edge>getTreeEdgesStream()An iterator on the tree edges.voidinit(org.graphstream.graph.Graph graph)Initialization of the algorithm.voidsetFlagAttribute(String flagAttribute)Set the flag attribute.voidsetFlagOff(Object flagOff)Set value used to set that an edge is not in the spanning tree.voidsetFlagOn(Object flagOn)Set value used to set that an edge is in the spanning tree.
-
Constructor Details
-
AbstractSpanningTree
public AbstractSpanningTree()Create a new SpanningTree algorithm. By default edges are not tagged. -
AbstractSpanningTree
Create a new SpanningTree algorithm. Default flag attribute values aretruefor edges in the tree andfalsefor the remaining edges.- Parameters:
flagAttribute- attribute used to compare edges
-
AbstractSpanningTree
Create a new SpanningTree algorithm.- Parameters:
flagAttribute- attribute used to set if an edge is in the spanning treeflagOn- value of the flagAttribute if edge is in the spanning treeflagOff- value of the flagAttribute if edge is not in the spanning tree
-
-
Method Details
-
getFlagAttribute
Description copied from interface:SpanningTreeGet key attribute which will be used to set if edges are in the spanning tree, or not.- Specified by:
getFlagAttributein interfaceSpanningTree- Returns:
- flag attribute
-
setFlagAttribute
Description copied from interface:SpanningTreeSet the flag attribute.- Specified by:
setFlagAttributein interfaceSpanningTree- Parameters:
flagAttribute- New attribute used. Ifnulledges are not tagged.
-
getFlagOn
Description copied from interface:SpanningTreeGet value used to set that an edge is in the spanning tree.- Specified by:
getFlagOnin interfaceSpanningTree- Returns:
- on value
-
setFlagOn
Description copied from interface:SpanningTreeSet value used to set that an edge is in the spanning tree.- Specified by:
setFlagOnin interfaceSpanningTree- Parameters:
flagOn- on value. Ifnulledges in the tree are not tagged.
-
getFlagOff
Description copied from interface:SpanningTreeGet value used to set that an edge is not in the spanning tree.- Specified by:
getFlagOffin interfaceSpanningTree- Returns:
- off value
-
setFlagOff
Description copied from interface:SpanningTreeSet value used to set that an edge is not in the spanning tree.- Specified by:
setFlagOffin interfaceSpanningTree- Parameters:
flagOff- off value. Ifnulledges out of the tree are not tagged.
-
getTreeEdgesStream
Description copied from interface:SpanningTreeAn iterator on the tree edges.- Specified by:
getTreeEdgesStreamin interfaceSpanningTree- Returns:
- An iterator on the tree edges
-
getTreeEdges
Description copied from interface:SpanningTreeIterable view of the spanning tree edges. This implementation usesSpanningTree.getTreeEdgesStream().- Specified by:
getTreeEdgesin interfaceSpanningTree- Returns:
- Iterable view of the tree edges.
-
clear
public void clear()Description copied from interface:SpanningTreeRemoves the tags of all edges. Use this method to save memory if the spanning tree is used no more.- Specified by:
clearin interfaceSpanningTree
-
init
public void init(org.graphstream.graph.Graph graph)Description copied from interface:AlgorithmInitialization of the algorithm. This method has to be called before theAlgorithm.compute()method to initialize or reset the algorithm according to the new given graph. -
compute
public void compute()Description copied from interface:AlgorithmRun the algorithm. TheAlgorithm.init(Graph)method has to be called before computing.- Specified by:
computein interfaceAlgorithm- See Also:
Algorithm.init(Graph)
-