浏览代码

very rough sketch for TeamManager interface

/develop/centralizedcritic/counterfact
Ruo-Ping Dong 3 年前
当前提交
4bad484b
共有 7 个文件被更改,包括 72 次插入4 次删除
  1. 26
      com.unity.ml-agents/Runtime/Agent.cs
  2. 3
      com.unity.ml-agents.extensions/Runtime/Teams.meta
  3. 12
      com.unity.ml-agents/Runtime/ITeamManager.cs
  4. 3
      com.unity.ml-agents/Runtime/ITeamManager.cs.meta
  5. 29
      com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs
  6. 3
      com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs.meta

26
com.unity.ml-agents/Runtime/Agent.cs


/// </summary>
float[] m_LegacyActionCache;
private ITeamManager m_TeamManager;
/// <summary>
/// Called when the attached [GameObject] becomes enabled and active.
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html

/// <summary>
/// The reason that the Agent has been set to "done".
/// </summary>
enum DoneReason
public enum DoneReason
{
/// <summary>
/// The episode was ended manually by calling <see cref="EndEpisode"/>.

}
}
// Request the last decision with no callbacks
// We request a decision so Python knows the Agent is done immediately
m_Brain?.RequestDecision(m_Info, sensors);
ResetSensors();
if (m_TeamManager != null)
{
// Send final observations to TeamManager if it exists.
// The TeamManager is responsible to keeping track of the Agent after it's
// done, including propagating any "posthumous" rewards.
m_TeamManager.OnAgentDone(this, doneReason, sensors);
}
else
{
// We request a decision so Python knows the Agent is done immediately
m_Brain?.RequestDecision(m_Info, sensors);
ResetSensors();
}
// We also have to write any to any DemonstationStores so that they get the "done" flag.
foreach (var demoWriter in DemonstrationWriters)

var actions = m_Brain?.DecideAction() ?? new ActionBuffers();
m_Info.CopyActions(actions);
m_ActuatorManager.UpdateActions(actions);
}
public void SetTeamManager(ITeamManager teamManager)
{
m_TeamManager = teamManager;
teamManager?.RegisterAgent(this);
}
}
}

3
com.unity.ml-agents.extensions/Runtime/Teams.meta


fileFormatVersion: 2
guid: 77124df6c18c4f669052016b3116147e
timeCreated: 1610064454

12
com.unity.ml-agents/Runtime/ITeamManager.cs


using System.Collections.Generic;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents
{
public interface ITeamManager
{
void RegisterAgent(Agent agent);
// TODO not sure this is all the info we need, maybe pass a class/struct instead.
void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors);
}
}

3
com.unity.ml-agents/Runtime/ITeamManager.cs.meta


fileFormatVersion: 2
guid: 75810d91665e4477977eb78c9b15aeb3
timeCreated: 1610057818

29
com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs


using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
namespace Teams
{
// TODO abstract? inherit from MonoBehavior?
public class BaseTeamManager : ITeamManager
{
public void RegisterAgent(Agent agent)
{
throw new System.NotImplementedException();
}
public void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors)
{
// Possible implementation - save reference to Agent's IPolicy so that we can repeatedly
// call IPolicy.RequestDecision on behalf of the Agent after it's dead
// If so, we'll need dummy sensor impls with the same shape as the originals.
throw new System.NotImplementedException();
}
public void AddTeamReward(float reward)
{
}
}
}

3
com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs.meta


fileFormatVersion: 2
guid: b2967f9c3bd4449a98ad309085094769
timeCreated: 1610064493
正在加载...
取消
保存