crowdmodel.agents
Class Memory

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by repast.simphony.context.AbstractContext<T>
          extended by repast.simphony.context.SmallDefaultContext<T>
              extended by repast.simphony.context.DefaultContext
                  extended by crowdmodel.agents.Memory
All Implemented Interfaces:
java.lang.Iterable, java.util.Collection, repast.simphony.context.Context, repast.simphony.context.ContextListener, repast.simphony.context.RepastElement

public class Memory
extends repast.simphony.context.DefaultContext

Memory is a main part of the model structure. The main types of the model structure consists out of a sensor, motor, memory and physiology part. All there is to describe (behaviour, influences factors, processes, characteristics etc.) need to be described in either one of the (derived) main parts of the model structure Memory: describes the functional part of the model structure This is where behaviour is chosen and (mainly) is influenced. Memory consists out of memoryElements that represent the knowledge (goals, facts & rules) TODO (check: does the term knowledge capture all the content of the memory?) The memory exists only in an agent, this is why it is not an CObject and not a part of the overall context. Memory is a context on its own, in which the memory elements are the members of the context and a projection describes their underlying relationship (in an association network) The elements stored in memory are stored in a Map. Which makes them callable by name. This is different from the usual context in which this is stored in a Collection. To be able to work with this I overloaded some functions:

But also added some functions as you want some of the collection functionality:
This makes the usage of some other functions abundant, however still callable. Due to lack of time I cannot catch these exceptions or to write a new AbstractContext that implements the Collections framework that that allows me to override the add/remove function or just specificly for this Memory. So causion in using:
- Iterable() : creates an iterable over an empty collection, that doesn't reperesent memory as everything is stored in memoryMap. Use getIterator instead
- add or remove (Object o) % would be nice to overload this one
- actually any function of the Collections framework as it doesn't refers to a collection of MemoryElements

Author:
Nanda Wijermans

Field Summary
private  repast.simphony.space.graph.Network<MemoryElement> d_associations
           
private  java.util.HashMap<java.lang.String,BehaviourFact> d_behaviourFacts
           
private  java.util.Iterator<BehaviourRule> d_behaviours
           
protected  LocomotionRule d_dance
           
private  BehaviourFact d_danceExp
           
private  Goal d_domGoal
           
private  Goal d_empty
           
private  java.util.ArrayList<PersonFact> d_friends
           
private  java.util.HashMap<java.lang.String,PersonFact> d_hashFriends
           
private  Goal d_identity
           
private  PersonFact d_ingroup
           
protected  LocomotionRule d_kneel
           
private  BehaviourFact d_kneelExp
           
private  java.util.ArrayList<PersonFact> d_leaders
           
protected  LocomotionRule d_lieDown
           
private  BehaviourFact d_lieExp
           
private  java.util.HashMap<java.lang.String,MemoryElement> d_memoryMap
           
private  BehaviourRule d_nothing
           
private  BehaviourFact d_nothingExp
           
private  java.util.LinkedList<BehaviourRule> d_orderedBehaviours
           
private  BehaviourRule d_other
           
private  BehaviourFact d_otherExp
           
private  PersonFact d_outgroup
           
private  java.util.ArrayList<PersonFact> d_persons
           
private  java.util.Random d_rng
           
protected  LocomotionRule d_run
           
private  BehaviourFact d_runExp
           
private  Goal d_safety
           
private  PersonFact d_self
           
protected  LocomotionRule d_sitDown
           
private  BehaviourFact d_sitExp
           
private  Goal d_social
           
private  BehaviourFact d_standExp
           
protected  LocomotionRule d_standUp
           
private  Goal d_subsistence
           
private  CrowdAgent d_thisAgent
           
private  boolean d_thisAgentFlag
           
private  double d_time
           
private  PersonFact d_unknown
           
protected  LocomotionRule d_walk
           
private  BehaviourFact d_walkExp
           
 
Fields inherited from class repast.simphony.context.SmallDefaultContext
allObjs, objectMap
 
Fields inherited from class repast.simphony.context.AbstractContext
subContexts
 
Fields inherited from interface repast.simphony.context.Context
SYN_CONTEXT_PREFIX
 
Constructor Summary
Memory()
          The memory constructor initialises memory by creating goals, other memory elements, and their associations
 
Method Summary
 boolean add(MemoryElement element)
          This function overloads the general add function that is specified in Collection and (overridden by Context) The elements of Memory are collected within a Map instead of a Collection.
 boolean contains(MemoryElement me)
          Function that checks whether a MemoryElement is stored in Memory This overloads the contains function of AbstractContext, which isn't suitable here as an abstractContext stores its objects in a Collections, whereas we do so in a Map.
 java.lang.Boolean contains(java.lang.String eName)
          Returns whether memory has this element This is an overloading function.
 void createBehaviours()
          Creates the internal representation of a behaviour (= a behaviourRule) There are 3 general types of behaviour: locomotion, manipulation and communication
 void createFacts()
          Creates the facts an individual has in its memory There are 3 types of facts: behaviour, person, (event) facts
