Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            PopulationDensity populationDensity = db.PopulationDensities.Find(id);

            db.PopulationDensities.Remove(populationDensity);
            db.SaveChanges();
            return(RedirectToAction("Create"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "PopDensityID,MunicipalityID,LandArea,PopulationPerArea,YearTaken")] PopulationDensity populationDensity)
 {
     if (ModelState.IsValid)
     {
         db.Entry(populationDensity).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Create"));
     }
     return(View(populationDensity));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Prefix = "Item1", Include = "PopDensityID,MunicipalityID,LandArea,PopulationPerArea,YearTaken")] PopulationDensity populationDensity)
        {
            if (ModelState.IsValid)
            {
                db.PopulationDensities.Add(populationDensity);
                db.SaveChanges();
                return(RedirectToAction("Create"));
            }

            return(View(populationDensity));
        }
Exemplo n.º 4
0
        // GET: PopulationDensity/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PopulationDensity populationDensity = db.PopulationDensities.Find(id);

            if (populationDensity == null)
            {
                return(HttpNotFound());
            }
            return(View(populationDensity));
        }
        public FuzzyLogicController()
        {
            populationDensity = new PopulationDensity();
            nonWhiteBritishEthnicityPercentage = new NonWhiteBritishEthnicityPercentage();
            numberOfUniversities = new NumberOfUniversities();
            averageSalary        = new AverageSalary();

            politicalLeaning = new PoliticalLeaning();

            fuzzyEngine = new FuzzyEngineFactory().Default();

            //Hard Left Leaning Rules
            var hardLeftRule1 = Rule
                                .If(populationDensity.Input
                                    .Is(populationDensity.Medium)
                                    .And(nonWhiteBritishEthnicityPercentage.Input
                                         .Is(nonWhiteBritishEthnicityPercentage.Medium))
                                    .And(numberOfUniversities.Input
                                         .Is(numberOfUniversities.Medium))
                                    .And(averageSalary.Input
                                         .Is(averageSalary.High)))
                                .Then(politicalLeaning.Output
                                      .Is(politicalLeaning.HardLeft));

            //Left Leaning Rules
            var leftRule1 = Rule
                            .If(populationDensity.Input
                                .Is(populationDensity.High)
                                .And(nonWhiteBritishEthnicityPercentage.Input
                                     .Is(nonWhiteBritishEthnicityPercentage.Medium))
                                .And(numberOfUniversities.Input
                                     .Is(numberOfUniversities.Low))
                                .And(averageSalary.Input
                                     .Is(averageSalary.Medium)))
                            .Then(politicalLeaning.Output
                                  .Is(politicalLeaning.Left));

            var leftRule2 = Rule
                            .If(populationDensity.Input
                                .Is(populationDensity.High)
                                .And(nonWhiteBritishEthnicityPercentage.Input
                                     .Is(nonWhiteBritishEthnicityPercentage.Low))
                                .And(numberOfUniversities.Input
                                     .Is(numberOfUniversities.Low))
                                .And(averageSalary.Input
                                     .Is(averageSalary.Medium)))
                            .Then(politicalLeaning.Output
                                  .Is(politicalLeaning.Left));

            var leftRule3 = Rule
                            .If(populationDensity.Input
                                .Is(populationDensity.Medium)
                                .And(nonWhiteBritishEthnicityPercentage.Input
                                     .Is(nonWhiteBritishEthnicityPercentage.Low))
                                .And(numberOfUniversities.Input
                                     .Is(numberOfUniversities.High))
                                .And(averageSalary.Input
                                     .Is(averageSalary.Medium)))
                            .Then(politicalLeaning.Output
                                  .Is(politicalLeaning.Left));

            //Centre Left Leaning Rules
            var centreLeftRule1 = Rule
                                  .If(populationDensity.Input
                                      .Is(populationDensity.High)
                                      .And(nonWhiteBritishEthnicityPercentage.Input
                                           .Is(nonWhiteBritishEthnicityPercentage.Medium))
                                      .And(numberOfUniversities.Input
                                           .Is(numberOfUniversities.Medium))
                                      .And(averageSalary.Input
                                           .Is(averageSalary.Medium)))
                                  .Then(politicalLeaning.Output
                                        .Is(politicalLeaning.CentreLeft));

            var centreLeftRule2 = Rule
                                  .If(populationDensity.Input
                                      .Is(populationDensity.Medium)
                                      .And(nonWhiteBritishEthnicityPercentage.Input
                                           .Is(nonWhiteBritishEthnicityPercentage.High))
                                      .And(numberOfUniversities.Input
                                           .Is(numberOfUniversities.Low))
                                      .And(averageSalary.Input
                                           .Is(averageSalary.Medium)))
                                  .Then(politicalLeaning.Output
                                        .Is(politicalLeaning.CentreLeft));

            var centreLeftRule3 = Rule
                                  .If(populationDensity.Input
                                      .Is(populationDensity.Medium)
                                      .And(nonWhiteBritishEthnicityPercentage.Input
                                           .Is(nonWhiteBritishEthnicityPercentage.Medium))
                                      .And(numberOfUniversities.Input
                                           .Is(numberOfUniversities.Low))
                                      .And(averageSalary.Input
                                           .Is(averageSalary.VeryHigh)))
                                  .Then(politicalLeaning.Output
                                        .Is(politicalLeaning.CentreLeft));

            //Centre Leaning Rules
            var centreRule1 = Rule
                              .If(populationDensity.Input
                                  .Is(populationDensity.Medium)
                                  .And(nonWhiteBritishEthnicityPercentage.Input
                                       .Is(nonWhiteBritishEthnicityPercentage.Low))
                                  .And(numberOfUniversities.Input
                                       .Is(numberOfUniversities.Low))
                                  .And(averageSalary.Input
                                       .Is(averageSalary.Medium)))
                              .Then(politicalLeaning.Output
                                    .Is(politicalLeaning.Centre));

            var centreRule2 = Rule
                              .If(populationDensity.Input
                                  .Is(populationDensity.VeryHigh)
                                  .And(nonWhiteBritishEthnicityPercentage.Input
                                       .Is(nonWhiteBritishEthnicityPercentage.High))
                                  .And(numberOfUniversities.Input
                                       .Is(numberOfUniversities.VeryHigh))
                                  .And(averageSalary.Input
                                       .Is(averageSalary.VeryHigh)))
                              .Then(politicalLeaning.Output
                                    .Is(politicalLeaning.Centre));

            //Centre Right Leaning Rules
            var centreRightRule1 = Rule
                                   .If(populationDensity.Input
                                       .Is(populationDensity.Low)
                                       .And(nonWhiteBritishEthnicityPercentage.Input
                                            .Is(nonWhiteBritishEthnicityPercentage.Low))
                                       .And(numberOfUniversities.Input
                                            .Is(numberOfUniversities.Medium))
                                       .And(averageSalary.Input
                                            .Is(averageSalary.Medium)))
                                   .Then(politicalLeaning.Output
                                         .Is(politicalLeaning.CentreRight));

            var centreRightRule2 = Rule
                                   .If(populationDensity.Input
                                       .Is(populationDensity.Medium)
                                       .And(nonWhiteBritishEthnicityPercentage.Input
                                            .Is(nonWhiteBritishEthnicityPercentage.High))
                                       .And(numberOfUniversities.Input
                                            .Is(numberOfUniversities.Low))
                                       .And(averageSalary.Input
                                            .Is(averageSalary.High)))
                                   .Then(politicalLeaning.Output
                                         .Is(politicalLeaning.CentreRight));

            var centreRightRule3 = Rule
                                   .If(populationDensity.Input
                                       .Is(populationDensity.Medium)
                                       .And(nonWhiteBritishEthnicityPercentage.Input
                                            .Is(nonWhiteBritishEthnicityPercentage.Medium))
                                       .And(numberOfUniversities.Input
                                            .Is(numberOfUniversities.Low))
                                       .And(averageSalary.Input
                                            .Is(averageSalary.High)))
                                   .Then(politicalLeaning.Output
                                         .Is(politicalLeaning.CentreRight));

            //Right Leaning Rules
            var rightRule1 = Rule
                             .If(populationDensity.Input
                                 .Is(populationDensity.Low)
                                 .And(nonWhiteBritishEthnicityPercentage.Input
                                      .Is(nonWhiteBritishEthnicityPercentage.Low))
                                 .And(numberOfUniversities.Input
                                      .Is(numberOfUniversities.Low))
                                 .And(averageSalary.Input
                                      .Is(averageSalary.Medium)))
                             .Then(politicalLeaning.Output
                                   .Is(politicalLeaning.Right));

            var rightRule2 = Rule
                             .If(populationDensity.Input
                                 .Is(populationDensity.VeryLow)
                                 .And(nonWhiteBritishEthnicityPercentage.Input
                                      .Is(nonWhiteBritishEthnicityPercentage.Low))
                                 .And(numberOfUniversities.Input
                                      .Is(numberOfUniversities.Low))
                                 .And(averageSalary.Input
                                      .Is(averageSalary.Medium)))
                             .Then(politicalLeaning.Output
                                   .Is(politicalLeaning.Right));

            var rightRule3 = Rule
                             .If(populationDensity.Input
                                 .Is(populationDensity.Medium)
                                 .And(nonWhiteBritishEthnicityPercentage.Input
                                      .Is(nonWhiteBritishEthnicityPercentage.Low))
                                 .And(numberOfUniversities.Input
                                      .Is(numberOfUniversities.Low))
                                 .And(averageSalary.Input
                                      .Is(averageSalary.High)))
                             .Then(politicalLeaning.Output
                                   .Is(politicalLeaning.Right));

            //Hard Right Leaning Rules
            var hardRightRule1 = Rule
                                 .If(populationDensity.Input
                                     .Is(populationDensity.Low)
                                     .And(nonWhiteBritishEthnicityPercentage.Input
                                          .Is(nonWhiteBritishEthnicityPercentage.Low))
                                     .And(numberOfUniversities.Input
                                          .Is(numberOfUniversities.Low))
                                     .And(averageSalary.Input
                                          .Is(averageSalary.High)))
                                 .Then(politicalLeaning.Output
                                       .Is(politicalLeaning.HardRight));


            fuzzyEngine.Rules.Add(hardLeftRule1, leftRule1, leftRule2, leftRule3, centreLeftRule1, centreLeftRule2, centreLeftRule3, centreRule1, centreRule2, centreRightRule1, centreRightRule2, centreRightRule3, rightRule1, rightRule2, rightRule3, hardRightRule1);
        }