Module org.jgrapht.core
Package org.jgrapht.alg.spanning
Class AbstractCapacitatedMinimumSpanningTree.CapacitatedSpanningTreeSolutionRepresentation
java.lang.Object
org.jgrapht.alg.spanning.AbstractCapacitatedMinimumSpanningTree.CapacitatedSpanningTreeSolutionRepresentation
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- AbstractCapacitatedMinimumSpanningTree<V,
E>
protected class AbstractCapacitatedMinimumSpanningTree.CapacitatedSpanningTreeSolutionRepresentation
extends Object
implements Cloneable
This class represents a solution instance by managing the labels and the partition mapping.
With the help of this class, a capacitated spanning tree based on the label and partition
mapping can be calculated.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCalculates the resulting spanning tree based on this solution representation.void
cleanUp()
Cleans up the solution representation by removing all empty sets from the partition.clone()
Returns a shallow copy of this solution representation instance.int
Returns the label of the subset that containsvertex
.Returns all labels of all subsets.int
Returns the next free label in the label map respectively partitiongetPartitionSet
(Integer label) Returns the set of vertices that are in the subset with labellabel
.double
getPartitionWeight
(Integer label) Returns the sum of the weights of all vertices that are in the subset with labellabel
.void
moveVertex
(V vertex, Integer fromLabel, Integer toLabel) Movesvertex
from the subset represented byfromLabel
to the subset represented bytoLabel
.void
moveVertices
(Set<V> vertices, Integer fromLabel, Integer toLabel) Moves all vertices invertices
from the subset represented byfromLabel
to the subset represented bytoLabel
.partitionSubtreesOfSubset
(Set<V> vertexSubset, int label) Refines the partition by adding new subsets if the designated root has more than one subtree in the subsetlabel
of the partition.
-
Constructor Details
-
CapacitatedSpanningTreeSolutionRepresentation
public CapacitatedSpanningTreeSolutionRepresentation()Constructs a new solution representation for the CMST problem. -
CapacitatedSpanningTreeSolutionRepresentation
public CapacitatedSpanningTreeSolutionRepresentation(Map<V, Integer> labels, Map<Integer, Pair<Set<V>, Double>> partition) Constructs a new solution representation for the CMST problem based onlabels
andpartition
. All labels have to be positive.- Parameters:
labels
- the labels of the subsets in the partitionpartition
- the partition map
-
-
Method Details
-
calculateResultingSpanningTree
public CapacitatedSpanningTreeAlgorithm.CapacitatedSpanningTree<V,E> calculateResultingSpanningTree()Calculates the resulting spanning tree based on this solution representation.- Returns:
- the resulting spanning tree based on this solution representation
-
moveVertex
Movesvertex
from the subset represented byfromLabel
to the subset represented bytoLabel
.- Parameters:
vertex
- the vertex to movefromLabel
- the subset to move the vertex fromtoLabel
- the subset to move the vertex to
-
moveVertices
Moves all vertices invertices
from the subset represented byfromLabel
to the subset represented bytoLabel
.- Parameters:
vertices
- the vertices to movefromLabel
- the subset to move the vertices fromtoLabel
- the subset to move the vertices to
-
partitionSubtreesOfSubset
Refines the partition by adding new subsets if the designated root has more than one subtree in the subsetlabel
of the partition.- Parameters:
vertexSubset
- the subset represented bylabel
, that is the subset that has to be refinedlabel
- the label of the subset of the partition that were refined- Returns:
- the set of all labels of subsets that were changed during the refinement
-
cleanUp
public void cleanUp()Cleans up the solution representation by removing all empty sets from the partition. -
getNextFreeLabel
public int getNextFreeLabel()Returns the next free label in the label map respectively partition- Returns:
- the next free label in the label map respectively partition
-
getLabel
Returns the label of the subset that containsvertex
.- Parameters:
vertex
- the vertex to return the label from- Returns:
- the label of
vertex
-
getLabels
Returns all labels of all subsets.- Returns:
- the labels of all subsets
-
getPartitionSet
Returns the set of vertices that are in the subset with labellabel
.- Parameters:
label
- the label of the subset to return the vertices from- Returns:
- the set of vertices that are in the subset with label
label
-
getPartitionWeight
Returns the sum of the weights of all vertices that are in the subset with labellabel
.- Parameters:
label
- the label of the subset to return the weight from- Returns:
- the sum of the weights of all vertices that are in the subset with label
label
-
clone
public AbstractCapacitatedMinimumSpanningTree<V,E>.CapacitatedSpanningTreeSolutionRepresentation clone()Returns a shallow copy of this solution representation instance. Vertices are not cloned.- Overrides:
clone
in classObject
- Returns:
- a shallow copy of this solution representation.
- Throws:
RuntimeException
- in case the clone is not supported- See Also:
-