浏览代码
Merge remote-tracking branch 'origin/develop-base-teammanager' into develop-agentprocessor-teammanager
/develop/coma2/samenet
Merge remote-tracking branch 'origin/develop-base-teammanager' into develop-agentprocessor-teammanager
/develop/coma2/samenet
Ervin Teng
4 年前
当前提交
281fcdbe
共有 27 个文件被更改,包括 408 次插入 和 177 次删除
-
63com.unity.ml-agents/Runtime/Agent.cs
-
4com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
-
74com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/AgentInfo.cs
-
2com.unity.ml-agents/Runtime/MultiAgentGroupIdCounter.cs.meta
-
7gym-unity/gym_unity/tests/test_gym.py
-
40ml-agents-envs/mlagents_envs/base_env.py
-
8ml-agents-envs/mlagents_envs/communicator_objects/agent_info_pb2.py
-
12ml-agents-envs/mlagents_envs/communicator_objects/agent_info_pb2.pyi
-
25ml-agents-envs/mlagents_envs/rpc_utils.py
-
4ml-agents-envs/mlagents_envs/tests/test_steps.py
-
10ml-agents/mlagents/trainers/tests/mock_brain.py
-
65ml-agents/mlagents/trainers/tests/simple_test_envs.py
-
4protobuf-definitions/proto/mlagents_envs/communicator_objects/agent_info.proto
-
2com.unity.ml-agents.extensions/Runtime/MultiAgent/BaseMultiAgentGroup.cs.meta
-
8com.unity.ml-agents.extensions/Runtime/MultiAgent.meta
-
26com.unity.ml-agents/Runtime/IMultiAgentGroup.cs
-
11com.unity.ml-agents/Runtime/IMultiAgentGroup.cs.meta
-
13com.unity.ml-agents/Runtime/MultiAgentGroupIdCounter.cs
-
161com.unity.ml-agents.extensions/Runtime/MultiAgent/BaseMultiAgentGroup.cs
-
8com.unity.ml-agents.extensions/Runtime/Teams.meta
-
14com.unity.ml-agents/Runtime/ITeamManager.cs
-
13com.unity.ml-agents/Runtime/TeamManagerIdCounter.cs
-
11com.unity.ml-agents/Runtime/ITeamManager.cs.meta
-
0/com.unity.ml-agents/Runtime/MultiAgentGroupIdCounter.cs.meta
-
0/com.unity.ml-agents.extensions/Runtime/MultiAgent/BaseMultiAgentGroup.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 8fe59ded1da3043db8d91c6d9c61eefe |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
/// <summary>
|
|||
/// MultiAgentGroup interface for grouping agents to support multi-agent training.
|
|||
/// </summary>
|
|||
public interface IMultiAgentGroup |
|||
{ |
|||
/// <summary>
|
|||
/// Get the ID of MultiAgentGroup.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// MultiAgentGroup ID.
|
|||
/// </returns>
|
|||
int GetId(); |
|||
|
|||
/// <summary>
|
|||
/// Register agent to the MultiAgentGroup.
|
|||
/// </summary>
|
|||
void RegisterAgent(Agent agent); |
|||
|
|||
/// <summary>
|
|||
/// UnRegister agent from the MultiAgentGroup.
|
|||
/// </summary>
|
|||
void UnregisterAgent(Agent agent); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3744ac27d956e43e1a39c7ba2550ab82 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Threading; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
internal static class MultiAgentGroupIdCounter |
|||
{ |
|||
static int s_Counter; |
|||
public static int GetGroupId() |
|||
{ |
|||
return Interlocked.Increment(ref s_Counter); ; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Unity.MLAgents.Extensions.MultiAgent |
|||
{ |
|||
/// <summary>
|
|||
/// A base class implementation of MultiAgentGroup.
|
|||
/// </summary>
|
|||
public class BaseMultiAgentGroup : IMultiAgentGroup, IDisposable |
|||
{ |
|||
int m_StepCount; |
|||
int m_GroupMaxStep; |
|||
readonly int m_Id = MultiAgentGroupIdCounter.GetGroupId(); |
|||
List<Agent> m_Agents = new List<Agent> { }; |
|||
|
|||
|
|||
public BaseMultiAgentGroup() |
|||
{ |
|||
Academy.Instance.PostAgentAct += _GroupStep; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
Academy.Instance.PostAgentAct -= _GroupStep; |
|||
while (m_Agents.Count > 0) |
|||
{ |
|||
UnregisterAgent(m_Agents[0]); |
|||
} |
|||
} |
|||
|
|||
void _GroupStep() |
|||
{ |
|||
m_StepCount += 1; |
|||
if ((m_StepCount >= m_GroupMaxStep) && (m_GroupMaxStep > 0)) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.EpisodeInterrupted(); |
|||
} |
|||
} |
|||
Reset(); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Register the agent to the MultiAgentGroup.
|
|||
/// Registered agents will be able to receive group rewards from the MultiAgentGroup
|
|||
/// and share observations during training.
|
|||
/// </summary>
|
|||
public virtual void RegisterAgent(Agent agent) |
|||
{ |
|||
if (!m_Agents.Contains(agent)) |
|||
{ |
|||
agent.SetMultiAgentGroup(this); |
|||
m_Agents.Add(agent); |
|||
agent.UnregisterFromGroup += UnregisterAgent; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Remove the agent from the MultiAgentGroup.
|
|||
/// </summary>
|
|||
public virtual void UnregisterAgent(Agent agent) |
|||
{ |
|||
if (m_Agents.Contains(agent)) |
|||
{ |
|||
m_Agents.Remove(agent); |
|||
agent.UnregisterFromGroup -= UnregisterAgent; |
|||
} |
|||
} |
|||
|
|||
public int GetId() |
|||
{ |
|||
return m_Id; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get list of all agents registered to this MultiAgentGroup.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// List of agents belongs to the MultiAgentGroup.
|
|||
/// </returns>
|
|||
public List<Agent> GetRegisteredAgents() |
|||
{ |
|||
return m_Agents; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Add group reward for all agents under this MultiAgentGroup.
|
|||
/// Disabled agent will not receive this reward.
|
|||
/// </summary>
|
|||
public void AddGroupReward(float reward) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.AddGroupReward(reward); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Set group reward for all agents under this MultiAgentGroup.
|
|||
/// Disabled agent will not receive this reward.
|
|||
/// </summary>
|
|||
public void SetGroupReward(float reward) |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.SetGroupReward(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 GroupMaxStep |
|||
{ |
|||
get { return m_GroupMaxStep; } |
|||
} |
|||
|
|||
public void SetGroupMaxStep(int maxStep) |
|||
{ |
|||
m_GroupMaxStep = maxStep; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// End Episode for all agents under this MultiAgentGroup.
|
|||
/// </summary>
|
|||
public void EndGroupEpisode() |
|||
{ |
|||
foreach (var agent in m_Agents) |
|||
{ |
|||
if (agent.enabled) |
|||
{ |
|||
agent.EndEpisode(); |
|||
} |
|||
} |
|||
Reset(); |
|||
} |
|||
|
|||
void Reset() |
|||
{ |
|||
m_StepCount = 0; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 77124df6c18c4f669052016b3116147e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.MLAgents.Sensors; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
public interface ITeamManager |
|||
{ |
|||
int GetId(); |
|||
|
|||
void RegisterAgent(Agent agent); |
|||
|
|||
void UnregisterAgent(Agent agent); |
|||
} |
|||
} |
|
|||
using System.Threading; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
internal static class TeamManagerIdCounter |
|||
{ |
|||
static int s_Counter; |
|||
public static int GetTeamManagerId() |
|||
{ |
|||
return Interlocked.Increment(ref s_Counter); ; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8b061f82569af4ffba715297f77a95ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue