Ejemplo n.º 1
0
        public ActionResult Save(Householder householder)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var householderViewModel = new HouseholderViewModel
                    {
                        Householder = householder
                    };

                    return(View("HouseholdersForm", householderViewModel));
                }

                var             store       = new UserStore <ApplicationUser>(new ApplicationDbContext());
                var             userManager = new UserManager <ApplicationUser>(store);
                ApplicationUser user        = userManager.FindByNameAsync(User.Identity.Name).Result;

                var locationService = new GoogleLocationService(ConfigurationManager.AppSettings["GooglePlaceAPIKey"]);
                var point           = locationService.GetLatLongFromAddress(householder.Address + ", " + householder.Neighbourhood + "-" + householder.City);

                householder.Latitude  = point.Latitude;
                householder.Longitude = point.Longitude;

                if (householder.Id == 0)
                {
                    householder.CreationDate   = DateTime.Now;
                    householder.CongregationId = user.CongregationId;
                    _context.Householders.Add(householder);
                }
                else
                {
                    var householderdb = _context.Householders.Single(h => h.Id == householder.Id);

                    householderdb.Name           = householder.Name;
                    householderdb.Neighbourhood  = householder.Neighbourhood;
                    householderdb.Phone          = householder.Phone;
                    householderdb.ZipCode        = householder.ZipCode;
                    householderdb.CongregationId = user.CongregationId;
                    householderdb.Address        = householder.Address;
                    householderdb.City           = householder.City;
                    householderdb.Latitude       = householder.Latitude;
                    householderdb.Longitude      = householder.Longitude;
                    householderdb.Publisher      = householder.Publisher;
                    householderdb.Observations   = householder.Observations;
                    householderdb.Category       = householder.Category;
                }

                _context.SaveChanges();

                return(RedirectToAction("Index", "Householders"));
            }
            catch (Exception e)
            {
                System.Threading.Thread.Sleep(1000);
                return(ViewHouseholderData(householder.Id));
            }
        }
        public void When_Transpose_Q(int size)
        {
            // Arrange
            Random device = new Random();
            Matrix A      = new Matrix(size, size);
            Matrix I      = new Matrix(size, size);

            for (int i = 0; i < size; i++)
            {
                I.Elem[i][i] = 1;
                for (int j = 0; j < size; j++)
                {
                    A.Elem[i][j] = device.NextDouble();
                }
            }

            Matrix Q1 = new Matrix(A.Row, A.Column);
            Matrix R1 = new Matrix(A.Row, A.Column);

            Matrix Q2 = new Matrix(A.Row, A.Column);
            Matrix R2 = new Matrix(A.Row, A.Column);

            Matrix Q3 = new Matrix(A.Row, A.Column);
            Matrix R3 = new Matrix(A.Row, A.Column);

            for (int i = 0; i < A.Row; i++)
            {
                Q3.Elem[i][i] = 1.0;
            }

            Matrix Q4 = new Matrix(A.Row, A.Column);
            Matrix R4 = new Matrix(A.Row, A.Column);

            for (int i = 0; i < A.Row; i++)
            {
                Q4.Elem[i][i] = 1.0;
            }

            GramSchmidt.Classic(A, Q1, R1);
            GramSchmidt.Modified(A, Q2, R2);
            Givens.Orthogon(A, Q3, R3);
            Householder.Orthogon(A, Q4, R4);

            // Act
            Matrix QT1 = Q1.Transpose();
            Matrix QT2 = Q2.Transpose();
            Matrix QT3 = Q3.Transpose();
            Matrix QT4 = Q4.Transpose();

            // Assert
            Assert.That(QT1 * Q1 == I);
            Assert.That(QT2 * Q2 == I);
            Assert.That(QT3 * Q3 == I);
            Assert.That(QT4 * Q4 == I);
        }
