Package mgui.models.environments
Class SimpleEnvironment<T extends MguiNumber>
java.lang.Object
mgui.interfaces.AbstractInterfaceObject
mgui.models.environments.SimpleEnvironment<T>
- All Implemented Interfaces:
java.lang.Cloneable
,InterfaceObject
,NamedObject
,TreeObject
,CleanableObject
,DynamicModelEnvironment<T>
,TimeStepListener
,Updateable
public class SimpleEnvironment<T extends MguiNumber> extends AbstractInterfaceObject implements DynamicModelEnvironment<T>, InterfaceObject, TreeObject
Represents a simple environment, with a set of named observable scalar state variables.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Field Summary
Fields Modifier and Type Field Description protected double
clock
protected SimpleEnvironmentInputDataSource<T>
input_data_source
protected NameMap
input_names
protected double[]
inputState
protected boolean
isDestroyed
int
mode
protected SimpleEnvironmentObservableDataSource<T>
observable_data_source
protected NameMap
observable_names
protected double[]
observableState
java.util.ArrayList<DynamicModelEnvironmentSensor>
sensors
protected java.util.ArrayList<InterfaceTreeNode>
treeNodes
boolean
updated
SimpleEnvironmentUpdater
updater
Fields inherited from class mgui.interfaces.AbstractInterfaceObject
tree_nodes
-
Constructor Summary
Constructors Constructor Description SimpleEnvironment()
SimpleEnvironment(SimpleEnvironmentUpdater updater)
Creates an instance of SimpleEnvironment with the specified updater. -
Method Summary
Modifier and Type Method Description void
addListener(DynamicModelEnvironmentListener l)
void
addSensor(DynamicModelEnvironmentSensor s)
java.lang.Object
clone()
void
destroy()
Destroy this object (prepare it to be removed from memory)protected void
fireListeners()
protected void
fireSensors()
double
getClock()
java.util.List<InterfaceDataSource<T>>
getDataSources()
double[]
getDeltas(double[] comp)
Returns the difference between this environment's current state and the given values.AbstractEnvironmentDataSource<T>
getInputDataSource()
java.util.List<java.lang.String>
getInputNames()
double[]
getInputState()
double
getInputState(int i)
int
getMode()
AbstractEnvironmentDataSource<T>
getObservableDataSource()
java.util.ArrayList<java.lang.String>
getObservableNames()
int
getObservableSize()
double[]
getObservableState()
double
getObservableState(int i)
double[]
getSquaredDeltas(double[] comp)
Returns the squared difference between this environment's current state and the given values.InterfaceTreeNode
getTreeNodeCopy()
void
handleOutputEvent(DynamicModelOutputEvent e)
boolean
hasSensor(DynamicModelEnvironmentSensor s)
boolean
isDestroyed()
Test whether this object has been destroyedInterfaceTreeNode
issueTreeNode()
Issues a new tree node and sets it usingAbstractInterfaceObject.setTreeNode(mgui.interfaces.trees.InterfaceTreeNode)
.void
removeListener(DynamicModelEnvironmentListener l)
void
removeObservableName(int index)
void
removeObservableName(java.lang.String name)
void
removeSensor(DynamicModelEnvironmentSensor s)
void
reset()
void
resetInputDataSource()
protected void
resetInputNames()
protected void
resetInputState()
void
resetObservableDataSource()
protected void
resetObservableState()
void
setInputName(int index, java.lang.String name)
void
setInputNames(java.util.List<java.lang.String> names)
void
setInputSize(int s)
void
setInputState(double[] v)
void
setMode(int m)
void
setObservableName(int index, java.lang.String name)
void
setObservableNames(NameMap names)
void
setObservableSize(int s)
void
setObservableState(double[] values)
void
setObservableState(int index, double value)
void
setTreeNode()
void
setUpdater(DynamicModelUpdater updater)
void
timeElapsed(double time)
java.lang.String
toString()
Methods inherited from class mgui.interfaces.AbstractInterfaceObject
clean, getName, getTreeLabel, setName, setTreeNode, updateTreeNodes
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface mgui.interfaces.util.CleanableObject
clean
Methods inherited from interface mgui.interfaces.NamedObject
getName, setName
Methods inherited from interface mgui.interfaces.trees.TreeObject
getTreeLabel, setTreeNode
-
Field Details
-
inputState
protected double[] inputState -
observableState
protected double[] observableState -
clock
protected double clock -
updater
-
sensors
-
updated
public boolean updated -
mode
public int mode -
observable_data_source
-
input_data_source
-
treeNodes
-
observable_names
-
input_names
-
isDestroyed
protected boolean isDestroyed
-
-
Constructor Details
-
SimpleEnvironment
public SimpleEnvironment() -
SimpleEnvironment
Creates an instance of SimpleEnvironment with the specified updater.- Parameters:
updater
-
-
-
Method Details
-
getClock
public double getClock()- Specified by:
getClock
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
addListener
- Specified by:
addListener
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
removeListener
- Specified by:
removeListener
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
fireListeners
protected void fireListeners() -
setUpdater
- Specified by:
setUpdater
in interfaceDynamicModelEnvironment<T extends MguiNumber>
- Throws:
DynamicModelException
-
getDataSources
- Specified by:
getDataSources
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setInputState
public void setInputState(double[] v) -
getInputState
public double[] getInputState()- Specified by:
getInputState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getInputState
public double getInputState(int i)- Specified by:
getInputState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setInputName
public void setInputName(int index, java.lang.String name)- Specified by:
setInputName
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setInputNames
public void setInputNames(java.util.List<java.lang.String> names)- Specified by:
setInputNames
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getInputNames
public java.util.List<java.lang.String> getInputNames()- Specified by:
getInputNames
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setObservableName
public void setObservableName(int index, java.lang.String name)- Specified by:
setObservableName
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setObservableNames
- Specified by:
setObservableNames
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getObservableNames
public java.util.ArrayList<java.lang.String> getObservableNames()- Specified by:
getObservableNames
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
removeObservableName
public void removeObservableName(java.lang.String name)- Specified by:
removeObservableName
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
removeObservableName
public void removeObservableName(int index)- Specified by:
removeObservableName
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setObservableState
public void setObservableState(double[] values)- Specified by:
setObservableState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setObservableState
public void setObservableState(int index, double value)- Specified by:
setObservableState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getObservableState
public double getObservableState(int i)- Specified by:
getObservableState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getObservableState
public double[] getObservableState()- Specified by:
getObservableState
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getObservableSize
public int getObservableSize()- Specified by:
getObservableSize
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getDeltas
public double[] getDeltas(double[] comp)Returns the difference between this environment's current state and the given values. Calculated as delta[i] = env[i] - comp[i].- Parameters:
comp
-- Returns:
-
getSquaredDeltas
public double[] getSquaredDeltas(double[] comp)Returns the squared difference between this environment's current state and the given values.- Parameters:
comp
-- Returns:
-
timeElapsed
public void timeElapsed(double time)- Specified by:
timeElapsed
in interfaceTimeStepListener
-
setMode
public void setMode(int m) -
getMode
public int getMode() -
reset
public void reset()- Specified by:
reset
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
resetInputState
protected void resetInputState() -
resetObservableState
protected void resetObservableState() -
fireSensors
protected void fireSensors() -
handleOutputEvent
- Specified by:
handleOutputEvent
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setObservableSize
public void setObservableSize(int s)- Specified by:
setObservableSize
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
setInputSize
public void setInputSize(int s)- Specified by:
setInputSize
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
addSensor
- Specified by:
addSensor
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
removeSensor
- Specified by:
removeSensor
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
getObservableDataSource
- Specified by:
getObservableDataSource
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
resetObservableDataSource
public void resetObservableDataSource() -
getInputDataSource
- Specified by:
getInputDataSource
in interfaceDynamicModelEnvironment<T extends MguiNumber>
-
resetInputDataSource
public void resetInputDataSource() -
resetInputNames
protected void resetInputNames() -
clone
public java.lang.Object clone()- Overrides:
clone
in classjava.lang.Object
-
issueTreeNode
Description copied from class:AbstractInterfaceObject
Issues a new tree node and sets it usingAbstractInterfaceObject.setTreeNode(mgui.interfaces.trees.InterfaceTreeNode)
. The tree node is stored in this object, which facilitates their destruction when necessary (e.g., when this object is destroyed). All issued tree nodes can informed of changes to their user object using the methodAbstractInterfaceObject.updateTreeNodes()
.- Specified by:
issueTreeNode
in interfaceTreeObject
- Overrides:
issueTreeNode
in classAbstractInterfaceObject
- Returns:
- a new
InterfaceTreeNode
-
hasSensor
-
getTreeNodeCopy
-
setTreeNode
public void setTreeNode() -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
destroy
public void destroy()Description copied from interface:InterfaceObject
Destroy this object (prepare it to be removed from memory)- Specified by:
destroy
in interfaceInterfaceObject
- Overrides:
destroy
in classAbstractInterfaceObject
-
isDestroyed
public boolean isDestroyed()Description copied from interface:InterfaceObject
Test whether this object has been destroyed- Specified by:
isDestroyed
in interfaceInterfaceObject
- Overrides:
isDestroyed
in classAbstractInterfaceObject
- Returns:
-