public override Formula Clone() { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].Clone(), Probabilities[i]); return pf; }
public override Formula PartiallyGround(Dictionary <string, Constant> dBindings) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].PartiallyGround(dBindings), Probabilities[i]); } return(pf); }
public override Formula RemoveUniversalQuantifiers(List <Constant> lConstants, List <Predicate> lConstantPredicates, Domain d) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].RemoveUniversalQuantifiers(lConstants, lConstantPredicates, d), Probabilities[i]); } return(pf); }
public override Formula Reduce(IEnumerable <Predicate> lKnown) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].Reduce(lKnown), Probabilities[i]); } return(pf); }
public override Formula Simplify() { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].Simplify(), Probabilities[i]); } return(pf); }
public override Formula Replace(Dictionary <Formula, Formula> dTranslations) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].Replace(dTranslations), Probabilities[i]); } return(pf); }
public override Formula Replace(Formula fOrg, Formula fNew) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) { pf.AddOption(Options[i].Replace(fOrg, fNew), Probabilities[i]); } return(pf); }
public override Formula RemoveNegations() { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Probabilities.Count; i++) { Formula fRemoved = Options[i].RemoveNegations(); if (fRemoved != null) { pf.AddOption(fRemoved, Probabilities[i]); } } return(pf); }
private Formula ReadFormula(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, bool bParamterized, Domain d) { bool bPredicate = true; //Console.WriteLine(exp); if (d != null && d.IsFunctionExpression(exp.Type)) { Predicate p = ReadFunctionExpression(exp, dParameterNameToType, d); return(new PredicateFormula(p)); } else if (IsUniversalQuantifier(exp)) { CompoundExpression eParameter = (CompoundExpression)exp.SubExpressions[0]; CompoundExpression eBody = (CompoundExpression)exp.SubExpressions[1]; string sParameter = eParameter.Type; string sType = eParameter.SubExpressions[1].ToString(); dParameterNameToType[sParameter] = sType; ParametrizedFormula cfQuantified = new ParametrizedFormula(exp.Type); cfQuantified.Parameters[sParameter] = sType; Formula fBody = ReadFormula(eBody, dParameterNameToType, true, d); cfQuantified.AddOperand(fBody); return(cfQuantified); } else if (exp.Type == "probabilistic") { ProbabilisticFormula pf = new ProbabilisticFormula(); int iExpression = 0; for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression += 2) { //if (exp.SubExpressions[iExpression] is StringExpression) // throw new InvalidDataException(); string sProb = exp.SubExpressions[iExpression].ToString(); double dProb = 0.0; if (sProb.Contains("/")) { string[] a = sProb.Split('/'); dProb = double.Parse(a[0]) / double.Parse(a[1]); } else { dProb = double.Parse(sProb); } Formula f = ReadFormula((CompoundExpression)exp.SubExpressions[iExpression + 1], dParameterNameToType, bParamterized, d); pf.AddOption(f, dProb); } return(pf); } else { foreach (Expression eSub in exp.SubExpressions) { if (eSub is CompoundExpression) { bPredicate = false; break; } } if (bPredicate) { return(ReadPredicate(exp, dParameterNameToType, bParamterized, d)); } else { CompoundFormula cf = new CompoundFormula(exp.Type); int iExpression = 0; for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++) { if (exp.SubExpressions[iExpression] is StringExpression) { throw new InvalidDataException(); } Formula f = ReadFormula((CompoundExpression)exp.SubExpressions[iExpression], dParameterNameToType, bParamterized, d); cf.SimpleAddOperand(f); } if (cf.Operator == "not" && cf.Operands[0] is PredicateFormula) { PredicateFormula fNegate = new PredicateFormula(((PredicateFormula)cf.Operands[0]).Predicate.Negate()); return(fNegate); } return(cf); } } }
public override Formula Replace(Formula fOrg, Formula fNew) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].Replace(fOrg, fNew), Probabilities[i]); return pf; }
public override Formula Replace(Dictionary<Formula, Formula> dTranslations) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].Replace(dTranslations), Probabilities[i]); return pf; }
public override Formula RemoveUniversalQuantifiers(List<Constant> lConstants, List<Predicate> lConstantPredicates, Domain d) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].RemoveUniversalQuantifiers(lConstants, lConstantPredicates, d), Probabilities[i]); return pf; }
public override Formula RemoveNegations() { ProbabilisticFormula pf = new ProbabilisticFormula(); for(int i = 0 ; i < Probabilities.Count ; i++) { Formula fRemoved = Options[i].RemoveNegations(); if (fRemoved != null) { pf.AddOption(fRemoved, Probabilities[i]); } } return pf; }
public override Formula Reduce(IEnumerable<Predicate> lKnown) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].Reduce(lKnown), Probabilities[i]); return pf; }
public override Formula PartiallyGround(Dictionary<string, Constant> dBindings) { ProbabilisticFormula pf = new ProbabilisticFormula(); for (int i = 0; i < Options.Count; i++) pf.AddOption(Options[i].PartiallyGround(dBindings), Probabilities[i]); return pf; }
private Formula ReadFormula(CompoundExpression exp, Dictionary<string, string> dParameterNameToType, bool bParamterized, Domain d) { bool bPredicate = true; //Console.WriteLine(exp); if (d!= null && d.IsFunctionExpression(exp.Type)) { Predicate p = ReadFunctionExpression(exp, dParameterNameToType, d); return new PredicateFormula(p); } else if (IsUniversalQuantifier(exp)) { CompoundExpression eParameter = (CompoundExpression)exp.SubExpressions[0]; CompoundExpression eBody = (CompoundExpression)exp.SubExpressions[1]; string sParameter = eParameter.Type; string sType = eParameter.SubExpressions[1].ToString(); dParameterNameToType[sParameter] = sType; ParametrizedFormula cfQuantified = new ParametrizedFormula(exp.Type); cfQuantified.Parameters[sParameter] = sType; Formula fBody = ReadFormula(eBody, dParameterNameToType, true, d); cfQuantified.AddOperand(fBody); return cfQuantified; } else if (exp.Type == "probabilistic") { ProbabilisticFormula pf = new ProbabilisticFormula(); int iExpression = 0; for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression+=2) { //if (exp.SubExpressions[iExpression] is StringExpression) // throw new InvalidDataException(); string sProb = exp.SubExpressions[iExpression].ToString(); double dProb = 0.0; if (sProb.Contains("/")) { string[] a = sProb.Split('/'); dProb = double.Parse(a[0]) / double.Parse(a[1]); } else { dProb = double.Parse(sProb); } Formula f = ReadFormula((CompoundExpression)exp.SubExpressions[iExpression + 1], dParameterNameToType, bParamterized, d); pf.AddOption(f, dProb); } return pf; } else { foreach (Expression eSub in exp.SubExpressions) { if (eSub is CompoundExpression) { bPredicate = false; break; } } if (bPredicate) return ReadPredicate(exp, dParameterNameToType, bParamterized, d); else { CompoundFormula cf = new CompoundFormula(exp.Type); int iExpression = 0; for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++) { if (exp.SubExpressions[iExpression] is StringExpression) throw new InvalidDataException(); Formula f = ReadFormula((CompoundExpression)exp.SubExpressions[iExpression], dParameterNameToType, bParamterized, d); cf.SimpleAddOperand(f); } if (cf.Operator == "not" && cf.Operands[0] is PredicateFormula) { PredicateFormula fNegate = new PredicateFormula(((PredicateFormula)cf.Operands[0]).Predicate.Negate()); return fNegate; } return cf; } } }