示例#1
0
        public void Run()
        {
            Console.WriteLine("Choose file:");   // Prompt
            Console.WriteLine("1 - routes.txt"); // Prompt
            Console.WriteLine("2 - movies.txt"); // Prompt
            //Console.WriteLine("3 - largeG.zip"); // Prompt
            Console.WriteLine("or quit");        // Prompt

            var           fileNumber = Console.ReadLine();
            string        fileName;
            char          delimiter;
            string        source;
            List <string> names;

            switch (fileNumber)
            {
            case "1":
                fileName  = "routes.txt";
                delimiter = '\u0020';
                source    = "JFK";
                names     = new List <string> {
                    "LAS", "DFW", "EWR"
                };
                break;

            case "2":
                fileName  = "movies.txt";
                delimiter = '/';
                source    = "Bacon, Kevin";
                names     = new List <string> {
                    "Kidman, Nicole", "Grant, Cary"
                };
                break;

            //case "3":
            //    fieName = "largeG.zip";
            //    break;
            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fileName}");
            var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var degreesOfSeparation = new DegreesOfSeparation(lines, delimiter, source);

            Console.WriteLine($"{source}");
            foreach (var name in names)
            {
                Console.WriteLine($"{name}");
                degreesOfSeparation.Find(name);
            }
            Console.ReadLine();
        }
示例#2
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - jobs.txt"); // Prompt
            Console.WriteLine("or quit");      // Prompt

            var    fileNumber = Console.ReadLine();
            string fileName;
            char   delimiter;

            switch (fileNumber)
            {
            case "1":
                fileName  = "jobs.txt";
                delimiter = '/';
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fileName}");
            var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var sg = new SymbolDigraph(lines, delimiter);

            Console.WriteLine(sg.G);

            var topological = new Topological(sg.G);

            foreach (int v in topological.Order())
            {
                Console.WriteLine(sg.Name(v));
            }

            Console.ReadLine();
        }
示例#3
0
        public void Run()
        {
            Console.WriteLine("Choose file:");   // Prompt
            Console.WriteLine("1 - routes.txt"); // Prompt
            Console.WriteLine("2 - movies.txt"); // Prompt
            //Console.WriteLine("3 - largeG.zip"); // Prompt
            Console.WriteLine("or quit");        // Prompt

            var           fileNumber = Console.ReadLine();
            string        fileName;
            char          delimiter;
            List <string> names;

            switch (fileNumber)
            {
            case "1":
                fileName  = "routes.txt";
                delimiter = '\u0020';
                names     = new List <string> {
                    "JFK", "LAX"
                };
                break;

            case "2":
                fileName  = "movies.txt";
                delimiter = '/';
                names     = new List <string> {
                    "Tin Men (1987)", "Bacon, Kevin"
                };
                break;

            //case "3":
            //    fieName = "largeG.zip";
            //    break;
            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fileName}");
            var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var sg    = new SymbolGraph(lines, delimiter);
            var graph = sg.G;


            foreach (var name in names)
            {
                Console.WriteLine($"{name}");
                if (sg.Contains(name))
                {
                    var s = sg.Index(name);
                    foreach (int v in graph.Adj(s))
                    {
                        Console.WriteLine($"   {sg.Name(v)}");
                    }
                }
                else
                {
                    Console.WriteLine($"input not contain '{name}'");
                }
            }
            Console.ReadLine();
        }
示例#4
0
        public void Run()
        {
            Console.WriteLine("Choose file:");   // Prompt
            Console.WriteLine("1 - aminol.csv"); // Prompt
            Console.WriteLine("2 - movies.txt"); // Prompt
            Console.WriteLine("or quit");        // Prompt

            var fileNumber    = Console.ReadLine();
            var fieName       = string.Empty;
            var lineSeparator = ',';

            switch (fileNumber)
            {
            case "1":
                fieName       = "aminol.csv";
                lineSeparator = ',';
                break;

            case "2":
                fieName       = "movies.txt";
                lineSeparator = '/';
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Searching\\{fieName}");
            var lines = !fieName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();


            //var list = words.Select(word => new StringComparable(word)).ToList();
            //var listComparable = list.Cast<IComparable>().ToList();
            //var arrayComparable = list.Cast<IComparable>().ToArray();
            //var listStrings = words.ToList();

            var lookupIndex = new LookupIndex();


            foreach (var line in lines)
            {
                var lineSplitted  = line.Split(new[] { lineSeparator }, StringSplitOptions.RemoveEmptyEntries);
                var key           = string.Empty;
                var fields        = new List <string>();
                var fieldIterator = 0;
                foreach (var field in lineSplitted)
                {
                    if (fieldIterator == 0)
                    {
                        key = field;
                    }
                    else
                    {
                        fields.Add(field);
                    }
                    fieldIterator++;
                }

                lookupIndex.CreateLookup(key, fields);
            }

            lookupIndex.Check("Alanine");
            lookupIndex.Check("Glycine");
            lookupIndex.Check("CGA");
            Console.WriteLine("----------------------------------------------------------------------");
            lookupIndex.Check("Amants du Pont-Neuf, Les (1991)");
            lookupIndex.Check("Bad Boys (1983)");
            lookupIndex.Check("Sheen, Martin");
            Console.WriteLine("----------------------------------------------------------------------");

            Console.ReadLine();
        }
示例#5
0
        public void Run()
        {
            Console.WriteLine("Choose file:");    // Prompt
            Console.WriteLine("1 - tinyDG.txt");  // Prompt
            Console.WriteLine("2 - tinyDAG.txt"); // Prompt
            //Console.WriteLine("3 - largeG.zip"); // Prompt
            Console.WriteLine("or quit");         // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "tinyDG.txt";
                break;

            case "2":
                fieName = "tinyDAG.txt";
                break;

            //case "3":
            //    fieName = "largeG.zip";
            //    break;
            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fieName}");
            var lines = !fieName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var lineIterator = 0;
            var v            = 0;
            var e            = 0;
            var edges        = new List <EdgeD>();

            foreach (var line in lines)
            {
                if (lineIterator == 0)
                {
                    v = Convert.ToInt32(line);
                }
                if (lineIterator == 1)
                {
                    e = Convert.ToInt32(line);
                }
                if (lineIterator > 1)
                {
                    var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var ve           = Convert.ToInt32(lineSplitted[0]);
                    var we           = Convert.ToInt32(lineSplitted[1]);
                    var edge         = new EdgeD(ve, we);
                    edges.Add(edge);
                }

                lineIterator++;
            }

            var graph = new Digraph(v, e, edges);

            if (fileNumber != "3")
            {
                Console.WriteLine(graph);
            }


            var finder = new DirectedCycle(graph);

            if (finder.HasCycle())
            {
                Console.Write("Directed cycle: ");
                foreach (int vi in finder.Cycle())
                {
                    Console.Write($"{vi} ");
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("No directed cycle");
            }


            Console.ReadLine();
        }
示例#6
0
        public void Run()
        {
            Console.WriteLine("Choose file:");    // Prompt
            Console.WriteLine("1 - tinyCG.txt");  // Prompt
            Console.WriteLine("2 - mediumG.txt"); // Prompt
            Console.WriteLine("3 - largeG.zip");  // Prompt
            Console.WriteLine("or quit");         // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "tinyCG.txt";
                break;

            case "2":
                fieName = "mediumG.txt";
                break;

            case "3":
                fieName = "largeG.zip";
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fieName}");
            var lines = !fieName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var lineIterator = 0;
            var v            = 0;
            var e            = 0;
            var edges        = new List <EdgeU>();

            foreach (var line in lines)
            {
                if (lineIterator == 0)
                {
                    v = Convert.ToInt32(line);
                }
                if (lineIterator == 1)
                {
                    e = Convert.ToInt32(line);
                }
                if (lineIterator > 1)
                {
                    var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var ve           = Convert.ToInt32(lineSplitted[0]);
                    var we           = Convert.ToInt32(lineSplitted[1]);
                    var edge         = new EdgeU(ve, we);
                    edges.Add(edge);
                }

                lineIterator++;
            }

            var graph = new Graph(v, e, edges);

            if (fileNumber != "3")
            {
                Console.WriteLine(graph);
            }


            const int s    = 0;
            var       bfs1 = new BreadthFirstPaths(graph, s);

            for (var vi = 0; vi < graph.V; vi++)
            {
                if (bfs1.HasPathTo(vi))
                {
                    Console.Write($"{s} to {vi}:  ");
                    foreach (int x in bfs1.PathTo(vi))
                    {
                        if (x == s)
                        {
                            Console.Write(x);
                        }
                        else
                        {
                            Console.Write($"-{x}");
                        }
                    }
                    Console.WriteLine();
                }

                else
                {
                    Console.WriteLine($"{s} to {v}:  not connected{Environment.NewLine}");
                }
                if (vi >= 1 && fileNumber == "3")
                {
                    break;
                }
            }

            //Console.WriteLine("------------------------------------------------");

            Console.ReadLine();
        }
