Exemple #1
0
    private List <int> FindMainPoints(AI_TYPE InType)
    {
        List <int> points = G.GetSingleAttachedPoint();

        List <List <int> > resultPath = new List <List <int> >();

        foreach (var p1 in points)
        {
            DepthFirstPaths dfs = new DepthFirstPaths(G, p1);

            foreach (var p2 in points)
            {
                if (p1 != p2)
                {
                    List <int> paths = dfs.pathTo(p2);

                    resultPath.Add(paths);
                }
            }
        }

        resultPath.Sort((Left, Right) => { return(Right.Count - Left.Count); });

        return(resultPath.Count > 0 ? resultPath[0] : new List <int>());
    }
Exemple #2
0
    public static void Test(TextAsset txt)
    {
        Graph G = new Graph(txt);
        int   s = 0;
        //int s = Random.Range(0, int.Parse(txt.text.Split('\n')[0]));
        DepthFirstPaths dfs = new DepthFirstPaths(G, s);

        for (int v = 0; v < G.V(); v++)
        {
            if (dfs.hasPathTo(v))
            {
                string str = s + " to " + v + ":  ";

                foreach (int x in dfs.pathTo(v))
                {
                    if (x == s)
                    {
                        str += x;
                    }
                    else
                    {
                        str += ("-" + x);
                    }
                }
                print(str);
            }
            else
            {
                print(s + " to " + v + ":  not connected\n");
            }
        }
    }
Exemple #3
0
    /**/ public static void main(string[] strarr)
    {
        In              i               = new In(strarr[0]);
        Graph           graph           = new Graph(i);
        int             num             = Integer.parseInt(strarr[1]);
        DepthFirstPaths depthFirstPaths = new DepthFirstPaths(graph, num);

        for (int j = 0; j < graph.V(); j++)
        {
            if (depthFirstPaths.hasPathTo(j))
            {
                StdOut.printf("%d to %d:  ", new object[]
                {
                    Integer.valueOf(num),
                    Integer.valueOf(j)
                });
                Iterator iterator = depthFirstPaths.pathTo(j).iterator();
                while (iterator.hasNext())
                {
                    int num2 = ((Integer)iterator.next()).intValue();
                    if (num2 == num)
                    {
                        StdOut.print(num2);
                    }
                    else
                    {
                        StdOut.print(new StringBuilder().append("-").append(num2).toString());
                    }
                }
                StdOut.println();
            }
            else
            {
                StdOut.printf("%d to %d:  not connected\n", new object[]
                {
                    Integer.valueOf(num),
                    Integer.valueOf(j)
                });
            }
        }
    }