Class 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 Detail

      • updateCost

        protected void updateCost​(double[] edgeSegmentCosts,
                                  boolean updateS1)
        update costs of an alternative
        Parameters:
        edgeSegmentCosts - to use
        updateS1 - 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 alternative
        flowShiftPcuH - amount to shift from high cost to low cost segment
        flowAcceptanceFactors - 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 use
        s2 - 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 verify
        lowCost - when true check with low cost alternative otherwise high cost
        linkSegmentFlowAcceptanceFactors - 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 verify
        lowCost - 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 segments
        lowCost - 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 segment
        vertexConsumer - 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 segment
        edgeSegmentConsumer - 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 an updateCost(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 s2
        predicate - to test
        Returns:
        edge segment that matches, null if none matches