/// <summary> /// Calculates a hashcode for a predicate /// </summary> /// <param name="predicate">Predicate to evaluate</param> /// <returns>Hashcode</returns> /// <remarks>Written separately so that it can be used for calculating hashes on predicat caching</remarks> protected static int CalculateHashCode(Predicate predicate) { return CalculateHashCode(predicate.Name, predicate.IsNegative, predicate.Parameters); }
/// <summary> /// Are the Predicates Negatives of Eachother /// </summary> /// <param name="predicate">Predicate to Compare</param> /// <returns>True is the Predicate is the Compliment</returns> public bool IsComplimentOf(Predicate predicate) { bool result = false; if (Name == predicate.Name && IsNegative != predicate.IsNegative && Parameters.Count == predicate.Parameters.Count) { result = true; for (int i = 0; i < Parameters.Count; i++) { if (Parameters[i] != predicate.Parameters[i]) { result = false; break; } } } return result; }
/// <summary> /// Adds a Predicate to the current cache /// </summary> /// <param name="predicate">Predicate to add</param> protected static void AddPredicate(Predicate predicate) { moPredicateCache[predicate.GetHashCode()] = predicate; }
/// <summary> /// Create an Action /// </summary> /// <param name="actionIdentity"></param> public Action(Predicate actionIdentity) { moActionIdentity = actionIdentity; }
/// <summary> /// Create a Predicate /// </summary> /// <param name="name">Name of Predicate</param> /// <param name="isNegative">Is Negative</param> /// <param name="parameters">Parameters</param> /// <returns>Predicate</returns> public static Predicate Create(string name, bool isNegative, params Term[] parameters) { Predicate predicate = Predicate.FindPredicate(name, isNegative, parameters); ConstantTerm ct = null; if (predicate == null) { predicate = new Predicate(name, isNegative, parameters); Predicate.AddPredicate(predicate); } return predicate; }
/// <summary> /// Add a Precondition /// </summary> /// <param name="predicate">A Predicate to Add</param> public void AddPrecondition(Predicate predicate) { moPreconditionList.Add(predicate); }
/// <summary> /// Add an Effect to the Effects /// </summary> /// <param name="predicate">A Predicate to Add</param> public void AddEffect(Predicate predicate) { moEffectList.Add(predicate); }
/// <summary> /// Add a Causal Link /// </summary> /// <param name="from">From Action</param> /// <param name="achieves">The Predicate that Achieves</param> /// <param name="to">To Action</param> public void AddCausalLink(Action from, Predicate achieves, Action to) { moCausalLinks.Add(new CausalLink(from, achieves, to)); }
/// <summary> /// Create a Non-Primitive Task /// </summary> /// <param name="actionIdentity"></param> /// <param name="subTasks"></param> public Task(Predicate actionIdentity, params Task[] subTasks) : base(actionIdentity) { mbIsPrimitive = false; moSubTasks = new TaskList(subTasks); }
/// <summary> /// Create a Task /// </summary> /// <param name="actionIdentity"></param> public Task(Predicate actionIdentity) : base(actionIdentity) { mbIsPrimitive = true; }