org.micropsi.nodenet
Class NetEntity

java.lang.Object
  extended byorg.micropsi.nodenet.NetEntity
All Implemented Interfaces:
NetIntegrityIF
Direct Known Subclasses:
Module, Node

public abstract class NetEntity
extends java.lang.Object
implements NetIntegrityIF

The abstract ancestor of all net entities. An entity is basically a thing in a MicroPSI net that can have links to other entities and can be linked by entities. Incoming links are attached to Slots, outgoing links are maintained by Gates. (Slots, Gates and Links are not entities themselves, but part of entities.)
NetEntities are managed by the NetEntityManager and produced by the NetEntityFactory.

See Also:
NetEntityFactory, NetEntityManager, Gate, Slot, NetEntityTypesIF

Field Summary
protected  NetEntityManager entityManager
           
protected  java.util.ArrayList gates
           
protected  java.util.ArrayList slots
           
 
Fields inherited from interface org.micropsi.nodenet.NetIntegrityIF
BAD_KEY, BAD_LINK, BAD_OUTPUT_FUNCTION, BAD_SLOT, DUPLICATE_KEY, UNKNOWN_ENTITY, UNKNOWN_MODULE
 
Constructor Summary
protected NetEntity(java.lang.String id, NetEntityManager manager)
          Creates a new NetEntity, using the given id.
 
Method Summary
protected  void addGate(Gate g)
          Adds a gate to the entity.
protected  void addSlot(Slot s)
          Adds a slot to the entity.
protected abstract  void calculateGates()
          Calculates the gates.
protected  void changeParameter(int parameterType, int subID, java.lang.String newValue)
          Changes a parameter of this entity or one of it's slots, gates or hidden implementation.
 void checkIntegrity()
          Checks the integrity.
protected  void confirmNewActivation()
          Confirms the current activations of the gates.
protected  Link createLinkTo(java.lang.String id, int slot, Gate from, double weight, double confidence)
          Creates a new link.
protected  void createLinkTo(java.lang.String id, int slot, Gate from, double weight, double confidence, double x, double y, double z, int t)
          Creates a new link.
protected  void deleteGate(int gateType)
          Deletes a gate and all links originating from it.
protected  void deleteLink(int gate, java.lang.String to, int slot)
          Deletes a link originating from this entity.
protected  void deleteSlot(int slotType)
          Deletes a slot and all links attached to it.
protected  void destroy()
          Frees as many references as possible to avoid too much gc activity
 java.lang.String getEntityName()
          Returns the name of the entity, if the entity has a name.
abstract  int getEntityType()
          Returns the type of the entity
 Link getFirstLinkAt(int gate)
          Returns the first link of the given gate or null if there is no link at that gate.
 Gate getGate(int type)
          Returns a gate of the entity.
 java.util.Iterator getGates()
          Returns all gates of this entity.
 java.lang.String getID()
          Returns the unique ID of the entity.
 Link getLastLinkAt(int gate)
          Returns the last link of the given gate or null if there is no link at that gate.
 Link getLink(int gate, int at)
          Returns the n-th link of the given gate or null if there is no link at that gate
 int getNumberOfGates()
          Returns the number of gates of this entity.
 int getNumberOfSlots()
          Returns the number of slots.
 java.lang.String getParentID()
          Returns the ID of the entity's parent entity
 Slot getSlot(int type)
          Get the slot with the given type.
 java.util.Iterator getSlots()
          Returns all slots of this entity.
 boolean hasName()
          Returns true if the entity has a name.
 boolean isActive()
          Checks if one of the gates is active
protected  void propagateActivation()
          Propagates the activation of all active gates along all links attached to active gates, calculating new activation values and putting it into the linked slots.
 java.lang.String reportIntegrityStatus()
          Returns a String with integrity-relevant information about the entity
protected  void setEntityName(java.lang.String name)
          Sets the entity's name.
protected  void setParentID(java.lang.String parentID)
          Sets the parent ID
 java.lang.String toString()
           
protected  void unlinkCompletely()
          This removes all incoming and outgoing links, leaving the entity completely alone.
 void updateDecayState()
          Updates the decay state of all links attached to this entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gates

protected java.util.ArrayList gates

slots

protected java.util.ArrayList slots

