src/demo/TSP.java
private Agent createAgent(int inputSize, int outputSize) throws MatrixException, NeuralNetworkException, DynamicParamException, IOException, ClassNotFoundException, AgentException {
        int policyType = 0;
        ExecutablePolicyType executablePolicyType = null;
        String policyTypeParams = "";
        switch (policyType) {
            case 0 -> executablePolicyType = ExecutablePolicyType.GREEDY;
            case 1 -> {
                executablePolicyType = ExecutablePolicyType.EPSILON_GREEDY;
                policyTypeParams = "epsilonInitial = 0.4, epsilonDecayRate = 0.999, epsilonMin = 0";
            }
            case 2 -> {
                executablePolicyType = ExecutablePolicyType.NOISY_NEXT_BEST;
                policyTypeParams = "initialExplorationNoise = 0.2, explorationNoiseDecay = 0.999, minExplorationNoise = 0";
            }
            case 3 -> {
                executablePolicyType = ExecutablePolicyType.SAMPLED;
                policyTypeParams = "thresholdInitial = 0.7, thresholdMin = 0.0";
            }
        }
        boolean singleFunctionEstimator = false;
        boolean onlineMemory = true;
        AgentFactory.AgentAlgorithmType agentAlgorithmType = AgentFactory.AgentAlgorithmType.MCTS;
        String algorithmParams = switch (agentAlgorithmType) {
            case QN -> "agentUpdateCycle = 100, lambda = 0.5, optimizerName = AMSGrad, learningRate = 0.01";
            case DDQN -> "lambda = 0.5, applyImportanceSamplingWeights = true, applyUniformSampling = false, capacity = 20000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01";
            case Sarsa, ActorCritic, PPO, REINFORCE -> "lambda = 1";
            case SACDiscrete -> "lambda = 0, applyImportanceSamplingWeights = false, applyUniformSampling = true, capacity = 2000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01, agentUpdateCycle = 1";
            case MCTS -> "lambda = 1, gamma = 1, updateValuePerEpisode = true";
            default -> "";
        };

        String params = "";
        if (policyTypeParams.isEmpty() && !algorithmParams.isEmpty()) params = algorithmParams;
        if (!policyTypeParams.isEmpty() && algorithmParams.isEmpty()) params = policyTypeParams;
        if (!policyTypeParams.isEmpty() && !algorithmParams.isEmpty()) params = policyTypeParams + ", " + algorithmParams;

        Agent agent = AgentFactory.createAgent(this, agentAlgorithmType, this, inputSize, outputSize, onlineMemory, singleFunctionEstimator, executablePolicyType, params);
        agent.start();
        return agent;
    }
/**
     * Creates agent (player).
     *
     * @param inputSize number of inputs for agent.
     * @param outputSize number of outputs for agent.
     * @return agent
     * @throws MatrixException throws exception if neural network has less output than actions.
     * @throws NeuralNetworkException throws exception if neural network operation fails.
     * @throws DynamicParamException throws exception if setting of dynamic parameter fails.
     * @throws IOException throws exception if cloning of neural network fails.
     * @throws ClassNotFoundException throws exception if cloning of neural network fails.
     * @throws AgentException throws exception if state action value function is applied to non-updateable policy.
     */
