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
      • 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, or null when alternative segment(s) is/are null
      • 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
      • registerBush

        public boolean registerBush​(RootedLabelledBush bush)
        Register origin on the PAS
        Parameters:
        bush - bush to register
        Returns:
        true when newly added, false, when already present
      • hasRegisteredBush

        public boolean hasRegisteredBush​(RootedLabelledBush bush)
        Verify if bush is registered on PAS
        Parameters:
        bush - to check
        Returns:
        true when registered, false otherwise
      • getRegisteredBushes

        public Set<RootedLabelledBush> getRegisteredBushes()
        The registered bushes
        Returns:
        registered bushes
      • hasRegisteredBushes

        public boolean hasRegisteredBushes()
        Verify if PAS (still) has origins registered on it
        Returns:
        true when origins are present, false otherwise
      • removeAllRegisteredBushes

        public void removeAllRegisteredBushes()
        Remove all currently registered bushes from PAS
      • removeBushes

        public void removeBushes​(List<RootedLabelledBush> bushes)
        Remove bushes from this PAS
        Parameters:
        bushes - to remove
      • removeBush

        public void removeBush​(RootedLabelledBush bush)
        Remove bush from this PAS
        Parameters:
        bush - to remove
      • computeOverlappingAcceptedFlow

        public double computeOverlappingAcceptedFlow​(RootedLabelledBush 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 pathSearchResult,
                                         boolean lowCost)
        check if shortest path tree is overlapping with one of the alternatives
        Parameters:
        pathSearchResult - to verify
        lowCost - when true check with low cost alternative otherwise high cost
        Returns:
        true when overlapping, false otherwise
      • isAlternativeEqual

        public boolean isAlternativeEqual​(EdgeSegment[] pathToVerify,
                                          boolean lowCost)
        Verify if the provided path is equal to the PAS alternative
        Parameters:
        pathToVerify - to verify
        lowCost - which of the two alternatives to check against
        Returns:
        true when equal, false otherwise
      • isAlternativeEqual

        public boolean isAlternativeEqual​(Collection<EdgeSegment> pathToVerify,
                                          boolean lowCost)
        Verify if the provided path is equal to the PAS alternative
        Parameters:
        pathToVerify - to verify
        lowCost - which of the two alternatives to check against
        Returns:
        true when equal, 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
      • getNormalisedReducedCost

        public double getNormalisedReducedCost()
        Returns the difference between the cost of the high cost and the low cost segment normalised based on the total number of edge segments across both alternatives. Should always be larger than zero.
        Returns:
        (s2Cost - s2Cost)/(#numEdgeSegmentsS1+#numEdgeSegmentsS2)
      • 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
      • isCostEqual

        public boolean isCostEqual​(double epsilon)
        Verify if the current known cost for the PAS is considered equal under the given epsilon
        Parameters:
        epsilon - to use
        Returns:
        true when abs(costS1-costS2) smaller or equal than epsilon
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object obj)
        A PAS equals another pas if the alternative segments are the same. The registered origins or current cost are not considered in this equality test
        Overrides:
        equals in class Object