private  void createGoals()
          Creates the goals an individual has in its memory.
 BehaviourRule getBehaviour(java.lang.String name)
          Returns the behaviourRule given a name
 BehaviourFact getBehaviourFact(java.lang.String bName)
          Returns the behaviourFact corresponding to a behaviour name.
 Goal getDomGoal()
          Returns the dominant goal that is currently dominant and influencing behaviour in the cognitive system.
 MemoryElement getElement(java.lang.String eName)
          Returns an element from memory based on its name In naming elements we distinct betwee
 java.util.ArrayList<PersonFact> getFriends()
          Returns the friends an individual has.
 Goal getIdentity()
          Returns the identity goal
 double getIDPref()
           
 java.util.Iterator getIterator()
          Function that returns an iterator of all MemoryElements in Memory.
 java.util.ArrayList<PersonFact> getLeaders()
          Returns the agent this agent perceives as a leader
 java.util.HashMap<java.lang.String,MemoryElement> getMemoryElements()
          Returns the HashMap in which all the memoryElements are stored
 java.lang.String getNamesMemoryElements()
           
 BehaviourRule getNextActiveB()
          Returns the next most active behaviour.
 double getSafePref()
           
 Goal getSafety()
          Returns the safety goal
 Goal getSocial()
          Returns the social goal
 double getSocialPref()
           
 Goal getSubsistence()
          Returns the subsistence goal
 double getSubsPref()
           
 double getTime()
          Returns the internal time an agent has to select a behaviour
 boolean hasNextB()
          Returns whether there is a next active behaviour in memory left
 void initSubs(double initVal)
           
 boolean remove(MemoryElement element)
          This function overloads the general remove function that is specified in Collection and (overridden by Context) The elements of Memory are collected within a Map instead of a Collection.
 void setBehaviourIterator()
          Sets the iterator that returns behaviours in order of their current activation level As this is a class variable, it needs to be set before starting to compare behaviours as during comparing the iterator while first return the highest activation, then the second highest, etc.
 void setDomGoal()
          Sets d_domGoal with the most dominant goal for the given time There is a order of importance when the dominance values are identical then the goals become dominant in the order of: safety, subsistence, social (i doubt about the order of the last two in our setting)
 void setElementsWithAgentAndMemory()
          Sets for all memoryElements that they belong to which memory and corresponding agent.
 void setMyLeaders(java.util.HashSet<CrowdAgent> leaders)
          Sets in memory which agents this agent perceives as a leader NOTE: need to change this structure, PersonFacts need to be in one set, not separate for friends and leaders
 void setSocialScenario(repast.simphony.space.graph.Network socNetwork)
          Function sets the scenario in the memory of an agent This incorporates an individual having friends by having a personFact for each one of them
 void setThisAgent(CrowdAgent thisAgent)
          Sets the Agent to whom this memory belongs This allows for the 'direct' access of methods/vars concerning memory by the functions in Memory; The function checks whether this has already been assigned, at this is only done once while initialising.
protected  void setTime(double time)
          Sets the internal time an agent has, to select a behaviour
 void setupAssociations()
          Creates the links between the memory element with a certain initial association value Now I directly connected behaviourRules with behaviourFacts.
 void step()
          The step function defines what an agent does internally every simulation step/tick.
 void updateBehaviourOrdering(BehaviourRule b)
          This function is called when one of the behaviourRules activation has been changed.
 
Methods inherited from class repast.simphony.context.DefaultContext
addInternal, containsInternal, iteratorInternal, removeInternal, sizeInternal
 
Methods inherited from class repast.simphony.context.SmallDefaultContext
getObjects, getRandomObject, getRandomObjects
 
Methods inherited from class repast.simphony.context.AbstractContext
add, addContextListener, addProjection, addSubContext, addValueLayer, clear, contains, eventOccured, findContext, findParent, fireAddContextEvent, fireRemoveEvent, fireSubContextAdded, fireSubContextRemoved, getAgentLayer, getAgentTypes, getContextListeners, getId, getProjection, getProjection, getProjections, getProjections, getSubContext, getSubContexts, getTypeID, getValueLayer, getValueLayers, handleRemove, iterator, query, remove, removeContextListener, removeProjection, removeSubContext, removeValueLayer, setId, setTypeID, size
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Field Detail

d_thisAgent

private CrowdAgent d_thisAgent

d_thisAgentFlag

