예제 #1
0
파일: RewardFunc.cs 프로젝트: gilcoder/AI4U
        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();
        }
예제 #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);
                }
            }
        }
예제 #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);
                }
            }
        }
예제 #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);
     }
 }
예제 #5
0
 public void Start()
 {
     if (target == null)
     {
         Debug.LogWarning("ForwardTargetReward error: target don't specified!");
     }
     agent = GetComponent <RLAgent>();
     agent.AddResetListener(this);
     minDist = -1;
 }
예제 #6
0
 void OnCollisionExit(Collision other)
 {
     if (triggerOnExit)
     {
         RLAgent agent = other.gameObject.GetComponent <RLAgent>();
         agent.boxListener(this);
         counter[agent.Id]++;
         agent.AddReward(rewardValue, this);
     }
 }
예제 #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;
            }
        }
예제 #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.");
            }
        }
예제 #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;
        }
예제 #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);
            }
        }
예제 #11
0
 public virtual void RewardFrom(string actionName, RLAgent agent)
 {
 }
예제 #12
0
 public bool wasTouched(RLAgent agent) {
     return touched[agent.Id];
 }
예제 #13
0
 public virtual void RewardFrom(RLAgent agent)
 {
 }
예제 #14
0
 void Start()
 {
     fall  = false;
     agent = GetComponent <RLAgent>();
     agent.AddResetListener(this);
 }
예제 #15
0
 public bool wasTouched(RLAgent agent)
 {
     return(counter[agent.Id] >= precondictionMin);
 }