entityManager

protected NetEntityManager entityManager
Constructor Detail

NetEntity

protected NetEntity(java.lang.String id,
                    NetEntityManager manager)
Creates a new NetEntity, using the given id. This should only be called by the NetEntityFactory.

Parameters:
id - The id of the entity
manager -
Method Detail

setParentID

protected void setParentID(java.lang.String parentID)
Sets the parent ID


getParentID

public java.lang.String getParentID()
Returns the ID of the entity's parent entity

Returns:
String

getID

public java.lang.String getID()
Returns the unique ID of the entity.

Returns:
String the ID of the entity.

getEntityType

public abstract int getEntityType()
Returns the type of the entity

Returns:
int the type
See Also:
NetEntityTypesIF

getGate

public Gate getGate(int type)
Returns a gate of the entity.

Parameters:
type - The type of the gate to be retrieved.
Returns:
Gate or null if there is no gate of that type
See Also:
Gate

getNumberOfGates

public int getNumberOfGates()
Returns the number of gates of this entity.

Returns:
int the number of gates

getGates

public java.util.Iterator getGates()
Returns all gates of this entity. Do not call
 remove()
 
.

Returns:
Iterator an iterator with all gates.

getSlots

public java.util.Iterator getSlots()
Returns all slots of this entity. Do not call
 remove()
 
.

Returns:
Iterator an iterator with all slots.

getNumberOfSlots

public int getNumberOfSlots()
Returns the number of slots.

Returns:
int the number of slots.

getSlot

public Slot getSlot(int type)
Get the slot with the given type.

Parameters:
type - the type of the slot to be retrieved.
Returns:
Slot the slot or null if there is no slot of that type

addGate

protected void addGate(Gate g)
                throws NetIntegrityException
Adds a gate to the entity.

Parameters:
g - the gate to be added
Throws:
NetIntegrityException - if there is already a gate of the same type

addSlot

protected void addSlot(Slot s)
                throws NetIntegrityException
Adds a slot to the entity.

Parameters:
s - the slot to be added
Throws:
NetIntegrityException - if there is already a slot of the same type

deleteGate

protected void deleteGate(int gateType)
                   throws NetIntegrityException
Deletes a gate and all links originating from it. The method will simply return if there is no such gate.

Parameters:
gateType - the type of the gate to be deleted
Throws:
NetIntegrityException - if the gate has bad links

deleteSlot

protected void deleteSlot(int slotType)
                   throws NetIntegrityException
Deletes a slot and all links attached to it. The method will simply return if there is no such slot.

Parameters:
slotType - the type of the slot that will be deleted
Throws:
NetIntegrityException - if the slot has bad links

isActive

public boolean isActive()
Checks if one of the gates is active

Returns:
boolean true if any gate is active, false otherwise

confirmNewActivation

protected void confirmNewActivation()
Confirms the current activations of the gates.


calculateGates

protected abstract void calculateGates()
                                throws NetIntegrityException
Calculates the gates.

Throws:
NetIntegrityException

propagateActivation

protected void propagateActivation()
                            throws NetIntegrityException
Propagates the activation of all active gates along all links attached to active gates, calculating new activation values and putting it into the linked slots.

Throws:
NetIntegrityException - if there is a bad link

getFirstLinkAt

public Link getFirstLinkAt(int gate)
Returns the first link of the given gate or null if there is no link at that gate.

Parameters:
gate - the gate
Returns:
Link the link
Throws:
java.lang.NullPointerException - if there is no such gate

getLastLinkAt

public Link getLastLinkAt(int gate)
Returns the last link of the given gate or null if there is no link at that gate.

Parameters:
gate - the gate
Returns:
Link the link
Throws:
java.lang.NullPointerException - if there is no such gate

getLink

public Link getLink(int gate,
                    int at)
Returns the n-th link of the given gate or null if there is no link at that gate

Parameters:
gate - the gate
at - the index of the link
Returns:
Link the link
Throws:
java.lang.NullPointerException - if there is no such gate

createLinkTo

protected void createLinkTo(java.lang.String id,
                            int slot,
                            Gate from,
                            double weight,
                            double confidence,
                            double x,
                            double y,
                            double z,
                            int t)
                     throws NetIntegrityException
