本文整理汇总了C#中Domain.IsFunctionExpression方法的典型用法代码示例。如果您正苦于以下问题:C# Domain.IsFunctionExpression方法的具体用法?C# Domain.IsFunctionExpression怎么用?C# Domain.IsFunctionExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domain
的用法示例。
在下文中一共展示了Domain.IsFunctionExpression方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFormula
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;
}
}
}
示例2: ReadInitState
private void ReadInitState(Problem p, Domain d, CompoundExpression eInitState)
{
foreach (Expression e in eInitState.SubExpressions)
{
CompoundExpression eSub = (CompoundExpression)e;
if(d.IsFunctionExpression(eSub.Type))
{
p.AddKnown(ReadFunctionExpression(eSub, null, d));
}
else if (d.ContainsPredicate(eSub.Type))
{
p.AddKnown(ReadGroundedPredicate(eSub, d));
}
else
{
if (eSub.Type != "unknown")
{
Formula f = ReadGroundedFormula(eSub, d);
if (f is CompoundFormula)
p.AddHidden((CompoundFormula)f);
if (f is PredicateFormula)//this happens in (not (p)) statments
p.AddKnown(((PredicateFormula)f).Predicate);
}
else
{
//causing a problem - add operand does some basic reasoning - adding p and ~p results in true for or statements.
//skipping unknown for now...
Predicate pUnknown = ReadGroundedPredicate((CompoundExpression)eSub.SubExpressions[0], d);
CompoundFormula cfOr = new CompoundFormula("or");
cfOr.SimpleAddOperand(pUnknown);
cfOr.SimpleAddOperand(pUnknown.Negate());
p.AddHidden(cfOr);
}
}
}
p.ComputeRelevanceClosure();
}
示例3: KnowWhetherTagCompilation
public Action KnowWhetherTagCompilation(Dictionary<string, List<Predicate>> dTags, Domain d, List<string> lIncludedTags, List<string> lExcludedTags)
{
string sName = Name + "-KW";
foreach (string sTag in lIncludedTags)
sName += "-" + sTag;
ParametrizedAction aNew = new ParametrizedAction(sName);
if (this is ParametrizedAction)
{
foreach (Parameter p in ((ParametrizedAction)this).Parameters)
aNew.AddParameter(p);
}
List<CompoundFormula> lConditions = new List<CompoundFormula>();
List<Formula> lObligatory = new List<Formula>();
SplitEffects(lConditions, lObligatory);
aNew.Preconditions = GetKnowWhetherPreconditions(dTags, d, lIncludedTags, lExcludedTags);
if (Effects != null)
{
HashSet<Predicate> lKnowEffects = new HashSet<Predicate>();
CompoundFormula cfEffects = new CompoundFormula("and");
//CompoundFormula cfMandatoryEffects = new CompoundFormula("and");
foreach (Formula f in lObligatory)
{
f.GetAllPredicates(lKnowEffects);
}
if (lKnowEffects.Count > 0)
{
List<Predicate> lFunctionExpressions = new List<Predicate>();
List<Predicate> lPredicates = new List<Predicate>();
foreach (Predicate p in lKnowEffects)
{
if (d.IsFunctionExpression(p.Name))
lFunctionExpressions.Add(p);
else
lPredicates.Add(p);
}
foreach (string sTag in lIncludedTags)
{
//~KNot t|?t -> effects|t
CompoundFormula cfKEffects = new CompoundFormula("and");
foreach (Predicate p in lPredicates)
{
Predicate pAdd = p.GenerateGiven(sTag);
cfKEffects.AddOperand(pAdd);
if (!d.AlwaysKnown(p))
{
pAdd = p.GenerateKnowGiven(sTag, true);
cfKEffects.AddOperand(pAdd);
}
}
cfEffects.SimpleAddOperand(cfKEffects);
}
foreach (Predicate p in lFunctionExpressions)
cfEffects.AddOperand(p);
}
List<Predicate> lAllKnowledgeToRemove = new List<Predicate>();
foreach (CompoundFormula cfCondition in lConditions)
{
CompoundFormula cfK = null, cfAnd = null;
HashSet<Predicate> lConditionEffects = cfCondition.Operands[1].GetAllPredicates();
cfAnd = new CompoundFormula("and");
foreach (string sTag in lIncludedTags)
{
cfK = CreateTaggedCondition(cfCondition, d, sTag);
if (cfK != null)
{
cfEffects.SimpleAddOperand(cfK);
}
}
if (SDRPlanner.RemoveAllKnowledge)
{
foreach (Predicate p in cfCondition.Operands[1].GetAllPredicates())
{
Predicate pTag = p;
if (p.Negation)
pTag = p.Negate();
if (!lAllKnowledgeToRemove.Contains(pTag))
lAllKnowledgeToRemove.Add(pTag);
}
}
else
{
cfK = CreateTaggedKnowledgeWhetherGainConditions(cfCondition, d, lIncludedTags);
if (cfK != null)
{
cfEffects.SimpleAddOperand(cfK);
}
cfK = CreateTaggedKnowledgeWhetherLossCondition(cfCondition, d, lIncludedTags);
if (cfK != null && cfK.Operands.Count > 0)
{
cfEffects.SimpleAddOperand(cfK);
}
}
/* causes the plan to add many merge actions
//.........这里部分代码省略.........