Beispiel #1
0
 public override int Similarity(Predicate p)
 {
     if (Negation != p.Negation)
     {
         //if (Name != p.Name || Negation != p.Negation)
         return(0);
     }
     if (p is GroundedPredicate)
     {
         GroundedPredicate gpGrounded = (GroundedPredicate)p;
         int iSimilarity = 0;
         if (Name == p.Name)
         {
             for (int i = 0; i < Constants.Count; i++)
             {
                 if (Constants[i].Equals(gpGrounded.Constants[i]))
                 {
                     iSimilarity++;
                 }
             }
         }
         else
         {
             foreach (Constant c in Constants)
             {
                 if (gpGrounded.Constants.Contains(c))
                 {
                     iSimilarity++;
                 }
             }
         }
         return(iSimilarity);
     }
     return(0);
 }
        public GroundedPredicate Ground(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate gpred = GroundedPredicateFactory.Get(Name, m_lParameters, dBindings, Negation);

            /*if (gpred != null)
             * {
             *  return gpred;
             * }*///sagi
            gpred = new GroundedPredicate(Name, Negation);
            foreach (Argument a in Parameters)
            {
                if (a is Parameter)
                {
                    if (!dBindings.ContainsKey(a.Name))
                    {
                        return(null);
                    }
                    gpred.AddConstant(dBindings[a.Name]);
                }
                else
                {
                    gpred.AddConstant((Constant)a);
                }
            }
            GroundedPredicateFactory.Add(Name, m_lParameters, dBindings, gpred, Negation);
            return(gpred);
        }
Beispiel #3
0
        public override Predicate GenerateKnowGiven(string sTag, bool bKnowWhether)
        {
            GroundedPredicate pKGiven = null;

            if (bKnowWhether)
            {
                pKGiven = new GroundedPredicate("KWGiven" + Name);
            }
            else
            {
                pKGiven = new GroundedPredicate("KGiven" + Name);
            }
            foreach (Constant c in Constants)
            {
                pKGiven.AddConstant(c);
            }
            pKGiven.AddConstant(new Constant(Domain.TAG, sTag));
            if (!bKnowWhether)
            {
                if (Negation)
                {
                    pKGiven.AddConstant(new Constant(Domain.VALUE, Domain.FALSE_VALUE));
                }
                else
                {
                    pKGiven.AddConstant(new Constant(Domain.VALUE, Domain.TRUE_VALUE));
                }
            }
            return(pKGiven);
        }
Beispiel #4
0
        public override bool ConsistentWith(Predicate p)
        {
            if (Name != p.Name)
            {
                return(true); //irrelvant predicate - no contradiction
            }
            if (p is ParameterizedPredicate)
            {
                //TODO
                throw new NotImplementedException();
            }
            GroundedPredicate gp = (GroundedPredicate)p;

            if (((List <Constant>)Constants).Count != ((List <Constant>)gp.Constants).Count)
            {
                return(true);
            }
            for (int i = 0; i < Constants.Count; i++)
            {
                if (!gp.Constants[i].Equals(Constants[i]))
                {
                    return(true);//irrelvant predicate - no contradiction
                }
            }
            return(Negation == p.Negation);
        }
