Ejemplo n.º 1
0
        private void Check(Collider collider)
        {
            RLAgent agent = collider.gameObject.GetComponent <RLAgent>();

            agent.boxListener(this);
            if (counter[agent.Id] < maxNumberOfTheRewards || maxNumberOfTheRewards < 0)
            {
                if (checkInside)
                {
                    Collider[] colliders = Physics.OverlapBox(myCollider.bounds.center, myCollider.bounds.extents, transform.rotation);

                    int idx = System.Array.IndexOf(colliders, collider);
                    if (idx >= 0)
                    {
                        counter[agent.Id]++;
                        agent.AddReward(rewardValue, this);
                    }
                }
                else
                {
                    counter[agent.Id]++;
                    agent.AddReward(rewardValue, this);
                }
            }
        }
Ejemplo n.º 2
0
        public void Check(Collider collider)
        {
            RLAgent agent = collider.gameObject.GetComponent<RLAgent>();
            if (agent != null) {
                touched[agent.Id] = true;
                agent.touchListener(this);  

                if (precondition != null) {
                    if (!precondition.allowNext || !precondition.wasTouched(agent)){
                        agent.AddReward(-painForViolatinPrecondition, this);
                        agent.PreconditionFailListener(this, precondition);
                        return;
                    }
                }

                if (multiplePreconditions != null)
                {
                    if (!multiplePreconditions.allowNext || !multiplePreconditions.wasTouched(agent))
                    {
                        agent.AddReward(-painForViolatinPrecondition, this);
                        agent.PreconditionFailListener(this, multiplePreconditions);
                        return;
                    }
                }

                if ( (counter[agent.Id] <
                    maxTouch) || (maxTouch < 0)  )
                {
                    counter[agent.Id]++;
                    agent.AddReward(rewardValue, this);
                } else if (maxTouch >= 0 && counter[agent.Id] >= maxTouch) {
                    agent.AddReward(-painForOverTouch, this);
                }
            }
        }
Ejemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (agent != null)
     {
         if (transform.localPosition.y < threshold)
         {
             if (!stopRewardingAfterFall)
             {
                 agent.AddReward(rewardValue, this);
             }
             else if (!fall)
             {
                 agent.AddReward(rewardValue, this);
             }
             fall = true;
         }
     }
 }
Ejemplo n.º 4
0
 void OnCollisionExit(Collision other)
 {
     if (triggerOnExit)
     {
         RLAgent agent = other.gameObject.GetComponent <RLAgent>();
         agent.boxListener(this);
         counter[agent.Id]++;
         agent.AddReward(rewardValue, this);
     }
 }
Ejemplo n.º 5
0
        public override void RewardFrom(string actionName, RLAgent agent)
        {
            float d = Vector3.Distance(transform.localPosition, target.transform.localPosition);

            if (minDist >= 0)
            {
                agent.AddReward(Math.Max(minDist - d, 0) - penalityByAction);
            }

            if (minDist < 0 || minDist > d)
            {
                minDist = d;
            }
        }
Ejemplo n.º 6
0
        private void Check(Collider collider)
        {
            RLAgent agent = collider.gameObject.GetComponent <RLAgent>();

            if (precondition != null)
            {
                if (!precondition.allowNext || !precondition.wasTouched(agent))
                {
                    agent.AddReward(-painForViolatinPrecondition, this);
                    return;
                }
            }


            if ((counter[agent.Id] < maxTouch || maxTouch < 0))
            {
                counter[agent.Id]++;
                agent.AddReward(rewardValue, this);
            }
            else if (maxTouch >= 0 && counter[agent.Id] >= maxTouch)
            {
                agent.AddReward(-painForOverTouch, this);
            }
        }
Ejemplo n.º 7
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (agent != null)
     {
         if (maxRewardByEpisode <= 0 || sumOfRewards < maxRewardByEpisode)
         {
             Vector3 p    = Vector3.Scale(transform.localPosition, f);
             Vector3 pp   = Vector3.Scale(prevPosition, f);
             float   dist = Vector3.Distance(p, pp);
             if (dist >= minimumDistance)
             {
                 sumOfRewards += System.Math.Abs(reward);
                 agent.AddReward(reward, this);
             }
         }
     }
     else
     {
         Debug.LogWarning("Warning: an agent was not specified or this game object is not an agent!!!");
     }
     prevPosition = transform.localPosition;
 }
Ejemplo n.º 8
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (target != null)
            {
                Vector3 tp = Vector3.Scale(target.transform.localPosition, f);
                Vector3 p  = Vector3.Scale(transform.localPosition, f);
                Vector3 pp = Vector3.Scale(prevPosition, f);

                float distance = Vector3.Distance(p, tp);
                float autoDist = Vector3.Distance(p, pp);
                if (maxRewardByEpisode <= 0 || totalReceivedReward < maxRewardByEpisode)
                {
                    float mean = GetMean(hist, len);
                    if (autoDist >= minimumDistance && distance < mean)
                    {
                        totalReceivedReward += System.Math.Abs(reward);
                        agent.AddReward(reward, this);
                    }
                }
                hist[head] = distance;
                head++;
                if (head >= samples)
                {
                    head = 0;
                }
                if (len < samples)
                {
                    len++;
                }
            }
            else
            {
                Debug.LogWarning("Warning: target is not specified in AutoDistanceRewardFunction");
            }
            prevPosition = transform.localPosition;
        }