private float DecomposeTask(DomainSelector domain, ITask parent, ITask task, IHTNContext context, ref List <PrimitiveTaskSelector> plan, ref int score, int scoreThreshold, out int localCost)
        {
            localCost = 0;
            float single = TaskQualifier.TestPreconditions(task, context);

            if (single <= 0f)
            {
                this.GetFullDecompositionCost(ref localCost);
                return(single);
            }
            return(task.Decompose(domain, parent, context, ref plan, ref score, scoreThreshold, out localCost));
        }
 public float Decompose(DomainSelector domain, ITask parent, IHTNContext context, ref List <PrimitiveTaskSelector> plan, ref int score, int scoreThreshold, out int localCost)
 {
     localCost = 0;
     if (this._task == null)
     {
         this.FindTaskOfQualifier();
     }
     if (this._task == null)
     {
         this._lastScore = -1f;
         return(this._lastScore);
     }
     this._lastScore = this.DecomposeTask(domain, parent, this._task, context, ref plan, ref score, scoreThreshold, out localCost);
     score          += localCost;
     return(this._lastScore);
 }
Esempio n. 3
0
        public float Decompose(DomainSelector domain, ITask parent, IHTNContext context, ref List <PrimitiveTaskSelector> plan, ref int score, int scoreThreshold, out int localCost)
        {
            int num;

            localCost = 0;
            if (parent != null && !this.Parents.Contains(parent))
            {
                this.Parents.Clear();
                this.Parents.Add(parent);
            }
            if (!this._UpdateTasksQualifiers())
            {
                return(0f);
            }
            localCost++;
            for (int i = 0; i < this._taskQualifiers.Count; i++)
            {
                TaskQualifier item = this._taskQualifiers[i];
                if (!item.isDisabled)
                {
                    int num1 = score + localCost;
                    if (num1 >= scoreThreshold)
                    {
                        this.RemovalAtFailedDecomposition(context, ref plan);
                        return(0f);
                    }
                    float single = item.Decompose(domain, this, context, ref plan, ref num1, scoreThreshold, out num);
                    if (this._decomposition == DecompositionType.One && single > 0f)
                    {
                        localCost += num;
                        return(1f);
                    }
                    if (this._decomposition == DecompositionType.All && single <= 0f)
                    {
                        this.RemovalAtFailedDecomposition(context, ref plan);
                        this.GetDecompositionCostFromIndex(ref localCost, i);
                        return(0f);
                    }
                    localCost += num;
                }
            }
            if (this._decomposition == DecompositionType.All)
            {
                return(1f);
            }
            return(0f);
        }
Esempio n. 4
0
        public float Decompose(DomainSelector domain, ITask parent, IHTNContext context, ref List <PrimitiveTaskSelector> plan, ref int score, int scoreThreshold, out int localCost)
        {
            localCost = 0;
            if (this._id == Guid.Empty)
            {
                return(0f);
            }
            if (parent != null && !this.Parents.Contains(parent))
            {
                this.Parents.Clear();
                this.Parents.Add(parent);
            }
            plan.Add(this);
            Stack <IEffect> effects  = Pool.Get <Stack <IEffect> >();
            Stack <IEffect> effects1 = Pool.Get <Stack <IEffect> >();

            for (int i = 0; i < this._effects.Count; i++)
            {
                IEffect item = this._effects[i];
                item.Apply(context, true, false);
                effects.Push(item);
            }
            for (int j = 0; j < this._expectedEffects.Count; j++)
            {
                IEffect effect = this._expectedEffects[j];
                effect.Apply(context, true, true);
                effects1.Push(effect);
            }
            if (effects.Count <= 0)
            {
                Pool.Free <Stack <IEffect> >(ref effects);
            }
            else if (!context.AppliedEffects.ContainsKey(base.id))
            {
                context.AppliedEffects.Add(base.id, effects);
            }
            else
            {
                Stack <IEffect> item1 = context.AppliedEffects[base.id];
                if (item1 != null)
                {
                    Pool.Free <Stack <IEffect> >(ref item1);
                }
                context.AppliedEffects[base.id] = effects;
            }
            if (effects1.Count <= 0)
            {
                Pool.Free <Stack <IEffect> >(ref effects1);
            }
            else if (!context.AppliedExpectedEffects.ContainsKey(base.id))
            {
                context.AppliedExpectedEffects.Add(base.id, effects1);
            }
            else
            {
                Stack <IEffect> item2 = context.AppliedExpectedEffects[base.id];
                if (item2 != null)
                {
                    Pool.Free <Stack <IEffect> >(ref item2);
                }
                context.AppliedExpectedEffects[base.id] = effects1;
            }
            return(1f);
        }