Package jsl.modeling.elements.spatial
Class SpatialModelElement
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.spatial.SpatialModelElement
-
- All Implemented Interfaces:
PositionIfc
,SpatialElementIfc
,ObservableIfc
,GetNameIfc
,IdentityIfc
- Direct Known Subclasses:
AbstractMover
,ResourceLocation
public class SpatialModelElement extends SchedulingElement implements SpatialElementIfc
SpatialModelElement represents a ModelElement within a SpatialModel. A SpatialModelElement does not have the ability to move within the SpatialModel. Sub-classes may implement this behavior. A SpatialModelElement has a fixed location within the SpatialModel
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Constructor Summary
Constructors Constructor Description SpatialModelElement(ModelElement parent)
Creates a Location2D with (0.0, 0.0) position.SpatialModelElement(ModelElement parent, java.lang.String name)
Creates a Location2D with (0.0, 0.0) position.SpatialModelElement(ModelElement parent, java.lang.String name, SpatialModel spatialModel)
Creates a Location2D with the given parent and SpatialModel2D.SpatialModelElement(ModelElement parent, java.lang.String name, SpatialModel spatialModel, CoordinateIfc coordinate)
Creates a Location2D with the given parent and SpatialModel2D.SpatialModelElement(ModelElement parent, CoordinateIfc position)
Creates a Location2D with at the coordinates of the supplied position.SpatialModelElement(ModelElement parent, SpatialElementIfc position)
Creates a Location2D with at the coordinates of the supplied position.SpatialModelElement(ModelElement parent, SpatialModel spatialModel)
Creates a Location2D with the given parent and SpatialModel2D.SpatialModelElement(ModelElement parent, SpatialModel spatialModel, SpatialElementIfc element)
Creates a Location2D with the given parent and SpatialModel2D.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attachPositionObserver(ObserverIfc observer)
Implementor of this interface should allow Observers to be attached.void
changeSpatialModel(SpatialModel spatialModel, CoordinateIfc coordinate)
Changes the spatial model for this element and places the element at the supplied coordinate within the new spatial model.double
distanceTo(CoordinateIfc coordinate)
This is a "convenience" method for getting the distance from this element to the supplied coordinate within the underlying spatial modeldouble
distanceTo(SpatialElementIfc element)
This is a "convenience" method for getting the distance from this element to the supplied element within the underlying spatial model Requirement: The elements must be in the same spatial model.CoordinateIfc
getInitialPosition()
SpatialModel
getInitialSpatialModel()
Returns the spatial model that should hold this element at the beginning of each replication of a simulationModelElement
getModelElement()
Gets the ModelElement associated with this spatial element May be nullCoordinateIfc
getPosition()
CoordinateIfc
getPreviousPosition()
protected SpatialElement
getSpatialElement()
Returns the spatial element associated with this spatial model elementprotected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.void
initializeSpatialElement()
This method should be called to initialize the spatial element prior to running a simulationboolean
isPositionEqualTo(CoordinateIfc coordinate)
Returns true if the position of this element is the same as supplied coordinate within the underlying spatial model.boolean
isPositionEqualTo(SpatialElementIfc element)
Returns true if the position of this element is the same as the position of the supplied element within the underlying spatial model.void
removePositionObserver(ObserverIfc observer)
Remove the observer from this PositionIfcprotected void
setCurrentPosition(CoordinateIfc currentPosition)
void
setInitialPosition(CoordinateIfc coordinate)
Sets the initial position of the element.protected void
setModelElement(ModelElement modelElement)
protected void
setSpatialElement(SpatialElement spatialElement)
Sets the underlying SpatialElement-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication, afterReplication_, asString, beforeExperiment, beforeExperiment_, beforeReplication, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, initialize_, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removedFromModel, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate, timedUpdate_, toString, update, useControls, warmUp, warmUp_, week
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.GetNameIfc
getName
-
Methods inherited from interface jsl.utilities.IdentityIfc
getId
-
Methods inherited from interface jsl.modeling.elements.spatial.SpatialElementIfc
getObserverState, getSpatialModel
-
-
-
-
Constructor Detail
-
SpatialModelElement
public SpatialModelElement(ModelElement parent)
Creates a Location2D with (0.0, 0.0) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, java.lang.String name)
Creates a Location2D with (0.0, 0.0) position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-name
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, CoordinateIfc position)
Creates a Location2D with at the coordinates of the supplied position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-position
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, SpatialElementIfc position)
Creates a Location2D with at the coordinates of the supplied position. The SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-position
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, java.lang.String name, SpatialModel spatialModel)
Creates a Location2D with the given parent and SpatialModel2D. The default position is (0.0, 0.0). If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-name
-spatialModel
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, SpatialModel spatialModel)
Creates a Location2D with the given parent and SpatialModel2D. The default position is (0.0, 0.0). If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-spatialModel
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, SpatialModel spatialModel, SpatialElementIfc element)
Creates a Location2D with the given parent and SpatialModel2D. The default position is (0.0, 0.0). If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-spatialModel
-element
-
-
SpatialModelElement
public SpatialModelElement(ModelElement parent, java.lang.String name, SpatialModel spatialModel, CoordinateIfc coordinate)
Creates a Location2D with the given parent and SpatialModel2D. If the SpatialModel2D is null, the SpatialModel2D of the parent is used as the SpatialModel2D. If the parent does not have a SpatialModel2D, then an IllegalArgumentException is thrown- Parameters:
parent
-name
-spatialModel
-coordinate
-
-
-
Method Detail
-
getPosition
public final CoordinateIfc getPosition()
- Specified by:
getPosition
in interfacePositionIfc
- Specified by:
getPosition
in interfaceSpatialElementIfc
- Returns:
- Returns the current Position.
-
getInitialPosition
public final CoordinateIfc getInitialPosition()
- Specified by:
getInitialPosition
in interfaceSpatialElementIfc
- Returns:
- Returns the initialPosition.
-
getPreviousPosition
public final CoordinateIfc getPreviousPosition()
- Specified by:
getPreviousPosition
in interfaceSpatialElementIfc
- Returns:
- Returns the previousPosition.
-
distanceTo
public final double distanceTo(CoordinateIfc coordinate)
Description copied from interface:SpatialElementIfc
This is a "convenience" method for getting the distance from this element to the supplied coordinate within the underlying spatial model- Specified by:
distanceTo
in interfaceSpatialElementIfc
- Parameters:
coordinate
- the coordinate to check- Returns:
- the distance
-
isPositionEqualTo
public final boolean isPositionEqualTo(CoordinateIfc coordinate)
Description copied from interface:SpatialElementIfc
Returns true if the position of this element is the same as supplied coordinate within the underlying spatial model. This is not necessarily object reference equality, but rather whether or not the positions within the underlying spatial model can be considered the same (equivalent).- Specified by:
isPositionEqualTo
in interfaceSpatialElementIfc
- Parameters:
coordinate
- the coordinate to check- Returns:
- true if position is equal
-
distanceTo
public final double distanceTo(SpatialElementIfc element)
Description copied from interface:SpatialElementIfc
This is a "convenience" method for getting the distance from this element to the supplied element within the underlying spatial model Requirement: The elements must be in the same spatial model. The distance should be calculated by the spatial model. If they are not in the same spatial model this method will throw and IllegalArgumentException- Specified by:
distanceTo
in interfaceSpatialElementIfc
- Parameters:
element
- the element to check- Returns:
- the distance
-
isPositionEqualTo
public final boolean isPositionEqualTo(SpatialElementIfc element)
Description copied from interface:SpatialElementIfc
Returns true if the position of this element is the same as the position of the supplied element within the underlying spatial model. This is not necessarily object reference equality, but rather whether or not the positions within the underlying spatial model can be considered the same (equivalent). Requirement: The elements must be in the same spatial model. If they are not in the same spatial model, then this method should return false.- Specified by:
isPositionEqualTo
in interfaceSpatialElementIfc
- Parameters:
element
- the element to check- Returns:
- the distance
-
getInitialSpatialModel
public final SpatialModel getInitialSpatialModel()
Description copied from interface:SpatialElementIfc
Returns the spatial model that should hold this element at the beginning of each replication of a simulation- Specified by:
getInitialSpatialModel
in interfaceSpatialElementIfc
- Returns:
- the spatial model
-
changeSpatialModel
public final void changeSpatialModel(SpatialModel spatialModel, CoordinateIfc coordinate)
Description copied from interface:SpatialElementIfc
Changes the spatial model for this element and places the element at the supplied coordinate within the new spatial model. Throws IllegalArgumentException if the coordinate is not valid for the supplied spatial model. This spatial element becomes a child element of the new spatial model.- Specified by:
changeSpatialModel
in interfaceSpatialElementIfc
- Parameters:
spatialModel
- the spatial modelcoordinate
- the coordinate
-
getModelElement
public final ModelElement getModelElement()
Description copied from interface:SpatialElementIfc
Gets the ModelElement associated with this spatial element May be null- Specified by:
getModelElement
in interfaceSpatialElementIfc
- Returns:
- the model element
-
attachPositionObserver
public void attachPositionObserver(ObserverIfc observer)
Description copied from interface:SpatialElementIfc
Implementor of this interface should allow Observers to be attached. For example, the observers should be notified when the position changes. It is the responsibility of implementers to properly notify the observers.- Specified by:
attachPositionObserver
in interfaceSpatialElementIfc
- Parameters:
observer
- the observer
-
removePositionObserver
public void removePositionObserver(ObserverIfc observer)
Description copied from interface:SpatialElementIfc
Remove the observer from this PositionIfc- Specified by:
removePositionObserver
in interfaceSpatialElementIfc
- Parameters:
observer
- the observer
-
setInitialPosition
public void setInitialPosition(CoordinateIfc coordinate)
Description copied from interface:SpatialElementIfc
Sets the initial position of the element. This position should be used when initializeSpatialElement() is called, typically at the beginning of a replication.- Specified by:
setInitialPosition
in interfaceSpatialElementIfc
- Parameters:
coordinate
- the coordinate
-
initializeSpatialElement
public void initializeSpatialElement()
Description copied from interface:SpatialElementIfc
This method should be called to initialize the spatial element prior to running a simulation- Specified by:
initializeSpatialElement
in interfaceSpatialElementIfc
-
initialize
protected void initialize()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called- Overrides:
initialize
in classModelElement
-
getSpatialElement
protected final SpatialElement getSpatialElement()
Returns the spatial element associated with this spatial model element- Returns:
-
setSpatialElement
protected final void setSpatialElement(SpatialElement spatialElement)
Sets the underlying SpatialElement- Parameters:
spatialElement
- the element
-
setModelElement
protected void setModelElement(ModelElement modelElement)
-
setCurrentPosition
protected final void setCurrentPosition(CoordinateIfc currentPosition)
-
-