Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private InternalActionLiteral CheckInternalActionsInContext(ILogicalFormula f, Agent ag)
 {
     if (f != null)
     {
         if (f.GetType() == typeof(InternalActionLiteral))
         {
             InternalActionLiteral ial = (InternalActionLiteral)f;
             if (!ial.GetIA(ag).CanBeUsedInContext())
             {
                 return(ial);
             }
         }
         else if (f.GetType() == typeof(LogExpr))
         {
             LogExpr le = (LogExpr)f;
             InternalActionLiteral ial = CheckInternalActionsInContext(le.GetLHS(), ag);
             if (ial != null)
             {
                 return(ial);
             }
             if (!le.IsUnary())
             {
                 return(CheckInternalActionsInContext(le.GetRHS(), ag));
             }
         }
     }
     return(null);
 }
Esempio n. 3
0
        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);
            }
        }