Esempio n. 1
0
        /// <summary>
        /// Checks if the operator effects contain the action cost fluent and extracts it as the operator cost. The default operator cost is 1.
        /// </summary>
        private void ExtractCostFromEffects()
        {
            if (!IdManager.Functions.IsRegistered("total-cost"))
            {
                return;
            }

            IAtom operatorCostAtom = new Atom(IdManager.Functions.GetId("total-cost"));

            foreach (var effect in Effects)
            {
                NumericIncreaseEffect increaseEffect = effect as NumericIncreaseEffect;
                if (increaseEffect != null)
                {
                    if (increaseEffect.FunctionAtom.Equals(operatorCostAtom))
                    {
                        Number costValue = increaseEffect.Value as Number;
                        if (costValue != null)
                        {
                            Cost = (int)costValue.Value;
                        }
                        else
                        {
                            throw new System.NotSupportedException("General numeric fluents are not supported as an operator cost, at the moment.");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Visits the given input data node.
        /// </summary>
        /// <param name="data">Input data node.</param>
        public override void PostVisit(InputData.PDDL.NumericAssignEffect data)
        {
            int          functionNameId = IdManager.Functions.GetId(data.Function.Name, data.Function.Terms.Count);
            List <ITerm> terms          = new List <ITerm>();

            data.Function.Terms.ForEach(term => terms.Add(TermsBuilder.Value.Build(term)));

            NumericExpressionsBuilder numericExpressionsBuilder = new NumericExpressionsBuilder(IdManager);
            INumericExpression        valueExpression           = numericExpressionsBuilder.Build(data.Value);

            IAtom functionAtom = new Atom(functionNameId, terms);

            IEffect newEffect = null;

            switch (data.AssignOperator)
            {
            case InputData.PDDL.Traits.AssignOperator.ASSIGN:
            {
                newEffect = new NumericAssignEffect(functionAtom, valueExpression, IdManager);
                break;
            }

            case InputData.PDDL.Traits.AssignOperator.INCREASE:
            {
                newEffect = new NumericIncreaseEffect(functionAtom, valueExpression, IdManager);
                break;
            }

            case InputData.PDDL.Traits.AssignOperator.DECREASE:
            {
                newEffect = new NumericDecreaseEffect(functionAtom, valueExpression, IdManager);
                break;
            }

            case InputData.PDDL.Traits.AssignOperator.SCALE_UP:
            {
                newEffect = new NumericScaleUpEffect(functionAtom, valueExpression, IdManager);
                break;
            }

            case InputData.PDDL.Traits.AssignOperator.SCALE_DOWN:
            {
                newEffect = new NumericScaleDownEffect(functionAtom, valueExpression, IdManager);
                break;
            }

            default:
            {
                Debug.Assert(false);
                break;
            }
            }

            EffectsStack.Push(newEffect);
        }