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.
Spanning tree algorithms have to extend this class and to implements the
makeTree()
and getTreeEdgesIterator()
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.
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(); ..
Modifier and Type | Field and Description |
---|---|
protected String |
flagAttribute
Attribute which will be used to set is an edge is in the spanning tree or
not.
|
protected Object |
flagOff
Value of the flagAttribute if the edge is not in the spanning
tree.
|
protected Object |
flagOn
Value of the flagAttribute if the edge is in the spanning tree.
|
protected Graph |
graph
The graph on which algorithm try to extract a spanning tree.
|
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes the tags of all edges.
|
void |
compute()
Run the algorithm.
|
protected void |
edgeOff(Edge e)
Remove an edge of the spanning tree.
|
protected void |
edgeOn(Edge e)
Add an edge to the spanning tree.
|
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.
|
<T extends Edge> |
getTreeEdges()
Iterable view of the spanning tree edges.
|
abstract <T extends Edge> |
getTreeEdgesIterator()
An iterator on the tree edges.
|
void |
init(Graph graph)
Initialization of the algorithm.
|
protected abstract void |
makeTree()
Method that will be implemented by spanning tree's algorithms to build
the tree.
|
protected void |
resetFlags()
Reset flag attribute values.
|
void |
setFlagAttribute(String flagAttribute)
Set the flag attribute.
|
void |
setFlagOff(Object flagOff)
Set value used to set that an edge is not in the spanning tree.
|
void |
setFlagOn(Object flagOn)
Set value used to set that an edge is in the spanning tree.
|
protected String flagAttribute
public AbstractSpanningTree()
public AbstractSpanningTree(String flagAttribute)
true
for edges in the tree and false
for the remaining
edges.flagAttribute
- attribute used to compare edgespublic AbstractSpanningTree(String flagAttribute, Object flagOn, Object flagOff)
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 treepublic String getFlagAttribute()
SpanningTree
getFlagAttribute
in interface SpanningTree
public void setFlagAttribute(String flagAttribute)
SpanningTree
setFlagAttribute
in interface SpanningTree
flagAttribute
- New attribute used. If null
edges are not tagged.public Object getFlagOn()
SpanningTree
getFlagOn
in interface SpanningTree
public void setFlagOn(Object flagOn)
SpanningTree
setFlagOn
in interface SpanningTree
flagOn
- on value. If null
edges in the tree are not tagged.public Object getFlagOff()
SpanningTree
getFlagOff
in interface SpanningTree
public void setFlagOff(Object flagOff)
SpanningTree
setFlagOff
in interface SpanningTree
protected void edgeOff(Edge e)
e
- edge to removeprotected void resetFlags()
protected abstract void makeTree()
public abstract <T extends Edge> Iterator<T> getTreeEdgesIterator()
SpanningTree
getTreeEdgesIterator
in interface SpanningTree
public <T extends Edge> Iterable<T> getTreeEdges()
SpanningTree
SpanningTree.getTreeEdgesIterator()
.getTreeEdges
in interface SpanningTree
public void clear()
SpanningTree
clear
in interface SpanningTree
public void init(Graph graph)
Algorithm
Algorithm.compute()
method to initialize or reset the algorithm according
to the new given graph.public void compute()
Algorithm
Algorithm.init(Graph)
method has to be called
before computing.compute
in interface Algorithm
Algorithm.init(Graph)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses