コード例 #1
0
 private bool MatchParametersToPredicateDeclaration(ParametrizedPredicate pp, Domain d)
 {
     foreach (Predicate pDefinition in d.Predicates)
     {
         if (pDefinition.Name == pp.Name)
         {
             if (pDefinition is ParametrizedPredicate)
             {
                 ParametrizedPredicate ppDefinition = (ParametrizedPredicate)pDefinition;
                 if (pp.Parameters.Count() != ppDefinition.Parameters.Count())
                 {
                     return(false);
                 }
                 for (int i = 0; i < pp.Parameters.Count(); i++)
                 {
                     if (ppDefinition.Parameters.ElementAt(i).Type == "")
                     {
                         ppDefinition.Parameters.ElementAt(i).Type = pp.Parameters.ElementAt(i).Type;
                     }
                     else if (!d.ParentOf(ppDefinition.Parameters.ElementAt(i).Type, pp.Parameters.ElementAt(i).Type))
                     {
                         return(false);
                     }
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #2
0
        public Dictionary <string, Constant> Bind(ParametrizedPredicate p, Domain d)
        {
            if (Name != p.Name)
            {
                return(null);
            }

            if (((List <Constant>)Constants).Count != ((List <Argument>)p.Parameters).Count)
            {
                return(null);
            }

            Dictionary <string, Constant> dBindings = new Dictionary <string, Constant>();

            for (int i = 0; i < Constants.Count; i++)
            {
                Argument arg = p.Parameters.ElementAt(i);
                if (arg is Constant)
                {
                    if (!Constants[i].Equals(arg))
                    {
                        return(null);
                    }
                }
                if (arg is Parameter)
                {
                    if (!d.ParentOf(arg.Type, Constants[i].Type))
                    {
                        return(null);
                    }
                    dBindings[arg.Name] = Constants[i];
                }
            }
            return(dBindings);
        }