Ejemplo n.º 3
0
        private void button6_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            eps = Math.Pow(10, -Convert.ToInt32(tbeps.Text));

            button7.Enabled = false;
            button8.Enabled = false;
            button9.Enabled = false;

            double[,] mat = tomat(tbA.Text);
            lA            = new SparseMatrix(mat);
            n             = lA.Rows;
            show("Lib A initiated !");

            lB = new SparseMatrix(n, 1);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    lB[i, 0] += mat[i, j] * (j + 1);
                }
            }
            tbB.Clear();
            tbB.AppendText(lB.ToString());

            h = new Householder(lA);
            tbR.Clear();
            tbR.AppendText(h.R().ToString());
            tbQ.Clear();
            tbQ.AppendText(h.Q().ToString());

            Matrix lQp = new SparseMatrix(n, n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    lQp[j, i] = h.Q()[i, j];
                }
            }

            Matrix lBp = lQp.Multiply(lB);

            tbBb.Clear();
            tbBb.AppendText(lBp.ToString());

            show("Lib Q,R calculated !");
            button7.Enabled = true;
            button9.Enabled = true;

            tqr = DateTime.Now - dt;
        }
        public ActionResult SaveVisit(VisitViewModel visit)
        {
            var user = GetUser();

            var          territoryMaps      = _context.TerritoryMaps.Include(t => t.Householders).Where(t => t.UserId.Equals(user.Id)).ToList();
            Householder  householderVisited = new Householder();
            TerritoryMap territoryMapUsed   = new TerritoryMap();

            foreach (var territoryMap in territoryMaps)
            {
                var householderFound = territoryMap.Householders.Find(h => h.Id == visit.VisitedHouseHolder.Id);
                if (householderFound != null)
                {
                    territoryMapUsed   = territoryMap;
                    householderVisited = householderFound;
                    break;
                }
            }

            visit.TerritoryMapUsed   = territoryMapUsed;
            visit.VisitedHouseHolder = householderVisited;

            var householderInDb = _context.Householders.Include(h => h.Visits).SingleOrDefault(h => h.Id == visit.VisitedHouseHolder.Id);
            var territoyMapInDb = _context.TerritoryMaps.Include(t => t.Householders).SingleOrDefault(t => t.Id == visit.TerritoryMapUsed.Id);

            territoyMapInDb.Householders.Remove(householderInDb);
            var Visit = new Visit()
            {
                PublisherName = visit.PublisherName,
                DateOfVisit   = DateTime.Now,
                Description   = visit.VisitDescription
            };

            householderInDb.Visits.Add(Visit);

            if (territoyMapInDb.Householders.Count > 0)
            {
                _context.SaveChanges();
                return(RedirectToAction("Show", visit.TerritoryMapUsed));
            }
            else
            {
                _context.TerritoryMaps.Remove(_context.TerritoryMaps.Single(t => t.Id == territoyMapInDb.Id));
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        public void MFW_HW()
        {
            var A = new Matrix(4, 4);

            A.Elem[0][0] = 5; A.Elem[0][1] = 20; A.Elem[0][2] = 49; A.Elem[0][3] = 4;
            A.Elem[1][0] = 55; A.Elem[1][1] = 17; A.Elem[1][2] = 12; A.Elem[1][3] = 19;
            A.Elem[2][0] = 0; A.Elem[2][1] = 11; A.Elem[2][2] = 47; A.Elem[2][3] = 61;
            A.Elem[3][0] = 48; A.Elem[3][1] = 60; A.Elem[3][2] = 9; A.Elem[3][3] = 70;

            var F = new Vector(4);

            for (int i = 0; i < 4; i++)
            {
                F.Elem[i] = 1;
            }

            Householder.StartSolverQR(A, F);

            Assert.True(true);
        }
Ejemplo n.º 6
0
        private void button1_MouseClick(object sender, MouseEventArgs e)
        {
            ReadFromFile();
                b = new DenseVector(n, n);
                b = A.Multiply(s);    // Punctul 1

                Giv_R = new DenseMatrix(n, n);
                Giv_Q = new DenseMatrix(n, n);

                //Givens
                Givens_Decomposition(A,b); // Punctul 2

                dnAnalytics.LinearAlgebra.Decomposition.IQR t;
                t = new Householder(A);
                textBox1.AppendText("\r\nR\r\n\r\n");
                print_matrix(t.R());
                textBox1.AppendText("\r\nR\r\n\r\n");
                print_matrix(Giv_R);
                textBox1.AppendText("Q\r\n\r\n");
                print_matrix(t.Q());
                textBox1.AppendText("Q\r\n\r\n");
                print_matrix(Giv_Q);
        }
        public void When_Solve_ORT()
        {
            // Arrange
            Matrix A = new Matrix(3, 3);

            A.Elem[0][0] = 2;
            A.Elem[0][1] = 3;
            A.Elem[0][2] = -1;

            A.Elem[1][0] = 1;
            A.Elem[1][1] = -2;
            A.Elem[1][2] = 1;

            A.Elem[2][0] = 1;
            A.Elem[2][1] = 0;
            A.Elem[2][2] = 2;

            Vector F = new Vector(3);

            F.Elem[0] = 9;
            F.Elem[1] = 3;
            F.Elem[2] = 2;


            // Act
            Vector gramSchmidtC = GramSchmidt.StartModifiedSolverQR(A, F);
            Vector gramSchmidtM = GramSchmidt.StartModifiedSolverQR(A, F);
            Vector givens       = Givens.StartSolverQR(A, F);
            Vector householder  = Householder.StartSolverQR(A, F);

            // Assert
            Assert.That(A * gramSchmidtC == F);
            Assert.That(A * gramSchmidtM == F);
            Assert.That(A * givens == F);
            Assert.That(A * householder == F);
        }
Ejemplo n.º 8
0
        private void button6_Click(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;

            eps = Math.Pow(10, -Convert.ToInt32(tbeps.Text));

            button7.Enabled = false;
            button8.Enabled = false;
            button9.Enabled = false;

            double[,] mat = tomat(tbA.Text);
            lA = new SparseMatrix(mat);
            n=lA.Rows;
            show("Lib A initiated !");

            lB = new SparseMatrix(n, 1);
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    lB[i, 0] += mat[i, j] * (j + 1);
            tbB.Clear();
            tbB.AppendText(lB.ToString());

            h = new Householder(lA);
            tbR.Clear();
            tbR.AppendText(h.R().ToString());
            tbQ.Clear();
            tbQ.AppendText(h.Q().ToString());

            Matrix lQp = new SparseMatrix(n, n);
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    lQp[j, i] = h.Q()[i, j];

            Matrix lBp = lQp.Multiply(lB);
            tbBb.Clear();
            tbBb.AppendText(lBp.ToString());

            show("Lib Q,R calculated !");
            button7.Enabled = true;
            button9.Enabled = true;

            tqr = DateTime.Now - dt;
        }