private boolean d_thisAgentFlag

d_associations

private repast.simphony.space.graph.Network<MemoryElement> d_associations

d_memoryMap

private java.util.HashMap<java.lang.String,MemoryElement> d_memoryMap

d_behaviourFacts

private java.util.HashMap<java.lang.String,BehaviourFact> d_behaviourFacts

d_hashFriends

private java.util.HashMap<java.lang.String,PersonFact> d_hashFriends

d_orderedBehaviours

private java.util.LinkedList<BehaviourRule> d_orderedBehaviours

d_friends

private java.util.ArrayList<PersonFact> d_friends

d_leaders

private java.util.ArrayList<PersonFact> d_leaders

d_persons

private java.util.ArrayList<PersonFact> d_persons

d_behaviours

private java.util.Iterator<BehaviourRule> d_behaviours

d_time

private double d_time

d_domGoal

private Goal d_domGoal

d_rng

private java.util.Random d_rng

d_identity

private Goal d_identity

d_social

private Goal d_social

d_safety

private Goal d_safety

d_subsistence

private Goal d_subsistence

d_empty

private Goal d_empty

d_walk

protected LocomotionRule d_walk

d_run

protected LocomotionRule d_run

d_dance

protected LocomotionRule d_dance

d_sitDown

protected LocomotionRule d_sitDown

d_standUp

protected LocomotionRule d_standUp

d_kneel

protected LocomotionRule d_kneel

d_lieDown

protected LocomotionRule d_lieDown

d_other

private BehaviourRule d_other

d_nothing

private BehaviourRule d_nothing

d_otherExp

private BehaviourFact d_otherExp

d_nothingExp

private BehaviourFact d_nothingExp

d_walkExp

private BehaviourFact d_walkExp

d_runExp

private BehaviourFact d_runExp

d_danceExp

private BehaviourFact d_danceExp

d_sitExp

private BehaviourFact d_sitExp

d_standExp

private BehaviourFact d_standExp

d_kneelExp

private BehaviourFact d_kneelExp

d_lieExp

private BehaviourFact d_lieExp

d_self

private PersonFact d_self

d_ingroup

private PersonFact d_ingroup

d_outgroup

private PersonFact d_outgroup

d_unknown

private PersonFact d_unknown
Constructor Detail

Memory

public Memory()
The memory constructor initialises memory by creating goals, other memory elements, and their associations

Method Detail

add

public boolean add(MemoryElement element)
This function overloads the general add function that is specified in Collection and (overridden by Context) The elements of Memory are collected within a Map instead of a Collection. As they are easily called based on their name.

Parameters:
name -
element -
Returns:
boolean, whether the addition worked or not

remove

public boolean remove(MemoryElement element)
This function overloads the general remove function that is specified in Collection and (overridden by Context) The elements of Memory are collected within a Map instead of a Collection. As they are easily called based on their name.

Parameters:
name -
element -
Returns:
boolean, whether the addition worked or not

contains

public boolean contains(MemoryElement me)
Function that checks whether a MemoryElement is stored in Memory This overloads the contains function of AbstractContext, which isn't suitable here as an abstractContext stores its objects in a Collections, whereas we do so in a Map.

Parameters:
me -
Returns:

getIterator

public java.util.Iterator getIterator()
Function that returns an iterator of all MemoryElements in Memory.

Returns:
iterator of the elements in Memory

step

public void step()
The step function defines what an agent does internally every simulation step/tick. This is a temporarily solution as I want the processes to be going parallel. Furthermore, I want to relate this to the internal time of an agent, that not necessarily need to be synchrony with the world time.


setThisAgent

public void setThisAgent(CrowdAgent thisAgent)
Sets the Agent to whom this memory belongs This allows for the 'direct' access of methods/vars concerning memory by the functions in Memory; The function checks whether this has already been assigned, at this is only done once while initialising. As this cannot be done in the constructor this is the 'ugly' solution.

Parameters:
thisAgent -

setElementsWithAgentAndMemory

public void setElementsWithAgentAndMemory()
Sets for all memoryElements that they belong to which memory and corresponding agent. This allows for the 'direct' access of methods/vars concerning memory and agent by the by the functions in MemoryElement; The function checks whether this has already been assigned, at this is only done once while initialising. As this cannot be done in the constructor this is the 'ugly' solution.

Parameters:
thisAgent -

setSocialScenario

public void setSocialScenario(repast.simphony.space.graph.Network socNetwork)
Function sets the scenario in the memory of an agent This incorporates an individual having friends by having a personFact for each one of them


setMyLeaders

public void setMyLeaders(java.util.HashSet<CrowdAgent> leaders)
Sets in memory which agents this agent perceives as a leader NOTE: need to change this structure, PersonFacts need to be in one set, not separate for friends and leaders


