Exemple #1
0
        private void GenerateGroundActions()
        {
            //now for each action, generate all possible argument lists and then generate an id.
            foreach (ProblemParser.Operator op in mDC.Operators)
            {
                // now for all possible arguments:
                op.ComputeHash();
                int argCount = op.ParamNames.Count;
                //TODO: Check this
                List <int> argList          = Enumerable.Repeat(0, argCount).ToList <int>();
                int        maxParamLinIndex = mDC.GetMaxIndexForSize(argCount);

                PlanAction.ID actID = new PlanAction.ID();
                actID.ActionName = op.Name;
                actID.ParamCount = op.ParamNames.Count;
                actID.DC         = mDC;

                for (int paramLinearIndex = 0; paramLinearIndex < maxParamLinIndex;
                     paramLinearIndex++)
                {
                    mDC.GetMultiIndex(paramLinearIndex, ref argList);
                    // now make them ground!
                    PlanAction act = GenerateSingleGroundAction(op, argList);
                    act.ActionID        = actID;
                    act.ParametersIndex = paramLinearIndex;

                    Actions.Add(act);
                }
            }
        }
Exemple #2
0
 public static bool InconsistentEffects(PlanAction act1, PlanAction act2)
 {
     // an effect of one negates an effect of other
     //TODO: Debug this
     return(act1.Effects.Positive.Overlaps(act2.Effects.Negative) ||
            act1.Effects.Negative.Overlaps(act2.Effects.Positive));
 }
Exemple #3
0
        private void Initialize()
        {
            MutexActions      = new Dictionary <PlanAction, HashSet <PlanAction> >(Actions.Count);
            PositiveProducers = new Dictionary <int, HashSet <PlanAction> >();
            NegativeProducers = new Dictionary <int, HashSet <PlanAction> >();
            // Initialize action mutexes
            for (int i = 0; i < Actions.Count; i++)
            {
                PlanAction act1 = Actions[i];
                if (!MutexActions.ContainsKey(act1))
                {
                    MutexActions.Add(act1, new HashSet <PlanAction>());
                }
                for (int j = i + 1; j < Actions.Count; j++)
                {
                    PlanAction act2 = Actions[j];
                    if (!MutexActions.ContainsKey(act2))
                    {
                        MutexActions.Add(act2, new HashSet <PlanAction>());
                    }

                    if (PlanMutex.ActionsMutex(act1, act2))
                    {
                        MutexActions[act1].Add(act2);
                        MutexActions[act2].Add(act1);
                    }
                }
            }
        }
Exemple #4
0
        private PlanAction GenerateSingleGroundAction(ProblemParser.Operator op, List <int> argList)
        {
            PlanAction action = new PlanAction();

            GenerateGroundActionArgs(op, op.Preconds, argList, ref action.Preconds.Positive);
            GenerateGroundActionArgs(op, op.PosEffect, argList, ref action.Effects.Positive);
            GenerateGroundActionArgs(op, op.NegEffect, argList, ref action.Effects.Negative);
            return(action);
        }
Exemple #5
0
 public static bool Interference(PlanAction act1, PlanAction act2)
 {
     // one deletes a precondition of the other
     //TODO: Debug this
     return(act1.Effects.Positive.Overlaps(act2.Preconds.Negative) ||
            act1.Effects.Negative.Overlaps(act2.Preconds.Positive) ||
            act2.Effects.Positive.Overlaps(act1.Preconds.Negative) ||
            act2.Effects.Negative.Overlaps(act1.Preconds.Positive));
 }
Exemple #6
0
            private void AddTo(PlanAction act1, PlanAction act2)
            {
                HashSet <PlanAction> hs;

                if (mutex.TryGetValue(act1, out hs))
                {
                    hs.Add(act2);
                }
                else
                {
                    hs = new HashSet <PlanAction>();
                    hs.Add(act2);
                    mutex.Add(act1, hs);
                }
            }
Exemple #7
0
            public bool AreActionsMutex(PlanAction act1, PlanAction act2)
            {
                HashSet <PlanAction> hs;

                if (mutex.TryGetValue(act1, out hs))
                {
                    return(hs.Contains(act2));
                }
                else
                {
                    // what if mutexes dont exists?
                    // BUG
                    throw new Exception("(GraphPlan.AMutex.AreActionsMutex) BUG");
                }
            }
Exemple #8
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);
        }
Exemple #9
0
 public bool IsActionExecutable(PredicateList state, PlanAction act)
 {
     return(act.Preconds.Positive.IsSubsetOf(state.Positive));
 }
Exemple #10
0
 public void AddPair(PlanAction act1, PlanAction act2)
 {
     AddTo(act1, act2);
     AddTo(act2, act1);
 }
Exemple #11
0
/*        public static bool CompetingNeeds(PlanAction act1, PlanAction act2)
 *      {
 *          // having mutually exclusive precondition
 *          //TODO: Debug this
 *          return (act1.Preconds.Positive.Overlaps(act2.Preconds.Positive) ||
 *              act1.Preconds.Negative.Overlaps(act2.Preconds.Negative));
 *      }
 */
        public static bool ActionsMutex(PlanAction act1, PlanAction act2)
        {
            return(InconsistentEffects(act1, act2) || Interference(act1, act2));
        }