Beispiel #1
0
        private static void StartYenAlgorithm()
        {
            Console.WriteLine("csv format: < string;node1;node2;weight >");
            string file = "";

            while (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
            {
                Console.WriteLine("CSV Input filepath:");
                file = Console.ReadLine().Trim('"').Trim();
            }
            FileInfo fi = new FileInfo(file);

            Console.WriteLine($"Found file {fi.Name}.");
            double min; double max;
            string ml1 = "";

            while (!double.TryParse(ml1, out min))
            {
                Console.WriteLine("Minimum line length:");
                ml1 = Console.ReadLine();
            }
            string mxl = "";

            while (!double.TryParse(mxl, out max))
            {
                Console.WriteLine("Maximum line length: ");
                mxl = Console.ReadLine();
            }
            if (min > max)
            {
                Console.WriteLine("Minimum > Maximum. Quitting..");
            }
            else
            {
                Console.WriteLine("Hit key to start line generation.");
                Console.ReadKey();
                CsvFileReader  r  = new CsvFileReader();
                LineGeneration lg = new LineGeneration();
                try
                {
                    Graph graph = r.ReadGraphFromFile(file);
                    var   paths = lg.GenerateLines(min, max, graph);
                    foreach (var p in paths)
                    {
                        Console.WriteLine(PathPrinter.PrintTaggedPath(p));
                    }
                    LineOutputWriter.WriteCsv(Path.Combine(fi.DirectoryName, fi.Name.Replace(fi.Extension, "_solution" + fi.Extension)), paths);
                    Console.WriteLine("wrote solution to folder " + fi.DirectoryName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Execution Error: {ex.Message}");
                }
                Console.WriteLine("Hit key to exit.");
                Console.ReadKey();
            }
        }
Beispiel #2
0
        /// <summary>
        /// adrr contains the save address of the generated image,
        /// and must have the extension .pgm;
        /// Example /home/user/image.pgm
        /// </summary>
        public void ExportMapPGM(string adrr, int baseColor, int lineColor)
        {
            FrameBuffer frame = new FrameBuffer((int)this.size.X + 1,
                                                (int)this.size.Y + 1, baseColor);

            foreach (intTuple item in this.edge)
            {
                Vector2 a = this.vertex[item.A];
                Vector2 b = this.vertex[item.B];

                LineGeneration.plotLine(a, b, frame, lineColor);
            }
            frame.Export(adrr);
        }
Beispiel #3
0
        public static void ExportViewPGM(Player player, Map map, Vector2 resolution, RaycastingProperties properties, string adrr)
        {
            FrameBuffer frame = new FrameBuffer((int)resolution.X, (int)resolution.Y, 0);

            float angleInc   = player.FOV / resolution.Y;
            float angleAtt   = player.Rotation - (player.FOV / 2);
            float angleFinal = player.Rotation + (player.FOV / 2);

            int index = 0;

            while (angleAtt <= angleFinal)
            {
                Vector2 intersect = map.RayCasting(player, angleAtt);

                if (intersect == null)
                {
                    intersect = new Vector2(float.PositiveInfinity, float.PositiveInfinity);
                }
                else
                {
                    map.ViewRay("map.pgm", player.Position, intersect, 0, 255, 125);
                    Thread.Sleep(TimeSpan.FromSeconds(0.5f));
                }

                float distance = (float)Vector2.Distance(intersect, player.Position);

                float height = properties.getHeight((float)distance);

                int minH = (int)((resolution.X / 2) - (height / 2));
                int maxH = (int)((resolution.X / 2) + (height / 2));


                LineGeneration.plotLine(new Vector2(index, minH), new Vector2(index, maxH), frame, properties.getColor(distance, 255, 125));

                Console.WriteLine(minH + ", " + maxH + ", " + index);


                //Console.WriteLine(index);

                angleAtt += angleInc;
                index    += 1;
            }

            frame.Export("test.pgm");
            //Thread.Sleep(TimeSpan.FromSeconds(0.5f));

            //frame.Export(adrr);
        }
Beispiel #4
0
        public void ViewRay(string adrr, Vector2 pos, Vector2 intersect, int baseColor, int lineColor, int PlayerColor)
        {
            FrameBuffer frame = new FrameBuffer((int)this.size.X + 1,
                                                (int)this.size.Y + 1, baseColor);

            foreach (intTuple item in this.edge)
            {
                Vector2 a = this.vertex[item.A];
                Vector2 b = this.vertex[item.B];

                LineGeneration.plotLine(a, b, frame, lineColor);
            }

            LineGeneration.plotLine(pos, intersect, frame, 255);
            LineGeneration.plotPoint(pos, frame, PlayerColor);

            frame.Export(adrr);
        }
Beispiel #5
0
        public IActionResult LineGen(YenInputViewmodel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    GraphConvert   r      = new GraphConvert();
                    LineGeneration lg     = new LineGeneration();
                    var            graph  = r.ReadGraphFromString(model.CsvString, model.MirrorArcs);
                    var            paths  = lg.GenerateLines(model.MinimumLength, model.MaximumLength, graph);
                    string         result = r.WriteText(paths);

                    YenInputViewmodel vmResult = new YenInputViewmodel()
                    {
                        MinimumLength = model.MinimumLength,
                        MaximumLength = model.MaximumLength,
                        CsvString     = result
                    };

                    var          stream = new MemoryStream();
                    StreamWriter w      = new StreamWriter(stream);
                    w.Write(vmResult.CsvString);
                    w.Flush();
                    stream.Position = 0;
                    return(File(stream, "text/comma-separated-values", "Lineplanning.csv"));
                }
                catch (Exception ex)
                {
                    ViewBag.ExceptionMessage = ex.Message;
                    return(View("Failed"));
                }
            }
            else
            {
                return(View(model));
            }
        }