createGoals

private void createGoals()
Creates the goals an individual has in its memory. In this structure an agent has four abstract goals (identity, social, safety, subsistence) that represent the drives/desired states of an agent.


initSubs

public void initSubs(double initVal)

createFacts

public void createFacts()
Creates the facts an individual has in its memory There are 3 types of facts: behaviour, person, (event) facts


createBehaviours

public void createBehaviours()
Creates the internal representation of a behaviour (= a behaviourRule) There are 3 general types of behaviour: locomotion, manipulation and communication


setDomGoal

public void setDomGoal()
Sets d_domGoal with the most dominant goal for the given time There is a order of importance when the dominance values are identical then the goals become dominant in the order of: safety, subsistence, social (i doubt about the order of the last two in our setting)


setupAssociations

public void setupAssociations()
Creates the links between the memory element with a certain initial association value Now I directly connected behaviourRules with behaviourFacts. I am going to change this later, but I need this connection now to make it work. So it is a matter of restructuring the implementation, however this connections works as the model describes it.


getTime

public double getTime()
Returns the internal time an agent has to select a behaviour

Returns:
d_time

setTime

protected void setTime(double time)
Sets the internal time an agent has, to select a behaviour

Parameters:
time -

getDomGoal

public Goal getDomGoal()
Returns the dominant goal that is currently dominant and influencing behaviour in the cognitive system.

Returns:
d_domGoal

getIdentity

public Goal getIdentity()
Returns the identity goal

Returns:
d_identity - the identity goal

getSocial

public Goal getSocial()
Returns the social goal

Returns:
d_social - the social goal

getSafety

public Goal getSafety()
Returns the safety goal

Returns:
d_safety - the safety goal

getSubsistence

public Goal getSubsistence()
Returns the subsistence goal

Returns:
d_subsistence - the subsistence goal

getMemoryElements

public java.util.HashMap<java.lang.String,MemoryElement> getMemoryElements()
Returns the HashMap in which all the memoryElements are stored

Returns:
d_memoryMap - the collection of memoryElements

getNamesMemoryElements

public java.lang.String getNamesMemoryElements()
Returns:
a string containing all the names of the memoryElements currently in memory

getBehaviourFact

public BehaviourFact getBehaviourFact(java.lang.String bName)
Returns the behaviourFact corresponding to a behaviour name. Behaviour facts are currently stored within a hashmap of behaviourFacts. I want to associate behaviourRules with Facts in another way, however that takes more time as I have to create a subcontext for every agent in which all memory elements are connected. At this point I relate the behaviourRules with the facts by this HashMap where the name labels of the behaviourRules are the keys and the Facts are in the value slots

Returns:
d_behaviourFact - a fact about a behaviour

getFriends

public java.util.ArrayList<PersonFact> getFriends()
Returns the friends an individual has.

Returns:
d_friends - a hashSet of friends (personFacts).

getLeaders

public java.util.ArrayList<PersonFact> getLeaders()
Returns the agent this agent perceives as a leader

Returns:
d_friends - a hashSet of friends (personFacts).

setBehaviourIterator

public void setBehaviourIterator()
Sets the iterator that returns behaviours in order of their current activation level As this is a class variable, it needs to be set before starting to compare behaviours as during comparing the iterator while first return the highest activation, then the second highest, etc.


getNextActiveB

public BehaviourRule getNextActiveB()
Returns the next most active behaviour. As behaviours have an order based on their activation level. This order is used to compare behaviours with one and another.

Returns:
behaviour - next behaviour with the highest activation

hasNextB

public boolean hasNextB()
Returns whether there is a next active behaviour in memory left

Returns:
availability of a behaviour in the iterator

getBehaviour

public BehaviourRule getBehaviour(java.lang.String name)
Returns the behaviourRule given a name

Parameters:
name -
Returns:

getElement

public MemoryElement getElement(java.lang.String eName)
Returns an element from memory based on its name In naming elements we distinct betwee

Parameters:
eName -
Returns:

contains

public java.lang.Boolean contains(java.lang.String eName)
Returns whether memory has this element This is an overloading function. As the context memory has an function contains as well, however takes an object as an argument instead of a String (element name).

Parameters:
eName -
Returns:

updateBehaviourOrdering

public void updateBehaviourOrdering(BehaviourRule b)
This function is called when one of the behaviourRules activation has been changed. As d_orderedBehaviours is a list that contains all the behaviours ordered based on their activity This function keeps on having this ordening, allowing for changes.

Parameters:
b -

getIDPref

public double getIDPref()

getSocialPref

public double getSocialPref()

getSafePref

public double getSafePref()

getSubsPref

public double getSubsPref()