Exemplo n.º 1
0
 /* agent initialization */
 public override void InitializeAgent()
 {
     base.InitializeAgent();
     manager      = GetComponentInParent <AgentManager>();
     trainSetting = manager.GetTrainSetting();
     rayPercept   = GetComponent <RayPerception>();
     controller   = gameObject.GetComponent <SimpleCarControllers>();
     reward       = new AgentRewardSystem();
     ResetAgent();
 }
    public override void AcademyReset()
    {
#if UNITY_EDITOR
        Debug.unityLogger.logEnabled = true;
#else
        Debug.unityLogger.logEnabled = false;
#endif
        int           activeAgents    = (int)resetParameters["num_agents"];
        int           activeObstacles = (int)resetParameters["num_obstacles"];
        TRAIN_SETTING maSetting       = (TRAIN_SETTING)resetParameters["setting"];
        GameObject.Find("AgentManager").GetComponent <AgentManager>().SetAgents(activeAgents, maSetting, this.GetIsInference());
        GameObject.Find("ObstaclesManager").GetComponent <ObstaclesManager>().SetObstacles(activeObstacles);
    }
Exemplo n.º 3
0
 // Start is called before the first frame update
 public void SetAgents(int numberOfAgents, TRAIN_SETTING setting, bool isInfer)
 {
     isInference = isInfer;
     maSetting   = setting;
     NAgents     = 0;
     agents      = new List <MyRaceAgent>();
     foreach (Transform cp in transform)
     {
         if (cp.parent != null)
         {
             agents.Add(cp.gameObject.GetComponent <MyRaceAgent>());
             NAgents++;
         }
     }
     Debug.Log("Number of active agents: " + numberOfAgents);
     for (int i = numberOfAgents; i < NAgents; i++)
     {
         agents[i].gameObject.SetActive(false);
     }
 }
Exemplo n.º 4
0
 /* collect and calculate current reward (once every step) */
 public void CollectReward(
     TRAIN_SETTING trainSetting,     //training setting (selfish, cooperative, competative)
     float velocity,                 // car velocity magnitude
     float maxSpeed,                 // max speed normalization constant
     float direction,                // direction of drive
     float avgSpeedOfOtherAgents,    // average speed of the rest of the cars.
     int previousCheckpoint,         // index of last checkpoint in previous step
     int currentCheckpoint,          // index of last checkpoint in current step
     int numberOfCheckpoints,        // number of checkpoints in race track
     bool collision                  // did a collision accur
     )
 {
     if (trainSetting == TRAIN_SETTING.COOPERATIVE)
     {
         AddCooperativeVelocityReward(velocity, maxSpeed, direction, avgSpeedOfOtherAgents);
     }
     else // Selfish or Competative
     {
         AddVelocityReward(velocity, maxSpeed, direction);
     }
     AddCheckpointReward(previousCheckpoint, currentCheckpoint, numberOfCheckpoints);
     AddCollisionReward(collision);
 }