Esempio n. 1
0
        public override void _Ready()
        {
            Node n        = this;
            Node rootNode = GetNode("/root");

            while (agent == null && n != rootNode)
            {
                Node parent = n.GetParent();
                n     = parent;
                agent = parent as RLAgent;
            }

            if (resettable)
            {
                agent.AddResetListener(this);
            }
            if (usePathAsID)
            {
                this.id = GetPath();
            }
            else
            {
                this.id = Name;
            }
            OnCreate();
        }
Esempio 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);
                }
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
 public bool wasTouched(RLAgent agent)
 {
     if (this.preconditions != null && this.preconditions.Length > 0)
     {
         bool r = true;
         foreach (TouchRewardFunc t in preconditions)
         {
             if (atLeastOne)
             {
                 r = false;
                 if (t.wasTouched(agent))
                 {
                     return(true);
                 }
             }
             else
             {
                 if (!t.wasTouched(agent))
                 {
                     return(false);
                 }
             }
         }
         return(r);
     }
     else
     {
         return(true);
     }
 }
Esempio n. 5
0
 public void Start()
 {
     if (target == null)
     {
         Debug.LogWarning("ForwardTargetReward error: target don't specified!");
     }
     agent = GetComponent <RLAgent>();
     agent.AddResetListener(this);
     minDist = -1;
 }
Esempio n. 6
0
 void OnCollisionExit(Collision other)
 {
     if (triggerOnExit)
     {
         RLAgent agent = other.gameObject.GetComponent <RLAgent>();
         agent.boxListener(this);
         counter[agent.Id]++;
         agent.AddReward(rewardValue, this);
     }
 }
Esempio n. 7
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;
            }
        }
Esempio n. 8
0
        void Start()
        {
            if (ignoreX)
            {
                fx = 0;
            }
            else
            {
                fx = 1;
            }

            if (ignoreY)
            {
                fy = 0;
            }
            else
            {
                fy = 1;
            }

            if (ignoreZ)
            {
                fz = 0;
            }
            else
            {
                fz = 1;
            }

            f    = new Vector3(fx, fy, fz);
            hist = new float[samples];
            head = 0;
            len  = 0;
            totalReceivedReward = 0.0f;
            agent = GetComponent <RLAgent>();
            agent.AddResetListener(this);
            prevPosition = transform.localPosition;
            if (samples <= 0)
            {
                Debug.LogWarning("Warning: the field samples value must be greater than 0!!!");
            }
            if (target == null)
            {
                Debug.LogWarning("Warning: target is not specified for reward function named AutoApproximationReward.");
            }
        }
Esempio n. 9
0
        // Start is called before the first frame update
        void Start()
        {
            if (ignoreX)
            {
                fx = 0;
            }
            else
            {
                fx = 1;
            }

            if (ignoreY)
            {
                fy = 0;
            }
            else
            {
                fy = 1;
            }

            if (ignoreZ)
            {
                fz = 0;
            }
            else
            {
                fz = 1;
            }

            f = new Vector3(fx, fy, fz);

            prevPosition = transform.localPosition;
            agent        = GetComponent <RLAgent>();
            agent.AddResetListener(this);
            sumOfRewards = 0;
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
 public virtual void RewardFrom(string actionName, RLAgent agent)
 {
 }
Esempio n. 12
0
 public bool wasTouched(RLAgent agent) {
     return touched[agent.Id];
 }
Esempio n. 13
0
 public virtual void RewardFrom(RLAgent agent)
 {
 }
Esempio n. 14
0
 void Start()
 {
     fall  = false;
     agent = GetComponent <RLAgent>();
     agent.AddResetListener(this);
 }
Esempio n. 15
0
 public bool wasTouched(RLAgent agent)
 {
     return(counter[agent.Id] >= precondictionMin);
 }