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); }
public override Predicate GenerateKnowGiven(string sTag, bool bKnowWhether) { if (bKnowWhether) { throw new NotImplementedException("There should no longer be any Know Whether prediate"); } ParametrizedPredicate pKGiven = null; if (bKnowWhether) { pKGiven = new ParametrizedPredicate("KWGiven" + Name); } else { pKGiven = new ParametrizedPredicate("KGiven" + Name); } foreach (Argument a in Parameters) { pKGiven.AddParameter(a); } pKGiven.AddParameter(new Parameter(Domain.TAG, sTag)); if (!bKnowWhether) { if (Negation) { pKGiven.AddParameter(new Parameter(Domain.VALUE, Domain.FALSE_VALUE)); } else { pKGiven.AddParameter(new Parameter(Domain.VALUE, Domain.TRUE_VALUE)); } } return(pKGiven); }
//for SDR public static Predicate GenerateKNot(Argument pTag) { ParametrizedPredicate pp = new ParametrizedPredicate("KNot"); pp.AddParameter(pTag); return(pp); }
public override bool Equals(object obj) { if (obj is ParametrizedPredicate) { ParametrizedPredicate pp = (ParametrizedPredicate)obj; if (pp.Name != Name) { return(false); } if (m_lParameters.Count != pp.m_lParameters.Count) { return(false); } for (int iParameter = 0; iParameter < m_lParameters.Count; iParameter++) { if (!m_lParameters[iParameter].Equals(pp.m_lParameters[iParameter])) { return(false); } } return(Negation == pp.Negation); } return(false); }
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); }
public override Predicate Negate() { ParametrizedPredicate pNegate = new ParametrizedPredicate(Name); pNegate.Negation = !Negation; pNegate.m_lParameters = new List <Argument>(m_lParameters); return(pNegate); }
public Predicate PartiallyGround(Dictionary <string, Constant> dBindings) { GroundedPredicate gpred = new GroundedPredicate(Name); ParametrizedPredicate ppred = new ParametrizedPredicate(Name); gpred.Negation = Negation; ppred.Negation = 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(new GroundedPredicate(Domain.TRUE_PREDICATE)); } else { return(new GroundedPredicate(Domain.FALSE_PREDICATE)); } } return(gpred); } else { return(ppred); } }
public override Predicate GenerateGiven(string sTag) { ParametrizedPredicate pGiven = new ParametrizedPredicate("Given" + Name); foreach (Argument a in Parameters) { pGiven.AddParameter(a); } pGiven.AddParameter(new Parameter(Domain.TAG, sTag)); if (Negation) { return(pGiven.Negate()); } return(pGiven); }
private Formula ReadPredicate(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, bool bParametrized, Domain d) { Predicate p = null; int iExpression = 0; string sName = ""; if (bParametrized) { p = new ParametrizedPredicate(exp.Type); } else { p = new GroundedPredicate(exp.Type); } for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++) { sName = exp.SubExpressions[iExpression].ToString(); if (bParametrized) { Argument a = null; if (sName.StartsWith("?")) { a = new Parameter(dParameterNameToType[sName], sName); } else { a = new Constant(d.ConstantNameToType[sName], sName); } ((ParametrizedPredicate)p).AddParameter(a); } else { Constant c = new Constant(d.ConstantNameToType[sName], sName); ((GroundedPredicate)p).AddConstant(c); } } if (bParametrized) { if (!MatchParametersToPredicateDeclaration((ParametrizedPredicate)p, d)) { throw new NotImplementedException(); } } PredicateFormula vf = new PredicateFormula(p); return(vf); }
public override Predicate ToTag() { ParametrizedPredicate ppNew = new ParametrizedPredicate(this); if (Negation) { ppNew.Name = ppNew.Name + "-Remove"; } else { ppNew.Name = ppNew.Name + "-Add"; } ppNew.Negation = false; return(ppNew); }
public override Formula Ground(Dictionary <string, Constant> dBindings) { if (Predicate is ParametrizedPredicate) { ParametrizedPredicate ppred = (ParametrizedPredicate)Predicate; GroundedPredicate gpred = ppred.Ground(dBindings); return(new PredicateFormula(gpred)); } if (Predicate is KnowPredicate) { KnowPredicate kp = (KnowPredicate)Predicate; GroundedPredicate gpred = kp.Ground(dBindings); return(new PredicateFormula(gpred)); } if (Predicate is KnowGivenPredicate) { throw new NotImplementedException(); } return(this); }
public override Formula PartiallyGround(Dictionary <string, Constant> dBindings) { if (Predicate is ParameterizedFunctionPredicate) { //not handling functions in grounding for now return(null); } if (Predicate is ParametrizedPredicate) { ParametrizedPredicate ppred = (ParametrizedPredicate)Predicate; Predicate pGrounded = ppred.PartiallyGround(dBindings); return(new PredicateFormula(pGrounded)); } if (Predicate is KnowPredicate) { throw new NotImplementedException(); } if (Predicate is KnowGivenPredicate) { throw new NotImplementedException(); } return(this); }
private Predicate ReadPredicate(CompoundExpression exp, Domain d) { ParametrizedPredicate pp = new ParametrizedPredicate(exp.Type); int iExpression = 0; Parameter p = null; string sName = ""; List <Parameter> lUntypedParameters = new List <Parameter>(); for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++) { sName = exp.SubExpressions[iExpression].ToString(); if (sName == "-") { string sType = exp.SubExpressions[iExpression + 1].ToString(); foreach (Parameter pUntyped in lUntypedParameters) { pUntyped.Type = sType; } lUntypedParameters.Clear(); iExpression++;//skip the "-" and the type } else { p = new Parameter("N/A", sName); lUntypedParameters.Add(p); pp.AddParameter(p); } } if (d.Types.Count == 1) { foreach (Parameter pUntyped in lUntypedParameters) { pUntyped.Type = d.Types[0]; } } return(pp); }
public ParametrizedPredicate(ParametrizedPredicate pp) : base(pp.Name) { m_lParameters = new List <Argument>(pp.m_lParameters); Parameterized = pp.Parameterized; }