Exemplo n.º 1
0
        public void Add(ICompoundTask parent, Slot slot)
        {
            if (parent == slot)
            {
                throw new Exception("Parent-task and Sub-task can't be the same instance!");
            }

            if (_slots != null)
            {
                if (_slots.ContainsKey(slot.SlotId))
                {
                    throw new Exception("This slot id already exist in the domain definition!");
                }
            }

            parent.AddSubtask(slot);
            slot.Parent = parent;

            if (_slots == null)
            {
                _slots = new Dictionary <int, Slot>();
            }

            _slots.Add(slot.SlotId, slot);
        }
        // ========================================================= HIERARCHY HANDLING

        public void Add(ICompoundTask<StateType> parent, ITask<StateType> subtask)
        {
            if (parent == subtask)
                throw new Exception("Parent-task and Sub-task can't be the same instance!");

            parent.AddSubtask(subtask);
            subtask.Parent = parent;
        }
Exemplo n.º 3
0
        // ========================================================= SET / REMOVE

        public bool Set(ICompoundTask subtask)
        {
            if (Subtask != null)
            {
                return(false);
            }

            Subtask = subtask;
            return(true);
        }
 public SimulationCompoundsSelectionPresenter(ISimulationCompoundsSelectionView view, IBuildingBlockRepository buildingBlockRepository,
                                              IBuildingBlockInSimulationManager buildingBlockInSimulationManager, ICompoundTask compoundTask, IBuildingBlockSelectionDisplayer buildingBlockSelectionDisplayer)
     : base(view)
 {
     _buildingBlockRepository          = buildingBlockRepository;
     _buildingBlockInSimulationManager = buildingBlockInSimulationManager;
     _compoundTask = compoundTask;
     _buildingBlockSelectionDisplayer = buildingBlockSelectionDisplayer;
     _compoundSelectionDTOs           = new NotifyList <CompoundSelectionDTO>();
     _view.BindTo(_compoundSelectionDTOs);
     _compoundSelectionDTOs.CollectionChanged += onCollectionChanged;
 }
Exemplo n.º 5
0
        protected override DecompositionStatus OnDecomposeCompoundTask(IContext ctx, ICompoundTask task, int taskIndex,
                                                                       int[] oldStackDepth, out Queue <ITask> result)
        {
            // We need to record the task index before we decompose the task,
            // so that the traversal record is set up in the right order.
            ctx.MethodTraversalRecord.Add(taskIndex);
            if (ctx.DebugMTR)
            {
                ctx.MTRDebug.Add(task.Name);
            }

            var status = task.Decompose(ctx, 0, out var subPlan);

            // If status is rejected, that means the entire planning procedure should cancel.
            if (status == DecompositionStatus.Rejected)
            {
                result = null;
                return(DecompositionStatus.Rejected);
            }

            // If the decomposition failed
            if (status == DecompositionStatus.Failed)
            {
                // Remove the taskIndex if it failed to decompose.
                ctx.MethodTraversalRecord.RemoveAt(ctx.MethodTraversalRecord.Count - 1);
                if (ctx.DebugMTR)
                {
                    ctx.MTRDebug.RemoveAt(ctx.MTRDebug.Count - 1);
                }
                result = Plan;
                return(DecompositionStatus.Failed);
            }

            while (subPlan.Count > 0)
            {
                Plan.Enqueue(subPlan.Dequeue());
            }

            if (ctx.HasPausedPartialPlan)
            {
                result = Plan;
                return(DecompositionStatus.Partial);
            }

            result = Plan;
            return(DecompositionStatus.Succeeded);
        }
Exemplo n.º 6
0
        protected override DecompositionStatus OnDecomposeCompoundTask(IContext ctx, ICompoundTask task,
                                                                       int taskIndex, int[] oldStackDepth, out Queue <ITask> result)
        {
            var status = task.Decompose(ctx, 0, out var subPlan);

            // If result is null, that means the entire planning procedure should cancel.
            if (status == DecompositionStatus.Rejected)
            {
                Plan.Clear();
                ctx.TrimToStackDepth(oldStackDepth);

                result = null;
                return(DecompositionStatus.Rejected);
            }

            // If the decomposition failed
            if (status == DecompositionStatus.Failed)
            {
                Plan.Clear();
                ctx.TrimToStackDepth(oldStackDepth);
                result = Plan;
                return(DecompositionStatus.Failed);
            }

            while (subPlan.Count > 0)
            {
                Plan.Enqueue(subPlan.Dequeue());
            }

            if (ctx.HasPausedPartialPlan)
            {
                if (taskIndex < Subtasks.Count - 1)
                {
                    ctx.PartialPlanQueue.Enqueue(new PartialPlanEntry()
                    {
                        Task      = this,
                        TaskIndex = taskIndex + 1,
                    });
                }

                result = Plan;
                return(DecompositionStatus.Partial);
            }

            result = Plan;
            return(DecompositionStatus.Succeeded);
        }
Exemplo n.º 7
0
        protected override void Context()
        {
            _compoundTask                     = A.Fake <ICompoundTask>();
            _view                             = A.Fake <ISimulationCompoundsSelectionView>();
            _buildingBlockRepository          = A.Fake <IBuildingBlockRepository>();
            _buildingBlockInSimulationManager = A.Fake <IBuildingBlockInSimulationManager>();
            _buildingBlockSelectionDisplayer  = A.Fake <IBuildingBlockSelectionDisplayer>();


            A.CallTo(() => _buildingBlockRepository.All <Compound>()).Returns(_allCompoundTemplates);
            A.CallTo(() => _view.BindTo(A <NotifyList <CompoundSelectionDTO> > ._))
            .Invokes(x => _compoundDTOList = x.GetArgument <NotifyList <CompoundSelectionDTO> >(0));

            sut = new SimulationCompoundsSelectionPresenter(_view, _buildingBlockRepository, _buildingBlockInSimulationManager, _compoundTask, _buildingBlockSelectionDisplayer);

            sut.Initialize();

            CompoundSelectionDTOFor(_compound1).Selected = true;
        }
