Polarith AI
1.7
AIMContext Class Reference

Description

AIMContext builds the foundation of the AI system by providing access to all important modules (front-end component).

Every GameObject having this component becomes a moving agent controlled by the Polarith AI. This component enables you to control the general AI configuration right from the inspector, for example, how much objectives the agent should have, if the objectives should be normalized or minimized and many other settings. In addition, it holds and visualizes all environmental data sampled through active AIMBehaviour components. With the help of this data, the AIMContext executes all the algorithms necessary to evaluate the world of its agent and to find the best decision/solution for the current movement situation. The made decision can directly be obtained via properties like DecidedDirection and DecidedValues and so forth.

By default, an AIMContext component processes everything within Unity's update method, or, if a certain UpdateFrequency greater than 0 is specified, it uses its own coroutine for updating. When you set Threaded to true and there is an AIMPerformance component (Pro only) within the scene, the evaluation of all AIMContext components which are Threaded and ThreadSafe are distributed equally over the configured sub-threads where they get evaluated in parallel. An AIMContext is considered ThreadSafe if all of its associated Behaviours are also thread-safe. Through multithreading, the overall system might run about two to three times faster than without multithreading. Of course, this mainly depends on the number of agents, active behaviours and the number of perceived objects per agent. Multithreading performs best on large-scale scenes which have got hundreds of agents.

Furthermore, this component provides you with a lot of methods to quickly access and modify the underlying data, e.g. AddObjective(bool, bool, float, bool), GetObjective(int) and so forth. Note, you can achieve the same through modifying the data directly using the context object hierarchy, e.g. Problem<T>.AddObjective(bool) or, Problem<T>.GetObjective(int) within Context.

Front-end component of the underlying Move.Context class. Only one single component can be attached to one GameObject at a time.

Inheritance diagram for AIMContext:

Public Fields

readonly IList< IEvaluationPreparerEvaluationPreparers = new List<IEvaluationPreparer>()
 Contains references of instances which need to prepare certain things before Context.Evaluate must be called. More...
 
readonly IList< AIMBehaviourBehaviours = new List<AIMBehaviour>()
 All associated AIMBehaviour components which are attached on the GameObject of this agent (read only). More...
 
float UpdateFrequency = 20.0f
 Specifies how often the AI system should update this agent per second. More...
 
bool Threaded
 Specifies if this movement AI context should be evaluated in parallel to other existing agents. More...
 
bool SensorShared = true
 If set to false, this agent clones the associated Sensor on start so that it can safely be manipulated at runtime without disturbing other agents having the same sensor specified in its inspector. More...
 
AIMSensor Sensor
 The currently used sensor asset which determines how this agent observes the world. More...
 
bool BehaviourSortRequired = true
 If true, this component re-sorts all known Behaviours to match the specified CriteriaBehaviour.Order during the next PrepareEvaluation call. More...
 
bool ThreadSafetyCheckRequired = true
 Indicates whether this instance needs to re-check all of the associated Behaviours for thread-safety to figure out if is ThreadSafe itself. More...
 

Properties

static ReadOnlyCollection< AIMContextThreadedComponents [get]
 Contains all AIMContext instances corresponding to the ThreadedContexts which are suitable for multithreading (read only). More...
 
static ReadOnlyCollection< AIMContextNonThreadedComponents [get]
 Contains all AIMContext instances that are not suitable for multithreading (read only). More...
 
static ReadOnlyCollection< ContextThreadedContexts [get]
 Contains all Move.Context instances corresponding to the ThreadedComponents which are suitable for multithreading (read only). More...
 
Context Context [get]
 The underlying back-end class representing the movement AI context (read only). More...
 
int ObjectiveCount [get]
 The number of objectives (read only). More...
 
int ValueCount [get]
 The number of values per objective (read only). More...
 
IList< float > DecidedValues [get]
 The objective values of the current decision made by the movement AI system (read only). More...
 
Vector3 DecidedDirection [get]
 The result direction of the current decision made by the movement AI system (world coordinates, read only). More...
 
Vector3 LocalDecidedDirection [get]
 The DecidedDirection in local coordinates (read only). More...
 
