Esempio n. 1
0
        public Dictionary <int, List <Formula> > ScanEffects(Dictionary <int, List <Formula> > CollectedEffects)
        {
            if (Action != null)
            {
                int     time        = Action.GetTime();
                Formula currEffects = Action.Effects;

                if (!CollectedEffects.ContainsKey(time))
                {
                    CollectedEffects.Add(time, new List <Formula>());
                }

                CollectedEffects[time].Add(currEffects);
            }
            if (SingleChild != null)
            {
                SingleChild.ScanEffects(CollectedEffects);
            }
            if (FalseObservationChild != null)
            {
                FalseObservationChild.ScanEffects(CollectedEffects);
            }
            if (TrueObservationChild != null)
            {
                TrueObservationChild.ScanEffects(CollectedEffects);
            }
            return(CollectedEffects);
        }
        public bool ValidatePlan(PartiallySpecifiedState pssCurrent)
        {
            if (pssCurrent == null)
            {
                return(false);
            }
            if (pssCurrent.IsGoalState())
            {
                return(true);
            }

            if (Action == null)
            {
                return(false);
            }
            Formula fObserved = null;
            PartiallySpecifiedState psTrueState, psFalseState;

            pssCurrent.ApplyOffline(Action, out fObserved, out psTrueState, out psFalseState);
            if (Action.Observe == null)
            {
                return(SingleChild.ValidatePlan(psTrueState));
            }
            bool bTrueOk  = TrueObservationChild.ValidatePlan(psTrueState);
            bool bFalseOk = FalseObservationChild.ValidatePlan(psFalseState);

            return(bTrueOk && bFalseOk);
        }
Esempio n. 3
0
        private List <IMAP.Action> ScanEffectsForConst(Predicate goal)
        {
            List <IMAP.Action> ans = new List <IMAP.Action>();

            if (Action != null)
            {
                string actionName = Action.Name.Split('_')[0];
                if (!actionName.StartsWith("wait-goal"))
                {
                    if (Action.Effects != null)
                    {
                        Formula fEffects = Action.Effects;
                        if (fEffects is CompoundFormula)
                        {
                            CompoundFormula cf = (CompoundFormula)fEffects;
                            foreach (Formula formula in cf.Operands)
                            {
                                if (formula is PredicateFormula)
                                {
                                    PredicateFormula pf = (PredicateFormula)formula;
                                    if (pf.Predicate.ToString() == goal.ToString())
                                    {
                                        ans.Add(Action);
                                    }
                                }
                            }
                        }
                        else if (fEffects is PredicateFormula)
                        {
                            PredicateFormula pf = (PredicateFormula)fEffects;
                            if (pf.Predicate.ToString() == goal.ToString())
                            {
                                ans.Add(Action);
                            }
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                }
            }
            if (SingleChild != null)
            {
                ans.AddRange(SingleChild.ScanEffectsForConst(goal));
            }
            if (FalseObservationChild != null)
            {
                ans.AddRange(FalseObservationChild.ScanEffectsForConst(goal));
            }
            if (TrueObservationChild != null)
            {
                ans.AddRange(TrueObservationChild.ScanEffectsForConst(goal));
            }
            return(ans);
        }
Esempio n. 4
0
 public void GetActionUsed(ref List <Action> usedActions)
 {
     if (Action != null)
     {
         usedActions.Add(Action);
     }
     if (SingleChild != null)
     {
         SingleChild.GetActionUsed(ref usedActions);
     }
     if (FalseObservationChild != null)
     {
         FalseObservationChild.GetActionUsed(ref usedActions);
     }
     if (TrueObservationChild != null)
     {
         TrueObservationChild.GetActionUsed(ref usedActions);
     }
 }
        private string ToString(string sIndent)
        {
            if (Action == null)
            {
                return("");
            }
            string s = sIndent + ID + ") " + Action.Name + "\n";

            if (SingleChild != null)
            {
                s += SingleChild.ToString(sIndent);
            }
            else
            {
                s += FalseObservationChild.ToString(sIndent + "\t");
                s += "\n";
                s += TrueObservationChild.ToString(sIndent + "\t");
            }
            return(s);
        }
Esempio n. 6
0
        private string ToString(string sIndent, HashSet <int> lHistory)
        {
            if (lHistory.Contains(ID))
            {
                return(")connect to " + ID);
            }
            //HashSet<int> lNewHistory = new HashSet<int>(lHistory);
            lHistory.Add(ID);
            if (Action == null)
            {
                return(")goal");
            }
            string s = sIndent + ID + ") " + Action.Name + "\n";

            if (SingleChild != null)
            {
                s += SingleChild.ToString(sIndent, lHistory);
            }
            else
            {
                s += "branching...\n";
                if (FalseObservationChild != null)
                {
                    s += FalseObservationChild.ToString(sIndent + "\t", lHistory);
                }
                else
                {
                    s += "Can't be false";
                }
                s += "\n";
                if (TrueObservationChild != null)
                {
                    s += TrueObservationChild.ToString(sIndent + "\t", lHistory);
                }
                else
                {
                    s += "Can't be true";
                }
            }
            return(s);
        }
Esempio n. 7
0
        public int MaxOperatingTime()
        {
            int maxTime = 0;

            if (Action != null)
            {
                int time = Action.GetTime();
                if (maxTime < time)
                {
                    maxTime = time;
                }
            }
            if (SingleChild != null)
            {
                int time = SingleChild.MaxOperatingTime();
                if (maxTime < time)
                {
                    maxTime = time;
                }
            }
            if (FalseObservationChild != null)
            {
                int time = FalseObservationChild.MaxOperatingTime();
                if (maxTime < time)
                {
                    maxTime = time;
                }
            }
            if (TrueObservationChild != null)
            {
                int time = TrueObservationChild.MaxOperatingTime();
                if (maxTime < time)
                {
                    maxTime = time;
                }
            }
            return(maxTime);
        }
Esempio n. 8
0
 public void ScanLeafDepth(ref List <int> leafsDepth)
 {
     if (SingleChild != null)
     {
         if (SingleChild.Action == null)
         {
             leafsDepth.Add(Action.GetTime());
         }
         else
         {
             SingleChild.ScanLeafDepth(ref leafsDepth);
         }
     }
     if (FalseObservationChild != null)
     {
         if (FalseObservationChild.Action == null)
         {
             leafsDepth.Add(Action.GetTime());
         }
         else
         {
             FalseObservationChild.ScanLeafDepth(ref leafsDepth);
         }
     }
     if (TrueObservationChild != null)
     {
         if (TrueObservationChild.Action == null)
         {
             leafsDepth.Add(Action.GetTime());
         }
         else
         {
             TrueObservationChild.ScanLeafDepth(ref leafsDepth);
         }
     }
 }
Esempio n. 9
0
        private Dictionary <Action, int> CollectJointActionsWithTime(List <string> jointActions)
        {
            Dictionary <Action, int> ans = new Dictionary <Action, int>();

            if (Action != null)
            {
                foreach (var action in jointActions)
                {
                    if (Action.Name.StartsWith(action))
                    {
                        if (!ans.ContainsKey(Action))
                        {
                            ans.Add(Action, Action.GetTime());
                        }
                        if (ans[Action] > Action.GetTime())
                        {
                            ans[Action] = Action.GetTime();
                        }
                    }
                }
            }
            if (SingleChild != null)
            {
                foreach (var item in SingleChild.CollectJointActionsWithTime(jointActions))
                {
                    if (!ans.ContainsKey(item.Key))
                    {
                        ans.Add(item.Key, item.Value);
                    }
                    if (ans[item.Key] > item.Value)
                    {
                        ans[item.Key] = item.Value;
                    }
                }
            }
            if (FalseObservationChild != null)
            {
                foreach (var item in FalseObservationChild.CollectJointActionsWithTime(jointActions))
                {
                    if (!ans.ContainsKey(item.Key))
                    {
                        ans.Add(item.Key, item.Value);
                    }
                    if (ans[item.Key] > item.Value)
                    {
                        ans[item.Key] = item.Value;
                    }
                }
            }
            if (TrueObservationChild != null)
            {
                foreach (var item in TrueObservationChild.CollectJointActionsWithTime(jointActions))
                {
                    if (!ans.ContainsKey(item.Key))
                    {
                        ans.Add(item.Key, item.Value);
                    }
                    if (ans[item.Key] > item.Value)
                    {
                        ans[item.Key] = item.Value;
                    }
                }
            }
            return(ans);
        }