浏览代码
Merge branch 'develop-base-teammanager' into develop-agentprocessor-teammanager
/develop/coma2/samenet
Merge branch 'develop-base-teammanager' into develop-agentprocessor-teammanager
/develop/coma2/samenet
Ervin Teng
4 年前
当前提交
3fbed6dc
共有 12 个文件被更改,包括 260 次插入 和 42 次删除
-
155com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs
-
3com.unity.ml-agents/Runtime/Academy.cs
-
46com.unity.ml-agents/Runtime/Agent.cs
-
1com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
-
38com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/AgentInfo.cs
-
6com.unity.ml-agents/Runtime/ITeamManager.cs
-
12ml-agents-envs/mlagents_envs/base_env.py
-
11ml-agents-envs/mlagents_envs/communicator_objects/agent_info_pb2.py
-
6ml-agents-envs/mlagents_envs/communicator_objects/agent_info_pb2.pyi
-
1protobuf-definitions/proto/mlagents_envs/communicator_objects/agent_info.proto
-
12com.unity.ml-agents/Runtime/Actuators/ITeamManager.cs
-
11com.unity.ml-agents/Runtime/Actuators/ITeamManager.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
public class BaseTeamManager : ITeamManager |
|||
public class BaseTeamManager : ITeamManager, IDisposable |
|||
int m_StepCount; |
|||
int m_TeamMaxStep; |
|||
List<Agent> m_Agents = new List<Agent> { }; |
|||
public virtual void RegisterAgent(Agent agent) { } |
|||
public BaseTeamManager() |
|||
{ |
|||
Academy.Instance.PostAgentAct += _ManagerStep; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
Academy.Instance.PostAgentAct -= _ManagerStep; |
|||
} |
|||
|
|||
void _ManagerStep() |
|||
{ |
|||
m_StepCount += 1; |
|||
if ((m_StepCount >= m_TeamMaxStep) && (m_TeamMaxStep > 0)) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.EpisodeInterrupted(); |
|||
} |
|||
} |
|||
Reset(); |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// Register the agent to the TeamManager.
|
|||
/// Registered agents will be able to receive team rewards from the TeamManager
|
|||
/// and share observations during training.
|
|||
/// </summary>
|
|||
public virtual void RegisterAgent(Agent agent) |
|||
{ |
|||
if (!m_Agents.Contains(agent)) |
|||
{ |
|||
m_Agents.Add(agent); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Remove the agent from the TeamManager.
|
|||
/// </summary>
|
|||
public virtual void UnregisterAgent(Agent agent) |
|||
{ |
|||
if (m_Agents.Contains(agent)) |
|||
{ |
|||
m_Agents.Remove(agent); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get the ID of the TeamManager.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// TeamManager ID.
|
|||
/// </returns>
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get list of all agents registered to this TeamManager.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// List of agents belongs to the TeamManager.
|
|||
/// </returns>
|
|||
public List<Agent> GetRegisteredAgents() |
|||
{ |
|||
return m_Agents; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Add team reward for all agents under this Teammanager.
|
|||
/// Disabled agent will not receive this reward.
|
|||
/// </summary>
|
|||
public void AddTeamReward(float reward) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.AddTeamReward(reward); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Set team reward for all agents under this Teammanager.
|
|||
/// Disabled agent will not receive this reward.
|
|||
/// </summary>
|
|||
public void SetTeamReward(float reward) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.SetTeamReward(reward); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the current step counter (within the current episode).
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// Current step count.
|
|||
/// </returns>
|
|||
public int StepCount |
|||
{ |
|||
get { return m_StepCount; } |
|||
} |
|||
|
|||
public int TeamMaxStep |
|||
{ |
|||
get { return m_TeamMaxStep; } |
|||
} |
|||
|
|||
public void SetTeamMaxStep(int maxStep) |
|||
{ |
|||
m_TeamMaxStep = maxStep; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// End Episode for all agents under this TeamManager.
|
|||
/// </summary>
|
|||
public void EndTeamEpisode() |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.EndEpisode(); |
|||
} |
|||
} |
|||
Reset(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// End Episode for all agents under this TeamManager.
|
|||
/// </summary>
|
|||
public virtual void OnTeamEpisodeBegin() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void Reset() |
|||
{ |
|||
m_StepCount = 0; |
|||
OnTeamEpisodeBegin(); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.MLAgents.Sensors; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
public interface ITeamManager |
|||
{ |
|||
int GetId(); |
|||
|
|||
void RegisterAgent(Agent agent); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8b061f82569af4ffba715297f77a95ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue