示例#1
0
        public void Reset()
        {
            PrevStates      = new PredicateList();
            CurrStates      = new PredicateList();
            PrevStates.DC   = mProbDef.DC;
            CurrStates.DC   = mProbDef.DC;
            PrevActionLayer = new HashSet <PlanAction>();
            CurrActionLayer = new HashSet <PlanAction>();

            RemainingActions.Clear();
            RemainingActions.UnionWith(mProbDef.Actions);
            NumLevelsExpanded = 0;
            SearchState       = GraphSearchState.ContinueSearch;

            StateMutexes.Clear();
            PrevStateMutexes.Clear();
            StateMutexes.DC     = mProbDef.DC;
            PrevStateMutexes.DC = mProbDef.DC;

            ActionMutexes.Clear();
            ActionMutexes.DC = mProbDef.DC;

            //NewActions.Clear();
            //NewPreds.Clear();
            //NewPreds.DC = mProbDef.DC;
            U.Clear();
            PU.Clear();
        }
示例#2
0
        void GenerateNextLevelStates()
        {
            PrevStates.Clear();
            PrevStates.Union(CurrStates);

            foreach (PlanAction act in ExecutableActions)
            {
                // do execute the action
                CurrStates = mProbDef.ExecuteAction(CurrStates, act, false, true);
            }

            //NewPreds.Clear();
            //NewPreds.Union(CurrStates);
            //NewPreds.IntersectWith(PrevStates);

            // now for the added predicates compute mutexes between themselves and previous predicates
            // but first, compute action mutexes. these are between executable actions and previousely
            // executed actions.

            //TODO:Think about prevactionlayer
            GenerateActionMutexes();
            GenerateStateMutexes();

            NumLevelsExpanded++;
        }
示例#3
0
 public void Union(PredicateList other)
 {
     if (DC == null)
     {
         DC = other.DC;
     }
     Positive.UnionWith(other.Positive);
     Negative.UnionWith(other.Negative);
 }
示例#4
0
        public void GenerateGraph(PredicateList startState)
        {
            Reset();
            CurrStates.Union(startState);

            CheckGoal();
            while (SearchState == GraphSearchState.ContinueSearch)
            {
                GenerateNextLevelStates();
                CheckGoal();
            }
        }
示例#5
0
        public HashSet <PlanAction> GetExecutableActions(PredicateList state, HashSet <PlanAction> allowedActs)
        {
            HashSet <PlanAction> lst = new HashSet <PlanAction>();

            foreach (PlanAction act in allowedActs)
            {
                if (IsActionExecutable(state, act))
                {
                    lst.Add(act);
                }
            }
            return(lst);
        }
示例#6
0
            private bool CheckPrec(PredicateList p1, PredicateList p2)
            {
                HashSet <int> hs;

                foreach (int p in p1.Positive)
                {
                    if (PosPos.TryGetValue(p, out hs))
                    {
                        if (hs.Overlaps(p2.Positive))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
示例#7
0
        private void GenerateGroundStates(List <ProblemParser.DataContainer.State> statList,
                                          ref PredicateList output)
        {
            foreach (ProblemParser.DataContainer.State stat in statList)
            {
                List <int> objectIds = new List <int>(stat.Objects.Count);
                for (int i = 0; i < stat.Objects.Count; i++)
                {
                    objectIds.Add(mDC.ObjectID[stat.Objects[i]]);
                }
                int predID = stat.Pred.PredID;

                int finalPredID = mDC.GetLinearIndex(predID, objectIds);

                output.Positive.Add(finalPredID);
            }

            output.DC = mDC;
        }
示例#8
0
            public override string ToString()
            {
                if (DC == null)
                {
                    return(base.ToString());
                }

                StringBuilder sb  = new StringBuilder();
                PredicateList tmp = new PredicateList();

                tmp.DC = DC;

                HashSet <Tuple <int, int> > allMutexes = new HashSet <Tuple <int, int> >();

                foreach (int st1 in PosPos.Keys)
                {
                    HashSet <int> mu = PosPos[st1];
                    foreach (int st2 in mu)
                    {
                        Tuple <int, int> norm = new Tuple <int, int>(st1, st2),
                                 rev          = new Tuple <int, int>(st2, st1);

                        if (!(allMutexes.Contains(norm) || allMutexes.Contains(rev)))
                        {
                            allMutexes.Add(norm);
                        }
                    }
                }

                foreach (Tuple <int, int> mutex in allMutexes)
                {
                    sb.Append("{");
                    sb.Append(DC.GetPredicateString(mutex.Item1));
                    sb.Append(", ");
                    sb.Append(DC.GetPredicateString(mutex.Item2));
                    sb.Append("}");
                }

                return(sb.ToString());
            }
示例#9
0
        public PredicateList ExecuteAction(PredicateList currState, PlanAction act, bool remove = true, bool inplace = false)
        {
            Debug.Assert(IsActionExecutable(currState, act));
            PredicateList nextState;

            if (inplace)
            {
                nextState = currState;
            }
            else
            {
                nextState = new PredicateList(currState, mDC);
            }

            if (remove)
            {
                nextState.Positive.ExceptWith(act.Effects.Negative);
                nextState.Negative.ExceptWith(act.Effects.Positive);
            }
            nextState.Positive.UnionWith(act.Effects.Positive);
            nextState.Negative.UnionWith(act.Effects.Negative);

            return(nextState);
        }
示例#10
0
        public HashSet <PlanAction> GetExecutableActions(PredicateList state)
        {
            HashSet <PlanAction> hs = new HashSet <PlanAction>(this.Actions);

            return(GetExecutableActions(state, hs));
        }
示例#11
0
 public bool IsActionExecutable(PredicateList state, int actID)
 {
     return(IsActionExecutable(state, this.Actions[actID]));
 }
示例#12
0
 public bool IsActionExecutable(PredicateList state, PlanAction act)
 {
     return(act.Preconds.Positive.IsSubsetOf(state.Positive));
 }
示例#13
0
 public bool IsSubsetOf(PredicateList other)
 {
     return(Positive.IsSubsetOf(other.Positive) && Negative.IsSubsetOf(other.Negative));
 }
示例#14
0
 public void IntersectWith(PredicateList other)
 {
     Positive.IntersectWith(other.Positive);
     Negative.IntersectWith(other.Negative);
 }
示例#15
0
 public SMutex(PredicateList pred)
 {
 }
示例#16
0
 public bool PreconditionsMutex(PredicateList p1, PredicateList p2)
 {
     //NOTE: Only positive preconditions
     return(CheckPrec(p1, p2) || CheckPrec(p2, p1));
 }
示例#17
0
 public PredicateList(PredicateList other, ProblemParser.DataContainer dc)
 {
     Positive = new System.Collections.Generic.HashSet <int>(other.Positive);
     Negative = new System.Collections.Generic.HashSet <int>(other.Negative);
     DC       = dc;
 }
示例#18
0
 public bool AddPredicate(PredicateList pred)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public bool Overlaps(PredicateList other)
 {
     return(Positive.Overlaps(other.Positive) || Negative.Overlaps(other.Negative));
 }