Ejemplo n.º 1
0
    /// <summary>
    /// Updates the vertex.
    /// </summary>
    /// <param name='node'>
    /// Node to be updated
    /// </param>
    void UpdateVertex(ARAstarNode node)
    {
        //[06]
        if (!currentStart.Equals(node.action.state))
        {
            float minCost = Mathf.Infinity;
            //List<DefaultState> neighbors = new List<DefaultState>();
            //domain.generateNeighbors(node.action.state, ref neighbors);
            List <DefaultAction> transitions = new List <DefaultAction>();
            selectedPlanningDomain.generatePredecessors(node.action.state, ref transitions);
            foreach (DefaultAction action in transitions)
            {
                if (Visited.ContainsState(action.state))                 //Was visited
                {
                    if (Visited.nodeForState(action.state).g + action.cost < minCost && !Visited.nodeForState(action.state).previousState.Equals(node.action.state))
                    {
                        minCost            = Visited.nodeForState(action.state).g + action.cost;
                        node.previousState = action.state;
                    }
                }
            }
            //node.action = new ARAstarAction(node.previousState, node.action.state);
            node.action = selectedPlanningDomain.generateAction(node.previousState, node.action.state);
            node.rhs    = minCost;
        }
        if (selectedPlanningDomain.equals(node.action.state, goalState, false))
        {
            goalPair = new KeyValuePair <DefaultState, ARAstarNode> (node.action.state, node);
        }
        if (Open.ContainsState(node.action.state))
        {
            Open.Remove(node.action.state);
        }
        if (node.g != node.rhs)
        {
            if (!Close.Contains(node.action.state))
            {
                Open.Insert(node);
            }
            else
            {
                Incons.Insert(node);
            }
        }

        Visited.insertNode(ref node);
    }