public override _Term Replace(_MGU s) { _Term result = new _Variable(this); for (int i = 0; i < s.Count; ++i) { if (s[i].Arg1.CompareTo(result)) { if (s[i].Arg2.GetType() != _TypeOfTerm.COMPOSITE) { result = _Term.arrPatternObject[(int)s[i].Arg2.GetType()].NewObject(s[i].Arg2); if (result.GetType() == _TypeOfTerm.VARIABLE) { result = result.Replace(s); } } else { result = s[i].Arg2.Replace(s); } break; } } return(result); }
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); }
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); } }
private Boolean Unify_var(_Variable var, _Term x, ref _MGU s) { _Element val; if ((val = s.Find(var)) != null) { return(Run(val.Arg2, x, ref s)); } else if ((val = s.Find(x)) != null) { return(Run(var, val.Arg1, ref s)); } else if (x.IsAppear(var) == true) { return(false); } else { s.Add(new _Element(var, x)); return(true); } }
// The term bang tap s public abstract _Term Replace(_MGU s);
public override _Term Replace(_MGU s) { _Constant result = new _Constant(this); return(result); }
public Boolean Run(out _MGU s) { s = new _MGU(); return(Run(mArg1, mArg2, ref s));; }