Example #1
0
    /// <summary>
    /// Expands all of the transitions and adds the resulting world states
    /// to the list of nodes during exploration
    /// </summary>
    /// <param name="openList">The list of nodes we haven't explored
    /// yet</param>
    /// <param name="seen">The list of nodes we've seen</param>
    /// <param name="curNode">The current node from the open list</param>
    private static void AddExpansionsToLists(
        EventDescriptor[] evtDescs,
        List<ExplorationNode> openList,
        Dictionary<WorldState, ExplorationNode> seen,
        ExplorationNode curNode)
    {
        // Find all of the event signatures
        foreach (EventDescriptor evtDesc in evtDescs)
        {
            IEnumerable<Tuple<WorldState, uint[]>> expansions =
                GetExpansions(curNode.State, evtDesc);

            // Get all of the expansions
            foreach (Tuple<WorldState, uint[]> expansion in expansions)
            {
                WorldState expansionState = expansion.Item1;
                ExplorationNode expansionNode;

                // If we haven't seen the world state
                if (seen.TryGetValue(expansionState, out expansionNode) == false)
                {
                    expansionNode = new ExplorationNode(expansionState);
                    openList.Add(expansionNode);
                    seen.Add(expansionState, expansionNode);
                }

                DebugUtil.Assert(expansionNode != null);

                TransitionEvent transition = new TransitionEvent(evtDesc, expansion.Item2);
                ExplorationEdge edge = new ExplorationEdge(
                    curNode,
                    expansionNode,
                    transition);
                curNode.AddOutgoing(edge);
                expansionNode.AddIncoming(edge);
            }
        }
    }
Example #2
0
    private static void AssignEdgesToNode(
        Dictionary<uint, ExplorationEdge> idToEdge,
        NodeData data,
        ExplorationNode node)
    {
        // Add the incoming and outgoing nodes, in order
        foreach (uint id in data.Incoming)
            node.AddIncoming(idToEdge[id]);
        foreach (uint id in data.Outgoing)
            node.AddOutgoing(idToEdge[id]);

        List<ExplorationEdge> edges = new List<ExplorationEdge>();
        // Convert the path to path edges for each target
        for (int tIdx = 0; tIdx < data.Paths.Length; tIdx++)
        {
            uint[] pathIds = data.Paths[tIdx];
            ExplorationEdge[] pathEdges =
                pathIds.Convert((id) => idToEdge[id]).ToArray();
            ExplorationNode target = pathEdges.Last().Target;
            node.SetPathOut(target.Id, pathEdges);
        }
    }