Package org.goplanit.assignment.ltm.sltm
Class LabelledBushTurnData
- java.lang.Object
-
- org.goplanit.assignment.ltm.sltm.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 Summary
Constructors Constructor Description LabelledBushTurnData(LabelledBushTurnData other, boolean deepCopy)
copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 remainsdouble
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 desiredboolean
containsTurnSendingFlow(EdgeSegment fromSegment, BushFlowLabel fromComposition, EdgeSegment toSegment, BushFlowLabel toComposition)
Verify if the turn sending flow for a given turn is positiveboolean
containsTurnSendingFlow(EdgeSegment fromSegment, EdgeSegment toSegment)
Check if entry existsLabelledBushTurnData
deepClone()
Support deep cloneTreeSet<BushFlowLabel>
getFlowCompositionLabels(EdgeSegment edgeSegment)
The currently registered flow composition labels for this edge segmentdouble
getSplittingRate(EdgeSegment fromSegment, EdgeSegment toSegment)
Collect the splitting rate for a given link segment.double
getSplittingRate(EdgeSegment fromSegment, EdgeSegment toSegment, BushFlowLabel entryExitLabel)
Collect the bush splitting rate on the given turn for a given label.double[]
getSplittingRates(EdgeSegment fromSegment)
Collect the splitting rates for a given link segment and composition.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.double[]
getSplittingRates(EdgeSegment fromSegment, BushFlowLabel fromLabel, BushFlowLabel toLabel)
Collect the bush splitting rates for a given incoming edge segment and entry-exit composition labelling.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 returneddouble
getTotalSendingFlowFromPcuH(EdgeSegment edgeSegment)
Total sending flows s_a from given segmentdouble
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 returneddouble
getTurnSendingFlowPcuH(EdgeSegment fromSegment, BushFlowLabel fromComposition, EdgeSegment toSegment, BushFlowLabel toComposition)
Get the turn sending flow for a given turndouble
getTurnSendingFlowPcuH(EdgeSegment fromSegment, EdgeSegment toSegment)
Get the turn sending flow for a given turn regardless of the composition labelboolean
hasFlowCompositionLabel(EdgeSegment edgeSegment)
Verify if the edge segment has any flow composition labels registered on itboolean
hasFlowCompositionLabel(EdgeSegment edgeSegment, BushFlowLabel compositionLabel)
Verify if the edge segment has the flow composition label providedboolean
hasTurnFlows()
Verify if any turn flows have been registereddouble
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 labeldouble
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 labeldouble
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 labelvoid
removeTurn(EdgeSegment fromEdgeSegment, EdgeSegment toEdgeSegment)
Remove the turn entirelyvoid
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 processboolean
setTurnSendingFlow(EdgeSegment fromSegment, BushFlowLabel fromComposition, EdgeSegment toSegment, BushFlowLabel toComposition, double turnSendingFlow, boolean allowTurnRemoval)
Update the turn sending flow for a given turnLabelledBushTurnData
shallowClone()
shallow copy
-
-
-
Constructor Detail
-
LabelledBushTurnData
public LabelledBushTurnData(LabelledBushTurnData other, boolean deepCopy)
copy constructor.- Parameters:
other
- to copydeepCopy
- 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 turnfromComposition
- of turn flowtoSegment
- of turntoComposition
- of turn flowturnSendingFlow
- to updateallowTurnRemoval
- 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 turnfromLabel
- of turn flowto
- of turntoLabel
- of turn flowflowPcuH
- 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 turnfromLabel
- of turn flowto
- of turntoLabel
- of turn flowflowPcuH
- to addallowTurnRemoval
- 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 turntoEdgeSegment
- 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 turnfromLabel
- of turn flowtoEdgeSegment
- of turntoLabel
- 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 turnfromComposition
- of turn flowtoSegment
- of turntoComposition
- 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 turntoSegment
- 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 forcompositionLabel
- 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 tocompositionLabel
- to filter byflowAcceptanceFactors
- 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 turntoSegment
- 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 turnfromComposition
- of turn flowtoSegment
- of turntoComposition
- 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 usefromLabel
- to usetoLabel
- 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 usefromLabel
- 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 fortoSegment
- 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 usetoSegment
- to useentryExitLabel
- 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 verifycompositionLabel
- 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 turnoldFromLabel
- from composition label to replacetoSegment
- to segment of turnoldToLabel
- to composition label to replacenewFromToLabel
- 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 turnoldFromLabel
- from composition label to replacetoSegment
- to segment of turntoLabel
- to composition labelnewFromLabel
- 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 turnfromLabel
- from composition labeltoSegment
- to segment of turnoldToLabel
- to composition label to replacenewToLabel
- label to replace flow with- Returns:
- the amount of flow that was relabeled
-
shallowClone
public LabelledBushTurnData shallowClone()
shallow copy- Returns:
- shallow copy
-
deepClone
public LabelledBushTurnData deepClone()
Support deep clone- Returns:
- deep copy
-
hasTurnFlows
public boolean hasTurnFlows()
Verify if any turn flows have been registered- Returns:
- true if so, false otherwise
-
-