public override Boolean CompareTo(_Term p)
        {
            if (p.GetType() != _TypeOfTerm.COMPOSITE)
            {
                return(false);
            }

            if (Name != p.Name)
            {
                return(false);
            }

            _Composite temp = (_Composite)p;

            if (mComponents.Count != temp.mComponents.Count)
            {
                return(false);
            }

            for (int i = 0; i < mComponents.Count; ++i)
            {
                _Term temp1 = (_Term)mComponents[i];
                _Term temp2 = (_Term)temp.mComponents[i];
                if (temp1.CompareTo(temp2) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
        public override _Term Replace(_MGU s)
        {
            _Term     result = null;
            ArrayList temp   = new ArrayList();

            for (int i = 0; i < mComponents.Count; ++i)
            {
                temp.Add(this[i].Replace(s));
            }

            result = new _Composite(Name, temp);

            return(result);
        }
Пример #3
0
        private Boolean Run(_Term x, _Term y, ref _MGU s)
        {
            if (x.CompareTo(y))
            {
                return(true);
            }
            else
            if (x.GetType() == _TypeOfTerm.VARIABLE)
            {
                return(Unify_var((_Variable)x, y, ref s));
            }
            else
            if (y.GetType() == _TypeOfTerm.VARIABLE)
            {
                return(Unify_var((_Variable)y, x, ref s));
            }
            else
            if (x.GetType() == _TypeOfTerm.COMPOSITE && y.GetType() == _TypeOfTerm.COMPOSITE)
            {
                if (x.Name != y.Name)
                {
                    return(false);
                }

                _Composite comX = (_Composite)x;
                _Composite comY = (_Composite)y;

                if (comX.Count != comY.Count)             // Khong cung toan tu
                {
                    return(false);
                }

                for (int i = 0; i < comX.Count; ++i)
                {
                    _Term tempArrX = comX[i].Replace(s);
                    _Term tempArrY = comY[i].Replace(s);

                    if (Run(tempArrX, tempArrY, ref s) == false)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else             // x hoac y la hang
            {
                return(false);
            }
        }
 public _Composite(_Composite p)
     : base(p.Name)
 {
     Init(p.mComponents);
 }