Package org.goplanit.assignment.ltm.sltm
Class PasManager
- java.lang.Object
-
- org.goplanit.assignment.ltm.sltm.PasManager
-
public class PasManager extends Object
Container class for tracking all unique PASs indexed by their last (merge) vertex- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description PasManager()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pas
createNewPas(Bush originBush, EdgeSegment[] s1, EdgeSegment[] s2)
create a new PAS for the given cheap and expensive paired alternative segments (subpaths) and register the origin bush on it that was responsible for creating itstatic EdgeSegment[]
createSubpathArrayFrom(DirectedVertex start, DirectedVertex end, Map<DirectedVertex,EdgeSegment> pathTree, int arrayLength, boolean truncateArray)
Extract a subpath in the form of a raw edge segment array from start to end vertex based on a map representing a tree with succeeding edge segments for each vertexstatic EdgeSegment[]
createSubpathArrayFrom(DirectedVertex start, DirectedVertex end, ShortestPathResult pathTree, int arrayLength, boolean truncateArray)
Extract a subpath in the form of a raw edge segment array from start to end vertex based on the shortest path result provided.Pas
findFirstSuitableExistingPas(Bush originBush, DirectedVertex mergeVertex, double[] flowAcceptanceFactors, double reducedCost)
find the first PAS which has the given merge vertex as end vertex and which if we would extend the bush with its least cost alternative would improve to the point it is considered effective enough compared to the upper bound (reduced cost) improvement provided as well as that the bush has sufficient flow on the high cost alternative of the PAS such that it can improve sufficiently by shifting flow towards the new low cost segment.void
forEachPas(Consumer<Pas> pasConsumer)
Loop over all PassCollection<Pas>
getPassByMergeVertex(DirectedVertex mergeVertex)
Collect all PASs that share the same merge (end) vertexPriorityQueue<Pas>
getPassSortedByReducedCost()
Construct a priority queue based on the PASs reduced cost, i.e., difference between their high and low cost segments in descending order.void
removePas(Pas pas)
Remove the PAS from the managervoid
updateCosts(double[] linkSegmentCosts)
Update costs on all registered PASsvoid
updateCosts(Collection<Pas> pass, double[] linkSegmentCosts)
Update cost for a selection of PASs only
-
-
-
Method Detail
-
createSubpathArrayFrom
public static EdgeSegment[] createSubpathArrayFrom(DirectedVertex start, DirectedVertex end, ShortestPathResult pathTree, int arrayLength, boolean truncateArray)
Extract a subpath in the form of a raw edge segment array from start to end vertex based on the shortest path result provided. Since the path tree is in reverse direction, the array is filled from the back, i.e.,if there is spare capacity the front of the array would be empty.- Parameters:
start
- start vertex upstreamend
- end vertex downstreampathTree
- to extract path from, tree is in upstream directionarrayLength
- to use for the to be created array which should be at least as long as the path that is to be extractedtruncateArray
- flag indicating to truncate the subpath array in case the front of the array is not fully used due to the existence of spare capacity- Returns:
- created array, null if no path could be found
-
createSubpathArrayFrom
public static EdgeSegment[] createSubpathArrayFrom(DirectedVertex start, DirectedVertex end, Map<DirectedVertex,EdgeSegment> pathTree, int arrayLength, boolean truncateArray)
Extract a subpath in the form of a raw edge segment array from start to end vertex based on a map representing a tree with succeeding edge segments for each vertex- Parameters:
start
- start vertex upstreamend
- end vertex downstreampathTree
- to extract path from, tree is in downstream directionarrayLength
- to use for the to be created array which should be at least as long as the path that is to be extractedtruncateArray
- flag indicating to truncate the subpath array in case the back of the array is not fully used due to the existence of spare capacity- Returns:
- created array, null if no path could be found
-
createNewPas
public Pas createNewPas(Bush originBush, EdgeSegment[] s1, EdgeSegment[] s2)
create a new PAS for the given cheap and expensive paired alternative segments (subpaths) and register the origin bush on it that was responsible for creating it- Parameters:
originBush
- responsible for triggering the creation of this PASs1
- cheap alternative segments2
- expensive alternative segment- Returns:
- createdPas
-
removePas
public void removePas(Pas pas)
Remove the PAS from the manager- Parameters:
pas
- to remove
-
getPassByMergeVertex
public Collection<Pas> getPassByMergeVertex(DirectedVertex mergeVertex)
Collect all PASs that share the same merge (end) vertex- Parameters:
mergeVertex
- to collect for- Returns:
- found PAS matches
-
findFirstSuitableExistingPas
public Pas findFirstSuitableExistingPas(Bush originBush, DirectedVertex mergeVertex, double[] flowAcceptanceFactors, double reducedCost)
find the first PAS which has the given merge vertex as end vertex and which if we would extend the bush with its least cost alternative would improve to the point it is considered effective enough compared to the upper bound (reduced cost) improvement provided as well as that the bush has sufficient flow on the high cost alternative of the PAS such that it can improve sufficiently by shifting flow towards the new low cost segment. If this all holds the PAS is selected and returned. We select the first PAS we can find that matches this criteria.- Parameters:
originBush
- to find suitable PAS formergeVertex
- to useflowAcceptanceFactors
- to use (required to assess flow effectiveness in capacitated context)reducedCost
- the upper bound on the improvement that is known for this merge vertex- Returns:
- pas found, null if no suitable candidates exist
-
updateCosts
public void updateCosts(double[] linkSegmentCosts)
Update costs on all registered PASs- Parameters:
linkSegmentCosts
- to use
-
updateCosts
public void updateCosts(Collection<Pas> pass, double[] linkSegmentCosts)
Update cost for a selection of PASs only- Parameters:
pass
- collection of specific PASs to updatelinkSegmentCosts
- to use
-
getPassSortedByReducedCost
public PriorityQueue<Pas> getPassSortedByReducedCost()
Construct a priority queue based on the PASs reduced cost, i.e., difference between their high and low cost segments in descending order.- Returns:
- sorted PAS queue
-
-