public override GroundedPredicate Ground(Dictionary <string, Constant> dBindings) { GroundedFunctionPredicate gpred = new GroundedFunctionPredicate(Name); gpred.Negation = Negation; foreach (Argument a in Parameters) { if (a is Parameter) { if (!dBindings.ContainsKey(a.Name)) { return(null); } gpred.AddConstant(dBindings[a.Name]); } else if (a is Constant) { gpred.AddConstant((Constant)a); } else if (a is FunctionParameter) { FunctionParameter fp = (FunctionParameter)a; ParameterizedFunctionPredicate pfp = fp.Function; GroundedFunctionPredicate gfp = (GroundedFunctionPredicate)pfp.Ground(dBindings); FunctionConstant fc = new FunctionConstant(gfp); gpred.AddConstant(fc); } } return(gpred); }
public ParameterizedFunctionPredicate ReadFunctionExpression(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, Domain d) { ParameterizedFunctionPredicate pp = new ParameterizedFunctionPredicate(exp.Type); foreach (Expression e in exp.SubExpressions) { pp.AddParameter(ReadFunctionArgument(e, dParameterNameToType, d)); } return(pp); }
private Argument ReadFunctionArgument(Expression exp, Dictionary <string, string> dParameterNameToType, Domain d) { string sName = exp.ToString(); double dValue = 0.0; if (double.TryParse(sName, out dValue)) { Constant c = new Constant("Number", sName); return(c); } if (exp is CompoundExpression) { CompoundExpression ce = (CompoundExpression)exp; if (!d.Functions.Contains(ce.Type)) { throw new ArgumentException("Function arguments can only be numbers, parameters, or functions"); } ParameterizedFunctionPredicate fp = new ParameterizedFunctionPredicate(ce.Type); foreach (Expression e in ce.SubExpressions) { string sParam = e.ToString(); if (dParameterNameToType != null && dParameterNameToType.ContainsKey(sParam)) { fp.AddParameter(new Parameter(dParameterNameToType[sParam], sParam)); } else if (d.ConstantNameToType.ContainsKey(sParam)) { fp.AddParameter(new Constant(d.ConstantNameToType[sParam], sParam)); } else { throw new ArgumentException("Unknown function parameter"); } } FunctionParameter fa = new FunctionParameter(fp); return(fa); } if (dParameterNameToType.ContainsKey(sName)) { return(new Parameter(dParameterNameToType[sName], sName)); } throw new ArgumentException("Unknown function parameter"); }
public FunctionParameter(ParameterizedFunctionPredicate f) : base("Function", f.Name) { Function = f; }