您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
89 行
2.5 KiB
89 行
2.5 KiB
using Barracuda;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace MLAgents
|
|
{
|
|
|
|
/// <summary>
|
|
/// The Factory to generate policies.
|
|
/// </summary>
|
|
public class BehaviorParameters : MonoBehaviour
|
|
{
|
|
|
|
[Serializable]
|
|
private enum BehaviorType
|
|
{
|
|
Default,
|
|
HeuristicOnly,
|
|
InferenceOnly
|
|
}
|
|
|
|
[HideInInspector]
|
|
[SerializeField]
|
|
BrainParameters m_BrainParameters = new BrainParameters();
|
|
[HideInInspector]
|
|
[SerializeField]
|
|
NNModel m_Model;
|
|
[HideInInspector]
|
|
[SerializeField]
|
|
InferenceDevice m_InferenceDevice;
|
|
[HideInInspector]
|
|
[SerializeField]
|
|
BehaviorType m_BehaviorType;
|
|
[HideInInspector]
|
|
[SerializeField]
|
|
string m_BehaviorName = "My Behavior";
|
|
[HideInInspector] [SerializeField]
|
|
int m_TeamID = 0;
|
|
|
|
public BrainParameters brainParameters
|
|
{
|
|
get { return m_BrainParameters; }
|
|
}
|
|
|
|
public string behaviorName
|
|
{
|
|
|
|
get { return m_BehaviorName + "?team=" + m_TeamID;}
|
|
|
|
}
|
|
|
|
public IPolicy GeneratePolicy(Func<float[]> heuristic)
|
|
{
|
|
switch (m_BehaviorType)
|
|
{
|
|
case BehaviorType.HeuristicOnly:
|
|
return new HeuristicPolicy(heuristic);
|
|
case BehaviorType.InferenceOnly:
|
|
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
|
|
case BehaviorType.Default:
|
|
if (FindObjectOfType<Academy>().IsCommunicatorOn)
|
|
{
|
|
return new RemotePolicy(m_BrainParameters, behaviorName);
|
|
}
|
|
if (m_Model != null)
|
|
{
|
|
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
|
|
}
|
|
else
|
|
{
|
|
return new HeuristicPolicy(heuristic);
|
|
}
|
|
default:
|
|
return new HeuristicPolicy(heuristic);
|
|
}
|
|
}
|
|
|
|
public void GiveModel(
|
|
string behaviorName,
|
|
NNModel model,
|
|
InferenceDevice inferenceDevice = InferenceDevice.CPU)
|
|
{
|
|
m_Model = model;
|
|
m_InferenceDevice = inferenceDevice;
|
|
m_BehaviorName = behaviorName;
|
|
}
|
|
}
|
|
}
|