Class LabelledBushTurnData


  • public class LabelledBushTurnData
    extends Object
    Track the turn based data of a bush.

    For now we only track turn sending flows to minimise bookkeeping and memory usage, splitting rates are deduced from the turn sending flows when needed.

    Author:
    markr
    • Constructor Detail

      • LabelledBushTurnData

        public LabelledBushTurnData​(LabelledBushTurnData other,
                                    boolean deepCopy)
        copy constructor.
        Parameters:
        other - to copy
        deepCopy - when true, create a eep copy, shallow copy otherwise
    • Method Detail

      • setTurnSendingFlow

        public boolean setTurnSendingFlow​(EdgeSegment fromSegment,
                                          BushFlowLabel fromComposition,
                                          EdgeSegment toSegment,
                                          BushFlowLabel toComposition,
                                          double turnSendingFlow,
                                          boolean allowTurnRemoval)
        Update the turn sending flow for a given turn
        Parameters:
        fromSegment - of turn
        fromComposition - of turn flow
        toSegment - of turn
        toComposition - of turn flow
        turnSendingFlow - to update
        allowTurnRemoval - when true we allow for removal of turn/edge segment flow labels when no flow remains, when false we keep labelling regardless of the remaining flow
        Returns:
        true when turn has any labelled turn sending flow left after setting flow, false when labelled turn sending flow no longer exists
      • addTurnSendingFlow

        public double addTurnSendingFlow​(EdgeSegment from,
                                         BushFlowLabel fromLabel,
                                         EdgeSegment to,
                                         BushFlowLabel toLabel,
                                         double flowPcuH)
        Add turn sending flow for a given turn (can be negative), turn will not be removed if no flow remains
        Parameters:
        from - of turn
        fromLabel - of turn flow
        to - of turn
        toLabel - of turn flow
        flowPcuH - to add
        Returns:
        the new labelled turn sending flow after adding the given flow
      • addTurnSendingFlow

        public double addTurnSendingFlow​(EdgeSegment from,
                                         BushFlowLabel fromLabel,
                                         EdgeSegment to,
                                         BushFlowLabel toLabel,
                                         double flowPcuH,
                                         boolean allowTurnRemoval)
        Add turn sending flow for a given turn (can be negative), flow labelling can be removed if desired depdning on flags set if desired
        Parameters:
        from - of turn
        fromLabel - of turn flow
        to - of turn
        toLabel - of turn flow
        flowPcuH - to add
        allowTurnRemoval - when true we allow for removal of turn/edge segment flow labels when no flow remains, when false we keep labelling regardless of the remaining flow
        Returns:
        the new labelled turn sending flow after adding the given flow
      • removeTurn

        public void removeTurn​(EdgeSegment fromEdgeSegment,
                               EdgeSegment toEdgeSegment)
        Remove the turn entirely
        Parameters:
        fromEdgeSegment - of turn
        toEdgeSegment - of turn
      • removeTurnFlow

        public void removeTurnFlow​(EdgeSegment fromEdgeSegment,
                                   BushFlowLabel fromLabel,
                                   EdgeSegment toEdgeSegment,
                                   BushFlowLabel toLabel)
        Remove the turn flow of the given labels (if present) and update the link composition labels in the process
        Parameters:
        fromEdgeSegment - of turn
        fromLabel - of turn flow
        toEdgeSegment - of turn
        toLabel - of turn flow
      • getTurnSendingFlowPcuH

        public double getTurnSendingFlowPcuH​(EdgeSegment fromSegment,
                                             BushFlowLabel fromComposition,
                                             EdgeSegment toSegment,
                                             BushFlowLabel toComposition)
        Get the turn sending flow for a given turn
        Parameters:
        fromSegment - of turn
        fromComposition - of turn flow
        toSegment - of turn
        toComposition - of turn flow
        Returns:
        turn sending flow, 0 if not present
      • getTurnSendingFlowPcuH

        public double getTurnSendingFlowPcuH​(EdgeSegment fromSegment,
                                             EdgeSegment toSegment)
        Get the turn sending flow for a given turn regardless of the composition label
        Parameters:
        fromSegment - of turn
        toSegment - of turn
        Returns:
        turn sending flow, 0 if not present
      • getTotalSendingFlowFromPcuH

        public double getTotalSendingFlowFromPcuH​(EdgeSegment edgeSegment)
        Total sending flows s_a from given segment
        Parameters:
        edgeSegment - to use
        Returns:
        sending flow s_a
      • getTotalSendingFlowFromPcuH

        public double getTotalSendingFlowFromPcuH​(EdgeSegment edgeSegment,
                                                  BushFlowLabel compositionLabel)
        Collect the sending flow originating at an edge segment in the bush but only for the specified label, if not present, zero flow is returned
        Parameters:
        edgeSegment - to collect sending flow originating from for
        compositionLabel - to filter by
        Returns:
        bush sending flow found
      • getTotalAcceptedFlowToPcuH

        public double getTotalAcceptedFlowToPcuH​(EdgeSegment edgeSegment,
                                                 BushFlowLabel compositionLabel,
                                                 double[] flowAcceptanceFactors)
        Collect the accepted flow towards an edge segment in the bush with the specified label, if not present, zero flow is returned
        Parameters:
        edgeSegment - to collect sending flow towards to
        compositionLabel - to filter by
        flowAcceptanceFactors - to convert sending flow to accepted flow
        Returns:
        bush sending flow found
      • containsTurnSendingFlow

        public boolean containsTurnSendingFlow​(EdgeSegment fromSegment,
                                               EdgeSegment toSegment)
        Check if entry exists
        Parameters:
        fromSegment - of turn
        toSegment - of turn
        Returns:
        true when present, false otherwise
      • containsTurnSendingFlow

        public boolean containsTurnSendingFlow​(EdgeSegment fromSegment,
                                               BushFlowLabel fromComposition,
                                               EdgeSegment toSegment,
                                               BushFlowLabel toComposition)
        Verify if the turn sending flow for a given turn is positive
        Parameters:
        fromSegment - of turn
        fromComposition - of turn flow
        toSegment - of turn
        toComposition - of turn flow
        Returns:
        true when present, false otherwise
      • getSplittingRates

        public double[] getSplittingRates​(EdgeSegment fromSegment)
        Collect the splitting rates for a given link segment and composition. Splitting rates are based on the current (labelled) turn sending flows s_ab. In case no flows are present for the given composition label, zero splitting rates for all turns are returned.
        Parameters:
        fromSegment - to collect bush splitting rates for
        Returns:
        splitting rates in primitive array in order of which one iterates over the outgoing edge segments of the downstream from segment vertex
      • getSplittingRates

        public double[] getSplittingRates​(EdgeSegment fromSegment,
                                          BushFlowLabel fromLabel,
                                          BushFlowLabel toLabel)
        Collect the bush splitting rates for a given incoming edge segment and entry-exit composition labelling. If no flow exits for this input, zero splitting rates are returned for all turns
        Parameters:
        fromSegment - to use
        fromLabel - to use
        toLabel - to use
        Returns:
        splitting rates in primitive array in order of which one iterates over the outgoing edge segments of the downstream from segment vertex
      • getSplittingRates

        public org.apache.commons.collections4.map.MultiKeyMap<Object,​Double> getSplittingRates​(EdgeSegment fromSegment,
                                                                                                      BushFlowLabel fromLabel)
        Collect the bush splitting rates for a given incoming edge segment and entry label. If no flow exits, no splitting rates are returned in the map
        Parameters:
        fromSegment - to use
        fromLabel - to use
        Returns:
        splitting rates in multikey map where the key is the combination of exit segment and exit label and the value is the portion of the entry segment entry label flow directed to it
      • getSplittingRate

        public double getSplittingRate​(EdgeSegment fromSegment,
                                       EdgeSegment toSegment)
        Collect the splitting rate for a given link segment. Splitting rates are based on the current turn sending flows s_ab.

        When collecting multiple splitting rates with the same in link, do not use this method but instead collect all splitting rates at once and then filter the ones you require it is computationally more efficient.

        Parameters:
        fromSegment - of turn to collect splitting rate for
        toSegment - of turn to collect splitting rate for
        Returns:
        splitting rate, when turn is not present or not used, zero is returned
      • getSplittingRate

        public double getSplittingRate​(EdgeSegment fromSegment,
                                       EdgeSegment toSegment,
                                       BushFlowLabel entryExitLabel)
        Collect the bush splitting rate on the given turn for a given label. This might be 0, or 1, but cna also be something in between in case the label splits off in multiple directions
        Parameters:
        fromSegment - to use
        toSegment - to use
        entryExitLabel - label to be used for both entry and exit of the turn
        Returns:
        found splitting rate, in case the turn is not used, 0 is returned
      • getFlowCompositionLabels

        public TreeSet<BushFlowLabel> getFlowCompositionLabels​(EdgeSegment edgeSegment)
        The currently registered flow composition labels for this edge segment
        Parameters:
        edgeSegment - to collect for
        Returns:
        labels for edge segment
      • hasFlowCompositionLabel

        public boolean hasFlowCompositionLabel​(EdgeSegment edgeSegment)
        Verify if the edge segment has any flow composition labels registered on it
        Parameters:
        edgeSegment - to verify
        Returns:
        true when present, false otherwise
      • hasFlowCompositionLabel

        public boolean hasFlowCompositionLabel​(EdgeSegment edgeSegment,
                                               BushFlowLabel compositionLabel)
        Verify if the edge segment has the flow composition label provided
        Parameters:
        edgeSegment - to verify
        compositionLabel - to verify
        Returns:
        true when present, false otherwise
      • relabel

        public double relabel​(EdgeSegment fromSegment,
                              BushFlowLabel oldFromLabel,
                              EdgeSegment toSegment,
                              BushFlowLabel oldToLabel,
                              BushFlowLabel newFromToLabel)
        Relabel existing flow from one composition from-to combination to a new from-to label
        Parameters:
        fromSegment - from segment of turn
        oldFromLabel - from composition label to replace
        toSegment - to segment of turn
        oldToLabel - to composition label to replace
        newFromToLabel - label to replace flow with
        Returns:
        the amount of flow that was relabeled
      • relabelFrom

        public double relabelFrom​(EdgeSegment fromSegment,
                                  BushFlowLabel oldFromLabel,
                                  EdgeSegment toSegment,
                                  BushFlowLabel toLabel,
                                  BushFlowLabel newFromLabel)
        Relabel the from label of existing flow from one composition from-to combination to a new from-to label
        Parameters:
        fromSegment - from segment of turn
        oldFromLabel - from composition label to replace
        toSegment - to segment of turn
        toLabel - to composition label
        newFromLabel - label to replace flow with
        Returns:
        the amount of flow that was relabeled
      • relabelTo

        public double relabelTo​(EdgeSegment fromSegment,
                                BushFlowLabel fromLabel,
                                EdgeSegment toSegment,
                                BushFlowLabel oldToLabel,
                                BushFlowLabel newToLabel)
        Relabel the to label of existing flow from one composition from-to combination to a new from-to label
        Parameters:
        fromSegment - from segment of turn
        fromLabel - from composition label
        toSegment - to segment of turn
        oldToLabel - to composition label to replace
        newToLabel - label to replace flow with
        Returns:
        the amount of flow that was relabeled
      • hasTurnFlows

        public boolean hasTurnFlows()
        Verify if any turn flows have been registered
        Returns:
        true if so, false otherwise