Ejemplo n.º 1
0
        protected void AddInitialDesiresFromProjectInBB()
        {
            string sGoals = GetReasoner().GetSettings().GetUserParameter(Settings.INIT_DESIRES);

            if (sGoals != null)
            {
                try
                {
                    foreach (ITerm t in AsSyntax.AsSyntax.ParseList("[" + sGoals + "]"))
                    {
                        Literal g = ((Literal)t).ForceFullLiteralImpl();
                        g.MakeVarsAnnon();
                        if (!g.HasSource())
                        {
                            g.AddAnnot(BeliefBase.TSelf);
                        }
                        GetReasoner().GetCircumstance().AddAchieveDesire(g, Intention.emptyInt);
                    }
                }
                catch (Exception e)
                {
                    //logger.log(Level.WARNING, "Initial goals from project '[" + sGoals + "]' is not a list of literals.");
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public bool DelBel(Literal bel)
 {
     if (!bel.HasSource())
     {
         bel.AddAnnot(BeliefBase.TSelf);
     }
     List <Literal>[] result = Brf(null, bel, Intention.emptyInt);
     if (result != null && reasoner != null)
     {
         reasoner.UpdateEvents(result, Intention.emptyInt);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
            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));
                }
            }