//for SDR public static Predicate GenerateKNot(Argument pTag) { ParametrizedPredicate pp = new ParametrizedPredicate("KNot"); pp.AddParameter(pTag); return(pp); }
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 (ppDefinition.Parameters.ElementAt(i).Type != pp.Parameters.ElementAt(i).Type) { return(false); } } return(true); } } } return(false); }
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 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); }
public Dictionary <string, Constant> Bind(ParametrizedPredicate p) { 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) { 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 ReadFunctionExpression(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, Domain d) { Constant c = null; string sName = exp.SubExpressions[0].ToString(); if (exp.Type == "=") { string sParam1 = exp.SubExpressions[0].ToString(); string sParam2 = exp.SubExpressions[1].ToString(); if (!dParameterNameToType.ContainsKey(sParam1)) { throw new ArgumentException("First argument of = must be a parameter"); } ParametrizedPredicate pp = new ParametrizedPredicate("="); pp.AddParameter(new Parameter(dParameterNameToType[sParam1], sParam1)); if (dParameterNameToType.ContainsKey(sParam2)) { pp.AddParameter(new Parameter(dParameterNameToType[sParam2], sParam2)); } else { pp.AddParameter(new Constant(d.ConstantNameToType[sParam2], sParam2)); } return(pp); } GroundedPredicate p = new GroundedPredicate(exp.Type); double dValue = 0.0; if (d.Functions.Contains(sName)) { c = new Constant("Function", sName); } else { throw new ArgumentException("First argument of increase or decrease must be a function"); } p.AddConstant(c); sName = exp.SubExpressions[1].ToString(); if (double.TryParse(sName, out dValue)) { c = new Constant("Number", sName); } else { throw new ArgumentException("Second argument of increase or decrease must be a number"); } p.AddConstant(c); return(p); }
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); }
public Predicate PartiallyGround(Dictionary <string, Constant> dBindings) { GroundedPredicate gpred = new GroundedPredicate(Name, Negation); ParametrizedPredicate ppred = new ParametrizedPredicate(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); } }
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 PartiallyGround(Dictionary <string, Constant> dBindings) { 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("", sName); lUntypedParameters.Add(p); pp.AddParameter(p); } } if (d.Types.Count == 1) { foreach (Parameter pUntyped in lUntypedParameters) { pUntyped.Type = d.Types[0]; } } return(pp); }
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); } bool bAllConstants = true; 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); bAllConstants = false; } else { if (!d.ConstantNameToType.ContainsKey(sName)) { throw new Exception("Predicate " + sName + " undefined"); } a = new Constant(d.ConstantNameToType[sName], sName); } ((ParametrizedPredicate)p).AddParameter(a); } else { try { Constant c = new Constant(d.ConstantNameToType[sName], sName); ((GroundedPredicate)p).AddConstant(c); } catch (Exception e) { Console.WriteLine(); } } } if (bParametrized) { if (!MatchParametersToPredicateDeclaration((ParametrizedPredicate)p, d)) { throw new NotImplementedException(); } } if (bParametrized && bAllConstants) { GroundedPredicate gp = new GroundedPredicate(p.Name); foreach (Constant c in ((ParametrizedPredicate)p).Parameters) { gp.AddConstant(c); } p = gp; } PredicateFormula vf = new PredicateFormula(p); return(vf); }
public ParametrizedPredicate(ParametrizedPredicate pp) : base(pp.Name) { m_lParameters = new List <Argument>(pp.m_lParameters); Parameterized = pp.Parameterized; }