Exemple #1
0
 /// <summary>
 /// Constructs an empty conditions object.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 /// <param name="parameters">Parameters of the lifted arguments (null if fully grounded).</param>
 public Conditions(EvaluationManager evaluationManager, Parameters parameters = null)
 {
     EvaluationManager             = evaluationManager;
     ConditionsCNFBuilder          = new Lazy <ConditionsCNFBuilder>(() => new ConditionsCNFBuilder(evaluationManager));
     ConditionsParametersCollector = new Lazy <ConditionsParametersCollector>(() => new ConditionsParametersCollector());
     Parameters = parameters;
 }
 /// <summary>
 /// Constructs the effects backwards applier.
 /// </summary>
 /// <param name="operatorPreconditions">Corresponding operator preconditions.</param>
 /// <param name="operatorEffects">Corresponding operator effects.</param>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public EffectsBackwardsRelativeStateApplier(Conditions operatorPreconditions, List <IEffect> operatorEffects, EvaluationManager evaluationManager)
 {
     OperatorPreconditions = (operatorPreconditions != null && operatorPreconditions.Count > 0) ? operatorPreconditions : null;
     EvaluationManager     = evaluationManager;
     GroundingManager      = evaluationManager.GroundingManager;
     Effects.CollectEffects(operatorEffects);
 }
Exemple #3
0
 /// <summary>
 /// Constructs an empty conditions object.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 /// <param name="conditionsCNFBuilder">CNF builder.</param>
 /// <param name="conditionsParametersCollector">Conditions parameters collector.</param>
 /// <param name="parameters">Parameters of the lifted arguments (null if fully grounded).</param>
 protected Conditions(EvaluationManager evaluationManager, Lazy <ConditionsCNFBuilder> conditionsCNFBuilder, Lazy <ConditionsParametersCollector> conditionsParametersCollector, Parameters parameters = null)
 {
     EvaluationManager             = evaluationManager;
     ConditionsCNFBuilder          = conditionsCNFBuilder;
     ConditionsParametersCollector = conditionsParametersCollector;
     Parameters = parameters;
 }
Exemple #4
0
 /// <summary>
 /// Constructs the effects backwards applier.
 /// </summary>
 /// <param name="operatorPreconditions">Corresponding operator preconditions.</param>
 /// <param name="operatorEffects">Corresponding operator effects.</param>
 /// <param name="evaluationManager">Evaluation manager.</param>
 /// <param name="liftedApplication">Is the backward application lifted?</param>
 public EffectsBackwardsConditionsApplier(Conditions operatorPreconditions, List <IEffect> operatorEffects, EvaluationManager evaluationManager, bool liftedApplication = false)
 {
     OperatorPreconditions = (operatorPreconditions != null && operatorPreconditions.Count > 0) ? operatorPreconditions : null;
     GroundingManager      = evaluationManager.GroundingManager;
     EvaluationManager     = evaluationManager;
     IsApplicationLifted   = liftedApplication;
     Effects.CollectEffects(operatorEffects);
 }
