コード例 #1
0
    //LongestPath
    public float LongestPath(MazeGraph <T> G)
    {
        bool[] visited;
        KeyValuePair <KeyValuePair <int, int>, int> LP      = new KeyValuePair <KeyValuePair <int, int>, int>();
        List <KeyValuePair <int, int> >             adycost = new List <KeyValuePair <int, int> >();

        for (int i = 0; i < G.rows; ++i)
        {
            for (int j = 0; j < G.rows; ++j)
            {
                visited = new bool[G.NumVert];
                visited[G.GetNode(i, j)] = true;
                foreach (var n in G.ConnectedNeighbors(i, j))
                {
                    adycost.Add(new KeyValuePair <int, int>(n, 1));
                }
                while (adycost.Count != 0)
                {
                    KeyValuePair <int, int> c = adycost[0];
                    visited[c.Key] = true;
                    if (LP.Value < c.Value)
                    {
                        LP = new KeyValuePair <KeyValuePair <int, int>, int>(new KeyValuePair <int, int>(G.GetNode(i, j), c.Key), c.Value);
                    }
                    foreach (var n in G.ConnectedNeighbors(G.GetCoord(c.Key)[0], G.GetCoord(c.Key)[1]))
                    {
                        if (!visited[n])
                        {
                            adycost.Add(new KeyValuePair <int, int>(n, c.Value + 1));
                        }
                    }
                    adycost.RemoveAt(0);
                }
            }
        }
        return(100.0f * LP.Value / (G.rows * G.cols));
    }
コード例 #2
0
    static bool IsCycle(int current, bool[] visited, int parent, MazeGraph <T> G)
    {
        visited[current] = true;
        List <int> coord = G.GetCoord(current);

        foreach (int i in G.ConnectedNeighbors(coord[0], coord[1]))
        {
            if (visited[i])
            {
                if (IsCycle(i, visited, current, G))
                {
                    return(true);
                }
                else if (i != parent)
                {
                    return(true);
                }
            }
        }
        return(false);
    }