float DecidedMagnitude [get]
 The magnitude of the winning sensor receptor corresponding to the decision made by the movement AI system. More...
 
Vector3 DecidedReceptorPosition [get]
 The position of the winning sensor receptor corresponding to the decision made by the movement AI system (world coordinates, read only). More...
 
Vector3 LocalDecidedReceptorPosition [get]
 The DecidedReceptorPosition in local coordinates (read only). More...
 
float DecidedReceptorSensitivity [get]
 The sensitivity of the winning sensor receptor corresponding to the decision made by the movement AI system. More...
 
bool ThreadSafe [get]
 Indicates whether this AIMContext instance is suitable for multithreading (read only). More...
 
GameObject SelfObject [get, set]
 Can be used to receive the self percept data of this agent. More...
 
List< string > ObjectiveLabels [get]
 Returns a list containing labels which can be used to identify objectives instead of using indices. More...
 

Public Methods

void BuildContext ()
 Prepares the underlying Move.Context instance to be used, and if requested, clones the associated Sensor asset. More...
 
void Evaluate ()
 In most cases, this method must not be manually called at all because the system does that automatically. More...
 
void PrepareEvaluation ()
 Updates everything which is necessary before Context.Evaluate can be called. More...
 
void ObtainEvaluatedResults ()
 This method needs to be called in order to get the evaluated results from the AI back-end into this front-end component so that the corresponding properties like DecidedDirection and DecidedValues are updated to the latest results. More...
 
ReadOnlyCollection< float > AddObjective (bool minimized, bool normalized, float constraint=0.0f, bool unlimited=false)
 Adds an objective (one row to the problem matrix). More...
 
void AddValues (float value)
 Adds a value to every objective (one column to the problem matrix). More...
 
void AddValues (float[] values)
 Adds a value to every objective (one column to the problem matrix). More...
 
ReadOnlyCollection< float > GetObjective (int index)
 Gets the objective (problem matrix row) belonging to the specified index . More...
 
float GetValue (int objectiveIndex, int valueIndex)
 Gets an objective value (single element of the problem matrix). More...
 
float GetEpsilonConstraint (int index)
 If the given objective index is valid, the corresponding epsilon-constraint is returned. More...
 
bool IsObjectiveMinimized (int index)
 Determines if an objective is considered to be minimized or maximized. More...
 
bool IsObjectiveNormalized (int index)
 Determines whether the objective with the specified index is normalized when calling Context.Evaluate. More...
 
bool IsObjectiveUnlimited (int index)
 Determines whether the objective with the specified index is unlimited. More...
 
void SetValue (int objectiveIndex, int valueIndex, float value)
 Sets a value (single element of the problem matrix). More...
 
void SetEpsilonConstraint (int index, float value)
 If the given objective index is valid, the corresponding epsilon-constraint is set to the specified value . More...
 
void SetObjectiveMinimized (int index, bool minimized)
 Specifies if an objective is considered to be minimized or maximized. More...
 
void SetObjectiveNormalized (int index, bool normalized)
 Allows to set whether the objective with the specified index is normalized when calling Context.Evaluate. More...
 
void SetObjectiveUnlimited (int index)
 Determines if the objective with the specified index is unlimited. More...
 
void ResetValues ()
 Resets all objective values to the default value 0. More...
 
void RemoveObjectiveAt (int index)
 Removes the objective (problem matrix row) at the specified index . More...
 
void RemoveValuesAt (int index)
 Removes the objective values (problem matrix column) at the specified index . More...
 
void ResizeObjectives (int valueCount)
 Changes the number of values (column length) for each objective to the specified valueCount . More...
 
void ClearAgent ()
 Removes every behaviour, steering filter or steering tag from the agent and resets the AIMContext component to its default values. More...
 
void ClearObjectives ()
 Removes all objectives including all values. More...
 
void ClearValues ()
 Removes all values but preserves the number of objectives. More...
 
void UpdateIndicator ()
 A signal for the indicator gizmo that the current results from evaluating the context were properly obtained. More...
 
void Reset ()
 Reset to default values. More...
 
void UpdateThreadSafety ()
 Forces a recheck against thread-safety for all attached behaviours. More...
 
Imprint