Beispiel #1
0
        public MainWindowViewModel()
        {
            logger        = new Logger();
            logger.Write += Logger_Write;
            Settings.Load();
            run = new RelayCommand(x => {
                IMethod method = null;
                var a          = Matrix.FromArray(A);
                var b          = Vector.FromArray(B);
                switch (methodIndex)
                {
                case 0:
                    method = new Cholesky();
                    break;

                case 1:
                    method = new GaussSeidel();
                    break;

                case 2:
                    method = new successive_overrelaxation();
                    break;

                case 3:
                    method = new LUmet();
                    break;

                default:
                    logger.NewMsg("Такого методу немає");
                    break;
                }
                if (method != null)
                {
                    method.Log = logger;
                    X          = method.Run(a, b).ToArray();
                }
            });
            random = new RelayCommand(x =>
            {
                A         = Matrix.GetRandomMatrix(Size).ToArray();
                var randB = new double[1, Size];
                var r     = new Random();
                for (int i = 0; i < Size; ++i)
                {
                    randB[0, i] = r.Next(-1000, 1000);
                }
                B = randB;
            });
            close = new RelayCommand(x =>
            {
                App.Current.Shutdown();
            });
            clearLog = new RelayCommand(x =>
            {
                Log = "";
            });
            openSettings = new RelayCommand(x =>
            {
                var form = new SettingsWindow();
                form.Show();
            });
        }
Beispiel #2
0
        public void KnowedMatrixTestSize3()
        {
            var lu = new LUmet();

            Assert.IsTrue(MethodTest.KnowedMatrixTestSize3(lu));
        }
Beispiel #3
0
        public void RandomMatrixTestSize10()
        {
            var lu = new LUmet();

            Assert.IsTrue(MethodTest.RandomMatrixTestSize10(lu));
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var sw = new Stopwatch();
            var a  = new Matrix(3);

            a[0, 0] = 25;
            a[0, 1] = 15;
            a[0, 2] = -5;
            a[1, 0] = 15;
            a[1, 1] = 18;
            a[1, 2] = 0;
            a[2, 0] = -5;
            a[2, 1] = 0;
            a[2, 2] = 11;
            var x = new Vector(3);

            x[0] = 1;
            x[1] = 1;
            x[2] = 1;
            var     b      = a * x;
            IMethod method = null;

            Console.WriteLine("*** Performance Test ***");
            Console.WriteLine("*** Successive Overrelaxation ***");
            method = new successive_overrelaxation();
            method.Run(a, b);
            var listRes = new List <TimeSpan>();

            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** LU ***");
            method  = new LUmet();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** Gauss - Seidel ***");
            method  = new GaussSeidel();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.WriteLine("*** Cholesky ***");
            method  = new Cholesky();
            listRes = new List <TimeSpan>();
            for (int i = 0; i < 1000; i++)
            {
                sw.Start();
                var res = method.Run(a, b);
                sw.Stop();
                listRes.Add(sw.Elapsed);
                Console.WriteLine($"{sw.Elapsed.TotalMilliseconds} ms");
                sw.Reset();
            }
            Console.WriteLine($"Average - {listRes.Average(y => y.TotalMilliseconds)} ms");
            Console.ReadLine();
        }