Package org.goplanit.assignment.ltm.sltm
Class Pas
- java.lang.Object
-
- org.goplanit.assignment.ltm.sltm.Pas
-
public class Pas extends Object
Paired Alternative Segment (PAS) implementation comprising two subpaths (segments), one of a higher cost than the other. In a PAS both subpaths start at the same vertex and end at the same vertex without any intermediate links overlapping.- Author:
- markr
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublecomputeOverlappingAcceptedFlow(Bush bush, boolean lowCost, double[] linkSegmentFlowAcceptanceFactors)Check if bush is overlapping with one of the alternatives, and if it is how much sending flow this sub-path currently representsbooleancontainsAny(BitSet linkSegments)Check if any of the set link segments is present on either alternativebooleancontainsAny(BitSet linkSegments, boolean lowCost)Check if any of the set link segments is present on the indicated alternativeprotected static Pascreate(EdgeSegment[] s1, EdgeSegment[] s2)Create a new PAS (factory method)protected booleanexecuteFlowShift(double networkS2FlowPcuH, double flowShiftPcuH, double[] flowAcceptanceFactors)Shift flows for this PAS given the currently known costs and smoothing procedure to applyvoidforEachEdgeSegment(boolean lowCostSegment, Consumer<EdgeSegment> edgeSegmentConsumer)Apply consumer to each edgeSegment on one of the cost segmentsvoidforEachVertex(boolean lowCostSegment, Consumer<DirectedVertex> vertexConsumer)Apply consumer to each vertex on one of the cost segmentsEdgeSegment[]getAlternative(boolean lowCostSegment)Access to the two alternatives that reflect the PASdoublegetAlternativeHighCost()get cost of high cost alternative segmentdoublegetAlternativeLowCost()get cost of high cost alternative segmentDirectedVertexgetDivergeVertex()Collect the start vertex of the PASEdgeSegmentgetFirstEdgeSegment(boolean lowCostSegment)Collect the first edge segment of one of the two segmentsEdgeSegmentgetLastEdgeSegment(boolean lowCostSegment)Collect the last edge segment of one of the two segmentsDirectedVertexgetMergeVertex()Collect the end vertex of the PASdoublegetReducedCost()Returns the difference between the cost of the high cost and the low cost segment.booleanhasOrigins()Verify if PAS (still) has origins registered on itbooleanisOverlappingWith(ShortestPathResult pathMatchForCheapPath, boolean lowCost)check if shortest path tree is overlapping with one of the alternativesEdgeSegmentmatchFirst(boolean lowCostSegment, Predicate<EdgeSegment> predicate)Match first link segment of PAS segment to predicate providedvoidregisterOrigin(Bush origin)Register origin on the PASbooleanupdateCost(double[] edgeSegmentCosts)update costs of both paths.protected voidupdateCost(double[] edgeSegmentCosts, boolean updateS1)update costs of an alternative
-
-
-
Method Detail
-
updateCost
protected void updateCost(double[] edgeSegmentCosts, boolean updateS1)update costs of an alternative- Parameters:
edgeSegmentCosts- to useupdateS1- Flag indicating to update cost of s1 (cheap) segment, when false update the s2 (costlier) segment
-
executeFlowShift
protected boolean executeFlowShift(double networkS2FlowPcuH, double flowShiftPcuH, double[] flowAcceptanceFactors)Shift flows for this PAS given the currently known costs and smoothing procedure to apply- Parameters:
networkS2FlowPcuH- total flow currently using the high cost alternativeflowShiftPcuH- amount to shift from high cost to low cost segmentflowAcceptanceFactors- to use- Returns:
- true when flow shifted, false otherwise
-
create
protected static Pas create(EdgeSegment[] s1, EdgeSegment[] s2)
Create a new PAS (factory method)- Parameters:
s1- to uses2- to use- Returns:
- newly created PAS
-
getMergeVertex
public DirectedVertex getMergeVertex()
Collect the end vertex of the PAS- Returns:
- end vertex
-
getDivergeVertex
public DirectedVertex getDivergeVertex()
Collect the start vertex of the PAS- Returns:
- start vertex
-
registerOrigin
public void registerOrigin(Bush origin)
Register origin on the PAS- Parameters:
origin- bush to register
-
hasOrigins
public boolean hasOrigins()
Verify if PAS (still) has origins registered on it- Returns:
- true when origins are present, false otherwise
-
computeOverlappingAcceptedFlow
public double computeOverlappingAcceptedFlow(Bush bush, boolean lowCost, double[] linkSegmentFlowAcceptanceFactors)
Check if bush is overlapping with one of the alternatives, and if it is how much sending flow this sub-path currently represents- Parameters:
bush- to verifylowCost- when true check with low cost alternative otherwise high costlinkSegmentFlowAcceptanceFactors- to use to obtain accepted flow along subpath, where the flow at the start of the high cost segment is used as starting demand- Returns:
- when non-negative the segment is overlapping with the PAS, where the value indicates the accepted flow on this sub-path for the bush (with sendinf flow at start as base demand)
-
isOverlappingWith
public boolean isOverlappingWith(ShortestPathResult pathMatchForCheapPath, boolean lowCost)
check if shortest path tree is overlapping with one of the alternatives- Parameters:
pathMatchForCheapPath- to verifylowCost- when true check with low cost alternative otherwise high cost- Returns:
- true when overlapping, false otherwise
-
containsAny
public boolean containsAny(BitSet linkSegments, boolean lowCost)
Check if any of the set link segments is present on the indicated alternative- Parameters:
linkSegments- where we verify against set link segmentslowCost- when true check with low cost alternative otherwise high cost- Returns:
- true when overlapping, false otherwise
-
containsAny
public boolean containsAny(BitSet linkSegments)
Check if any of the set link segments is present on either alternative- Parameters:
linkSegments- where we verify against set link segments- Returns:
- true when overlapping, false otherwise
-
updateCost
public boolean updateCost(double[] edgeSegmentCosts)
update costs of both paths. In case the low cost path is no longer the low cost path, switch it with the high cost path- Parameters:
edgeSegmentCosts- to use- Returns:
- true when updated costs caused a switch in what is the high and low cost path
-
forEachVertex
public void forEachVertex(boolean lowCostSegment, Consumer<DirectedVertex> vertexConsumer)Apply consumer to each vertex on one of the cost segments- Parameters:
lowCostSegment- when true applied to low cost segment, when false the high cost segmentvertexConsumer- to apply
-
forEachEdgeSegment
public void forEachEdgeSegment(boolean lowCostSegment, Consumer<EdgeSegment> edgeSegmentConsumer)Apply consumer to each edgeSegment on one of the cost segments- Parameters:
lowCostSegment- when true applied to low cost segment, when false the high cost segmentedgeSegmentConsumer- to apply
-
getAlternativeHighCost
public double getAlternativeHighCost()
get cost of high cost alternative segment- Returns:
- cost
-
getAlternativeLowCost
public double getAlternativeLowCost()
get cost of high cost alternative segment- Returns:
- cost
-
getLastEdgeSegment
public EdgeSegment getLastEdgeSegment(boolean lowCostSegment)
Collect the last edge segment of one of the two segments- Parameters:
lowCostSegment- when true collect for low cost segment, otherwise the high cost segment- Returns:
- edge segment
-
getFirstEdgeSegment
public EdgeSegment getFirstEdgeSegment(boolean lowCostSegment)
Collect the first edge segment of one of the two segments- Parameters:
lowCostSegment- when true collect for low cost segment, otherwise the high cost segment- Returns:
- edge segment
-
getAlternative
public EdgeSegment[] getAlternative(boolean lowCostSegment)
Access to the two alternatives that reflect the PAS- Parameters:
lowCostSegment- when true return s1 (lowCost), otherwise s2 (highCost)- Returns:
- ordered edge segments representing the alternative
-
getReducedCost
public double getReducedCost()
Returns the difference between the cost of the high cost and the low cost segment. Should always be larger than zero assuming anupdateCost(double[])has been conducted to ensure the segments are labelled correctly regarding which one is high and which one is low cost- Returns:
- s2Cost - s2Cost
-
matchFirst
public EdgeSegment matchFirst(boolean lowCostSegment, Predicate<EdgeSegment> predicate)
Match first link segment of PAS segment to predicate provided- Parameters:
lowCostSegment- when true apply on s1, otherwise on s2predicate- to test- Returns:
- edge segment that matches, null if none matches
-
-