//public Unifier Next() //{ // if (solution == null) Find(); // Unifier b = solution; // Find(); // find next response // return b; //} bool IsSolution() { solution = un.Clone(); if (curInt.HasTrigger(g, solution)) { if (intAsTerm != null) { return(solution.Unifies(intAsTerm, curInt.GetAsTerm())); } else { return(true); } } return(false); }
/** * Drops an intention based on a goal argument * * returns true if the current intention is dropped */ public virtual bool DropInt(Circumstance C, Literal goal, Unifier un) { Unifier bak = un.Clone(); Trigger g = new Trigger(TEOperator.add, TEType.achieve, goal); bool isCurrentInt = false; IEnumerator <Intention> iint = C.GetAllIntentions(); while (iint.Current != null) { Intention i = iint.Current; if (i.HasTrigger(g, un)) { C.DropIntention(i); isCurrentInt = isCurrentInt || i.Equals(C.GetSelectedIntention()); un = bak.Clone(); } } return(isCurrentInt); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); suspendIntention = false; Circumstance C = ts.GetCircumstance(); if (args.Length == 0) { // suspend the current intention Intention i = C.GetSelectedIntention(); suspendIntention = true; i.SetSuspended(true); C.AddPendingIntention(SELF_SUSPENDED_INT + i.GetID(), i); return(true); } // use the argument to select the intention to suspend. Trigger g = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]); // ** Must test in PA/PI first since some actions (as .suspend) put intention in PI // suspending from Pending Actions foreach (ExecuteAction a in C.GetPendingActions().Values) { Intention ia = a.GetIntention(); if (ia.HasTrigger(g, un)) { ia.SetSuspended(true); C.AddPendingIntention(SUSPENDED_INT + ia.GetID(), ia); } } // suspending from Pending Intentions foreach (Intention ii in C.GetPendingIntentions().Values) { if (ii.HasTrigger(g, un)) { ii.SetSuspended(true); } } IEnumerator <Intention> itint = C.GetRunningIntentionsPlusAtomic(); while (itint.MoveNext()) { Intention i = itint.Current; if (i.HasTrigger(g, un)) { i.SetSuspended(true); C.RemoveRunningIntention(i); C.AddPendingIntention(SUSPENDED_INT + i.GetID(), i); } } // suspending the current intention? <-(Esta interrogación ya venía, lo juro) Intention ci = C.GetSelectedIntention(); if (ci != null && ci.HasTrigger(g, un)) { suspendIntention = true; ci.SetSuspended(true); C.AddPendingIntention(SELF_SUSPENDED_INT + ci.GetID(), ci); } // suspending G in Events int c = 0; IEnumerator <Event> ie = C.GetEventsPlusAtomic(); while (ie.MoveNext()) { Event e = ie.Current; ci = e.GetIntention(); if (un.Unifies(g, e.GetTrigger()) || (ci != null && ci.HasTrigger(g, un))) { C.RemoveEvent(e); C.AddPendingEvent(SUSPENDED_INT + e.GetTrigger() + (c++), e); if (ci != null) { ci.SetSuspended(true); } } } return(true); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Trigger g = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]); Circumstance C = ts.GetCircumstance(); // Search the goal in PI IEnumerator <string> ik = C.GetPendingIntentions().Keys.GetEnumerator(); while (ik.MoveNext()) { string k = ik.Current; Intention i = C.GetPendingIntentions()[k]; if (i.IsSuspended() && i.HasTrigger(g, un)) { i.SetSuspended(false); bool notify = true; if (k.StartsWith(SuspendStdLib.SUSPENDED_INT)) // if not SUSPENDED_INT, it was suspended while already in PI, so, do not remove it from PI, just change the suspeded status { ik.Dispose(); // add it back in I if not in PA if (!C.GetPendingActions().ContainsKey(i.GetID())) { C.ResumeIntention(i); notify = false; // the resumeIntention already notifies } } // notify meta event listeners if (notify && C.GetListeners() != null) { foreach (ICircumstanceListener el in C.GetListeners()) { el.IntentionResumed(i); } } // remove the IA .suspend in case of self-suspend if (k.StartsWith(SuspendStdLib.SELF_SUSPENDED_INT)) { i.Peek().RemoveCurrentStep(); } //System.out.println("res "+g+" from I "+i.getId()); } } // Search the goal in PE ik = C.GetPendingEvents().Keys.GetEnumerator(); while (ik.MoveNext()) { string k = ik.Current; if (k.StartsWith(SuspendStdLib.SUSPENDED_INT)) { Event e = C.GetPendingEvents()[k]; Intention i = e.GetIntention(); if (un.Unifies(g, e.GetTrigger()) || (i != null && i.HasTrigger(g, un))) { ik.Dispose(); C.AddEvent(e); if (i != null) { i.SetSuspended(false); } } } } return(true); }