Exemplo n.º 8
0
        protected override DecompositionStatus OnDecomposeCompoundTask(IContext ctx, ICompoundTask task, int taskIndex,
                                                                       int[] oldStackDepth, out Queue <ITask> result)
        {
            // We need to record the task index before we decompose the task,
            // so that the traversal record is set up in the right order.
            ctx.MethodTraversalRecord.Add(taskIndex);
            if (ctx.DebugMTR)
            {
                ctx.MTRDebug.Add(task.Name);
            }

            var status = task.Decompose(ctx, 0, out var subPlan);

            // If status is rejected, that means the entire planning procedure should cancel.
            if (status == DecompositionStatus.Rejected)
            {
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Selector.OnDecomposeCompoundTask:{status}: Decomposing {task.Name} was rejected.", ConsoleColor.Red);
                }
                result = null;
                return(DecompositionStatus.Rejected);
            }

            // If the decomposition failed
            if (status == DecompositionStatus.Failed)
            {
                // Remove the taskIndex if it failed to decompose.
                ctx.MethodTraversalRecord.RemoveAt(ctx.MethodTraversalRecord.Count - 1);
                if (ctx.DebugMTR)
                {
                    ctx.MTRDebug.RemoveAt(ctx.MTRDebug.Count - 1);
                }

                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Selector.OnDecomposeCompoundTask:{status}: Decomposing {task.Name} failed.", ConsoleColor.Red);
                }
                result = Plan;
                return(DecompositionStatus.Failed);
            }

            while (subPlan.Count > 0)
            {
                var p = subPlan.Dequeue();
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Selector.OnDecomposeCompoundTask:Decomposing {task.Name}:Pushed {p.Name} to plan!", ConsoleColor.Blue);
                }
                Plan.Enqueue(p);
            }

            if (ctx.HasPausedPartialPlan)
            {
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Selector.OnDecomposeCompoundTask:Return partial plan at index {taskIndex}!", ConsoleColor.DarkBlue);
                }
                result = Plan;
                return(DecompositionStatus.Partial);
            }

            result = Plan;
            var s = result.Count == 0 ? DecompositionStatus.Failed : DecompositionStatus.Succeeded;

            if (ctx.LogDecomposition)
            {
                Log(ctx, $"Selector.OnDecomposeCompoundTask:{s}!", s == DecompositionStatus.Succeeded ? ConsoleColor.Green : ConsoleColor.Red);
            }
            return(s);
        }
Exemplo n.º 9
0
        protected override DecompositionStatus OnDecomposeCompoundTask(IContext ctx, ICompoundTask task,
                                                                       int taskIndex, int[] oldStackDepth, out Queue <ITask> result)
        {
            var status = task.Decompose(ctx, 0, out var subPlan);

            // If result is null, that means the entire planning procedure should cancel.
            if (status == DecompositionStatus.Rejected)
            {
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Sequence.OnDecomposeCompoundTask:{status}: Decomposing {task.Name} was rejected.", ConsoleColor.Red);
                }

                Plan.Clear();
                ctx.TrimToStackDepth(oldStackDepth);

                result = null;
                return(DecompositionStatus.Rejected);
            }

            // If the decomposition failed
            if (status == DecompositionStatus.Failed)
            {
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Sequence.OnDecomposeCompoundTask:{status}: Decomposing {task.Name} failed.", ConsoleColor.Red);
                }

                Plan.Clear();
                ctx.TrimToStackDepth(oldStackDepth);
                result = Plan;
                return(DecompositionStatus.Failed);
            }

            while (subPlan.Count > 0)
            {
                var p = subPlan.Dequeue();
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Sequence.OnDecomposeCompoundTask:Decomposing {task.Name}:Pushed {p.Name} to plan!", ConsoleColor.Blue);
                }
                Plan.Enqueue(p);
            }

            if (ctx.HasPausedPartialPlan)
            {
                if (ctx.LogDecomposition)
                {
                    Log(ctx, $"Sequence.OnDecomposeCompoundTask:Return partial plan at index {taskIndex}!", ConsoleColor.DarkBlue);
                }
                if (taskIndex < Subtasks.Count - 1)
                {
                    ctx.PartialPlanQueue.Enqueue(new PartialPlanEntry()
                    {
                        Task      = this,
                        TaskIndex = taskIndex + 1,
                    });
                }

                result = Plan;
                return(DecompositionStatus.Partial);
            }

            result = Plan;
            if (ctx.LogDecomposition)
            {
                Log(ctx, $"Sequence.OnDecomposeCompoundTask:Succeeded!", ConsoleColor.Green);
            }
            return(DecompositionStatus.Succeeded);
        }
Exemplo n.º 10
0
 public void Clear()
 {
     Subtask = null;
 }
Exemplo n.º 11
0
 protected abstract DecompositionStatus OnDecomposeCompoundTask(IContext ctx, ICompoundTask task, int taskIndex, int[] oldStackDepth, out Queue <ITask> result);