Creates a new link. This will set all references correctly. (Also the one at the "remote" slot)

Parameters:
id - the NetEntity to be linked.
slot - the type of the slot the linke shall be attached to
from - the gate where the link originates from
weight - the initial weight of the link
confidence - the initial confidence of the link
x - the X value of the link
y - the Y value of the link
z - the Z value of the link
t - the T value of the link
Throws:
NetIntegrityException - if the linked entity does not exist or has no slot of the given type.
See Also:
Link, LinkFactory

createLinkTo

protected Link createLinkTo(java.lang.String id,
                            int slot,
                            Gate from,
                            double weight,
                            double confidence)
                     throws NetIntegrityException
Creates a new link. This will set all references correctly. (Also the one at the "remote" slot)

Parameters:
id - the NetEntity to be linked.
slot - the type of the slot the linke shall be attached to
from - the gate where the link originates from
weight - the initial weight of the link
confidence - the initial confidence of the link
Returns:
the newly created link
Throws:
NetIntegrityException - if the linked entity does not exist or has no slot of the given type.
See Also:
Link, LinkFactory

deleteLink

protected void deleteLink(int gate,
                          java.lang.String to,
                          int slot)
                   throws NetIntegrityException
Deletes a link originating from this entity. This will remove all references correctly, including the one at the "remote" slot. The link won't be referenced after a call to this method and will be eaten by the GC.

Parameters:
gate - the type of the gate the link originates from
to - the linked entity
slot - the linked entity's slot
Throws:
NetIntegrityException - if the link is bad
java.lang.NullPointerException - if this entity doesn't have a gate of the given type

unlinkCompletely

protected void unlinkCompletely()
                         throws NetIntegrityException
This removes all incoming and outgoing links, leaving the entity completely alone. This method will clear all references so all the links can now be eaten by the GC.

Throws:
NetIntegrityException - if there are any bad links attached to this entity.

checkIntegrity

public void checkIntegrity()
                    throws NetIntegrityException
Description copied from interface: NetIntegrityIF
Checks the integrity.

Specified by:
checkIntegrity in interface NetIntegrityIF
Throws:
NetIntegrityException - if the implementation violates the net's integrity.
See Also:
NetIntegrityIF.checkIntegrity()

reportIntegrityStatus

public java.lang.String reportIntegrityStatus()
Description copied from interface: NetIntegrityIF
Returns a String with integrity-relevant information about the entity

Specified by:
reportIntegrityStatus in interface NetIntegrityIF
Returns:
String the status
See Also:
NetIntegrityIF.reportIntegrityStatus()

getEntityName

public java.lang.String getEntityName()
Returns the name of the entity, if the entity has a name. Otherwise this method will return the ID of the entity.

Returns:
String the name of the entity.

setEntityName

protected void setEntityName(java.lang.String name)
Sets the entity's name.

Parameters:
name - the entity's name.

hasName

public boolean hasName()
Returns true if the entity has a name.

Returns:
boolean if there is a name, false otherwise

changeParameter

protected void changeParameter(int parameterType,
                               int subID,
                               java.lang.String newValue)
                        throws NetIntegrityException
Changes a parameter of this entity or one of it's slots, gates or hidden implementation. Possible values of parameterType can be found in NetParametersIF.

Parameters:
parameterType - the parameter to be changed
subID - the subid. Depending on the parameterType used, this can be the type of a slot, a gate or the key of a parameter of a hidden implementation (typically of a NativeModule)
newValue - The new value as String
Throws:
NetIntegrityException - if the slot or gate was not found
java.lang.NumberFormatException - if a conversion of the newValue had to be done and failed
See Also:
NetParametersIF

updateDecayState

public void updateDecayState()
                      throws NetIntegrityException
Updates the decay state of all links attached to this entity. Normally, this only happens just before the link's decayed weights are needed by the net, that is: when activation is propagatet on these links. However, you might want to know the link's current weights without having to propagate activation - if you work in any way with the weight of links that are subject to decays, you MUST call this method before doing so.

Throws:
MicropsiException - if there is no such entity
NetIntegrityException

toString

public java.lang.String toString()

destroy

protected void destroy()
Frees as many references as possible to avoid too much gc activity


(c) by Micropsi Project: http://www.cognitive-agents.org

.