コード例 #1
0
        //Build the graph using the generated data structures and a DFS algorithm
        private void DFSGraphBuilder(Dictionary <int, List <int> > roomsPerDoor, Dictionary <int, List <int> > doorsPerRoom, Dictionary <int, bool> isExit, List <int> visited, int door = 1)
        {
            visited.Add(door);
            foreach (int room in roomsPerDoor[door])      //foreach connected room
            {
                foreach (int child in doorsPerRoom[room]) //for each door in that room
                {
                    if (!(visited.Contains(child)))
                    {
                        //Creat the node
                        //Add incoming and outgoing edge between nodes
                        //recurese on that node

                        fGraph.AddNode(child, new List <int>(), isExit[child]);
                        int edgeId1 = centralEdgeId++;
                        int edgeId2 = centralEdgeId++;
                        fGraph.AddEdge(edgeId1, room, child, door);
                        fGraph.AddEdge(edgeId2, room, door, child);
                        fGraph.Node(door).GetIncident.Add(edgeId1);
                        fGraph.Node(door).GetIncident.Add(edgeId2);
                        fGraph.Node(child).GetIncident.Add(edgeId1);
                        fGraph.Node(child).GetIncident.Add(edgeId2);

                        //Recurse on child
                        DFSGraphBuilder(roomsPerDoor, doorsPerRoom, isExit, visited, child);
                    }
                }
            }
        }
コード例 #2
0
        //Adds all nodes from the external graph
        private void fullExpand(FloorGraph extGraph)
        {
            //Add nodes
            foreach (KeyValuePair <int, FloorGraphNode> pair in extGraph.Nodes)
            {
                List <int> incident = new List <int>();
                foreach (int i in pair.Value.GetIncident)
                {
                    incident.Add(i);
                }
                fGraph.AddNode(pair.Value.Id, incident, pair.Value.Exit, pair.Value.Certainty, pair.Value.Live);
            }

            //Add edges
            foreach (KeyValuePair <int, FloorGraphEdge> pair in extGraph.Edges)
            {
                fGraph.AddEdge(pair.Value.Id, pair.Value.Room, pair.Value.GetOrigin, pair.Value.GetDestination, pair.Value.Certainty, pair.Value.Live);
            }
        }
コード例 #3
0
        //Use DFS to expand both mental maps
        private void DFSExpand(FloorGraph extGraph, int commonNode)
        {
            //Start at common node, travel through the tree preferring lower EDGE id's
            //Travel along the external graphs path, add nodes, edges and references to internal graph

            //visited edges
            List <int> visited = new List <int>();

            //Set the highest certainty and liveness
            if (fGraph.Nodes[commonNode].Certainty > extGraph.Nodes[commonNode].Certainty)
            {
                extGraph.Nodes[commonNode].Certainty = fGraph.Nodes[commonNode].Certainty;
                extGraph.Nodes[commonNode].Live      = fGraph.Nodes[commonNode].Live;
            }
            else
            {
                fGraph.Nodes[commonNode].Certainty = extGraph.Nodes[commonNode].Certainty;
                fGraph.Nodes[commonNode].Live      = extGraph.Nodes[commonNode].Live;
            }

            foreach (int e in extGraph.Nodes[commonNode].GetIncident)
            {
                //If edge has not been visited yet
                if (!(visited.Contains(e)))
                {
                    //Set edge to visited
                    visited.Add(e);

                    //If iNodes does not contain a refrence to the edge
                    if (!(fGraph.Nodes[commonNode].GetIncident.Contains(e)))
                    {
                        int destNode = extGraph.Edges[e].GetDestination;

                        //Add reference in commonnode
                        fGraph.Nodes[commonNode].GetIncident.Add(e);

                        //Copy edge to iEdges
                        extGraph.AddEdge(extGraph.Edges[e].Id, extGraph.Edges[e].Room, extGraph.Edges[e].GetOrigin, extGraph.Edges[e].GetDestination, extGraph.Edges[e].Certainty, extGraph.Edges[e].Live);

                        //Add destination node to iNodes
                        fGraph.AddNode(destNode, new List <int>(), extGraph.Nodes[destNode].Exit, extGraph.Nodes[destNode].Certainty, extGraph.Nodes[destNode].Live);

                        //Recurse on destination
                        DFSExpand(extGraph, destNode);
                    }
                    else
                    {
                        //set certainty and liveness
                        if (fGraph.Edges[e].Certainty > extGraph.Edges[e].Certainty)
                        {
                            extGraph.Edges[e].Certainty = fGraph.Edges[e].Certainty;
                            extGraph.Edges[e].Live      = fGraph.Edges[e].Live;
                        }
                        else
                        {
                            fGraph.Edges[e].Certainty = extGraph.Edges[e].Certainty;
                            fGraph.Edges[e].Live      = extGraph.Edges[e].Live;
                        }

                        //Recurse on destination
                        DFSExpand(extGraph, fGraph.Edges[e].GetDestination);
                    }
                }
            }
        }