示例#7
0
        public void Run()
        {
            Console.WriteLine("Choose file:");  // Prompt
            Console.WriteLine("1 - ip.csv");    // Prompt
            Console.WriteLine("2 - DJIA.csv");  // Prompt
            Console.WriteLine("3 - amino.csv"); // Prompt
            Console.WriteLine("4 - UPC.zip");   // Prompt
            Console.WriteLine("or quit");       // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "ip.csv";
                break;

            case "2":
                fieName = "DJIA.csv";
                break;

            case "3":
                fieName = "amino.csv";
                break;

            case "4":
                fieName = "UPC.zip";
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Searching\\{fieName}");
            var lines = !fieName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();


            //var list = words.Select(word => new StringComparable(word)).ToList();
            //var listComparable = list.Cast<IComparable>().ToList();
            //var arrayComparable = list.Cast<IComparable>().ToArray();
            //var listStrings = words.ToList();

            var lookupCSV = new LookupCSV();

            foreach (var line in lines)
            {
                var lineSplitted = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (lineSplitted.Length >= 2)
                {
                    var key   = lineSplitted[0];
                    var value = lineSplitted[1];
                    lookupCSV.InsertItem(key, value);
                }
            }

            lookupCSV.Check("cnzz.com");
            lookupCSV.Check("americanexpress.com");
            lookupCSV.Check("www.1gl.ru");
            Console.WriteLine("----------------------------------------------------------------------");
            lookupCSV.Check("26-Oct-28");
            lookupCSV.Check("22-Oct-28");
            lookupCSV.Check("32-Oct-28");
            Console.WriteLine("----------------------------------------------------------------------");
            lookupCSV.Check("CAA");
            lookupCSV.Check("ACT");
            lookupCSV.Check("GRR");
            Console.WriteLine("----------------------------------------------------------------------");
            lookupCSV.Check("0000000010344");
            lookupCSV.Check("0000000492515");
            lookupCSV.Check("5024425379607");

            Console.ReadLine();
        }
示例#8
0
        public void Run()
        {
            Console.WriteLine("Choose file:");    // Prompt
            Console.WriteLine("1 - tinyG.txt");   // Prompt
            Console.WriteLine("2 - mediumG.txt"); // Prompt
            //Console.WriteLine("3 - largeG.zip"); // Prompt
            Console.WriteLine("or quit");         // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "tinyG.txt";
                break;

            case "2":
                fieName = "mediumG.txt";
                break;

            //case "3":
            //    fieName = "largeG.zip";
            //    break;
            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Graphs\\{fieName}");
            var lines = !fieName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var lineIterator = 0;
            var v            = 0;
            var e            = 0;
            var edges        = new List <EdgeU>();

            foreach (var line in lines)
            {
                if (lineIterator == 0)
                {
                    v = Convert.ToInt32(line);
                }
                if (lineIterator == 1)
                {
                    e = Convert.ToInt32(line);
                }
                if (lineIterator > 1)
                {
                    var lineSplitted = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var ve           = Convert.ToInt32(lineSplitted[0]);
                    var we           = Convert.ToInt32(lineSplitted[1]);
                    var edge         = new EdgeU(ve, we);
                    edges.Add(edge);
                }

                lineIterator++;
            }

            var graph = new Graph(v, e, edges);

            if (fileNumber != "3")
            {
                Console.WriteLine(graph);
            }

            var cc = new CC(graph);

            // number of connected components
            var m = cc.Count();

            Console.WriteLine($"{m} components");

            // compute list of vertices in each connected component
            var components = new Core.Collections.Queue <Integer> [m];

            for (var i = 0; i < m; i++)
            {
                components[i] = new Core.Collections.Queue <Integer>();
            }
            for (var vi = 0; vi < graph.V; vi++)
            {
                components[cc.Id(vi)].Enqueue(vi);
            }

            // print results
            for (var i = 0; i < m; i++)
            {
                foreach (int vi in components[i])
                {
                    Console.Write($"{vi} ");
                }
                Console.WriteLine();
            }

            Console.ReadLine();
        }