public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); Intention currentInt = (Intention)reasoner.GetCircumstance().GetSelectedIntention(); ForkData fd = (ForkData)((IObjectTerm)args[0]).GetObject(); fd.toFinish--; // in the case of fork and, all intentions should be finished to continue if (fd.isAnd) { if (fd.toFinish == 0) { currentInt.Peek().RemoveCurrentStep(); reasoner.GetCircumstance().AddRunningIntention(currentInt); } } else { // the first intention has finished, drop others fd.intentions.Remove(currentInt); foreach (Intention i in fd.intentions) { //System.out.println("drop "+i.getId()); reasoner.GetCircumstance().DropIntention(i); } currentInt.Peek().RemoveCurrentStep(); reasoner.GetCircumstance().AddRunningIntention(currentInt); } return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); //try to get the intention from the "body" Intention i = ts.GetCircumstance().GetSelectedIntention(); if (i == null) { //try to get the intention from the event Event evt = ts.GetCircumstance().GetSelectedEvent(); if (evt != null) { i = evt.GetIntention(); } } if (i != null) { return(un.Unifies(i.GetAsTerm(), args[0])); } else { return(false); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ts.GetCircumstance().ClearEvents(); ts.GetCircumstance().ClearPendingEvents(); return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ForkData fd = new ForkData(((Atom)args[0]).Equals(aAnd)); Intention currentInt = (Intention)ts.GetCircumstance().GetSelectedIntention(); for (int iPlans = 1; iPlans < args.Length; iPlans++) { Intention i = new ForkIntention(currentInt, fd); fd.AddIntention(i); i.Pop(); // remove the top IM, it will be introduced back later (modified) IntendedPlan im = (IntendedPlan)currentInt.Peek().Clone(); // adds the .join in the plan InternalActionLiteral joinL = new InternalActionLiteral(joinS, ts.GetAgent()); joinL.AddTerm(new ObjectTermImpl(fd)); IPlanBody joinPB = new PlanBodyImpl(BodyType.Body_Type.internalAction, joinL); joinPB.SetBodyNext(im.GetCurrentStep().GetBodyNext()); // adds the argument in the plan (before join) IPlanBody whattoadd = (IPlanBody)args[iPlans].Clone(); whattoadd.Add(joinPB); whattoadd.SetAsBodyTerm(false); im.InsertAsNextStep(whattoadd); im.RemoveCurrentStep(); // remove the .fork i.Push(im); ts.GetCircumstance().AddRunningIntention(i); } return(true); }
public int Buf(List <Literal> percepts) { if (percepts == null) { return(0); } int adds = 0; int dels = 0; HashSet <StructureWrapperForLiteral> perW = new HashSet <StructureWrapperForLiteral>(); IEnumerator <Literal> iper = percepts.GetEnumerator(); while (iper.MoveNext()) { perW.Add(new StructureWrapperForLiteral(iper.Current)); } IEnumerator <Literal> perceptsInBB = GetBB().GetPercepts(); while (perceptsInBB.MoveNext()) { Literal l = perceptsInBB.Current; if (l.SubjectToBUF() && !perW.Remove(new StructureWrapperForLiteral(l))) { dels++; perceptsInBB.Dispose(); Trigger te = new Trigger(TEOperator.del, TEType.belief, l); if (reasoner.GetCircumstance().HasListener() || pl.HasCandidatePlan(te)) { l = AsSyntax.AsSyntax.CreateLiteral(l.GetFunctor(), l.GetTermsArray()); l.AddAnnot(BeliefBase.TPercept); te.SetLiteral(l); reasoner.GetCircumstance().AddEvent(new Event(te, Intention.emptyInt)); } } } foreach (StructureWrapperForLiteral lw in perW) { try { Literal lp = lw.GetLiteral().Copy().ForceFullLiteralImpl(); lp.AddAnnot(BeliefBase.TPercept); if (GetBB().Add(lp)) { adds++; reasoner.UpdateEvents(new Event(new Trigger(TEOperator.add, TEType.belief, lp), Intention.emptyInt)); } } catch (Exception e) { //logger.log(Level.SEVERE, "Error adding percetion " + lw.getLiteral(), e); } } return(adds + dels); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); ILogicalFormula logExpr = (ILogicalFormula)args[0]; IPlanBody whattoadd = null; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(reasoner.GetAgent(), un); if (iu.MoveNext()) { whattoadd = (IPlanBody)args[1].Clone(); un.Compose(iu.Current); } else if (args.Length == 3) { whattoadd = (IPlanBody)args[2].Clone(); } if (whattoadd != null) { IntendedPlan ip = reasoner.GetCircumstance().GetSelectedIntention().Peek(); whattoadd.Add(ip.GetCurrentStep().GetBodyNext()); whattoadd.SetAsBodyTerm(false); ip.InsertAsNextStep(whattoadd); } return(true); }
public void Run() { Reasoner reasoner = GetReasoner(); while (running) { if (reasoner.GetSettings().IsSync()) { //WaitSyncSignal(); ReasoningCycle(); bool isBreakPoint = false; try { isBreakPoint = reasoner.GetCircumstance().GetSelectedOption().GetPlan().HasBreakpoint(); } catch (NullReferenceException e) { // no problem, there is no sel opt, no plan .... } InformCycleFinished(isBreakPoint, GetCycleNumber()); } else { GetUserAgArch().IncCycleNumber(); ReasoningCycle(); if (reasoner.CanSleep()) { Sleep(); } } } }
/* returns: >0 the intention was changed * 1 = intention must continue running * 2 = fail event was generated and added in C.E * 3 = simply removed without event */ public virtual int DropDesire(Intention i, Trigger g, Reasoner rs, Unifier un) { if (i != null && i.DropDesire(g, un)) { if (rs.HasDesireListener()) { foreach (Desire gl in rs.GetDesiresListeners()) { gl.DesireFinished(g, Desire.FinishStates.achieved); } } //continue the intention if (!i.IsFinished()) { if (rs.GetCircumstance().GetSelectedIntention() != i) { i.Peek().RemoveCurrentStep(); } rs.ApplyClrInt(i); return(1); } else { rs.ApplyClrInt(i); return(3); } } return(0); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Circumstance C = ts.GetCircumstance(); Trigger teGoal = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]); // search in PA foreach (ExecuteAction a in C.GetPendingActions().Values) { if (a.GetIntention().HasTrigger(teGoal, un)) { return(un.Unifies(args[1], aAct)); } } // search in PI Dictionary <string, Intention> pi = C.GetPendingIntentions(); foreach (string reason in pi.Keys) { if (pi[reason].HasTrigger(teGoal, un)) { return(un.Unifies(args[1], new StringTermImpl(reason))); } } return(false); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); long timeout = -1; Trigger te = null; ILogicalFormula f = null; ITerm elapsedTime = null; if (args[0].IsNumeric()) { // time in milliseconds INumberTerm time = (INumberTerm)args[0]; timeout = (long)time.Solve(); } else { te = Trigger.TryToGetTrigger(args[0]); // wait for event if (te == null && args[0].GetType() == typeof(ILogicalFormula)) { // wait for an expression to become true f = (ILogicalFormula)args[0]; if (ts.GetAgent().Believes(f, un)) { // if the agent already believes f // place current intention back in I, since .wait usually does not do that Intention si = ts.GetCircumstance().GetSelectedIntention(); si.Peek().RemoveCurrentStep(); ts.GetCircumstance().AddRunningIntention(si); return(true); } } if (args.Length >= 2) { timeout = (long)((INumberTerm)args[1]).Solve(); } if (args.Length == 3) { elapsedTime = args[2]; } } new WaitEvent(te, f, un, ts, timeout, elapsedTime); return(true); }
/* returns: >0 the intention was changed * 1 = intention must continue running * 2 = fail event was generated and added in C.E * 3 = simply removed without event */ public override int DropDesire(Intention i, Trigger g, Reasoner rs, Unifier un) { if (i != null) { if (i.DropDesire(g, un)) { //notify listener if (rs.HasDesireListener()) { foreach (Desire gl in rs.GetDesiresListeners()) { gl.DesireFailed(g); } } //generate failure event Event failEvent = rs.FindEventForFailure(i, g); //find fail event for the goal just dropped if (failEvent != null) { failEvent = new Event(failEvent.GetTrigger().Capply(un), failEvent.GetIntention()); rs.GetCircumstance().AddEvent(failEvent); return(2); } else //i is finished or without failure plan { if (rs.HasDesireListener()) { foreach (Desire gl in rs.GetDesiresListeners()) { gl.DesireFinished(g, Desire.FinishStates.unachieved); } } i.Fail(rs.GetCircumstance()); return(3); } } } return(0); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); resultSuspend = false; if (args.Length == 0) { resultSuspend = true; // to drop the current intention } else { resultSuspend = DropInt(ts.GetCircumstance(), args[0] as Literal, un); } return(true); }
public WaitEvent(Trigger te, ILogicalFormula f, Unifier un, Reasoner ts, long timeout, ITerm elapsedTimeTerm) { this.te = te; this.formula = f; this.un = un; this.ts = ts; c = ts.GetCircumstance(); si = c.GetSelectedIntention(); this.elapsedTimeTerm = elapsedTimeTerm; // register listener c.AddEventListener(this); if (te != null) { sEvt = te.ToString(); } else if (formula != null) { sEvt = formula.ToString(); } else { sEvt = "time" + (timeout); } sEvt = si.GetID() + "/" + sEvt; c.AddPendingIntention(sEvt, si); //startTime = System.currentTimeMillis(); //hay que usar el de c# o el de unity? MISTERIO startTime = DateTime.Now.Millisecond; // Seguramente lo que querramos en C# no son los milisegundos desde el año 1970... sino algo así: Environment.TickCount DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); startTime = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds; if (timeout >= 0) { Agent.GetExecutor().AddTask(new MyRunnable1(this)); //agent.getscheduler().schedule(new runnable() //{ // public void run() // { // resume(true); // } // }, timeout, timeunit.milliseconds); } }
public void Run() { try { if (!cancelled) { ts.GetCircumstance().AddEvent(@event); ts.GetUserAgArch().Wake(); } } finally { CheckDeadline result; ats.TryRemove(id, out result); } }
public void Run() { Literal newDesire = desire.ForceFullLiteralImpl().Copy(); Literal stateAnnot = AsSyntax.CreateLiteral("state", new Atom(state.ToString())); if (reason != null) { stateAnnot.AddAnnot(AsSyntax.CreateStructure("reason", new StringTermImpl(reason))); } newDesire.AddAnnot(stateAnnot); Trigger eEnd = new Trigger(TEOperator.desireState, type, newDesire); if (reasoner.GetAgent().GetPL().HasCandidatePlan(eEnd)) { reasoner.GetCircumstance().InsertMetaEvent(new Event(eEnd, null)); } }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { IntendedPlan ip = reasoner.GetCircumstance().GetSelectedIntention().Peek(); IPlanBody whileia = ip.GetCurrentStep(); // if the IA has a backup unifier, use that (it is an object term) if (args.Length == 2) { // first execution of while CheckArguments(args); // add backup unifier in the IA whileia = new PlanBodyImpl(BodyType.Body_Type.internalAction, (ITerm)whileia.GetBodyTerm().Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... whileia.Add(ip.GetCurrentStep().GetBodyNext()); ((Structure)whileia.GetBodyTerm()).AddTerm(new ObjectTermImpl(un.Clone())); } else if (args.Length == 3) { // restore the unifier of previous iterations Unifier ubak = (Unifier)((IObjectTerm)args[2]).GetObject(); un.Clear(); un.Compose(ubak); } else { throw JasonityException.CreateWrongArgumentNb(this); } ILogicalFormula logExpr = (ILogicalFormula)args[0]; // perform one iteration of the loop IEnumerator <Unifier> iu = logExpr.LogicalConsequence(reasoner.GetAgent(), un); if (iu.MoveNext()) { un.Compose(iu.Current); // add in the current intention: // 1. the body argument and // 2. the while internal action after the execution of the body // (to test the loop again) IPlanBody whattoadd = (IPlanBody)args[1].Clone(); whattoadd.Add(whileia); // the add clones whileia whattoadd.SetAsBodyTerm(false); ip.InsertAsNextStep(whattoadd); } return(true); }
public virtual void DropDesireInEvent(Reasoner rs, Event e, Intention i) { Circumstance C = rs.GetCircumstance(); C.RemoveEvent(e); if (i != null) { if (rs.HasDesireListener()) { foreach (Desire gl in rs.GetDesiresListeners()) { gl.DesireFinished(e.GetTrigger(), Desire.FinishStates.achieved); } i.Peek().RemoveCurrentStep(); rs.ApplyClrInt(i); C.AddRunningIntention(i); } } }
//int sumAct = 0; int nbAct = 0; protected void Act() { Reasoner reasoner = GetReasoner(); int i = 0; int ca = cyclesAct; if (ca != 1) { // not the default value, limit the value to the number of intentions ca = Math.Min(cyclesAct, reasoner.GetCircumstance().GetNbRunningIntentions()); if (ca == 0) { ca = 1; } } while (running && i++ < ca && !reasoner.CanSleepAct()) { reasoner.Act(); } //sumAct += i; nbAct++; //System.out.println("running act "+(sumAct/nbAct)+"/"+ca); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Circumstance C = ts.GetCircumstance(); C.ClearRunningIntentions(); C.ClearPendingIntentions(); C.ClearPendingActions(); // drop intentions in E IEnumerator <Event> ie = C.GetEventsPlusAtomic(); while (ie.Current != null) { Event e = ie.Current; if (e.IsInternal()) { C.RemoveEvent(e); } } //drop intentions in PE foreach (string ek in C.GetPendingEvents().Keys) { Event e = C.GetPendingEvents()[ek]; if (e.IsInternal()) { C.RemovePendingEvent(ek); } } AtStdLib atia = ts.GetAgent().GetIA(AtStdLib.atAtom) as AtStdLib; atia.CancelAts(); 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); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { IntendedPlan im = reasoner.GetCircumstance().GetSelectedIntention().Peek(); IPlanBody foria = im.GetCurrentStep(); IEnumerator <Unifier> iu; if (args.Length == 2) { // first execution of while CheckArguments(args); // get all solutions for the loop // Note: you should get all solutions here, otherwise a concurrent modification will occur for the iterator ILogicalFormula logExpr = (ILogicalFormula)args[0]; iu = logExpr.LogicalConsequence(reasoner.GetAgent(), un); List <Unifier> allsol = new List <Unifier>(); while (iu.MoveNext()) { allsol.Add(iu.Current); } if (allsol.Count == 0) { return(true); } iu = allsol.GetEnumerator(); foria = new PlanBodyImpl(BodyType.Body_Type.internalAction, (ITerm)foria.GetBodyTerm().Clone()); // Como uso el Clone de C# lo que clono son object que luego hay que castear... foria.Add(im.GetCurrentStep().GetBodyNext()); Structure forstructure = (Structure)foria.GetBodyTerm(); forstructure.AddTerm(new ObjectTermImpl(iu)); // store all solutions forstructure.AddTerm(new ObjectTermImpl(un.Clone())); // backup original unifier } else if (args.Length == 4) { // restore the solutions iu = (IEnumerator <Unifier>)((IObjectTerm)args[2]).GetObject(); } else { throw JasonityException.CreateWrongArgumentNb(this); } un.Clear(); if (iu.MoveNext()) { // add in the current intention: // 1. the body argument of for and // 2. the for internal action after the execution of the body // (to perform the next iteration) un.Compose(iu.Current); IPlanBody whattoadd = (IPlanBody)args[1].Clone(); whattoadd.Add(foria); whattoadd.SetAsBodyTerm(false); im.InsertAsNextStep(whattoadd); } else { un.Compose((Unifier)((IObjectTerm)args[3]).GetObject()); } return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); DropEvt(ts.GetCircumstance(), args[0] as Literal, un); return(true); }
public void FindDesireAndDrop(Reasoner rs, Literal l, Unifier un) { Trigger g = new Trigger(TEOperator.add, TEType.achieve, l); Circumstance C = rs.GetCircumstance(); Unifier bak = un.Clone(); IEnumerator <Intention> itinit = C.GetRunningIntentionsPlusAtomic(); while (itinit.MoveNext()) { Intention i = itinit.Current; if (DropDesire(i, g, rs, un) > 1) { C.DropRunningIntention(i); un = bak.Clone(); } } // dropping the current intention? DropDesire(C.GetSelectedIntention(), g, rs, un); un = bak.Clone(); //dropping G in Events IEnumerator <Event> ie = C.GetEventsPlusAtomic(); while (ie.MoveNext()) { Event e = ie.Current; //Test in the intention Intention i = e.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemoveEvent(e); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } else { //Test in the event Trigger t = e.GetTrigger(); if (i != Intention.emptyInt && !i.IsFinished()) { t = t.Capply(i.Peek().GetUnif()); } if (un.Unifies(g, t)) { DropDesireInEvent(rs, e, i); un = bak.Clone(); } } } //dropping G in Pending Events foreach (string ek in C.GetPendingEvents().Keys) { //Test in the intention Event e = C.GetPendingEvents()[ek]; Intention i = e.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemovePendingEvent(ek); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } else { //test in the event Trigger t = e.GetTrigger(); if (i != Intention.emptyInt && !i.IsFinished()) { t = t.Capply(i.Peek().GetUnif()); } if (un.Unifies(g, t)) { DropDesireInEvent(rs, e, i); un = bak.Clone(); } } } //Dropping from pending Actions foreach (ExecuteAction a in C.GetPendingActions().Values) { Intention i = a.GetIntention(); int r = DropDesire(i, g, rs, un); if (r > 0) //i was changed { C.RemovePendingAction(i.GetID()); // remove i from PA if (r == 1) // i must continue running { C.ResumeIntention(i); // and put the intention back in I } // if r > 1, the event was generated and i will be back soon un = bak.Clone(); } } //Dropping from pending intentions foreach (Intention i in C.GetPendingIntentions().Values) { int r = DropDesire(i, g, rs, un); if (r > 0) { C.RemovePendingIntention(i.GetID()); if (r == 1) { C.ResumeIntention(i); } un = bak.Clone(); } } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm to = args[0]; ITerm ilf = args[1]; ITerm pcnt = args[2]; // create a message to be sent Message m = new Message(ilf.ToString(), ts.GetUserAgArch().GetAgentName(), null, pcnt); // async ask has a fourth argument and should suspend the intention lastSendWasSynAsk = m.IsAsk() && args.Length > 3; if (lastSendWasSynAsk) { m.SetSyncAskMsgID(); ts.GetCircumstance().AddPendingIntention(m.GetMsgID(), ts.GetCircumstance().GetSelectedIntention()); } // (un)tell or unknown performative with 4 args is a reply to if ((m.IsTell() || m.IsUntell() || !m.IsKnownPerformative()) && args.Length > 3) { ITerm mid = args[3]; if (!mid.IsAtom()) { throw new JasonityException("The Message ID ('" + mid + "') parameter of the internal action 'send' is not an atom!"); } m.SetInReplyTo(mid.ToString()); } // send the message if (to.IsList()) { foreach (ITerm t in (IListTerm)to) { DelegateSendToArch(t, ts, m); } } else { DelegateSendToArch(to, ts, m); } if (lastSendWasSynAsk && args.Length == 5) { // get the timeout deadline ITerm tto = args[4]; if (tto.IsNumeric()) { // Agent.GetScheduler().schedule(new Runnable() // { // public void run() // { // // if the intention is still in PI, brings it back to C.I with the timeout // Intention intention = ts.GetCircumstance().RemovePendingIntention(m.GetMsgId()); // if (intention != null) // { // // unify "timeout" with the fourth parameter of .send // Structure send = (Structure)intention.Peek().RemoveCurrentStep(); // ITerm timeoutAns = null; // if (to.IsList()) // { // VarTerm answers = new VarTerm("AnsList___" + m.GetMsgId()); // Unifier un = intention.Peek().GetUnif(); // timeoutAns = un.Get(answers); // if (timeoutAns == null) // timeoutAns = new ListTermImpl(); // } // else // { // timeoutAns = new Atom("timeout"); // } // intention.Peek().GetUnif().Unifies(send.GetTerm(3), timeoutAns); // // add the intention back in C.I // ts.GetCircumstance().ResumeIntention(intention); // ts.GetUserAgArch().WakeUpAct(); // } // } //}, (long)((NumberTerm)tto).Solve(), TimeUnit.MILLISECONDS); } else { throw new JasonityException("The 5th parameter of send must be a number (timeout) and not '" + tto + "'!"); } } return(true); }
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); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); return(AllDesires(ts.GetCircumstance(), args[0] as Literal, args.Length == 2 ? args[1] : null, un)); }