Beispiel #5
0
        public GroundedPredicate Ground(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate gp = new GroundedPredicate("K" + Knowledge.Name);

            if (Knowledge is ParameterizedPredicate)
            {
                foreach (Argument a in ((ParameterizedPredicate)Knowledge).Parameters)
                {
                    if (a is Parameter)
                    {
                        if (dBindings.ContainsKey(a.Name))
                        {
                            gp.AddConstant(dBindings[a.Name]);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    else
                    {
                        gp.AddConstant((Constant)a);
                    }
                }
            }
            else
            {
                foreach (Constant c in ((GroundedPredicate)Knowledge).Constants)
                {
                    gp.AddConstant(c);
                }
            }
            return(gp);
        }
Beispiel #6
0
 public GroundedPredicate(string sName)
     : base(sName)
 {
     //if (sName == Domain.FALSE_PREDICATE)
     //    Debug.WriteLine("Initialized  a false predicate");
     m_gpNegation = null;
     Constants    = new List <Constant>();
 }
Beispiel #7
0
 public override Predicate Negate()
 {
     if (m_gpNegation == null)
     {
         m_gpNegation              = new GroundedPredicate(this);
         m_gpNegation.Negation     = !Negation;
         m_gpNegation.m_gpNegation = this;
     }
     return(m_gpNegation);
 }
        public static GroundedPredicate Get(string sName, List <Argument> lParameters, Dictionary <string, Constant> dBindings, bool bNegation)
        {
            string            sFullName = GetString(sName, lParameters, dBindings, bNegation);
            GroundedPredicate gp        = null;

            if (AllGrounded.TryGetValue(sFullName, out gp))
            {
                return(gp);
            }
            return(null);
        }
        public static void Add(string sName, List <Argument> lParameters, Dictionary <string, Constant> dBindings, GroundedPredicate gp, bool bNegation)
        {
            string sFullName    = GetString(sName, lParameters, dBindings, bNegation);
            string sNotFullName = GetString(sName, lParameters, dBindings, !bNegation);

            gp.Cached = true;
            AllGrounded[sFullName] = gp;
            GroundedPredicate gpNot = (GroundedPredicate)gp.Negate();

            gpNot.Cached = true;
            AllGrounded[sNotFullName] = gpNot;
        }
Beispiel #10
0
        public GroundedPredicate(GroundedPredicate gpOther)
            : base(gpOther.Name, gpOther.Negation)
        {
            //if (gpOther == Domain.FALSE_PREDICATE || gpOther == Domain.TRUE_PREDICATE)
            //Console.Write("*");
            List <Constant> newConstants = new List <Constant>();

            foreach (var item in gpOther.Constants)
            {
                newConstants.Add(new Constant(item.Type, item.Name));
            }
            Constants = newConstants;
        }
Beispiel #11
0
 public RegressedPredicate(GroundedPredicate pCurrent, Predicate pNext, int iChoice)
     : base(pCurrent)
 {
     Choice = iChoice;
     if (pNext is RegressedPredicate)
     {
         Next = (RegressedPredicate)pNext;
     }
     else
     {
         Next = null;
     }
 }
Beispiel #12
0
        public override Predicate GenerateGiven(string sTag)
        {
            GroundedPredicate pGiven = new GroundedPredicate("Given" + Name);

            foreach (Constant c in Constants)
            {
                pGiven.AddConstant(c);
            }
            pGiven.AddConstant(new Constant(Domain.TAG, sTag));
            if (Negation)
            {
                return(pGiven.Negate());
            }
            return(pGiven);
        }
Beispiel #13
0
        public Predicate PartiallyGround(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate      gpred = new GroundedPredicate(Name, Negation);
            ParameterizedPredicate ppred = new ParameterizedPredicate(Name, Negation);
            bool bAllGrounded            = true;

            foreach (Argument a in Parameters)
            {
                if (a is Parameter)
                {
                    if (!dBindings.ContainsKey(a.Name))
                    {
                        ppred.AddParameter(a);
                        bAllGrounded = false;
                    }
                    else
                    {
                        ppred.AddParameter(dBindings[a.Name]);
                        gpred.AddConstant(dBindings[a.Name]);
                    }
                }
                else
                {
                    gpred.AddConstant((Constant)a);
                    ppred.AddParameter(a);
                }
            }
            if (bAllGrounded)
            {
                if (gpred.Name == "=")
                {
                    bool bSame = gpred.Constants[0].Equals(gpred.Constants[1]);
                    if (bSame && !Negation || !bSame && Negation)
                    {
                        return(Domain.TRUE_PREDICATE);
                    }
                    else
                    {
                        return(Domain.FALSE_PREDICATE);
                    }
                }
                return(gpred);
            }
            else
            {
                return(ppred);
            }
        }
Beispiel #14
0
        public override Predicate ToTag()
        {
            GroundedPredicate gpNew = new GroundedPredicate(this);

            if (Negation)
            {
                gpNew.Name = gpNew.Name + "-Remove";
            }
            else
            {
                gpNew.Name = gpNew.Name + "-Add";
            }
            gpNew.Negation = false;

            return(gpNew);
        }
Beispiel #15
0
        //for MPSR
        public static Predicate GenerateKNot(Constant cTag1, Constant cTag2)
        {
            GroundedPredicate gp = new GroundedPredicate("KNot");
            int iTag1            = int.Parse(cTag1.Name.Substring(3));
            int iTag2            = int.Parse(cTag2.Name.Substring(3));

            if (iTag1 < iTag2)
            {
                gp.AddConstant(cTag1);
                gp.AddConstant(cTag2);
            }
            else
            {
                gp.AddConstant(cTag2);
                gp.AddConstant(cTag1);
            }
            return(gp);
        }
Beispiel #16
0
        public Dictionary <string, Constant> Match(GroundedPredicate pOther, Dictionary <string, Constant> dBindings)
        {
            if (pOther.Name != Name)
            {
                return(null);
            }
            //if (pOther.Negation != Negation)
            //    return null;
            if (pOther.Constants.Count != m_lParameters.Count)
            {
                return(null);
            }
            int i = 0;
            Dictionary <string, Constant> dNewBindings = new Dictionary <string, Constant>();

            for (i = 0; i < pOther.Constants.Count; i++)
            {
                Argument a = m_lParameters[i];
                if (a is Constant)
                {
                    if (pOther.Constants[i].Name != a.Name)
                    {
                        return(null);
                    }
                }
                else if (a is Parameter)
                {
                    if (dBindings.ContainsKey(a.Name))
                    {
                        if (!pOther.Constants[i].Equals(dBindings[a.Name]))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        dNewBindings[a.Name] = pOther.Constants[i];
                    }
                }
            }
            return(dNewBindings);
        }
Beispiel #17
0
 public KnowGivenPredicate(GroundedPredicate p, bool bValue, string sTag, bool bKnowWhether)
     : base((bKnowWhether ? "KWGiven" : "KGiven") + p.Name)
 {
     KnowWhether = bKnowWhether;
     Predicate   = p;
     Tag         = sTag;
     Value       = bValue;
     Constants   = new List <Constant>(p.Constants);
     Constants.Add(new Constant(Domain.TAG, Tag));
     if (!bKnowWhether)
     {
         if (Value)
         {
             Constants.Add(new Constant(Domain.VALUE, Domain.TRUE_VALUE));
         }
         else
         {
             Constants.Add(new Constant(Domain.VALUE, Domain.FALSE_VALUE));
         }
     }
 }
Beispiel #18
0
 public override bool SameInvariant(Predicate p, Argument aInvariant)
 {
     if (Name != p.Name)
     {
         return(false);
     }
     if (p is GroundedPredicate)
     {
         GroundedPredicate gpGrounded = (GroundedPredicate)p;
         for (int i = 0; i < Constants.Count; i++)
         {
             if (Constants[i].Equals(aInvariant) &&
                 !gpGrounded.Constants[i].Equals(aInvariant))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }