public class Prim extends Kruskal
Prim's algorithm is an algorithm which allows to find a minimal spanning tree in a weighted connected graph. More informations on Wikipedia.
import org.graphstream.graph.Graph; import org.graphstream.graph.implementations.DefaultGraph; import org.graphstream.algorithm.Prim; import org.graphstream.algorithm.generator.DorogovtsevMendesGenerator; public class PrimTest { public static void main(String... args) { DorogovtsevMendesGenerator gen = new DorogovtsevMendesGenerator(); Graph graph = new DefaultGraph("Prim Test"); String css = "edge .notintree {size:1px;fill-color:gray;} " + "edge .intree {size:3px;fill-color:black;}"; graph.addAttribute("ui.stylesheet", css); graph.display(); gen.addEdgeAttribute("weight"); gen.setEdgeAttributesRange(1, 100); gen.addSink(graph); gen.begin(); for (int i = 0; i < 100 && gen.nextEvents(); i++) ; gen.end(); Prim prim = new Prim("ui.class", "intree", "notintree"); prim.init(graph); prim.compute(); } }
AbstractSpanningTree
Modifier and Type | Class and Description |
---|---|
protected static class |
Prim.Data |
Kruskal.EdgeComparator, Kruskal.TreeIterator<T extends Edge>
DEFAULT_WEIGHT_ATTRIBUTE, treeEdges, treeWeight, weightAttribute
flagAttribute, flagOff, flagOn, graph
Constructor and Description |
---|
Prim()
Create a new Prim's algorithm.
|
Prim(String flagAttribute,
Object flagOn,
Object flagOff)
Create a new Prim's algorithm.
|
Prim(String weightAttribute,
String flagAttribute)
Create a new Prim's algorithm.
|
Prim(String weightAttribute,
String flagAttribute,
Object flagOn,
Object flagOff)
Create a new Prim's algorithm.
|
Modifier and Type | Method and Description |
---|---|
protected void |
makeTree()
Method that will be implemented by spanning tree's algorithms to build
the tree.
|
clear, getTreeEdgesIterator, getTreeWeight, getWeight, getWeightAttribute, setWeightAttribute
compute, edgeOff, edgeOn, getFlagAttribute, getFlagOff, getFlagOn, getTreeEdges, init, resetFlags, setFlagAttribute, setFlagOff, setFlagOn
public Prim()
public Prim(String weightAttribute, String flagAttribute)
true
for the tree edges and false for the non-tree edges.weightAttribute
- attribute used to compare edgesflagAttribute
- attribute used to set if an edge is in the spanning treepublic Prim(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 Prim(String weightAttribute, String flagAttribute, Object flagOn, Object flagOff)
weightAttribute
- attribute used to compare edgesflagAttribute
- 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 treeprotected void makeTree()
AbstractSpanningTree
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses