Class Conveyor<T>
- Type Parameters:
T- type (class or interface) whose instances represent materials
- All Implemented Interfaces:
IAbstractConveyor<T>
Multiple inflow connections are supported. At most one outflow connection can be specified for a Conveyor.
The physical path of material transportation inside the Conveyor is represented by an instance of a
Polyline.
A Conveyor is composed of several parts called 'conveyor segments' (see ConveyorSegment.
Multiple inflow connections are supported, each inflow connection delivers material to the starting point of some conveyor segment.
Material is delivered by a conveyor segment in a FIFO fashion: the first portion of a material to enter the segment of a Conveyor will be the first portion to be exported from that segment.
The delivery of material from entry to exit is not instantaneous. After material enters a Conveyor, it will take some time to deliver it to the Conveyor's output. This delivery duration (i.e. time required to deliver the material) depends on the 'logical length' of the path of material inside the Conveyor and the speed at which material is being transported within the Conveyor. The logical length is measured in so-called 'logical pixels'. A 'logical pixel' is a measure of distance, and its correspondence to some 'real' measurement units (like meters, inches, etc.) is arbitrary, lies beyond the realm of a Conveyor and is not specified explicitly for a Conveyor. Note that the 'speed' of the Conveyor is also measured in 'logical pixels' per unit of model time.
The Conveyor handles a situation when it can supply material at a higher rate than the downstream flow element can accept.
In this case, its Conveyor.DownstreamInflowRateShortagePolicy is applied.
The policy is only set in the constructor and cannot be changed later.
- Author:
- Alexander Morozov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper class to create aConveyorinstance.static enumDefines the behavior of a Conveyor when the current rate of its currently exportedConveyorRateRecordexceeds the rate at which material can be imported by the downstreamFlowElement.static interfaceHelper interface to build a Conveyor instance.static interfaceHelper interface to build a Conveyor instance.static interfaceHelper interface to build a Conveyor instance.static interfaceHelper interface to build a Conveyor instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEmptyHandler(Consumer<Conveyor<T>> handler) Adds an action that will be executed every time this Conveyor becomes empty.voidaddInflowRateChangedHandler(BiConsumer<Conveyor<T>, FlowConnection<T>> handler) Adds an action that will be executed every time the inflow rate changes.voidaddOutflowRateChangedHandler(Consumer<Conveyor<T>> handler) Adds an action that will be executed every time the outflow rate changes.voidaddSpeedChangedHandler(Consumer<Conveyor<T>> handler) Adds an action that will be executed every time the speed changes.static <T> Conveyor.PolylineBuilder<T> builder(FlowEnvironment<T> flowEnvironment) Returns a builder object to create a new instance of a Conveyor.voidconnectInputFlowWithLogicalOffset(FlowElement<T> sourceFlowElement, double logicalOffset) Connects thesourceFlowElement(as a source of material) to thisConveyor.voidconnectInputFlowWithRelativeOffset(FlowElement<T> sourceFlowElement, double relativeOffset) Connects thesourceFlowElement(as a source of material) to thisConveyor.connectToElement(FlowElement<T> dest) Connects the output of this flow element to the input of thedestflow element.doubleReturns the total quantity of all materials inside this flow element.doublegetContentsAmount(T material) Returns the current quantity of the specifiedmaterialinside this flow element.Returns all materials contained inside this flow element as an instance ofAccumulator.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.doubleReturns the length of thisConveyorin logical pixels.doublegetLogicalOffsetForConnection(FlowConnection<T> inflowConnection) Returns the logical offset of the inputinflowConnection.doubleReturns the max speed of material transportation inside this Conveyor.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 internal flow rate limit of thisConveyor.Returns thePolylinethat describes the physical layout of this Conveyor.Returns aCollectionofConveyorRateRecordinstances that represent the material mix portions on this Conveyor.Returns theConveyor.DownstreamInflowRateShortagePolicyof this Conveyor.doublegetRelativeOffsetForConnection(FlowConnection<T> inflowConnection) Returns the relative offset of the inputinflowConnection.doublegetSpeed()Returns the current speed of material transportation inside this Conveyor.doubleReturns the total amount of all materials that have entered this flow element.doublegetTotalInflowAmount(T element) 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 element) 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.booleanIndicates that thisConveyoris stopped.voidremoveEmptyHandler(Consumer<Conveyor<T>> handler) Removes a previously added empty Conveyor action.voidremoveInflowRateChangedHandler(BiConsumer<Conveyor<T>, FlowConnection<T>> handler) Removes the previously added inflow rate change handler.voidremoveOutflowRateChangedHandler(Consumer<Conveyor<T>> handler) Removes the previously added outflow rate change handler.voidremoveSpeedChangedHandler(Consumer<Conveyor<T>> handler) Removes the previously added speed change handler.voidsetSpeed(double speed) Sets the new current speed of material transportation inside thisConveyor.voidStarts thisConveyor.voidStops thisConveyor.Methods inherited from class com.amalgamasimulation.discreterate.FlowElement
addInflowElementConnectedHandler, addInflowElementDisconnectedHandler, addOutflowElementConnectedHandler, addOutflowElementDisconnectedHandler, disconnectFrom, getFlowEnvironment, getInflowConnections, getName, getOutflowConnections, inflowConnectionExists, isConnectedWith, outflowConnectionExists, removeInflowElementConnectedHandler, removeInflowElementDisconnectedHandler, removeOutflowElementConnectedHandler, removeOutflowElementDisconnectedHandler, toString
-
Method Details
-
builder
Returns a builder object to create a new instance of a Conveyor.- Parameters:
flowEnvironment-FlowEnvironmentwhich a newConveyorinstance will belong to- Returns:
- new Conveyor builder object
-
getLogicalLength
public double getLogicalLength()Returns the length of thisConveyorin logical pixels.- Specified by:
getLogicalLengthin interfaceIAbstractConveyor<T>- Returns:
- length of this
Conveyor
-
connectInputFlowWithRelativeOffset
public void connectInputFlowWithRelativeOffset(FlowElement<T> sourceFlowElement, double relativeOffset) Connects thesourceFlowElement(as a source of material) to thisConveyor.The 'connection point', i.e. the exact location along the Conveyor where the material coming from the
sourceFlowElementwill be accepted by the Conveyor is set byrelativeOffset(a number between 0 and 1).This method can only be called before the Conveyor's
FlowEnvironmenthas been initialized.- Specified by:
connectInputFlowWithRelativeOffsetin interfaceIAbstractConveyor<T>- Parameters:
sourceFlowElement- flow element that acts as a source of materialrelativeOffset- a number in the half-open interval [0..1) (0 - allowed, 1 - not allowed) that defines the point of incoming connection, where 0 means 'the beginning of the Conveyor'- Throws:
IllegalStateException- if theFlowEnvironmentof this Conveyor has already been initializedIllegalArgumentException- ifrelativeOffsetis not in the half-open interval [0..1)- See Also:
-
connectInputFlowWithLogicalOffset
public void connectInputFlowWithLogicalOffset(FlowElement<T> sourceFlowElement, double logicalOffset) Connects thesourceFlowElement(as a source of material) to thisConveyor.The 'connection point', i.e. the exact location along the Conveyor where the material coming from the
sourceFlowElementwill be accepted by the Conveyor is set bylogicalOffset(a number between 0 and the length of the Conveyor).This method can only be called before the Conveyor's
FlowEnvironmenthas been initialized.- Specified by:
connectInputFlowWithLogicalOffsetin interfaceIAbstractConveyor<T>- Parameters:
sourceFlowElement- flow element that acts as a source of materiallogicalOffset- a number in the half-open interval [0..length of the Conveyor) (0 - allowed, 'length of the Conveyor' - not allowed), where 0 means 'the beginning of the Conveyor'- Throws:
IllegalStateException- if theFlowEnvironmentof this Conveyor has already been initializedIllegalArgumentException- iflogicalOffsetis not in the half-open interval [0..length of the Conveyor)- See Also:
-
getPolyline
Returns thePolylinethat describes the physical layout of this Conveyor.- Specified by:
getPolylinein interfaceIAbstractConveyor<T>- Returns:
Polyline
-
setSpeed
public void setSpeed(double speed) Sets the new current speed of material transportation inside thisConveyor.- Specified by:
setSpeedin interfaceIAbstractConveyor<T>- Parameters:
speed- new current speed of thisConveyor
-
getMaxSpeed
public double getMaxSpeed()Returns the max speed of material transportation inside this Conveyor.The max speed is only set upon the creation of a Conveyor and cannot be changed later.
- Specified by:
getMaxSpeedin interfaceIAbstractConveyor<T>- Returns:
- max speed of this
Conveyor - See Also:
-
getSpeed
public double getSpeed()Returns the current speed of material transportation inside this Conveyor.The speed of material transportation is the same along the whole length of a Conveyor. However, the rate of material flow inside a Conveyor may be different in its different inner points.
- Specified by:
getSpeedin interfaceIAbstractConveyor<T>- Returns:
- current speed of this
Conveyor - See Also:
-
getPerformance
public double getPerformance()Returns the internal flow rate limit of thisConveyor.- Specified by:
getPerformancein interfaceIAbstractConveyor<T>- Returns:
- max flow rate of material inside this Conveyor
-
getRelativeOffsetForConnection
Returns the relative offset of the inputinflowConnection.'Relative offset' denotes the location along the Conveyor where the material coming from the
inflowConnectionwill be accepted by the Conveyor. Relative offset is a number between 0 and 1, where 0 means 'the beginning of the Conveyor'.- Specified by:
getRelativeOffsetForConnectionin interfaceIAbstractConveyor<T>- Parameters:
inflowConnection- input flow connection- Returns:
- relative offset of the input
inflowConnection(a value between 0 and 1) - Throws:
IllegalArgumentException- ifinflowConnectionis not related to this flow element- See Also:
-
getLogicalOffsetForConnection
Returns the logical offset of the inputinflowConnection.'Logical offset' denotes the location along the Conveyor where the material coming from the
inflowConnectionwill be accepted by the Conveyor. Logical offset is a number between 0 and 'Conveyor's length', where 0 means 'the beginning of the Conveyor'.- Specified by:
getLogicalOffsetForConnectionin interfaceIAbstractConveyor<T>- Parameters:
inflowConnection- input flow connection- Returns:
- logical offset of the input
inflowConnection(a value between 0 and the length of the Conveyor) - Throws:
IllegalArgumentException- ifinflowConnectionis not related to this flow element- See Also:
-
stopConveyor
public void stopConveyor()Stops thisConveyor. This method is idempotent.When the Conveyor is stopped, all material inside the Conveyor stops moving. The current rate at any point of the Conveyor becomes 0. The current inflow and outflow rates are also set to 0. All material inside a stopped Conveyor remains at its place.
If this method is called when the effective speed of the Conveyor is already 0 due to its inability to export materials (for instance, the downstream flow element is full, etc.), then a subsequent call to
startConveyor()will be required to restart the Conveyor.- Specified by:
stopConveyorin interfaceIAbstractConveyor<T>- See Also:
-
startConveyor
public void startConveyor()Starts thisConveyor. This method is idempotent.- Specified by:
startConveyorin interfaceIAbstractConveyor<T>- See Also:
-
isStopped
public boolean isStopped()Indicates that thisConveyoris stopped.- Specified by:
isStoppedin interfaceIAbstractConveyor<T>- Returns:
trueif theConveyoris stopped,falseotherwise
-
getRateShortagePolicy
Returns theConveyor.DownstreamInflowRateShortagePolicyof this Conveyor.- Specified by:
getRateShortagePolicyin interfaceIAbstractConveyor<T>- Returns:
Conveyor.DownstreamInflowRateShortagePolicyof this Conveyor
-
getRateRecords
Returns aCollectionofConveyorRateRecordinstances that represent the material mix portions on this Conveyor. The order of elements in the returned Collection instance is unspecified.- Specified by:
getRateRecordsin interfaceIAbstractConveyor<T>- Returns:
Collectionof Conveyor'sConveyorRateRecords
-
addEmptyHandler
Adds an action that will be executed every time this Conveyor becomes empty.- Parameters:
handler- action that will be executed every time this Conveyor becomes empty- See Also:
-
removeEmptyHandler
Removes a previously added empty Conveyor action.- Parameters:
handler- an empty Conveyor action added by theaddEmptyHandler(Consumer)method
-
addInflowRateChangedHandler
Adds an action that will be executed every time the inflow rate changes.BiConsumer has two parameters:
-Сonveyor
-FlowConnection- input connection in which the rate has changed- Parameters:
handler- action that will be executed every time the inflow rate changes- See Also:
-
removeInflowRateChangedHandler
Removes the previously added inflow rate change handler.- Parameters:
handler- previously added inflow rate change handler- See Also:
-
addOutflowRateChangedHandler
Adds an action that will be executed every time the outflow rate changes.- Parameters:
handler- action that will be executed every time the outflow rate changes- See Also:
-
removeOutflowRateChangedHandler
Removes the previously added outflow rate change handler.- Parameters:
handler- previously added outflow rate change handler- See Also:
-
connectToElement
Description copied from class:FlowElementConnects the output of this flow element to the input of thedestflow element.- Overrides:
connectToElementin classFlowElement<T>- Parameters:
dest- flow element to connect to- Returns:
- a new
FlowConnection, with this flow element as its source anddestflow element as its destination - See Also:
-
getContentsAmount
public double getContentsAmount()Description copied from class:FlowElementReturns the total quantity of all materials inside this flow element.- Specified by:
getContentsAmountin classFlowElement<T>- Returns:
- current sum of all material quantities inside this flow element
- See Also:
-
getContentsAmount
Description copied from class:FlowElementReturns the current quantity of the specifiedmaterialinside this flow element.- Specified by:
getContentsAmountin classFlowElement<T>- Parameters:
material- material- Returns:
- current quantity of the specified material inside this flow element
- See Also:
-
getContentsDescriptor
Description copied from class:FlowElementReturns all materials contained inside this flow element as an instance ofAccumulator.Each element of the Accumulator matches the amount of the corresponding material inside this flow element. The sum of amounts of materials in the Accumulator instance is equal to the value returned by the
FlowElement.getContentsAmount()method.- Specified by:
getContentsDescriptorin classFlowElement<T>- Returns:
Accumulatorcontaining all materials inside the flow element- 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:
-
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:
element- 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:
element- 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:
-
addSpeedChangedHandler
Adds an action that will be executed every time the speed changes.- Parameters:
handler- action that will be executed every time the speed changes- See Also:
-
removeSpeedChangedHandler
Removes the previously added speed change handler.- Parameters:
handler- previously added speed change handler- See Also:
-