本文整理汇总了C#中Domain.AlwaysConstant方法的典型用法代码示例。如果您正苦于以下问题:C# Domain.AlwaysConstant方法的具体用法?C# Domain.AlwaysConstant怎么用?C# Domain.AlwaysConstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Domain
的用法示例。
在下文中一共展示了Domain.AlwaysConstant方法的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: FilterImpossible
private List<Action> FilterImpossible(List<Action> lActions, HashSet<Predicate> lInitialState, Domain d)
{
List<Action> lPossible = new List<Action>();
List<Action> lImpossible = new List<Action>();
foreach (Action a in lActions)
{
bool bPossible = true;
HashSet<Predicate> lPreconditions = a.Preconditions.GetAllPredicates();
foreach (Predicate p in lPreconditions)
{
if (d.AlwaysConstant(p)) //we can remove them from the preconditions
{
if ((p.Negation && lInitialState.Contains(p.Negate())) || (!p.Negation && !lInitialState.Contains(p)))
{
bPossible = false;
break;
}
}
}
if (bPossible)
lPossible.Add(a);
else
lImpossible.Add(a);
}
return lPossible;
}
示例3: ParseProblem
private Problem ParseProblem(CompoundExpression exp, Domain d)
{
Problem p = null;
CompoundExpression eSub = null;
foreach (Expression e in exp.SubExpressions)
{
eSub = (CompoundExpression)e;
if (eSub.Type == "problem")
{
p = new Problem(eSub.SubExpressions.First().ToString(), d);
}
if (eSub.Type == ":domain")
{
if (eSub.SubExpressions.First().ToString() != d.Name)
throw new InvalidDataException("Domain and problem files don't match!");
}
if (eSub.Type == ":objects")
{
ReadConstants(eSub, d);
}
if (eSub.Type == ":init")
{
CompoundExpression eAnd = (CompoundExpression)eSub.SubExpressions.First();
if (eAnd.Type == "and")
ReadInitState(p, d, eAnd);
else
ReadInitState(p, d, eSub);
//throw new InvalidDataException("Expecting 'and', got " + eAnd.Type);
}
if (eSub.Type == ":goal")
ReadGoal(p, d, eSub.SubExpressions[0]);
if (eSub.Type == ":metric")
ReadMetric(p, d, eSub);
}
//p.AddReasoningActions(); not needed as long as we use FF to do the planning for us
d.ComputeAlwaysKnown();
p.CompleteKnownState();
List<Predicate> lConstantPredicates = new List<Predicate>();
foreach (Predicate pKnown in p.Known)
{
if (d.AlwaysConstant(pKnown))
lConstantPredicates.Add(pKnown);
}
//d.RemoveUniversalQuantifiers(lConstantPredicates);
//p.RemoveUniversalQuantifiers();
return p;
}
示例4: 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;
}
示例5: GetPreconditionsNoState
/*
*
public CompoundFormula GetPreconditionsNoState(Dictionary<string, List<Predicate>> dTags, Domain d, List<string> lIncludedTags, List<string> lExcludedTags)
{
CompoundFormula cfPreconditions = 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)))
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());
}
}
foreach (string sTag in lIncludedTags)
{
//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]));
cfPreconditions.AddOperand(pKNotT.Negate());
}
}
foreach (string sTag in lExcludedTags)
{
Predicate pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag),new Constant(Domain.TAG, lIncludedTags[0]));
cfPreconditions.AddOperand(pNotTag);
}
//if (cfPreconditions.Operands.Count > 0)
return cfPreconditions;
//return null;
}
*/
public CompoundFormula GetKnowWhetherPreconditions(Dictionary<string, List<Predicate>> dTags, Domain d, string sActionTag)
{
Argument pTag = new Constant(Domain.TAG, sActionTag);
CompoundFormula cfKWPreconditions = new CompoundFormula("and");
HashSet<Predicate> lKnowPreconditions = new HashSet<Predicate>();
CompoundFormula cfOr = null;
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(p);
}
foreach (string sTag in dTags.Keys)
{
Predicate pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag), (Constant)pTag);
cfOr = new CompoundFormula("or");
CompoundFormula cfAnd = new CompoundFormula("and");
cfAnd.AddOperand(pNotTag.Negate());
foreach (Predicate p in lKnowPreconditions)
{
//if (d.AlwaysKnown(p) && (d.AlwaysConstant(p)))
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)
cfOr.AddOperand(cfAnd);
if (sTag == sActionTag)
{
cfKWPreconditions.SimpleAddOperand(cfAnd);
}
else
{
cfOr.AddOperand(pNotTag);
//.........这里部分代码省略.........
示例6: CreateTaggedKnowledgeWhetherLossCondition
private CompoundFormula CreateTaggedKnowledgeWhetherLossCondition(CompoundFormula cfCondition, Domain d, IEnumerable<string> lTags, string sActionTag)
{
HashSet<Predicate> lPreconditions = new HashSet<Predicate>();
HashSet<Predicate> lEffects = new HashSet<Predicate>();
cfCondition.Operands[0].GetAllPredicates(lPreconditions);
cfCondition.Operands[1].GetAllPredicates(lEffects);
bool bContainsOption = false;
CompoundFormula cfAllConditions = new CompoundFormula("and");
Predicate pNotTag = null;
foreach (Predicate p in lPreconditions)
{
if (p.Name == Domain.OPTION_PREDICATE)
bContainsOption = true;
}
foreach (string sForgetTag in lTags)
{
CompoundFormula cfEffects = new CompoundFormula("and");
foreach (Predicate p in lEffects)
{
if (p.Name != Domain.OPTION_PREDICATE)
{
Predicate pKEffect = p.GenerateKnowGiven(sForgetTag, true);
cfEffects.AddOperand(pKEffect.Negate());
}
}
if (bContainsOption)
{
CompoundFormula cfWhen = new CompoundFormula("when");
CompoundFormula cfPreconditions = new CompoundFormula("and");
if (sForgetTag != sActionTag)
{
pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sForgetTag),new Constant(Domain.TAG, sActionTag));
cfPreconditions.AddOperand(pNotTag.Negate());
cfWhen.AddOperand(cfPreconditions);
cfWhen.AddOperand(cfEffects);
cfAllConditions.SimpleAddOperand(cfWhen);
}
else
{
cfAllConditions.AddOperand(cfEffects);
}
}
else
{
foreach (string sTag in lTags)
{
CompoundFormula cfWhen = new CompoundFormula("when");
CompoundFormula cfPreconditions = new CompoundFormula("and");
if (sForgetTag != sActionTag)
{
pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sForgetTag),new Constant(Domain.TAG, sActionTag));
cfPreconditions.AddOperand(pNotTag.Negate());
}
if (sTag != sActionTag)
{
pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag), new Constant(Domain.TAG, sActionTag));
cfPreconditions.AddOperand(pNotTag.Negate());
}
CompoundFormula cfOr = new CompoundFormula("or");
foreach (Predicate p in lPreconditions)
{
Predicate pKGiven = null, pGiven = null;
if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
{
continue;//there is an underlying assumption here that always known + always constant means that it is also always true
}
else
{
if (!d.AlwaysKnown(p))
{
pKGiven = p.GenerateKnowGiven(sTag, true);
cfOr.AddOperand(pKGiven.Negate());
//pGiven = p.GenerateGiven(sTag);
//cfOr.AddOperand(pGiven.Negate());
}
}
}
if(cfOr.Operands.Count > 0)
{
cfPreconditions.AddOperand(cfOr);
cfWhen.AddOperand(cfPreconditions.Simplify());
cfWhen.AddOperand(cfEffects.Simplify());
cfAllConditions.AddOperand(cfWhen);
}
}
}
}
return cfAllConditions;
}
示例7: 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;
}
示例8: CreateTaggedKnowledgeWhetherGainConditions
//C->L ==> KWC/t->KWL/t
private CompoundFormula CreateTaggedKnowledgeWhetherGainConditions(CompoundFormula cfCondition, Domain d, IEnumerable<string> lTags, string sActionTag)
{
HashSet<Predicate> lPreconditions = new HashSet<Predicate>();
HashSet<Predicate> lEffects = new HashSet<Predicate>();
cfCondition.Operands[0].GetAllPredicates(lPreconditions);
cfCondition.Operands[1].GetAllPredicates(lEffects);
CompoundFormula cfAllConditions = new CompoundFormula("and");
foreach (string sKWTag in lTags)
{
CompoundFormula cfWhen = new CompoundFormula("when");
CompoundFormula cfPreconditions = new CompoundFormula("and");
CompoundFormula cfEffects = new CompoundFormula("and");
if (sKWTag != sActionTag)
{
Predicate pNotKWTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sKWTag),new Constant(Domain.TAG, sActionTag));
cfPreconditions.AddOperand(pNotKWTag.Negate());
}
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 sTag in lTags)
{
CompoundFormula cfAnd = new CompoundFormula("and");
foreach (Predicate p in lPreconditions)
{
Predicate pKGiven = null;
//if (d.AlwaysKnown(p) && d.AlwaysConstant(p))
if (d.AlwaysKnown(p))
{
continue;
}
else
{
/*
if (!d.AlwaysKnown(p))
{
pKGiven = p.GenerateKnowGiven(sTag, true);
cfAnd.AddOperand(pKGiven);
}
* */
pKGiven = p.GenerateGiven(sTag);
cfAnd.AddOperand(pKGiven);
}
}
if (cfAnd.Operands.Count > 0)//if there are no conditions then it is always true, and we don't need to care about whether the tag is consistent or not
{
if (sTag == sActionTag)
{
cfPreconditions.AddOperand(cfAnd);
}
else
{
CompoundFormula cfOr = new CompoundFormula("or");
Predicate pNotTag = Predicate.GenerateKNot(new Constant(Domain.TAG, sTag),new Constant(Domain.TAG, sActionTag));
cfOr.AddOperand(pNotTag);
cfOr.AddOperand(cfAnd);
cfPreconditions.AddOperand(cfOr);
}
}
}
foreach (Predicate p in lEffects)
{
//Predicate pKEffect = p.GenerateKnowGiven(sKWTag, true);
Predicate pKEffect = p.GenerateGiven(sKWTag);
cfEffects.AddOperand(pKEffect);
}
cfWhen.AddOperand(cfPreconditions.Simplify());
cfWhen.AddOperand(cfEffects.Simplify());
cfAllConditions.SimpleAddOperand(cfWhen);
}
return cfAllConditions;
}
示例9: 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;
}
示例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;
}
//.........这里部分代码省略.........