/// <summary> /// Applies backwards the relevant operator effects and operator preconditions to the given target conditions. /// </summary> /// <param name="conditions">Target conditions to be modified.</param> /// <param name="operatorSubstitution">Variables substitution.</param> /// <returns>Preceding conditions.</returns> public IConditions ApplyBackwards(IConditions conditions, ISubstitution operatorSubstitution) { ConditionsCNF expression = (ConditionsCNF)conditions?.GetCNF(); if (expression == null) { return(null); } OperatorSubstitution = operatorSubstitution; Effects.GroundEffectsByCurrentOperatorSubstitution(GroundingManager, operatorSubstitution); if (expression.Parameters != null) { EffectsRelevanceConditionsEvaluator evaluator = new EffectsRelevanceConditionsEvaluator(Effects, GroundingManager); List <ConditionsCNF> subResults = new List <ConditionsCNF>(); IEnumerable <ISubstitution> expressionSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters); expression.Parameters = null; foreach (var expressionSubstitution in expressionSubstitutions) { // do backward apply only when the effects are relevant to the current grounding of the expression if (evaluator.Evaluate(expression, operatorSubstitution, expressionSubstitution)) { subResults.Add(ApplyBackwardsImpl(expression, expressionSubstitution)); } } return(ConstructCNFFromDisjunction(subResults)); } return(ApplyBackwardsImpl(expression, new Substitution())); }
/// <summary> /// Gets a list of atoms used in the specified conditions. /// </summary> /// <param name="conditions">Conditions to be evaluated.</param> /// <returns>Collection of used atoms.</returns> public HashSet <IAtom> Collect(IConditions conditions) { ConditionsCNF conditionsCNF = (ConditionsCNF)conditions.GetCNF(); Atoms = new HashSet <IAtom>(); conditionsCNF.Accept(this); return(Atoms); }
/// <summary> /// Gets a list of atoms from the specified state that are necessary to make these conditions true. /// </summary> /// <param name="conditions">Conditions to evaluate.</param> /// <param name="substitution">Variable substitution.</param> /// <param name="predecessorState">Preceding state.</param> /// <returns>List of satisfying atoms.</returns> public List <IAtom> Evaluate(IConditions conditions, ISubstitution substitution, IState predecessorState) { ConditionsCNF conditionsCNF = (ConditionsCNF)conditions.GetCNF(); Atoms = new List <IAtom>(); Substitution = substitution; ReferenceState = predecessorState; conditionsCNF.Accept(this); return(Atoms); }
/// <summary> /// Evaluates whether the operator effects are relevant for the specified conditions. /// </summary> /// <param name="conditions">Conditions expression.</param> /// <param name="operatorSubstitution">Variables substitution of the operator.</param> /// <param name="expressionSubstitution">Variables substitution of the expression.</param> /// <param name="relevantConditionalEffects">Output indices of relevant conditional effects (can be null).</param> /// <returns>Tuple of two values, where the first is true when the positive relevance condition (inclusion) is satisfied, while the second is /// true when the negative condition (exclusion) is not violated. False otherwise.</returns> public Tuple <bool, bool> EvaluateWithExtendedResult(IConditions conditions, ISubstitution operatorSubstitution, ISubstitution expressionSubstitution, IList <int> relevantConditionalEffects = null) { ConditionsCNF expression = (ConditionsCNF)conditions?.GetCNF(); if (expression == null) { return(Tuple.Create(false, false)); } Effects.GroundEffectsByCurrentOperatorSubstitution(GroundingManager, operatorSubstitution); OperatorSubstitution = operatorSubstitution; ExpressionSubstitution = expressionSubstitution; var primitivesResult = ProcessPrimitiveEffects(expression); if (!primitivesResult.Item2) { return(primitivesResult); } var forallResult = ProcessForallEffects(expression); if (!forallResult.Item2) { return(forallResult); } var whenResult = ProcessWhenEffects(expression, relevantConditionalEffects); if (!whenResult.Item2) { return(whenResult); } return(Tuple.Create((primitivesResult.Item1 || forallResult.Item1 || whenResult.Item1), true)); }
/// <summary> /// Generates all possible PDDL relative states meeting conditions specified by the given conditions. Lazy generated via yield return. /// </summary> /// <param name="conditions">Reference conditions.</param> /// <param name="problem">Planning problem.</param> /// <returns>All possible PDDL relative states meeting the conditions.</returns> public static IEnumerable <IRelativeState> EnumerateRelativeStates(IConditions conditions, Problem problem) { return(EnumerateRelativeStatesByCNF(0, new List <IConjunctCNF>((ConditionsCNF)conditions.GetCNF()), new RelativeState(problem.IdManager))); }
/// <summary> /// Gets a list of atoms from the specified state that are necessary to make these conditions true. /// </summary> /// <param name="conditions">Conditions to evaluate.</param> /// <param name="substitution">Variable substitution.</param> /// <param name="predecessorState">Preceding state.</param> /// <returns>List of satisfying atoms.</returns> public List <IAtom> GetSatisfyingAtoms(IConditions conditions, ISubstitution substitution, IState predecessorState) { return(SatisfyingAtomsEvaluator.Value.Evaluate(conditions.GetCNF(), substitution, predecessorState)); }