%% Configure Options for Training a Multi-Agent Environment
% Create an options object for concurrently training three agents in the same environment.
% Set the maximum number of episodes and the maximum steps per episode to 1000. Configure the options to stop training the first agent when its average reward over 5 episodes equals or exceeds 400, the second agent when its average reward over 10 episodes equals or exceeds 500, and the third when its average reward over 15 episodes  equals or exceeds 600. The order of agents is the one used during environment creation.
% Save the agents when the reward for the first agent in the current episode exceeds 100, or when the reward for the second agent exceeds 120, the reward for the third agent equals or exceeds 140.
% Turn on both the command-line display and Reinforcement Learning Episode Manager for displaying training results. You can set the options using name-value pair arguments when you create the options set. Any options that you do not explicitly set have their default values.

trainOpts = rlTrainingOptions(...
    'MaxEpisodes',1000,...
    'MaxStepsPerEpisode',1000,...    
    'ScoreAveragingWindowLength',[5 10 15],...        
    'StopTrainingCriteria',"AverageReward",...
    'StopTrainingValue',[400 500 600],...    
    'SaveAgentCriteria',"EpisodeReward",...
    'SaveAgentValue',[100 120 140],...    
    'Verbose',true,...
    'Plots',"training-progress")

%
% Alternatively, create a default options set and use dot notation to change some of the values.

trainOpts = rlTrainingOptions;
trainOpts.MaxEpisodes = 1000;
trainOpts.MaxStepsPerEpisode = 1000;

trainOpts.ScoreAveragingWindowLength = [5 10 15];

trainOpts.StopTrainingCriteria = "AverageReward";
trainOpts.StopTrainingValue = [400 500 600];

trainOpts.SaveAgentCriteria = "EpisodeReward";
trainOpts.SaveAgentValue = [100 120 140];

trainOpts.Verbose = true;
trainOpts.Plots = "training-progress";

trainOpts

%
% You can specify a scalar to apply the same criterion to all agents. For example, use a window length of 10 for all three agents.

trainOpts.ScoreAveragingWindowLength = 10

% You can now use trainOpts as an input argument to the train command.
% Copyright 2020 The MathWorks, Inc.