|
|
|
|
|
|
/// The Factory to generate policies.
|
|
|
|
/// </summary>
|
|
|
|
[AddComponentMenu("ML Agents/Behavior Parameters", (int)MenuGroup.Default)] |
|
|
|
internal class BehaviorParameters : MonoBehaviour |
|
|
|
public class BehaviorParameters : MonoBehaviour |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The associated <see cref="BrainParameters"/> for this behavior.
|
|
|
|
/// </summary>
|
|
|
|
public BrainParameters brainParameters |
|
|
|
{ |
|
|
|
get { return m_BrainParameters; } |
|
|
|
internal set { m_BrainParameters = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[HideInInspector, SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The neural network model used when in inference mode.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
/// </summary>
|
|
|
|
public NNModel model |
|
|
|
{ |
|
|
|
get { return m_Model; } |
|
|
|
internal set { m_Model = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[HideInInspector, SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// How inference is performed for this Agent's model.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
/// </summary>
|
|
|
|
public InferenceDevice inferenceDevice |
|
|
|
{ |
|
|
|
get { return m_InferenceDevice; } |
|
|
|
internal set { m_InferenceDevice = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[HideInInspector, SerializeField] |
|
|
|
BehaviorType m_BehaviorType; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The BehaviorType for the Agent.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.SetBehaviorType(BehaviorType)"/>
|
|
|
|
/// to set it.
|
|
|
|
/// </summary>
|
|
|
|
public BehaviorType behaviorType |
|
|
|
{ |
|
|
|
get { return m_BehaviorType; } |
|
|
|
internal set { m_BehaviorType = value; } |
|
|
|
} |
|
|
|
// Disable warning /com.unity.ml-agents/Runtime/Policy/BehaviorParameters.cs(...):
|
|
|
|
// warning CS0649: Field 'BehaviorParameters.m_BehaviorType' is never assigned to,
|
|
|
|
// and will always have its default value
|
|
|
|
// This field is set in the custom editor.
|
|
|
|
#pragma warning disable 0649
|
|
|
|
internal BehaviorType m_BehaviorType; |
|
|
|
#pragma warning restore 0649
|
|
|
|
[HideInInspector] |
|
|
|
[SerializeField] |
|
|
|
[HideInInspector, SerializeField] |
|
|
|
/// The name of this behavior, which is used as a base name. See
|
|
|
|
/// <see cref="fullyQualifiedBehaviorName"/> for the full name.
|
|
|
|
/// This cannot be set directly; use <see cref="Agent.GiveModel(string,NNModel,InferenceDevice)"/>
|
|
|
|
/// to set it.
|
|
|
|
/// </summary>
|
|
|
|
public string behaviorName |
|
|
|
{ |
|
|
|
get { return m_BehaviorName; } |
|
|
|
internal set { m_BehaviorName = value; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
// TODO properties here instead of Agent
|
|
|
|
|
|
|
|
[FormerlySerializedAs("m_useChildSensors")] |
|
|
|
[HideInInspector] |
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The associated <see cref="BrainParameters"/> for this behavior.
|
|
|
|
/// </summary>
|
|
|
|
internal BrainParameters brainParameters |
|
|
|
{ |
|
|
|
get { return m_BrainParameters; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The name of this behavior, which is used as a base name. See
|
|
|
|
/// <see cref="fullyQualifiedBehaviorName"/> for the full name.
|
|
|
|
/// </summary>
|
|
|
|
public string behaviorName |
|
|
|
{ |
|
|
|
get { return m_BehaviorName; } |
|
|
|
internal set { m_UseChildSensors = value; } // TODO make public, don't allow changes at runtime
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
get { return m_BehaviorName + "?team=" + TeamId; } |
|
|
|
} |
|
|
|
|
|
|
|
public IPolicy GeneratePolicy(Func<float[]> heuristic) |
|
|
|
internal IPolicy GeneratePolicy(Func<float[]> heuristic) |
|
|
|
{ |
|
|
|
switch (m_BehaviorType) |
|
|
|
{ |
|
|
|
|
|
|
default: |
|
|
|
return new HeuristicPolicy(heuristic); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Updates the model and related details for this behavior.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="newBehaviorName">New name for the behavior.</param>
|
|
|
|
/// <param name="model">New neural network model for this behavior.</param>
|
|
|
|
/// <param name="inferenceDevice">New inference device for this behavior.</param>
|
|
|
|
public void GiveModel( |
|
|
|
string newBehaviorName, |
|
|
|
NNModel model, |
|
|
|
InferenceDevice inferenceDevice = InferenceDevice.CPU) |
|
|
|
{ |
|
|
|
m_Model = model; |
|
|
|
m_InferenceDevice = inferenceDevice; |
|
|
|
m_BehaviorName = newBehaviorName; |
|
|
|
} |
|
|
|
} |
|
|
|
} |