示例#1
0
        public State GetSuccessorSuperposition(MediationTreeEdge edge)
        {
            VirtualMediationTreeNode parent = GetNode(edge.Parent) as VirtualMediationTreeNode;
            Superposition            pred   = parent.State as Superposition;
            Superposition            super  = new Superposition();

            if (edge is VirtualMediationTreeEdge)
            {
                VirtualMediationTreeEdge vEdge = edge as VirtualMediationTreeEdge;
                foreach (State state in pred.States)
                {
                    foreach (Operator action in vEdge.Actions)
                    {
                        if (state.Satisfies(action.Preconditions))
                        {
                            super.States.Add(state.NewState(action, data.problem.Objects));
                        }
                    }
                }
            }
            else
            {
                foreach (State state in pred.States)
                {
                    if (state.Satisfies(edge.Action.Preconditions))
                    {
                        super.States.Add(state.NewState(edge.Action as Operator, data.problem.Objects));
                    }
                }
            }

            return(super);
        }
示例#2
0
 protected override void UpdatePlan()
 {
     if (incoming != null)
     {
         if (incoming.ActionType.Equals(ActionType.Exceptional))
         {
             Superposition super = state as Superposition;
             foreach (State current in super.States)
             {
                 plan = PlannerInterface.Plan(Planner.FastDownward, domain, GetProblem(current));
                 if (plan.Steps.Count > 0)
                 {
                     return;
                 }
             }
         }
         else if (incoming.ActionType.Equals(ActionType.Constituent))
         {
             plan = plan.GetPlanUpdate(problem, incoming.Action as Operator);
         }
     }
     else
     {
         Superposition super = state as Superposition;
         foreach (State current in super.States)
         {
             plan = PlannerInterface.Plan(Planner.FastDownward, domain, GetProblem(current));
             if (plan.Steps.Count > 0)
             {
                 return;
             }
         }
     }
 }
示例#3
0
        public VirtualMediationTreeNode(Domain domain, Problem problem, MediationTreeEdge incoming, State state, Plan plan, int id, int depth)
        {
            this.domain   = domain;
            this.incoming = incoming;
            this.id       = id;
            this.state    = state.Clone() as State;
            this.depth    = depth;
            this.plan     = plan;

            // Create and populate a problem object based on the new file.
            this.problem = new Problem("rob", problem.OriginalName, problem.Domain, problem.Player, problem.Objects, this.state.Predicates, problem.Intentions, problem.Goal);

            outgoing = new List <MediationTreeEdge>();

            Superposition super = state as Superposition;

            satisfiesGoal = false;
            foreach (State st in super.States)
            {
                if (st.Satisfies(problem.Goal))
                {
                    satisfiesGoal = true;
                    break;
                }
            }

            UpdatePlan();
        }
示例#4
0
        /// <summary>
        /// Returns a list of outgoing edges for a given node.
        /// </summary>
        /// <param name="node">The node object.</param>
        /// <param name="actor">The name of the current actor.</param>
        /// <returns>A list of outgoing edges.</returns>
        public List <MediationTreeEdge> GetOutgoingEdges(MediationTreeNode node, string actor)
        {
            List <MediationTreeEdge> outgoing = StateSpaceTools.GetAllPossibleActions(actor, node);

            if (!data.superpositionManipulation)
            {
                return(outgoing);
            }

            List <MediationTreeEdge> unobservedActions = new List <MediationTreeEdge>();
            List <MediationTreeEdge> observedActions   = new List <MediationTreeEdge>();

            foreach (MediationTreeEdge edge in outgoing)
            {
                Superposition super = node.State as Superposition;
                bool          obs   = false;
                foreach (State state in super.States)
                {
                    if (state.Satisfies(edge.Action.Preconditions))
                    {
                        if (KnowledgeAnnotator.Observes(Player, edge.Action, state.Predicates))
                        {
                            observedActions.Add(edge);
                            obs = true;
                            break;
                        }
                    }
                }

                if (!obs)
                {
                    unobservedActions.Add(edge);
                }
            }

            if (unobservedActions.Count > 0)
            {
                VirtualMediationTreeEdge super = new VirtualMediationTreeEdge();
                foreach (MediationTreeEdge unobserved in unobservedActions)
                {
                    super.Actions.Add(unobserved.Action as Operator);
                }
                super.Parent = node.ID;
                observedActions.Add(super);
            }

            return(observedActions);
        }