Exemple #5
0
 /// <summary>
 /// Visits and handles the effect.
 /// </summary>
 /// <param name="effect">Effect.</param>
 public void Visit(WhenEffect effect)
 {
     if (EvaluationManager.Evaluate(effect.Expression, Substitution, State))
     {
         foreach (var localEffect in effect.Effects)
         {
             localEffect.Accept(this);
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Constructs the object from the input data.
        /// </summary>
        /// <param name="action">PDDL action definition.</param>
        /// <param name="idManager">ID manager.</param>
        /// <param name="evaluationManager">Evaluation manager.</param>
        public LiftedOperator(InputData.PDDL.Action action, IdManager idManager, EvaluationManager evaluationManager)
        {
            idManager.Variables.RegisterLocalParameters(action.Parameters);

            Name          = action.Name;
            Parameters    = new Parameters(action.Parameters, idManager);
            Preconditions = new Conditions(action.Preconditions, Parameters, idManager, evaluationManager);
            Effects       = new Effects(action.Effects, Preconditions, idManager, evaluationManager);
            IdManager     = idManager;

            ExtractCostFromEffects();

            idManager.Variables.UnregisterLocalParameters(action.Parameters);
        }
Exemple #7
0
        /// <summary>
        /// Constructs the PDDL planning problem from the input data.
        /// </summary>
        /// <param name="inputData">Input data.</param>
        public Problem(InputData.PDDLInputData inputData)
        {
            DomainName        = inputData.Domain.Name;
            ProblemName       = inputData.Problem.Name;
            OriginalInputData = inputData;

            IdManager         = new IdManager(inputData);
            EvaluationManager = new EvaluationManager(new GroundingManager(inputData, IdManager));

            Operators            = new LiftedOperators(inputData.Domain.Actions, IdManager, EvaluationManager);
            InitialState         = new State(inputData.Problem.Init, IdManager);
            GoalConditions       = new Conditions(inputData.Problem.Goal, null, IdManager, EvaluationManager);
            RigidRelations       = new RigidRelations(InitialState, Operators);
            TransitionsGenerator = new Lazy <TransitionsGenerator>(() => new TransitionsGenerator(this));

            EvaluationManager.SetRigidRelations(RigidRelations);
        }
        /// <summary>
        /// Removes rigid relations from the specified conditions.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        /// <returns>Conditions without rigid relations.</returns>
        private Conditions ClearRigidRelations(Conditions conditions)
        {
            Conditions newConditions = conditions.CloneEmpty();

            foreach (var expression in conditions)
            {
                PredicateExpression predicate = expression as PredicateExpression;
                if (predicate != null)
                {
                    if (EvaluationManager.IsPredicateRigidRelation(predicate.PredicateAtom))
                    {
                        continue;
                    }
                }
                newConditions.Add(expression);
            }

            return(newConditions);
        }
Exemple #9
0
 /// <summary>
 /// Gets a list of atoms from the specified state that are necessary to make these conditions true.
 /// </summary>
 /// <param name="substitution">Variable substitution.</param>
 /// <param name="predecessorState">Preceding state.</param>
 /// <returns>List of satisfying atoms.</returns>
 public List <IAtom> GetSatisfyingAtoms(ISubstitution substitution, IState predecessorState)
 {
     return(EvaluationManager.GetSatisfyingAtoms(this, substitution, predecessorState));
 }
Exemple #10
0
 /// <summary>
 /// Computes the operator label in the relaxed planning graph.
 /// </summary>
 /// <param name="substitution">Variable substitution.</param>
 /// <param name="stateLabels">Atom labels from the predecessor layer in the graph.</param>
 /// <param name="evaluationStrategy">Evaluation strategy of the planning graph.</param>
 /// <returns>Computed operator label in the relaxed planning graph.</returns>
 public double EvaluateOperatorPlanningGraphLabel(ISubstitution substitution, IStateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy)
 {
     return(EvaluationManager.EvaluateOperatorPlanningGraphLabel(this, substitution, (StateLabels)stateLabels, evaluationStrategy));
 }
 /// <summary>
 /// Creates the expression CNF builder.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public ConditionsCNFBuilder(EvaluationManager evaluationManager)
 {
     ExpressionToCNFTransformer = new ExpressionToCNFTransformer(evaluationManager);
     EvaluationManager          = evaluationManager;
 }
 /// <summary>
 /// Constructs an empty CNF expression.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 /// <param name="parameters">Condition parameters.</param>
 public ConditionsCNF(EvaluationManager evaluationManager, Parameters parameters)
 {
     EvaluationManager = evaluationManager;
     Parameters        = parameters;
 }
Exemple #13
0
        /// <summary>
        /// Constructs the object from the input data.
        /// </summary>
        /// <param name="inputData">Input data of the planning problem.</param>
        /// <param name="parameters">Parameters of the lifted arguments (null if fully grounded).</param>
        /// <param name="idManager">ID manager.</param>
        /// <param name="evaluationManager">Evaluation manager.</param>
        public Conditions(List <InputData.PDDL.Expression> inputData, Parameters parameters, IdManager idManager, EvaluationManager evaluationManager) : this(evaluationManager)
        {
            ExpressionsBuilder expressionsBuilder = new ExpressionsBuilder(idManager);
            inputData.ForEach(inputExpression => Add(expressionsBuilder.Build(inputExpression)));

            if (parameters != null)
            {
                Parameters = DetermineUsedParameters(parameters);
            }
        }
Exemple #14
0
        /// <summary>
        /// Constructs the object from the input data.
        /// </summary>
        /// <param name="inputData">Operator effects input data.</param>
        /// <param name="operatorPreconditions">Operator preconditions.</param>
        /// <param name="idManager">ID manager.</param>
        /// <param name="evaluationManager">Evaluation manager.</param>
        public Effects(InputData.PDDL.Effects inputData, Conditions operatorPreconditions, IdManager idManager, EvaluationManager evaluationManager)
        {
            EffectsBuilder effectsBuilder = new EffectsBuilder(idManager);

            inputData.ForEach(inputEffect => Add(effectsBuilder.Build(inputEffect)));

            EffectsApplier = new Lazy <EffectsApplier>(() => new EffectsApplier(evaluationManager));
            EffectsRelevanceConditionsEvaluator    = new Lazy <EffectsRelevanceConditionsEvaluator>(() => new EffectsRelevanceConditionsEvaluator(this, evaluationManager.GroundingManager));
            EffectsRelevanceRelativeStateEvaluator = new Lazy <EffectsRelevanceRelativeStateEvaluator>(() => new EffectsRelevanceRelativeStateEvaluator(this, evaluationManager.GroundingManager));
            EffectsBackwardsConditionsApplier      = new Lazy <EffectsBackwardsConditionsApplier>(() => new EffectsBackwardsConditionsApplier(operatorPreconditions, this, evaluationManager));
            EffectsBackwardsRelativeStateApplier   = new Lazy <EffectsBackwardsRelativeStateApplier>(() => new EffectsBackwardsRelativeStateApplier(operatorPreconditions, this, evaluationManager));
            EffectsResultAtomsCollector            = new Lazy <EffectsResultAtomsCollector>(() => new EffectsResultAtomsCollector(this, evaluationManager.GroundingManager));
        }
 /// <summary>
 /// Constructs the object from the input data.
 /// </summary>
 /// <param name="actions">PDDL actions definition.</param>
 /// <param name="idManager">ID manager.</param>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public LiftedOperators(InputData.PDDL.Actions actions, IdManager idManager, EvaluationManager evaluationManager)
 {
     actions.ForEach(action => Add(new LiftedOperator(action, idManager, evaluationManager)));
 }
 /// <summary>
 /// Creates the expression CNF transformer.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public ExpressionToCNFTransformer(EvaluationManager evaluationManager)
 {
     ExpressionToNNFTransformer = new ExpressionToNNFTransformer(evaluationManager);
 }
Exemple #17
0
 /// <summary>
 /// Constructs the object from a single grounded expression.
 /// </summary>
 /// <param name="expression">Expression.</param>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public Conditions(IExpression expression, EvaluationManager evaluationManager) : this(evaluationManager)
 {
     Add(expression);
 }
Exemple #18
0
 /// <summary>
 /// Evaluates the conditions with the given reference state and variable substitution.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <param name="substitution">Substitution.</param>
 /// <returns>True if all conditions are met in the given state, false otherwise.</returns>
 public bool Evaluate(IState state, ISubstitution substitution = null)
 {
     return(EvaluationManager.Evaluate(this, substitution, state));
 }
 /// <summary>
 /// Creates the expression NNF transformer.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public ExpressionToNNFTransformer(EvaluationManager evaluationManager)
 {
     GroundingManager = evaluationManager.GroundingManager;
 }
Exemple #20
0
 /// <summary>
 /// Evaluates whether the conditions are in compliance with the rigid relations of the planning problem. Ignores non-rigid relations.
 /// </summary>
 /// <param name="substitution">Substitution.</param>
 /// <returns>True if the conditions are in compliance with the rigid relations, false otherwise.</returns>
 public bool EvaluateRigidRelationsCompliance(ISubstitution substitution)
 {
     return(EvaluationManager.EvaluateRigidRelationsCompliance(this, substitution));
 }
 /// <summary>
 /// Constructs the CNF expression from the given conjuncts.
 /// </summary>
 /// <param name="conjuncts">Conjuncts.</param>
 /// <param name="evaluationManager">Evaluation manager.</param>
 /// <param name="parameters">Condition parameters.</param>
 public ConditionsCNF(HashSet <IConjunctCNF> conjuncts, EvaluationManager evaluationManager, Parameters parameters) : base(conjuncts)
 {
     EvaluationManager = evaluationManager;
     Parameters        = parameters;
 }
Exemple #22
0
 /// <summary>
 /// Gets the number of not accomplished condition constraints for the specified state.
 /// </summary>
 /// <param name="state">State to be evaluated.</param>
 /// <returns>Number of not accomplished condition constraints.</returns>
 public int GetNotAccomplishedConstraintsCount(IState state)
 {
     return(EvaluationManager.GetNotAccomplishedConstraintsCount(this, state));
 }
Exemple #23
0
 /// <summary>
 /// Constructs the effects applier.
 /// </summary>
 /// <param name="evaluationManager">Evaluation manager.</param>
 public EffectsApplier(EvaluationManager evaluationManager)
 {
     GroundingManager  = evaluationManager.GroundingManager;
     EvaluationManager = evaluationManager;
     NumericEvaluator  = new Lazy <NumericExpressionEvaluator>(() => new NumericExpressionEvaluator(GroundingManager));
 }
Exemple #24
0
 /// <summary>
 /// Returns a collection of all used predicates within this conditions. Can be used for some preprocessing.
 /// </summary>
 /// <returns>Collection of used predicates.</returns>
 public HashSet <IAtom> GetUsedPredicates()
 {
     return(EvaluationManager.CollectUsedPredicates(this));
 }