本文整理汇总了C#中Domain.AlwaysKnown方法的典型用法代码示例。如果您正苦于以下问题:C# Domain.AlwaysKnown方法的具体用法?C# Domain.AlwaysKnown怎么用?C# Domain.AlwaysKnown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domain
的用法示例。
在下文中一共展示了Domain.AlwaysKnown方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateClosedStates
public void UpdateClosedStates(Dictionary<string,List<PartiallySpecifiedState>> dClosedStates ,Domain d, bool bAlreadyClosed)
{
DateTime dtStart = DateTime.Now;
PartiallySpecifiedState pssIter = this;
//may be already intialized due to an identical closed state
if (m_lOfflinePredicatesKnown == null)
{
m_lOfflinePredicatesKnown = new HashSet<Predicate>();
m_lOfflinePredicatesUnknown = new HashSet<Predicate>();
m_dRelevantVariablesForPrecondition = new Dictionary<GroundedPredicate, HashSet<GroundedPredicate>>();
m_lOfflineObservedPredicates = new HashSet<Predicate>();
}
List<PartiallySpecifiedState> lPss = new List<PartiallySpecifiedState>();
//if (bAlreadyClosed)
// Console.WriteLine("*");
if (pssIter.IsGoalState())
pssIter.m_lOfflinePredicatesKnown = Problem.Goal.GetAllPredicates();
while (pssIter.Predecessor != null)
{
if (!dClosedStates.ContainsKey(pssIter.ToString())) dClosedStates[pssIter.ToString()] = new List<PartiallySpecifiedState>();
lPss.Add(pssIter);
Action a = pssIter.GeneratingAction;
pssIter.Predecessor.m_nPlan.Action = a;
if (a.Observe == null)
pssIter.Predecessor.m_nPlan.SingleChild = pssIter.m_nPlan;
else
{
if (pssIter.GeneratingObservation.GetAllPredicates().First().Negation)
pssIter.Predecessor.m_nPlan.FalseObservationChild = pssIter.m_nPlan;
else
pssIter.Predecessor.m_nPlan.TrueObservationChild = pssIter.m_nPlan;
}
if (pssIter.Predecessor.ChildCount == 1)
{
pssIter.Predecessor.m_lOfflinePredicatesUnknown = new HashSet<Predicate>(pssIter.m_lOfflinePredicatesUnknown);
pssIter.Predecessor.m_lOfflineObservedPredicates = new HashSet<Predicate>(pssIter.m_lOfflineObservedPredicates);
pssIter.Predecessor.m_lOfflinePredicatesKnown = new HashSet<Predicate>();
HashSet<Predicate> lMandatoryEffects = a.GetMandatoryEffects();
foreach (Predicate p in pssIter.m_lOfflinePredicatesKnown)
{
//if a predicate is always known and constant no need to do anything
if (!(d.AlwaysKnown(p) && d.AlwaysConstant(p)) && !lMandatoryEffects.Contains(p) && !(p.Name == "at"))
{
pssIter.Predecessor.m_lOfflinePredicatesKnown.Add(p);
}
}
HashSet<Predicate> hsPreconditions = new HashSet<Predicate>();
if (a.Preconditions != null)
hsPreconditions = a.Preconditions.GetAllPredicates();
pssIter.Predecessor.m_dRelevantVariablesForPrecondition = new Dictionary<GroundedPredicate, HashSet<GroundedPredicate>>();
foreach (KeyValuePair<GroundedPredicate, HashSet<GroundedPredicate>> p in pssIter.m_dRelevantVariablesForPrecondition)
{
pssIter.Predecessor.m_dRelevantVariablesForPrecondition[p.Key] = new HashSet<GroundedPredicate>(p.Value);
}
foreach (GroundedPredicate gp in hsPreconditions)
{
//if a predicate is always known and constant no need to do anything
if (d.AlwaysKnown(gp) && d.AlwaysConstant(gp))
continue;
if (d.AlwaysConstant(gp) && !Problem.InitiallyUnknown(gp))
continue;
if (Problem.InitiallyUnknown(gp))
{
pssIter.Predecessor.m_dRelevantVariablesForPrecondition[gp] = new HashSet<GroundedPredicate>();
}
pssIter.Predecessor.m_lOfflinePredicatesKnown.Add(gp);
}
if (!bAlreadyClosed)
{
pssIter.AddToClosedStates(dClosedStates);
}
}
else if (pssIter.Predecessor.m_pssFirstChild == null)
{
pssIter.Predecessor.m_pssFirstChild = pssIter;
if (!bAlreadyClosed)
pssIter.AddToClosedStates(dClosedStates);
break;
}
//.........这里部分代码省略.........
示例2: GetPreconditionsNoState
//this implementation requires ~Knot between all include tags, and Knot between every include and every exclude tags
public CompoundFormula GetPreconditionsNoState(Dictionary<string, List<Predicate>> dTags, Domain d, List<string> lIncludedTags, List<string> lExcludedTags)
{
CompoundFormula cfPreconditions = new CompoundFormula("and");
if (Preconditions != null)
{
HashSet<Predicate> lKnowPreconditions = Preconditions.GetAllPredicates();
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && (d.AlwaysConstant(p)))
cfPreconditions.AddOperand(p);
}
foreach (string sTag in lIncludedTags)
{
CompoundFormula cfAnd = new CompoundFormula("and");
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && (d.AlwaysConstant(p)))
continue;
else
{
cfAnd.AddOperand(p.GenerateGiven(sTag));
}
}
if (cfAnd.Operands.Count > 0)
cfPreconditions.SimpleAddOperand(cfAnd.Simplify());
}
}
//this allows only actions on non-distinguishable tag sets - it is possible to allow actions that apply to distinguishable tag sets
for (int iIncludeTag = 0; iIncludeTag < lIncludedTags.Count; iIncludeTag++)
{
for (int iOtherIncludeTag = iIncludeTag + 1; iOtherIncludeTag < lIncludedTags.Count; iOtherIncludeTag++)
{
Predicate pKNotT = Predicate.GenerateKNot(new Constant(Domain.TAG, lIncludedTags[iIncludeTag]), new Constant(Domain.TAG, lIncludedTags[iOtherIncludeTag]));
cfPreconditions.AddOperand(pKNotT.Negate());
}
}
foreach (string sIncludeTag in lIncludedTags)
{
foreach (string sExcludeTag in lExcludedTags)
{
Predicate pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sIncludeTag), new Constant(Domain.TAG, sExcludeTag));
cfPreconditions.AddOperand(pNotTag);
}
}
return cfPreconditions;
}
示例3: RemoveUniversalQuantifiers
public override Formula RemoveUniversalQuantifiers(List<Constant> lConstants, List<Predicate> lConstantPredicates, Domain d)
{
if (d != null && lConstantPredicates != null && d.AlwaysConstant(Predicate) && d.AlwaysKnown(Predicate) && !(Predicate is ParametrizedPredicate))
{
Predicate p = Predicate;
if (p.Negation)
p = p.Negate();
bool bContains = lConstantPredicates.Contains(p);
//assuming that list does not contain negations
if ((bContains && !Predicate.Negation) || (!bContains && Predicate.Negation))
return new PredicateFormula(new GroundedPredicate(Domain.TRUE_PREDICATE));
else
return new PredicateFormula(new GroundedPredicate(Domain.FALSE_PREDICATE));
}
return this;
}
示例4: GetKnowWhetherPreconditions
public CompoundFormula GetKnowWhetherPreconditions(Dictionary<string, List<Predicate>> dTags, Domain d, List<string> lIncludedTags, List<string> lExcludedTags)
{
CompoundFormula cfKWPreconditions = new CompoundFormula("and");
HashSet<Predicate> lKnowPreconditions = new HashSet<Predicate>();
if (Preconditions != null)
{
//foreach tag t, either KNot t | ?t, or forall precondition p, p|t
Preconditions.GetAllPredicates(lKnowPreconditions);
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && (d.AlwaysConstant(p)))
cfKWPreconditions.AddOperand(new KnowPredicate(p));
}
foreach (string sTag in lIncludedTags)
{
CompoundFormula cfAnd = new CompoundFormula("and");
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && (d.AlwaysConstant(p)))
continue;
else
{
cfAnd.AddOperand(p.GenerateGiven(sTag));
if (!d.AlwaysKnown(p))
cfAnd.AddOperand(p.GenerateKnowGiven(sTag, true));
}
}
if (cfAnd.Operands.Count > 0)
cfKWPreconditions.SimpleAddOperand(cfAnd.Simplify());
//this allows only actions on non-distinguishable tag sets - it is possible to allow actions that apply to distinguishable tag sets
if (sTag != lIncludedTags[0])
{
Predicate pKNotT = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag),new Constant(Domain.TAG, lIncludedTags[0]));
cfKWPreconditions.AddOperand(pKNotT.Negate());
}
}
}
foreach (string sTag in lExcludedTags)
{
Predicate pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag),new Constant(Domain.TAG, lIncludedTags[0]));
cfKWPreconditions.AddOperand(pNotTag);
}
if(cfKWPreconditions.Operands.Count > 0)
return cfKWPreconditions;
return null;
}
示例5: CreateTaggedKnowledgeWhetherLossCondition
//C->L ==> ~KW~C/t->~KW~L/t
private CompoundFormula CreateTaggedKnowledgeWhetherLossCondition(CompoundFormula cfCondition, Domain d, string sTag)
{
CompoundFormula cfWhen = new CompoundFormula("when");
HashSet<Predicate> lPreconditions = new HashSet<Predicate>();
HashSet<Predicate> lEffects = new HashSet<Predicate>();
cfCondition.Operands[0].GetAllPredicates(lPreconditions);
cfCondition.Operands[1].GetAllPredicates(lEffects);
CompoundFormula cfPreconditions = new CompoundFormula("and");
bool bContainsOption = false;
foreach (Predicate p in lPreconditions)
{
if (p.Name == Domain.OPTION_PREDICATE)
bContainsOption = true;
Predicate pKGiven = null;
if (!d.AlwaysKnown(p))
{
pKGiven = p.GenerateKnowGiven(sTag, true);
cfPreconditions.AddOperand(pKGiven.Negate());
}
}
if (cfPreconditions.Operands.Count == 0)
return null;
CompoundFormula cfEffects = new CompoundFormula("and");
foreach (Predicate p in lEffects)
{
if (p.Name == Domain.OPTION_PREDICATE)
continue;
Predicate pKGiven = p.Negate().GenerateKnowGiven(sTag, true);
cfEffects.AddOperand(pKGiven.Negate());
}
if (cfEffects.Operands.Count == 0)
return null;
if (bContainsOption)
return cfEffects;
cfWhen.AddOperand(cfPreconditions.Simplify());
cfWhen.AddOperand(cfEffects.Simplify());
return cfWhen;
}
示例6: CreateTaggedKnowledgeWhetherGainConditions
//C->L ==> KWC/t->KWL/t
private CompoundFormula CreateTaggedKnowledgeWhetherGainConditions(CompoundFormula cfCondition, Domain d, List<string> lIncludedTags)
{
HashSet<Predicate> lPreconditions = new HashSet<Predicate>();
HashSet<Predicate> lEffects = new HashSet<Predicate>();
cfCondition.Operands[0].GetAllPredicates(lPreconditions);
cfCondition.Operands[1].GetAllPredicates(lEffects);
CompoundFormula cfWhen = new CompoundFormula("when");
CompoundFormula cfPreconditions = new CompoundFormula("and");
CompoundFormula cfEffects = new CompoundFormula("and");
foreach (Predicate p in lPreconditions)
{
if (p.Name == Domain.OPTION_PREDICATE)
return null;
Predicate pKGiven = null;
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
{
pKGiven = new KnowPredicate(p);
cfPreconditions.AddOperand(pKGiven);
}
}
foreach (string sKWTag in lIncludedTags)
{
CompoundFormula cfAnd = new CompoundFormula("and");
foreach (Predicate p in lPreconditions)
{
Predicate pKGiven = null;
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
{
continue;
}
else
{
if (!d.AlwaysKnown(p))
{
pKGiven = p.GenerateKnowGiven(sKWTag, true);
cfAnd.AddOperand(pKGiven);
}
pKGiven = p.GenerateGiven(sKWTag);
cfAnd.AddOperand(pKGiven);
}
}
if (cfAnd.Operands.Count > 0)
{
cfPreconditions.AddOperand(cfAnd);
}
foreach (Predicate p in lEffects)
{
Predicate pKEffect = p.GenerateKnowGiven(sKWTag, true);
cfEffects.AddOperand(pKEffect);
}
}
cfWhen.AddOperand(cfPreconditions.Simplify());
cfWhen.AddOperand(cfEffects.Simplify());
return cfWhen;
}
示例7: CreateTaggedCondition
//C->L ==> C/t->L/t
private CompoundFormula CreateTaggedCondition(CompoundFormula cfCondition, Domain d, string sTag)
{
CompoundFormula cfWhen = new CompoundFormula("when");
HashSet<Predicate> lPreconditions = new HashSet<Predicate>();
HashSet<Predicate> lEffects = new HashSet<Predicate>();
cfCondition.Operands[0].GetAllPredicates(lPreconditions);
cfCondition.Operands[1].GetAllPredicates(lEffects);
CompoundFormula cfPreconditions = new CompoundFormula("and");
CompoundFormula cfEffects = new CompoundFormula("and");
foreach (Predicate p in lPreconditions)
{
//Predicate pKGiven = p.Negate().GenerateGiven(sTag);
//cfPreconditions.AddOperand(pKGiven.Negate());
Predicate pKGiven = null;
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
pKGiven = p;
else
pKGiven = p.GenerateGiven(sTag);
cfPreconditions.AddOperand(pKGiven);
}
foreach (Predicate p in lEffects)
{
Predicate pKEffect = p.GenerateGiven(sTag);
cfEffects.AddOperand(pKEffect);
}
cfWhen.AddOperand(cfPreconditions.Simplify());
cfWhen.AddOperand(cfEffects.Simplify());
return cfWhen;
}
示例8: KnowWhetherTagCompilationSplitConditions
public List<Action> KnowWhetherTagCompilationSplitConditions(Dictionary<string, List<Predicate>> dTags, Domain d, List<string> lIncludedTags,
List<string> lExcludedTags, List<Predicate> lAdditionalPredicates)
{
string sName = Name + "-KW";
foreach (string sTag in lIncludedTags)
sName += "-" + sTag;
ParametrizedAction aNewState = new ParametrizedAction(sName + "-State");
ParametrizedAction aNewKnowledgeGain = new ParametrizedAction(sName + "-KnowledgeGain");
ParametrizedAction aNewKnowledgeLoss = new ParametrizedAction(sName + "-KnowledgeLoss");
ParametrizedPredicate ppInFirst = new ParametrizedPredicate("P1-" + sName);
ParametrizedPredicate ppInSecond = new ParametrizedPredicate("P2-" + sName);
GroundedPredicate gpNotInAction = new GroundedPredicate("NotInAction");
if (this is ParametrizedAction)
{
foreach (Parameter p in ((ParametrizedAction)this).Parameters)
{
aNewKnowledgeLoss.AddParameter(p);
aNewKnowledgeGain.AddParameter(p);
aNewState.AddParameter(p);
ppInFirst.AddParameter(p);
ppInSecond.AddParameter(p);
}
}
List<CompoundFormula> lConditions = new List<CompoundFormula>();
List<Formula> lObligatory = new List<Formula>();
SplitEffects(lConditions, lObligatory);
CompoundFormula cfPreconditions = new CompoundFormula("and");
Formula cfKWPreconditions = GetKnowWhetherPreconditions(dTags, d, lIncludedTags, lExcludedTags);
cfPreconditions.AddOperand(cfKWPreconditions); //knowledge loss is the first action, so it will have all the preconditions
cfPreconditions.AddOperand(gpNotInAction);
if (Effects == null)
throw new NotImplementedException();
HashSet<Predicate> lKnowEffects = new HashSet<Predicate>();
CompoundFormula cfStateEffects = new CompoundFormula("and");
CompoundFormula cfKnowledgeLossEffects = new CompoundFormula("and");
CompoundFormula cfKnowledgeGainEffects = new CompoundFormula("and");
//CompoundFormula cfMandatoryEffects = new CompoundFormula("and");
foreach (Formula f in lObligatory)
{
f.GetAllPredicates(lKnowEffects);
}
if (lKnowEffects.Count > 0)
{
foreach (string sTag in lIncludedTags)
{
//~KNot t|?t -> effects|t
CompoundFormula cfKEffects = new CompoundFormula("and");
foreach (Predicate p in lKnowEffects)
{
Predicate pAdd = p.GenerateGiven(sTag);
cfKEffects.AddOperand(pAdd);
if (!d.AlwaysKnown(p))
{
pAdd = p.GenerateKnowGiven(sTag, true);
cfKEffects.AddOperand(pAdd);
}
}
cfStateEffects.SimpleAddOperand(cfKEffects);
}
}
List<Action> lActions = new List<Action>();
if (lConditions.Count > 0)
{
lAdditionalPredicates.Add(ppInFirst);
lAdditionalPredicates.Add(ppInSecond);
aNewKnowledgeLoss.Preconditions = cfPreconditions;
aNewKnowledgeGain.Preconditions = new PredicateFormula(ppInFirst);
aNewState.Preconditions = new PredicateFormula(ppInSecond);
cfKnowledgeLossEffects.AddOperand(ppInFirst);
cfKnowledgeLossEffects.AddOperand(gpNotInAction.Negate());
cfKnowledgeGainEffects.AddOperand(ppInSecond);
cfKnowledgeGainEffects.AddOperand(ppInFirst.Negate());
cfStateEffects.AddOperand(ppInSecond.Negate());
cfStateEffects.AddOperand(gpNotInAction);
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)
{
cfStateEffects.SimpleAddOperand(cfK);
//.........这里部分代码省略.........
示例9: 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
//.........这里部分代码省略.........
示例10: KnowWhetherObservationTranslation
public Action KnowWhetherObservationTranslation(Dictionary<string, List<Predicate>> dTags, Domain d)
{
Action aNew = Clone();
aNew.Name = Name + "-KW";
CompoundFormula cfPreconditions = new CompoundFormula("and");
HashSet<Predicate> lKnowPreconditions = new HashSet<Predicate>();
if (Observe == null)
throw new NotImplementedException();
if (Effects != null)
throw new NotImplementedException();
Predicate pObserve = ((PredicateFormula)Observe).Predicate;
if (Preconditions != null)
{
Preconditions.GetAllPredicates(lKnowPreconditions);
foreach (Predicate p in lKnowPreconditions)
{
if (!d.AlwaysKnown(p))
cfPreconditions.AddOperand(new KnowWhetherPredicate(p));
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
cfPreconditions.AddOperand(new KnowPredicate(p));
}
}
if (cfPreconditions.Operands.Count > 0)
aNew.Preconditions = cfPreconditions;
else
aNew.Preconditions = null;
CompoundFormula cfEffects = new CompoundFormula("and");
foreach (string sTag in dTags.Keys)
{
CompoundFormula cfCondition = new CompoundFormula("when");
CompoundFormula cfAnd = new CompoundFormula("and");
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
continue;
if (d.AlwaysConstant(p))
cfAnd.AddOperand(new KnowPredicate(p));
else
cfAnd.AddOperand(p.GenerateGiven(sTag));
}
cfCondition.AddOperand(cfAnd);
cfCondition.AddOperand(pObserve.GenerateKnowGiven(sTag, true));//know-whether given
if (cfAnd.Operands.Count > 0)
cfEffects.AddOperand(cfCondition);
else
cfEffects.AddOperand(cfCondition.Operands[1]);
}
aNew.Effects = cfEffects;
return aNew;
}
示例11: KnowWhetherCompilation
public Action KnowWhetherCompilation(Dictionary<string, List<Predicate>> dTags, Domain d)
{
Action aNew = Clone();
aNew.Name = Name + "-KW";
List<CompoundFormula> lConditions = new List<CompoundFormula>();
List<Formula> lObligatory = new List<Formula>();
SplitEffects(lConditions, lObligatory);
CompoundFormula cfKWPreconditions = new CompoundFormula("and");
HashSet<Predicate> lKnowPreconditions = new HashSet<Predicate>();
if (Preconditions != null)
{
Preconditions.GetAllPredicates(lKnowPreconditions);
foreach (Predicate p in lKnowPreconditions)
{
if(!d.AlwaysKnown(p))
cfKWPreconditions.AddOperand(new KnowWhetherPredicate(p));
if(d.AlwaysKnown(p) && d.AlwaysConstant(p))
cfKWPreconditions.AddOperand(new KnowPredicate(p));
}
if (cfKWPreconditions.Operands.Count > 0)
aNew.Preconditions = cfKWPreconditions;
else
aNew.Preconditions = null;
}
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);
//cfEffects.AddOperand(f);//BGUBGU - probably a bug here. Need to separate always known and the rest.
}
if (lKnowEffects.Count > 0)
{
foreach (string sTag in dTags.Keys)
{
//K(preconditions|s)->K(effects|s)
CompoundFormula cfKEffects = new CompoundFormula("and");
CompoundFormula cfKPreconditions = new CompoundFormula("and");
foreach (Predicate p in lKnowPreconditions)
{
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
continue;
else
cfKPreconditions.AddOperand(p.GenerateGiven(sTag));
}
foreach (Predicate p in lKnowEffects)
{
Predicate pAdd = p.GenerateGiven(sTag);
cfKEffects.AddOperand(pAdd);
//Predicate pDelete = p.Negate().GenerateKnowGiven(sTag).Negate();
//cfKEffects.AddOperand(pDelete);
}
if (cfKPreconditions.Operands.Count > 0)
{
CompoundFormula cfCondition = new CompoundFormula("when");
cfCondition.AddOperand(cfKPreconditions);
cfCondition.AddOperand(cfKEffects);
cfEffects.AddOperand(cfCondition);
}
else
cfEffects.AddOperand(cfKEffects);
}
}
//forgetting: ~K~p
foreach (Predicate p in lKnowEffects)
{
Predicate pKNotp = new KnowPredicate(p.Negate());
cfEffects.AddOperand(pKNotp.Negate());
}
foreach (CompoundFormula cfCondition in lConditions)
{
CompoundFormula cfK = null, cfOr = null, cfAnd = null;
//cfK = CreateKnowledgeGainCondition(cfCondition, d.m_lAlwaysKnown, false);
//if (cfK != null)
// cfEffects.AddOperand(cfK);
cfK = CreateKnowledgeLossCondition(cfCondition, d.m_lAlwaysKnown, false);
if (cfK != null)
{
cfOr = new CompoundFormula("or");
foreach (Predicate p in lKnowPreconditions)
{
Predicate pKNot = new KnowPredicate(p.Negate());
cfOr.AddOperand(pKNot.Negate());
}
if (cfK.Operator == "when")
{
if (cfK.Operands[0] is CompoundFormula && ((CompoundFormula)cfK.Operands[0]).Operands.Count > 0)
cfOr.AddOperand(cfK.Operands[0]);
cfK.Operands[0] = cfOr.Simplify();
}
else
{
CompoundFormula cfWhen = new CompoundFormula("when");
cfWhen.AddOperand(cfOr.Simplify());
cfWhen.AddOperand(cfK);
cfK = cfWhen;
}
//.........这里部分代码省略.........