示例#5
0
        /// <summary>
        /// Collapses the superposition given the player, the current tree node, and a strategy for choosing between unique state sets
        /// </summary>
        /// <param name="player">The player's name.</param>
        /// <param name="node">The current tree node.</param>
        /// <param name="chooser">A strategy for choosing between perceptually unique state sets.</param>
        /// <returns>A state superposition.</returns>
        public static HashSet <State> Collapse(string player, VirtualMediationTreeNode node, SuperpositionChooser.Choose chooser)
        {
            // Store the node's state as a superposition structure.
            Superposition super = node.State as Superposition;

            // Check to see if the node has more than one superposed state.
            if (super.States.Count > 0)
            {
                // Create a dictionary that maps sets of observed literals to sets of states that match the observation.
                Dictionary <List <IPredicate>, HashSet <State> > obs = new Dictionary <List <IPredicate>, HashSet <State> >(new PredicateListComparer());

                // Iterate through each state in the superposition.
                foreach (State state in super.States)
                {
                    // Find and store the set of literals observed by the player in the current state.
                    List <IPredicate> observed = KnowledgeAnnotator.FullKnowledgeState(node.Domain.Predicates, node.Problem.ObjectsByType, state.Predicates, player);

                    // If the current set of literals has been encountered before, add the state to its set.
                    if (obs.ContainsKey(observed))
                    {
                        obs[observed].Add(state);
                    }
                    // Otherwise, create a new dictionary key for the set of observed literals and initialize the state set with the current state.
                    else
                    {
                        obs.Add(observed, new HashSet <State> {
                            state
                        });
                    }
                }

                // Choose a set of states from the superposition according to the given strategy and return it.
                return(chooser(obs, node));
            }

            // Return the empty set of states.
            return(super.States);
        }
示例#6
0
        /// <summary>
        /// Allows custom plans to be passed in.
        /// </summary>
        /// <param name="domain">The node's domain.</param>
        /// <param name="problem">The node's problem.</param>
        /// <param name="incoming">The node's incoming edge.</param>
        /// <returns>A new tree node.</returns>
        private MediationTreeNode CreateNode(Domain domain, Problem problem, MediationTreeEdge incoming, Plan plan)
        {
            // Create a placeholder for the new node object.
            MediationTreeNode node = null;

            // If the node is a root, initialize a root node.
            if (incoming == null)
            {
                if (!data.superpositionManipulation)
                {
                    node = new MediationTreeNode(domain, problem, 0);
                }
                else
                {
                    node = new VirtualMediationTreeNode(domain, problem, 0);
                }
            }
            // Otherwise, it is a child node...
            else
            {
                // Store the current node's ID in the incoming edge.
                incoming.Child = ++data.nodeCounter;

                if (!data.superpositionManipulation)
                {
                    node = new MediationTreeNode(domain, problem, incoming, GetSuccessorState(incoming), plan, incoming.Child, GetDepth(incoming.Parent) + 1);
                }
                else
                {
                    node = new VirtualMediationTreeNode(domain, problem, incoming, GetSuccessorSuperposition(incoming), plan, incoming.Child, GetDepth(incoming.Parent) + 1);
                }

                // Add the edge to the tree hashtable.
                data.tree[incoming.Child] = incoming.Parent;

                MediationTreeNode parent = GetNode(incoming.Parent);
                if (incoming.Action != null)
                {
                    parent.Outgoing.Find(x => x.Action.Equals(incoming.Action)).Child = node.ID;
                }
                else
                {
                    foreach (MediationTreeEdge edge in parent.Outgoing)
                    {
                        if (edge is VirtualMediationTreeEdge)
                        {
                            if ((edge as VirtualMediationTreeEdge).Equals(incoming as VirtualMediationTreeEdge))
                            {
                                edge.Child = node.ID;
                            }
                        }
                    }
                }

                SetNode(parent);

                if (data.superpositionManipulation)
                {
                    Superposition super = node.State as Superposition;
                    super.States = SuperpositionManipulator.Collapse(data.player, node as VirtualMediationTreeNode, SuperpositionChooser.ChooseUtility);
                    node.State   = super;
                }
            }

            // If the node is a goal state, iterate the goal state counter.
            if (node.IsGoal)
            {
                data.goalStateCount++;
            }

            // If the node is a dead end, iterate the dead end counter.
            if (node.DeadEnd)
            {
                if (data.eventRevision)
                {
                    EventRevisor.EventRevision(Planner.FastDownward, node, this);
                }

                if (node.DeadEnd && data.domainRevision)
                {
                    DomainRevisor.DomainRevision(Planner.FastDownward, node, this);
                }

                if (node.DeadEnd)
                {
                    data.deadEndCount++;
                }
            }

            // If the node is at a lower depth than the previous record holder, update the depth counter.
            if (node.Depth > data.lowestDepth)
            {
                data.lowestDepth = node.Depth;
            }

            // If the node is not a dead end.
            if (!node.DeadEnd)
            {
                // Find and store the node's outgoing edges.
                node.Outgoing = GetOutgoingEdges(node, GetCurrentTurn(node));
            }

            // Save the current node to disk.
            SetNode(node);

            // Return the current node object.
            return(node);
        }