Class Merge<T>
- Type Parameters:
T- type (class or interface) whose instances represent types of material
Merge has no storage capacity.
Merge can have many inflow connections and at most one outflow connection. The total current rate of inflow connections is equal to the rate of the outflow connection.
The behavior of a Merge with its downstream element's inflow rate less than sum of actual input flow rates
of inflows being merged is defined by its FlowRateDistributionPolicy:
-
In a PRIORITY Merge, the material is taken from the top priority inputs first
until the downstream element's inflow rate limit is reached.
For instance, if the downstream flow element can accept material at the max rate of 12 and the Merge has five inflow connections,
with their respective inflow rates and priorities (see
setInflowPriority(FlowConnection, double)) being from 1 to 5 (1 is the highest priority), then connections 1-4 will be used at their full rates (for a total rate of 10), and the 5th connection will only be used at its partial rate of 2 (12 - (1+2+3+4) = 2). -
In a PROPORTIONAL Merge, material is taken from all inflow connections.
For each connection, a 'rate fraction' parameter is set (see
setInflowRateFraction(FlowConnection, double)) indicating the fraction of that connection's rate in the overall inflow rate of the Merge. Rate limits of each incoming connection are respected. For instance, if the downstream flow element can accept material at the max rate of 5 and the Merge has four inflow connections, with their respective max inflow rates being 1 to 4 and 'rate fractions' being 0.25, then the actual inflow rate via each of the inflow connections will be equal to 1, for a total inflow rate of 4. On the other hand, if rate fractions are set to be 0.1, 0.2, 0.3, and 0.4 - then the inflow connections will have respective actual rates of 0.5, 1.0, 1.5, and 2.0, for a total of 5 (this is the rate limit of the downstream element).
- Author:
- Alexander Morozov
-
Constructor Summary
ConstructorsConstructorDescriptionMerge(FlowEnvironment<T> flowEnvironment, FlowRateDistributionPolicy policy) Creates a new Merge instance.Merge(FlowEnvironment<T> flowEnvironment, String name, FlowRateDistributionPolicy policy) Creates a new Merge instance. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the current sum of quantities of all materials inside this flow element.doublegetContentsAmount(T material) Returns the current quantity of the specified material inside this flow element.Returns amounts of materials contained inside this flow element as anAccumulatorinstance.Returns theFlowRateDistributionPolicyof this merge.doublegetInflowPriority(FlowConnection<T> inflowConnection) Returns the priority of the specified inflow connection.doubleReturns the current flow rate of all materials at the input of thisflow element.Returns anAccumulatorinstance that describes the flow rate at the input of this flow element.getInflowRateDescriptor(FlowConnection<T> inflowConnection) Returns an Accumulator instance that describes the material flow rate at the specified input connection.doublegetInflowRateFraction(FlowConnection<T> inflowConnection) Returns the ratio of currentinflowConnectionflow rate to the overall inflow rate of this Merge.doubleReturns the current flow rate at the output of this flow element.Returns anAccumulatorinstance that describes the flow rate at the output of this flow element.getOutflowRateProportions(FlowConnection<T> outflowConnection) Returns anAccumulatorinstance that contains flow rate proportions of materials exported through theoutflowConnectionoutflow connection.doubleReturns the total quantity of all materials that have passed through this Merge.doublegetRate()Returns the current flow rate through this merge.doubleReturns the total amount of all materials that have entered this flow element.doublegetTotalInflowAmount(T material) Returns the total amount of the specifiedmaterialthat has entered this flow element.Returns anAccumulatorinstance that contains the total quantity of each material that has entered this flow element.doubleReturns the total quantity of materials that have left this flow element.doublegetTotalOutflowAmount(T material) Returns the total quantity of the specifiedmaterialthat has left this flow element.Returns anAccumulatorinstance that holds the total amounts of each material that has left this flow element.voidsetInflowPriority(FlowConnection<T> inflowConnection, double priority) Sets the priority of the inputinflowConnection.voidsetInflowRateFraction(FlowConnection<T> inflowConnection, double rateFraction) Sets the fraction ofinflowConnection's actual flow rate in the overall inflow rate of this Merge.Methods inherited from class com.amalgamasimulation.discreterate.FlowElement
addInflowElementConnectedHandler, addInflowElementDisconnectedHandler, addOutflowElementConnectedHandler, addOutflowElementDisconnectedHandler, connectToElement, disconnectFrom, getFlowEnvironment, getInflowConnections, getName, getOutflowConnections, inflowConnectionExists, isConnectedWith, outflowConnectionExists, removeInflowElementConnectedHandler, removeInflowElementDisconnectedHandler, removeOutflowElementConnectedHandler, removeOutflowElementDisconnectedHandler, toString
-
Constructor Details
-
Merge
Creates a new Merge instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich the new Merge belongs topolicy- flow rate distribution policy of the new Merge
-
Merge
Creates a new Merge instance.- Parameters:
flowEnvironment-FlowEnvironmentwhich the new Merge belongs toname- name of this Mergepolicy- flow rate distribution policy of the new Merge
-
-
Method Details
-
getPassedAmount
public double getPassedAmount()Returns the total quantity of all materials that have passed through this Merge.- Returns:
- total quantity of materials passed through this Merge
-
setInflowPriority
Sets the priority of the inputinflowConnection.Can only be called for a Merge with
FlowRateDistributionPolicy.PRIORITYpolicy. Lower values ofprioritycorrespond to HIGHER priority of theinflowConnection.- Parameters:
inflowConnection- input flow connection for which the priority is being setpriority- priority of the inputinflowConnection, must be non-negative- Throws:
IllegalStateException- if current policy of the Merge is notFlowRateDistributionPolicy.PRIORITYIllegalArgumentException- ifpriorityis less than 0IllegalArgumentException- ifinflowConnectionis not an inflow connection to this Merge
-
getInflowPriority
Returns the priority of the specified inflow connection. The lower the returned value, thehigher the priority. Throws an exception is the connection is not related to this flow element.
If the Merge's policy is
FlowRateDistributionPolicy.PROPORTIONAL, returns 0.- Parameters:
inflowConnection- inflow connection- Returns:
- priority of the incoming
inflowConnection
-
getInflowRateFraction
Returns the ratio of currentinflowConnectionflow rate to the overall inflow rate of this Merge.The returned value belongs to a closed interval [0..1].
- Parameters:
inflowConnection- input flow connection- Returns:
- fraction of the
inflowConnectionflow rate in the overall inflow rate of the Merge - Throws:
IllegalStateException- if called for a Merge with flow distribution policy other thanFlowRateDistributionPolicy.PROPORTIONALIllegalStateException- if the inflow rate fraction has not been configured for this inflowConnection and this MergeIllegalArgumentException- if theinflowConnectionis not related to this Merge- See Also:
-
setInflowRateFraction
Sets the fraction ofinflowConnection's actual flow rate in the overall inflow rate of this Merge.Can only be called for a Merge with
FlowRateDistributionPolicy.PROPORTIONALpolicy.In a Merge with
FlowRateDistributionPolicy.PROPORTIONALpolicy, each new inflow connection should be assigned a rate fraction. The sum of rate fractions for all such inflow connections must be equal to 1.- Parameters:
inflowConnection- input flow connection for which the rate fraction is being setrateFraction- a number in the closed interval [0..1] representing the ratio ofinflowConnectionflow rate to the overall inflow rate of this Merge- Throws:
IllegalStateException- if called for a Merge with flow distribution policy other thanFlowRateDistributionPolicy.PROPORTIONALIllegalArgumentException- if theinflowConnectionis not related to this MergeIllegalArgumentException- ifrateFractionis not in the closed interval [0..1]
-
getFlowRateDistributionPolicy
Returns theFlowRateDistributionPolicyof this merge. The policy is applied to the inflow rate.- Returns:
FlowRateDistributionPolicyof this merge
-
getRate
public double getRate()Returns the current flow rate through this merge.- Returns:
- current flow rate through this merge
-
getContentsAmount
public double getContentsAmount()Returns the current sum of quantities of all materials inside this flow element. Always returns zero for any Merge because Merges have no storage capacity and do not contain any material.- Specified by:
getContentsAmountin classFlowElement<T>- Returns:
- 0
- See Also:
-
getContentsAmount
Returns the current quantity of the specified material inside this flow element. Always returns zero for any Merge because Merges have no storage capacity and do not contain any material.- Specified by:
getContentsAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- 0
- See Also:
-
getContentsDescriptor
Returns amounts of materials contained inside this flow element as anAccumulatorinstance. Always returns an emptyAccumulatorfor any Merge because a merge has no storage capacity and does not contain any material.- Specified by:
getContentsDescriptorin classFlowElement<T>- Returns:
- empty
Accumulator - See Also:
-
getInflowRate
public double getInflowRate()Description copied from class:FlowElementReturns the current flow rate of all materials at the input of thisflow element.- Specified by:
getInflowRatein classFlowElement<T>- Returns:
- current flow rate of all materials at this
flow element's input - See Also:
-
getInflowRateDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that describes the flow rate at the input of this flow element.The returned
Accumulatorinstance contains the respective rates of all materials currently entering the flow element. The sum of values in the Accumulator is equal to 1.- Specified by:
getInflowRateDescriptorin classFlowElement<T>- Returns:
- descriptor of the current inflow rate
- See Also:
-
getInflowRateDescriptor
Returns an Accumulator instance that describes the material flow rate at the specified input connection.The returned
Accumulatorinstance contains the respective rates of all materials currently entering the Merge through the specified connection.- Parameters:
inflowConnection- input flow connection- Returns:
- current flow rate of material at specified input connection
- Throws:
IllegalArgumentException- if theinflowConnectionis not related to this Merge
-
getOutflowRate
public double getOutflowRate()Description copied from class:FlowElementReturns the current flow rate at the output of this flow element.- Specified by:
getOutflowRatein classFlowElement<T>- Returns:
- current flow rate at the output of this flow element
- See Also:
-
getOutflowRateDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that describes the flow rate at the output of this flow element.The returned
Accumulatorinstance contains the respective rates of all materials currently leaving the flow element. The sum of values in the Accumulator is equal to 1.- Specified by:
getOutflowRateDescriptorin classFlowElement<T>- Returns:
- descriptor of the current outflow rate
- See Also:
-
getOutflowRateProportions
Description copied from class:FlowElementReturns anAccumulatorinstance that contains flow rate proportions of materials exported through theoutflowConnectionoutflow connection.Each element of the returned
Accumulatorcorresponds to a material in the current material flow ofoutflowConnection. The value of each element in the Accumulator is the ratio of the rate of that material's partial flow to the overall flow rate ofoutflowConnection. The sum of values in the Accumulator is equal to 1.- Specified by:
getOutflowRateProportionsin classFlowElement<T>- Parameters:
outflowConnection- an outflow connection- Returns:
- material proportions in the outflow connection
-
getTotalInflowAmount
public double getTotalInflowAmount()Description copied from class:FlowElementReturns the total amount of all materials that have entered this flow element.- Specified by:
getTotalInflowAmountin classFlowElement<T>- Returns:
- total amount of all arrived materials
-
getTotalInflowAmount
Description copied from class:FlowElementReturns the total amount of the specifiedmaterialthat has entered this flow element.- Specified by:
getTotalInflowAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- total amount of the specified
materialthat has arrived to this flow element - See Also:
-
getTotalInflowDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that contains the total quantity of each material that has entered this flow element.The values of each element in the returned
Accumulatormatch the quantities of the respective materials that have entered the flow element. The sum of values in the Accumulator is equal to the value returned by theFlowElement.getTotalInflowAmount()method.- Specified by:
getTotalInflowDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining total amounts of materials that have entered this flow element- See Also:
-
getTotalOutflowAmount
public double getTotalOutflowAmount()Description copied from class:FlowElementReturns the total quantity of materials that have left this flow element.- Specified by:
getTotalOutflowAmountin classFlowElement<T>- Returns:
- total quantity of exported materials
- See Also:
-
getTotalOutflowAmount
Description copied from class:FlowElementReturns the total quantity of the specifiedmaterialthat has left this flow element.- Specified by:
getTotalOutflowAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- total quantity of the specified material that has left this flow element
- See Also:
-
getTotalOutflowDescriptor
Description copied from class:FlowElementReturns anAccumulatorinstance that holds the total amounts of each material that has left this flow element.The values of each element in the returned
Accumulatormatch the quantities of the respective materials that have left the flow element. The sum of values in the Accumulator is equal to the value returned by theFlowElement.getTotalOutflowAmount()method.- Specified by:
getTotalOutflowDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining total amounts of materials that have left this flow element- See Also:
-