Example #1
0
 public CyclicTerm(Literal t, VarTerm v, Unifier u) : base(t, u)
 {
     cyclicVar = v;
 }
Example #2
0
 public CyclicTerm(Literal t, VarTerm v) : base(t)
 {
     cyclicVar = v;
 }
Example #3
0
            //public bool HasNext()
            //{
            //    if (needsUpdate)
            //        Get();
            //    return current != null;
            //}

            //public Unifier Next()
            //{
            //    if (needsUpdate)
            //        Get();
            //    if (current != null)
            //        needsUpdate = true;
            //    return current;
            //}

            private void Get()
            {
                needsUpdate = false;
                current     = default;
                if (arch != null && !arch.IsRunning())
                {
                    return;
                }

                if (annotsOptions != null)
                {
                    while (annotsOptions.MoveNext())
                    {
                        Literal belToTry = belInBB.Copy().SetAnnots(null).AddAnnots(annotsOptions.Current);
                        Unifier u        = un.Clone();
                        if (u.UnifiesNoUndo(lit, belToTry))
                        {
                            current = u;
                            return;
                        }
                    }
                    annotsOptions = null;
                }

                if (ruleIt != null)
                {
                    while (ruleIt.MoveNext())
                    {
                        Unifier ruleUn = ruleIt.Current;
                        Literal rHead  = rule.HeadCApply(ruleUn);
                        UseDerefVars(rHead, ruleUn);
                        rHead.MakeVarsAnnon();

                        Unifier unC = un.Clone();
                        if (unC.UnifiesNoUndo(lit, rHead))
                        {
                            current = unC;
                            return;
                        }
                    }
                    ruleIt = null;
                }

                while (il.MoveNext())
                {
                    belInBB = il.Current;
                    if (belInBB.IsRule())
                    {
                        rule = (Rule)belInBB;
                        if (cloneAnnon == null)
                        {
                            cloneAnnon = (Literal)lit.CApply(un);
                            cloneAnnon.MakeVarsAnnon();
                        }

                        Unifier ruleUn = new Unifier();
                        if (ruleUn.UnifiesNoUndo(cloneAnnon, rule))
                        {
                            ruleIt = rule.GetBody().LogicalConsequence(ag, ruleUn);
                            Get();
                            if (current != null)
                            {
                                return;
                            }
                        }
                        else
                        {
                            if (nbAnnots > 0)
                            {
                                if (belInBB.HasAnnot())
                                {
                                    int nbAnnotsB = belInBB.GetAnnots().Count;
                                    if (nbAnnotsB >= nbAnnots)
                                    {
                                        annotsOptions = belInBB.GetAnnots().SubSets(nbAnnots);
                                        Get();
                                        if (current != null)
                                        {
                                            return;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Unifier u = un.Clone();
                                if (u.UnifiesNoUndo(lit, belInBB))
                                {
                                    current = u;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
Example #4
0
 public MyIEnumerator(AgentArchitecture arch, int nbAnnots, IEnumerator <Literal> il, Agent ag, Unifier un, Literal lit)
 {
     this.arch     = arch;
     this.nbAnnots = nbAnnots;
     this.il       = il;
     this.ag       = ag;
     this.un       = un;
     this.lit      = lit;
 }
Example #5
0
 /**
  * "import" annots from another predicate <i>p</i>. p will be changed
  * to contain only the annots actually imported (for Event),
  * for example:
  *     p    = b[a,b]
  *     this = b[b,c]
  *     after import, p = b[a]
  * It is used to generate event <+b[a]>.
  *
  * @return true if some annot was imported.
  */
 public virtual bool ImportAnnots(Literal p)
 {
     return(false);
 }
Example #6
0
 /**
  * Returns true if all this predicate's annots are in p's annots using the
  * unifier u.
  *
  * if p annots has a Tail, p annots's Tail will receive this predicate's annots,
  * e.g.:
  *   this[a,b,c] = p[x,y,b|T]
  * unifies and T is [a,c] (this will be a subset if p has a and c in its annots).
  *
  * if this annots has a tail, the Tail will receive all necessary term
  * to be a subset, e.g.:
  *   this[b|T] = p[x,y,b]
  * unifies and T is [x,y] (this will be a subset if T is [x,y].
  */
 public virtual bool HasSubsetAnnot(Literal p, Unifier u)
 {
     return(true);
 }