Creates agent (player).
@param inputSize number of inputs for agent.
@param outputSize number of outputs for agent.
@return agent
@throws MatrixException throws exception if neural network has less output than actions.
@throws NeuralNetworkException throws exception if neural network operation fails.
@throws DynamicParamException throws exception if setting of dynamic parameter fails.
@throws IOException throws exception if cloning of neural network fails.
@throws ClassNotFoundException throws exception if cloning of neural network fails.
@throws AgentException throws exception if state action value function is applied to non-updateable policy.
Creates agent ( player ) . @param inputSize number of inputs for agent . @param outputSize number of outputs for agent . @return agent @throws MatrixException throws exception if neural network has less output than actions . @throws NeuralNetworkException throws exception if neural network operation fails . @throws DynamicParamException throws exception if setting of dynamic parameter fails . @throws IOException throws exception if cloning of neural network fails . @throws ClassNotFoundException throws exception if cloning of neural network fails . @throws AgentException throws exception if state action value function is applied to non - updateable policy .
private Agent createAgent(int inputSize, int outputSize) throws MatrixException, NeuralNetworkException, DynamicParamException, IOException, ClassNotFoundException, AgentException {
        int policyType = 0;
        ExecutablePolicyType executablePolicyType = null;
        String policyTypeParams = "";
        switch (policyType) {
            case 0 -> executablePolicyType = ExecutablePolicyType.GREEDY;
            case 1 -> {
                executablePolicyType = ExecutablePolicyType.EPSILON_GREEDY;
                policyTypeParams = "epsilonInitial = 0.4, epsilonDecayRate = 0.999, epsilonMin = 0";
            }
            case 2 -> {
                executablePolicyType = ExecutablePolicyType.NOISY_NEXT_BEST;
                policyTypeParams = "initialExplorationNoise = 0.2, explorationNoiseDecay = 0.999, minExplorationNoise = 0";
            }
            case 3 -> {
                executablePolicyType = ExecutablePolicyType.SAMPLED;
                policyTypeParams = "thresholdInitial = 0.7, thresholdMin = 0.0";
            }
        }
        boolean singleFunctionEstimator = false;
        boolean onlineMemory = true;
        AgentFactory.AgentAlgorithmType agentAlgorithmType = AgentFactory.AgentAlgorithmType.MCTS;
        String algorithmParams = switch (agentAlgorithmType) {
            case QN -> "agentUpdateCycle = 100, lambda = 0.5, optimizerName = AMSGrad, learningRate = 0.01";
            case DDQN -> "lambda = 0.5, applyImportanceSamplingWeights = true, applyUniformSampling = false, capacity = 20000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01";
            case Sarsa, ActorCritic, PPO, REINFORCE -> "lambda = 1";
            case SACDiscrete -> "lambda = 0, applyImportanceSamplingWeights = false, applyUniformSampling = true, capacity = 2000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01, agentUpdateCycle = 1";
            case MCTS -> "lambda = 1, gamma = 1, updateValuePerEpisode = true";
            default -> "";
        };
        String params = "";
        if (policyTypeParams.isEmpty() && !algorithmParams.isEmpty()) params = algorithmParams;
        if (!policyTypeParams.isEmpty() && algorithmParams.isEmpty()) params = policyTypeParams;
        if (!policyTypeParams.isEmpty() && !algorithmParams.isEmpty()) params = policyTypeParams + ", " + algorithmParams;
        Agent agent = AgentFactory.createAgent(this, agentAlgorithmType, this, inputSize, outputSize, onlineMemory, singleFunctionEstimator, executablePolicyType, params);
        agent.start();
        return agent;
    }
private Agent createAgent ( int inputSize , int outputSize ) throws MatrixException , NeuralNetworkException , DynamicParamException , IOException , ClassNotFoundException , AgentException { int policyType = 0 ; ExecutablePolicyType executablePolicyType = null ; String policyTypeParams = "" ; switch ( policyType ) { case 0 -> executablePolicyType = ExecutablePolicyType . GREEDY ; case 1 -> { executablePolicyType = ExecutablePolicyType . EPSILON_GREEDY ; policyTypeParams = "epsilonInitial = 0.4, epsilonDecayRate = 0.999, epsilonMin = 0" ; } case 2 -> { executablePolicyType = ExecutablePolicyType . NOISY_NEXT_BEST ; policyTypeParams = "initialExplorationNoise = 0.2, explorationNoiseDecay = 0.999, minExplorationNoise = 0" ; } case 3 -> { executablePolicyType = ExecutablePolicyType . SAMPLED ; policyTypeParams = "thresholdInitial = 0.7, thresholdMin = 0.0" ; } } boolean singleFunctionEstimator = false ; boolean onlineMemory = true ; AgentFactory . AgentAlgorithmType agentAlgorithmType = AgentFactory . AgentAlgorithmType . MCTS ; String algorithmParams = switch ( agentAlgorithmType ) { case QN -> "agentUpdateCycle = 100, lambda = 0.5, optimizerName = AMSGrad, learningRate = 0.01" ; case DDQN -> "lambda = 0.5, applyImportanceSamplingWeights = true, applyUniformSampling = false, capacity = 20000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01" ; case Sarsa , ActorCritic , PPO , REINFORCE -> "lambda = 1" ; case SACDiscrete -> "lambda = 0, applyImportanceSamplingWeights = false, applyUniformSampling = true, capacity = 2000, targetFunctionUpdateCycle = 0, targetFunctionTau = 0.01, agentUpdateCycle = 1" ; case MCTS -> "lambda = 1, gamma = 1, updateValuePerEpisode = true" ; default -> "" ; } ; String params = "" ; if ( policyTypeParams . isEmpty ( ) && ! algorithmParams . isEmpty ( ) ) params = algorithmParams ; if ( ! policyTypeParams . isEmpty ( ) && algorithmParams . isEmpty ( ) ) params = policyTypeParams ; if ( ! policyTypeParams . isEmpty ( ) && ! algorithmParams . isEmpty ( ) ) params = policyTypeParams + ", " + algorithmParams ; Agent agent = AgentFactory . createAgent ( this , agentAlgorithmType , this , inputSize , outputSize , onlineMemory , singleFunctionEstimator , executablePolicyType , params ) ; agent . start ( ) ; return agent ; }
Creates agent (player).
Creates agent ( player ) .