override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm label = args[0]; ITerm source = BeliefBase.ASelf; if (args.Length > 1) { source = (Atom)args[1]; } if (label.IsList()) // arg[0] is a list { foreach (ITerm t in (IListTerm)args[0]) { //r = r && ts.getAg().getPL().remove((Atom)t, source); ts.GetAgent().GetPL().Remove(FixLabel(t), source); } } else // args[0] is a plan label { ts.GetAgent().GetPL().Remove(FixLabel(label), source); } return(true); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm label = args[1]; Plan p; if (label.IsLiteral()) { p = ts.GetAgent().GetPL().Get(((Literal)label).ToString()); } else { p = ts.GetAgent().GetPL().Get((new Atom(label.ToString()).ToString())); } if (p != null) { p = (Plan)p.Clone(); p.GetLabel().DelSources(); p.SetAsPlanTerm(true); p.MakeVarsAnnon(); //String ps = p.toASString().replaceAll("\"", "\\\\\""); //return un.unifies(new StringTermImpl(ps), args[0]); return(un.Unifies(p, args[0])); } else { return(false); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); string fileName = null; if (args[0].IsString()) { fileName = ((IStringTerm)args[0]).GetString(); } else { fileName = args[0].ToString(); } IListTerm goals = new ListTermImpl(); if (args.Length > 1) { goals = (IListTerm)args[1]; } StreamWriter bs = new StreamWriter(new FileStream(fileName, FileMode.Open)); // Not sure if this works, but it doesn't give an error // ORIGINAL: BufferedWriter bs = new BufferedWriter(new FileWriter(fileName)); // store beliefs (and rules) //Hemos cambiado todos los Append por Write bs.Write("// beliefs and rules\n"); foreach (Literal b in ts.GetAgent().GetBB()) { //b = b.copy(); //b.delSource(BeliefBase.ASelf); //out.append(b + ".\n"); var baux = b.Copy(); baux.DelSource(BeliefBase.ASelf); bs.Write(baux + ".\n"); } // store initial goals bs.Write("\n\n// initial goals\n"); foreach (ITerm g in goals) { bs.Write("!" + g + ".\n"); } // store plans bs.Write(ts.GetAgent().GetPL().GetAsTxt(false)); bs.Close(); return(true); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { try { Literal pattern = (Literal)args[0]; IListTerm result = new ListTermImpl(); //synchronized(ts.GetAgent().GetBB().GetLock()) { IEnumerator <Literal> i = ts.GetAgent().GetBB().GetCandidateBeliefs(pattern, un); while (i.MoveNext()) { Literal l = i.Current; if (l.IsRule()) { if (un.Clone().Unifies(pattern, l)) { l = l.Copy(); l.DelSources(); ((Rule)l).SetAsTerm(true); result.Add(l); } } } //} return(un.Unifies(args[1], result)); } catch (Exception e) { //ts.GetLogger().Warning("Error in internal action 'get_rules'! "+e); } return(false); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); Agent ag = reasoner.GetAgent(); Pred inc = new Pred(ns, "include"); inc.AddTerms(args); //-Cosas Java??? //-Sí Peterrr, cÓsas Naz* ¡digo! cÓsas Java Agent result = ((Include)DirectiveProcessor.GetDirective("include")).Process(inc, ag, null); ag.ImportComponents(result); ag.AddInitialBelsInBB(); ag.AddInitialDesiresInReasoner(); if (args.Length > 1 && args[1].IsVar()) { return(un.Unifies(args[1], inc.GetTerm(1))); } else { 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 override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { foreach (Literal b in reasoner.GetAgent().GetBB()) { } return(true); }
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 override object Execute(Reasoner ts, Unifier un, ITerm[] args) { string agName = ((IStringTerm)args[0]).GetString(); IRuntimeServices services = ts.GetUserAgArch().GetRuntimeServices(); services.Clone(ts.GetAgent(), ts.GetUserAgArch().GetAgArchClassesChain(), agName); return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); List <Literal>[] result = ts.GetAgent().Brf((Literal)args[0], null, null, true); if (result != null) { ts.UpdateEvents(result, null); } return(true); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); if (!args[0].IsVar()) { return(ts.GetAgent().GetBB().GetNameSpaces().Contains(args[0])); } else { return(new NameSpaceStdLibIterator <Unifier>(ts, un, args)); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ILogicalFormula logExpr = args[0] as ILogicalFormula; int n = 0; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); while (iu.Current != null) { iu.MoveNext(); n++; } return(un.Unifies(args[1], new NumberTermImpl(n))); }
public void EventAdded(Event e) { if (dropped) { return; } if (te != null && un.Unifies(te, e.GetTrigger())) { Resume(false); } else if (formula != null && ts.GetAgent().Believes(formula, un)) { // each new event, just test the formula being waited Resume(false); } }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm var = args[0]; ILogicalFormula logExpr = (ILogicalFormula)args[1]; ISet <ITerm> all = new HashSet <ITerm>(); IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); while (iu.MoveNext()) { all.Add(var.CApply(iu.Current)); } return(un.Unifies(args[2], SetToList(all))); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { CheckArguments(args); ITerm var = args[0]; ILogicalFormula logExpr = (ILogicalFormula)args[1]; IListTerm all = new ListTermImpl(); IListTerm tail = all; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(reasoner.GetAgent(), un); while (iu.MoveNext()) { tail = tail.Append(var.CApply(iu.Current)); } return(un.Unifies(args[2], all)); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ILogicalFormula logExpr = args[1] as ILogicalFormula; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(ts.GetAgent(), un); if (iu.Current != null) { return(un.Unifies(args[0], Literal.LTrue)); } else { return(un.Unifies(args[0], Literal.LFalse)); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ITerm source = BeliefBase.ASelf; if (args.Length > 1) { source = args[1]; } bool before = false; if (args.Length > 2) { before = args[2].ToString().Equals("begin"); } if (args[0].IsList()) { foreach (ITerm t in (IListTerm)args[0]) { ts.GetAgent().GetPL().Add(Transform2Plan(t), source, before); } } else { ts.GetAgent().GetPL().Add(Transform2Plan(args[0]), source, before); } if (ts.GetAgent().GetPL().HasMetaEventPlans()) { ts.AddDesireListener(new Desire(ts)); } return(true); }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); Literal l = (Literal)args[0]; if (!l.HasSource()) { l.AddAnnot(BeliefBase.TSelf); } List <Literal>[] result = ts.GetAgent().Brf(l, null, null, false); if (result != null) { ts.UpdateEvents(result, null); } return(true); }
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 override double Evaluate(Reasoner reasoner, ITerm[] args) { if (reasoner == null) { throw new JasonityException("The TransitionSystem parameter of the function '.count' cannot be null."); } ILogicalFormula logExpr = (ILogicalFormula)args[0]; int n = 0; IEnumerator <Unifier> iu = logExpr.LogicalConsequence(reasoner.GetAgent(), new Unifier()); Unifier aux = new Unifier(); while (iu.MoveNext()) { aux = iu.Current; n++; } return(n); }
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); }
public override object Execute(Reasoner reasoner, Unifier un, ITerm[] args) { if (args.Length == 1 && (args[0].GetType() == typeof(Trigger))) { Trigger te = Trigger.TryToGetTrigger(args[0]); if (!te.GetLiteral().HasSource()) { te.GetLiteral().AddSource(new UnnamedVar()); } foreach (Plan p in reasoner.GetAgent().GetPL()) { if (te == null || new Unifier().Unifies(p.GetTrigger(), te)) { } } } else { } return(true); }
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); }
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); string name = GetName(args); string source = GetSource(args); List <string> agArchClasses = GetAgArchClasses(args); string agClass = null; ClassParameters bbPars = null; if (args.Length > 2) { foreach (ITerm t in args[2] as IListTerm) { if (t.IsStructure()) { Structure s = t as Structure; if (s.GetFunctor().Equals("beliefBaseClass")) { bbPars = new ClassParameters(TestString(s.GetTerm(0))); } else if (s.GetFunctor().Equals("agentClass")) { agClass = TestString(s.GetTerm(0)).ToString(); } } } } IRuntimeServices rs = ts.GetUserAgArch().GetRuntimeServices(); name = rs.CreateAgent(name, source, agClass, agArchClasses, GetSettings(), ts.GetAgent()); rs.StartAgent(name); if (args[0].IsVar()) { return(un.Unifies(new StringTermImpl(name), args[0])); } else { return(true); } }
public override double Evaluate(Reasoner reasoner, ITerm[] args) { // create a literal to perform the query Literal r; if (literal.IndexOf(".") > 0) // is internal action { r = new InternalActionLiteral(literal); } else { r = new LiteralImpl(literal); } r.AddTerms(args); VarTerm answer = new VarTerm("__RuleToFunctionResult"); r.AddTerm(answer); // query the BB IEnumerator <Unifier> i = r.LogicalConsequence((reasoner == null ? null : reasoner.GetAgent()), new Unifier()); if (i.MoveNext()) { ITerm value = i.Current.Get(answer); if (value.IsNumeric()) { return(((INumberTerm)value).Solve()); } else { throw new JasonityException("The result of " + r + " (=" + value + ") is not numeric!"); } } else { throw new JasonityException("No solution was found for rule " + r); } }
public override object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ts.GetAgent().Abolish((Literal)args[0], un); return(true); }
override public object Execute(Reasoner ts, Unifier un, ITerm[] args) { CheckArguments(args); ts.GetAgent().Buf(ts.GetUserAgArch().Perceive()); return(true); }