Esempio n. 1
0
        /// <summary>
        /// Sets the initial state of the planning problem.
        /// </summary>
        /// <param name="state">Initial state.</param>
        public virtual void SetInitialState(Planner.IState state)
        {
            InitialState = (IState)state;

            // note: RigidRelations shouldn't be reset according to the new initial state - we assume that the new state
            // is a correct state from this planning problem and such state shouldn't contain any initial rigid relations
        }
Esempio n. 2
0
        /// <summary>
        /// Checks whether the specified state is meeting conditions given by the relative state (i.e. belong to the corresponding class of states).
        /// </summary>
        /// <param name="state">State to be checked.</param>
        /// <returns>True if the state is meeting conditions of the relative state, false otherwise.</returns>
        public bool Evaluate(Planner.IState state)
        {
            IState evaluatedState = (IState)state;

            if (Predicates != null)
            {
                foreach (var predicate in Predicates)
                {
                    if (!evaluatedState.HasPredicate(predicate))
                    {
                        return(false);
                    }
                }
            }

            if (NegatedPredicates != null)
            {
                foreach (var predicate in NegatedPredicates)
                {
                    if (evaluatedState.HasPredicate(predicate))
                    {
                        return(false);
                    }
                }
            }

            if (NumericFunctions != null)
            {
                foreach (var numericFunction in NumericFunctions)
                {
                    if (!evaluatedState.GetNumericFunctionValue(numericFunction.Key).Equals(numericFunction.Value))
                    {
                        return(false);
                    }
                }
            }

            if (ObjectFunctions != null)
            {
                foreach (var objectFunction in ObjectFunctions)
                {
                    if (evaluatedState.GetObjectFunctionValue(objectFunction.Key) != objectFunction.Value)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Checks whether the specified state is meeting conditions given by the relative state (i.e. belong to the corresponding class of states).
        /// </summary>
        /// <param name="state">State to be checked.</param>
        /// <returns>True if the state is meeting conditions of the relative state, false otherwise.</returns>
        public bool Evaluate(Planner.IState state)
        {
            IState evaluatedState = (IState)state;

            for (int variable = 0; variable < Values.Length; ++variable)
            {
                int value = Values[variable];
                if (value != WildCardValue)
                {
                    if (!evaluatedState.HasValue(variable, value))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the calculated heuristic value for the specified state.
        /// </summary>
        /// <param name="generalState">State.</param>
        /// <returns>Heuristic value for the state.</returns>
        public double GetValue(Planner.IState generalState)
        {
            IState state  = (IState)generalState;
            double result = 0;

            foreach (var pattern in this)
            {
                double distance = pattern.GetDistance(state);
                if (distance.Equals(PatternValuesDistances.MaxDistance))
                {
                    return(PatternValuesDistances.MaxDistance);
                }

                result += distance;
            }

            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Gets a collection of all possible successors (forward transitions) from the specified state. Lazy generated via yield return.
 /// </summary>
 /// <param name="state">Original state.</param>
 /// <returns>Lazy generated collection of successors.</returns>
 public IEnumerable <ISuccessor> GetSuccessors(Planner.IState state)
 {
     return(TransitionsGenerator.Value.GetSuccessors((IState)state));
 }
Esempio n. 6
0
 /// <summary>
 /// Enumeration method getting a list with a limited number of possible successors (forward transitions) from the specified state. The
 /// next call of this method returns new successors, until all of them are returned - then an empty collection is returned to signalize
 /// the end of enumeration. The next call starts the enumeration again from the beginning. The returned collection is lazy evaluated.
 /// </summary>
 /// <param name="state">Original state.</param>
 /// <param name="numberOfSuccessors">Number of successors to be returned.</param>
 /// <returns>Lazy generated collection of successors.</returns>
 public IEnumerable <ISuccessor> GetNextSuccessors(Planner.IState state, int numberOfSuccessors)
 {
     return(TransitionsGenerator.Value.GetNextSuccessors((IState)state, numberOfSuccessors));
 }
Esempio n. 7
0
 /// <summary>
 /// Checks whether the specified state is meeting goal conditions of the planning problem.
 /// </summary>
 /// <param name="state">A state to be checked.</param>
 /// <returns>True if the given state is a goal state of the problem, false otherwise.</returns>
 public bool IsGoalState(Planner.IState state)
 {
     return(GoalConditions.Evaluate((IState)state));
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the number of not accomplished goals for the specified state (forward search).
 /// </summary>
 /// <param name="state">State to be evaluated.</param>
 /// <returns>Number of not accomplished goals.</returns>
 public int GetNotAccomplishedGoalsCount(Planner.IState state)
 {
     return(GoalConditions.GetNotAccomplishedConstraintsCount((IState)state));
 }
Esempio n. 9
0
 /// <summary>
 /// Creates the state layer for the FF evaluation from the specified state.
 /// </summary>
 /// <param name="state">State.</param>
 /// <returns>New state layer.</returns>
 protected override IStateLayer CreateFFStateLayer(Planner.IState state)
 {
     return(new StateLayer((RelaxedState)state, false));
 }
Esempio n. 10
0
 /// <summary>
 /// Checks whether the operator is applicable to the given state.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <returns>True if the operator is applicable to the given state, false otherwise.</returns>
 public bool IsApplicable(Planner.IState state)
 {
     return(LiftedOperator.IsApplicable((IState)state, Substitution));
 }
Esempio n. 11
0
 /// <summary>
 /// Evaluates the conditions with the given reference state.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <returns>True if all conditions are met in the given state, false otherwise.</returns>
 public bool Evaluate(Planner.IState state)
 {
     return(Evaluate((IState)state));
 }
Esempio n. 12
0
        /// <summary>
        /// Creates the goal action node for the FF evaluation, from the specified goal conditions and the previous state layer.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        /// <param name="state">Previous state layer.</param>
        /// <returns>New action node.</returns>
        protected override ActionNode CreateFFGoalActionNode(Planner.IConditions conditions, Planner.IState state)
        {
            var precondAtoms = ((Conditions)conditions).GetSatisfyingAtoms(new Substitution(), (IState)state);

            return(new ActionNode(precondAtoms.ConvertAll(x => (IProposition) new Proposition(x))));
        }
Esempio n. 13
0
 /// <summary>
 /// Applies the operator to the given state. The result is a new state - successor.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <param name="directlyModify">Should the input state be directly modified? (otherwise a new node is created)</param>
 /// <returns>Successor state to the given state.</returns>
 public Planner.IState Apply(Planner.IState state, bool directlyModify = false)
 {
     return(Effects.Apply((IState)state, directlyModify));
 }
Esempio n. 14
0
 /// <summary>
 /// Evaluates the conditions with the given reference state.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <returns>True if all conditions are met in the given state, false otherwise.</returns>
 public bool Evaluate(Planner.IState state)
 {
     return(false);
 }
Esempio n. 15
0
 /// <summary>
 /// Checks whether the operator is applicable to the given state.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <returns>True if the operator is applicable to the given state, false otherwise.</returns>
 public bool IsApplicable(Planner.IState state)
 {
     return(Preconditions.Evaluate((IState)state) && MutexChecker.Value.CheckSuccessorCompatibility((IState)state, this));
 }
Esempio n. 16
0
        /// <summary>
        /// Creates the goal action node for the FF evaluation, from the specified goal conditions and the previous state layer.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        /// <param name="state">Previous state layer.</param>
        /// <returns>New action node.</returns>
        protected override ActionNode CreateFFGoalActionNode(Planner.IConditions conditions, Planner.IState state)
        {
            Conditions cond = (Conditions)conditions;

            List <IProposition> predecessors = new List <IProposition>();

            foreach (var assignment in cond)
            {
                predecessors.Add(new Proposition(assignment));
            }

            return(new ActionNode(predecessors));
        }
Esempio n. 17
0
        /// <summary>
        /// Creates the action node for the FF evaluation, from the specified operator and the previous state layer.
        /// </summary>
        /// <param name="appliedOperator">Applied operator.</param>
        /// <param name="state">Previous state layer.</param>
        /// <returns>New action node.</returns>
        protected override ActionNode CreateFFActionNode(Planner.IOperator appliedOperator, Planner.IState state)
        {
            Operator oper = (Operator)appliedOperator;

            List <IProposition> predecessors = new List <IProposition>();

            foreach (var assignment in oper.Preconditions)
            {
                predecessors.Add(new Proposition(assignment));
            }

            List <IProposition> successors = new List <IProposition>();

            foreach (var effect in oper.Effects)
            {
                if (effect.IsApplicable((IState)state))
                {
                    successors.Add(new Proposition(effect.GetAssignment()));
                }
            }

            return(new ActionNode(oper, predecessors, successors));
        }
Esempio n. 18
0
 /// <summary>
 /// Gets a random successor (forward transition) from the specified state.
 /// </summary>
 /// <param name="state">Original state.</param>
 /// <returns>Random successor from the given state. Null if no valid successor found.</returns>
 public ISuccessor GetRandomSuccessor(Planner.IState state)
 {
     return(TransitionsGenerator.Value.GetRandomSuccessor((IState)state));
 }
Esempio n. 19
0
        /// <summary>
        /// Creates the action node for the FF evaluation, from the specified operator and the previous state layer.
        /// </summary>
        /// <param name="appliedOperator">Applied operator.</param>
        /// <param name="state">Previous state layer.</param>
        /// <returns>New action node.</returns>
        protected override ActionNode CreateFFActionNode(Planner.IOperator appliedOperator, Planner.IState state)
        {
            Operator oper          = (Operator)appliedOperator;
            var      preconditions = oper.GetEffectivePreconditions((IState)state);
            var      effects       = oper.GetEffectiveEffects();

            return(new ActionNode(oper, preconditions.ConvertAll(x => (IProposition) new Proposition(x)), effects.ConvertAll(x => (IProposition) new Proposition(x))));
        }
Esempio n. 20
0
 /// <summary>
 /// Gets a collection of all explicitly enumerated predecessor states (created by relevant backwards applications) from the specified state. Lazy generated via yield return.
 /// </summary>
 /// <param name="state">Original state.</param>
 /// <returns>Lazy generated collection of all predecessor states.</returns>
 public IEnumerable <Planner.IState> GetPredecessorStates(Planner.IState state)
 {
     return(TransitionsGenerator.Value.GetPredecessorStates((IState)state));
 }
Esempio n. 21
0
 /// <summary>
 /// Checks whether the specified state is meeting goal conditions of the planning problem.
 /// </summary>
 /// <param name="state">A state to be checked.</param>
 /// <returns>True if the given state is a goal state of the problem, false otherwise.</returns>
 public bool IsGoalState(Planner.IState state)
 {
     return(GetGoalConditions().Evaluate((IState)state) && MutexChecker.Value.CheckState((IState)state));
 }
Esempio n. 22
0
 /// <summary>
 /// Sets the initial state of the planning problem.
 /// </summary>
 /// <param name="state">State.</param>
 public override void SetInitialState(Planner.IState state)
 {
     InitialState = new RelaxedState((State)state);
 }
Esempio n. 23
0
 /// <summary>
 /// Applies the operator to the given state. The result is a new state - successor.
 /// </summary>
 /// <param name="state">Reference state.</param>
 /// <param name="directlyModify">Should the input state be directly modified? (otherwise a new node is created)</param>
 /// <returns>Successor state to the given state.</returns>
 public Planner.IState Apply(Planner.IState state, bool directlyModify = false)
 {
     return(LiftedOperator.Apply((IState)state, Substitution, directlyModify));
 }
Esempio n. 24
0
 /// <summary>
 /// Sets the initial state of the planning problem.
 /// </summary>
 /// <param name="state">Initial state.</param>
 public virtual void SetInitialState(Planner.IState state)
 {
     InitialState = (IState)state;
     AxiomRules.SetInitialValues(Variables, InitialState);
 }
Esempio n. 25
0
 /// <summary>
 /// Creates the labeled state layer for the forward cost evaluation, from the specified state.
 /// </summary>
 /// <param name="state">State.</param>
 /// <returns>New state layer.</returns>
 protected override IStateLayer CreateLabeledStateLayer(Planner.IState state)
 {
     return(new StateLayer((IState)state));
 }