%% Simulate Simulink Environment with Multiple Agents
% Simulate an environment created for the Simulink® model used in the example Train Agent to Perform Collaborative Task, using the agents trained in that example.
% Load the agents in the MATLAB® workspace.

load rlCollaborativeTaskAgents

%
% Create an environment for the rlCollaborativeTask Simulink® model, which has two agent blocks. Since the agents used by the two blocks (agentA and agentB) are already in the workspace, you do not need to pass their observation and action specifications to create the environment.

env = rlSimulinkEnv('rlCollaborativeTask',["rlCollaborativeTask/Agent A","rlCollaborativeTask/Agent B"]);

%
% Load the parameters that are needed by the rlCollaborativeTask Simulink® model to run.

rlCollaborativeTaskParams

%
% Simulate the agents against the environment, saving the experiences in xpr.

xpr = sim(env,[agentA agentB]);

%
% Plot actions of both agents.

subplot(2,1,1); plot(xpr(1).Action.forces)
subplot(2,1,2); plot(xpr(2).Action.forces)

% Copyright 2020 The MathWorks, Inc.