示例#1
0
        public List<HTNTaskSet> AssignAndRefineTaskSet(
            ResourceProfileSet resourceSet,
            HTNState currentHTNState,
            HTNState targetHTNState,
            SpecificationKnowledge specificationKnowledge)
        {
            List<HTNTaskSet> newRefinedHTNTaskSetList = new List<HTNTaskSet>();

            List<string> waitingTaskList = new List<string>();
            foreach (string taskID in this.TaskIDList)
            {
                waitingTaskList.Add(taskID);
            }

            while (waitingTaskList.Count > 0)
            {
                List<string> allocatedResourceIDList = new List<string>();
                List<string> allocatedTaskIDList = new List<string>();
                List<bool> resourceAllocatedIndicator = new List<bool>();

                HTNTaskSet htnTaskSet = new HTNTaskSet();

                for (int i = 0; i < resourceSet.Resources.Count; i++)
                {
                    resourceAllocatedIndicator.Add(true);
                }

                foreach (string taskID in waitingTaskList)
                {
                    for (int i = 0; i < resourceSet.Resources.Count; i++)
                    {
                        ResourceProfile ra = resourceSet.Resources[i];

                        if (resourceAllocatedIndicator[i] && ra.CanExecuteThisTask(taskID))
                        {
                            resourceAllocatedIndicator[i] = false;
                            htnTaskSet.AddTaskID(taskID);
                            htnTaskSet.TaskExecutors.Add(taskID, ra.ID);
                            allocatedTaskIDList.Add(taskID);

                            //  added to prevent the re-added value
                            break;
                        }
                    }
                }

                foreach (string taskID in allocatedTaskIDList)
                {
                    waitingTaskList.Remove(taskID);
                }

                newRefinedHTNTaskSetList.Add(htnTaskSet);
            }
            return newRefinedHTNTaskSetList;
        }
示例#2
0
        public ComplexHTNPlanner()
        {
            InitialState = new HTNState();
            TargetState = new HTNState();
            TaskNetwork = new HTNTaskNetwork();

            StateConstraints = new List<HTNState>();
            TaskSets = new List<HTNTaskSet>();
            AllocationDictionary = new Dictionary<string, string>();
            ResourceProfileSet = new ResourceProfileSet();
        }
示例#3
0
        /// <summary>
        /// Decomposes and schedules the transition between current state and target state.
        /// </summary>
        public List<HTNTaskSet> DecomposeTaskSet(
            ResourceProfileSet resourceProfileSet,
            SpecificationKnowledge specificationKnowledge,
            ComplexHTNPlanner htnPlanner,
            HTNState currentHTNState,
            HTNState targetHTNState)
        {
            List<List<HTNTaskSet>> allNewDecomposedTaskSetList = new List<List<HTNTaskSet>>();
            HTNState currentState = currentHTNState;
            int longestSize = 1;

            // Start to decompose
            foreach (string taskID in TaskIDList)
            {
                // If the task needs to be decomposed, decompose it
                if (!specificationKnowledge.IsTaskAPrimitive(taskID))
                {
                    HTNMethod method = htnPlanner.FindASuitableMethodOrOperator(taskID, currentState);

                    HTNTaskNetwork decomposedTaskNetwork = specificationKnowledge.GetTaskNetwork(method.TaskNetworkID);
                    int constraintsCount = decomposedTaskNetwork.Constraints.Count;

                    Random random = new Random();
                    int selectedConstraint = random.Next(0, constraintsCount);
                    HTNTaskNetworkConstraints htnTaskNetworkConstraints
                        = decomposedTaskNetwork.Constraints.ElementAt(selectedConstraint).Value;

                    List<HTNTaskSet> decomposedTaskSetList = htnTaskNetworkConstraints.HTNTaskConstraints;
                    if (decomposedTaskSetList.Count > longestSize)
                    {
                        longestSize = decomposedTaskSetList.Count;
                    }

                    string resourceID = TaskExecutors[taskID];
                    foreach (HTNTaskSet decomposedHTNTask in decomposedTaskSetList)
                    {
                        foreach (string subTaskID in decomposedHTNTask.TaskIDList)
                        {
                            decomposedHTNTask.TaskExecutors.Add(subTaskID, resourceID);
                        }
                    }

                    allNewDecomposedTaskSetList.Add(decomposedTaskSetList);
                }
                // The task is primitive so does not need to be decomposed further
                else
                {
                    List<HTNTaskSet> decomposedTaskSetList = new List<HTNTaskSet>();
                    HTNTaskSet htnTaskSet = new HTNTaskSet();

                    string resourceID = TaskExecutors[taskID];

                    htnTaskSet.TaskExecutors.Add(taskID, resourceID);
                    htnTaskSet.TaskIDList.Add(taskID);

                    decomposedTaskSetList.Add(htnTaskSet);
                    allNewDecomposedTaskSetList.Add(decomposedTaskSetList);
                }
            }
            // end of decomposing

            // Schedule all tasks into a single list of task sets

            List<HTNTaskSet> mergeredHTNSetList = new List<HTNTaskSet>();
            for (int i = 0; i < longestSize; i++)
            {
                HTNTaskSet newlyMergeredHTNTaskSet = new HTNTaskSet();

                foreach (List<HTNTaskSet> htnTaskSetList in allNewDecomposedTaskSetList)
                {
                    if (htnTaskSetList.Count > i)
                    {
                        foreach (string taskID in htnTaskSetList[i].TaskIDList)
                        {
                            string resourceID = htnTaskSetList[i].TaskExecutors[taskID];

                            newlyMergeredHTNTaskSet.TaskExecutors.Add(taskID, resourceID);
                            newlyMergeredHTNTaskSet.AddTaskID(taskID);

                        }
                    }
                }
                mergeredHTNSetList.Add(newlyMergeredHTNTaskSet);
            }

            return mergeredHTNSetList;
        }
示例#4
0
 public abstract void SetPlannerProperties(
     HTNState initialHTNState,
     HTNState targetHTNState,
     string workitemID,
     SpecificationKnowledge specificationKnowledge,
     ResourceProfileSet resourceProfileSet);
示例#5
0
        public override void SetPlannerProperties(
            HTNState initialHTNState,
            HTNState targetHTNState,
            string workitemID,
            SpecificationKnowledge specificationKnowledge,
            ResourceProfileSet resourceProfileSet)
        {
            ResourceProfileSet = resourceProfileSet;
            SpecificationKnowledge = specificationKnowledge;

            StateConstraints.Clear();
            StateConstraints.Add(initialHTNState);
            StateConstraints.Add(targetHTNState);

            InitialState.StateAtoms.Clear();
            InitialState = new HTNState(initialHTNState);
            TargetState = new HTNState(targetHTNState);

            WorkitemID = workitemID;
        }
示例#6
0
 public override void SetPlannerProperties(HTNState initialHTNState, HTNState targetHTNState, string workitemID, SpecificationKnowledge specificationKnowledge, ResourceProfileSet resourceProfileSet)
 {
     throw new NotImplementedException();
 }