private List <LinguisticVariable> PrepareLinguisticVariables()
        {
            // Water variable
            MembershipFunctionList firstMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Cold", 0, 20, 20, 30),
                new TrapezoidalMembershipFunction("Hot", 50, 60, 60, 80)
            };
            LinguisticVariable firstLinguisticVariable =
                new LinguisticVariable("Water", firstMembershipFunctionList, isInitialData: true);

            // Pressure vatiable
            MembershipFunctionList secondsMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Low", 20, 50, 50, 60),
                new TrapezoidalMembershipFunction("Medium", 60, 65, 65, 80),
                new TrapezoidalMembershipFunction("High", 80, 100, 100, 150)
            };
            LinguisticVariable secondLinguisticVariable =
                new LinguisticVariable("Pressure", secondsMembershipFunctionList, isInitialData: false);

            List <LinguisticVariable> variables = new List <LinguisticVariable>
            {
                firstLinguisticVariable, secondLinguisticVariable
            };

            return(variables);
        }
        public void MembershipFunctionList_GetterReturnsValue()
        {
            // Act
            MembershipFunctionList membershipFunctionList = _linguisticVariable.MembershipFunctionList;

            // Assert
            Assert.IsTrue(ObjectComparer.MembershipFunctionListsAreEqual(_membershipFunctions, membershipFunctionList));
        }
        public void FindByVariableName_ThrowsArgumentNullExceptionIfThereAreNoMembershipFunctionsInList()
        {
            // Arrange
            _membershipFunctionList = new MembershipFunctionList();
            string variableName = "AnyName";

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => { _membershipFunctionList.FindByVariableName(variableName); });
        }
 public void SetUp()
 {
     _membershipFunctionList = new MembershipFunctionList
     {
         new StubMembershipFunction("FunctionNr1"),
         new StubMembershipFunction("FunctionNr2"),
         new StubMembershipFunction("FunctionNr3")
     };
 }
 private void PrepareMembershipFunctions()
 {
     _membershipFunctions = new MembershipFunctionList
     {
         new TrapezoidalMembershipFunction("Low", 0, 1, 2, 3),
         new TrapezoidalMembershipFunction("Middle", 4, 5, 6, 7),
         new TrapezoidalMembershipFunction("High", 10, 11, 12, 13)
     };
 }
Пример #6
0
        public void GetLinguisticVariables_ReturnsCorrectListOfVariables()
        {
            // Arrange
            var firstLinguisticVariableStringFromFile  = "[Water]:Initial:[Cold:Trapezoidal:(0,20,20,30)|Hot:Trapezoidal:(50,60,60,80)]";
            var secondLinguisticVariableStringFromFile = "[Pressure]:Derivative:[Low:Trapezoidal:(20,50,50,60)|High:Trapezoidal:(80,100,100,150)]";
            var linguisticVariablesInDatabase          = new List <string>
            {
                firstLinguisticVariableStringFromFile, secondLinguisticVariableStringFromFile
            };
            var profileName = "profile_name";
            var profile     = new InferenceProfile
            {
                ProfileName = profileName,
                Variables   = linguisticVariablesInDatabase
            };

            _profileRepositoryMock.Stub(x => x.GetProfileByName(profileName)).Return(Optional <InferenceProfile> .For(profile));

            // Water variable
            var firstMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Cold", 0, 20, 20, 30),
                new TrapezoidalMembershipFunction("Hot", 50, 60, 60, 80)
            };
            var firstLinguisticVariable  = new LinguisticVariable("Water", firstMembershipFunctionList, isInitialData: true);
            var firstLinguisticVariables = new List <LinguisticVariable> {
                firstLinguisticVariable
            };

            // Pressure variable
            var secondsMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Low", 20, 50, 50, 60),
                new TrapezoidalMembershipFunction("High", 80, 100, 100, 150)
            };
            var secondLinguisticVariable  = new LinguisticVariable("Pressure", secondsMembershipFunctionList, isInitialData: false);
            var secondLinguisticVariables = new List <LinguisticVariable> {
                secondLinguisticVariable
            };

            var expectedLinguisticVariables = new List <LinguisticVariable>
            {
                firstLinguisticVariable, secondLinguisticVariable
            };
            var expectedOptional = Optional <List <LinguisticVariable> > .For(expectedLinguisticVariables);

            // Stubs
            _linguisticVariableCreatorMock.Stub(x => x.CreateLinguisticVariableEntities(firstLinguisticVariableStringFromFile)).Return(firstLinguisticVariables);
            _linguisticVariableCreatorMock.Stub(x => x.CreateLinguisticVariableEntities(secondLinguisticVariableStringFromFile)).Return(secondLinguisticVariables);

            // Act
            var actualOptional = _databaseLinguisticVariableProvider.GetLinguisticVariables(profileName);

            // Assert
            Assert.IsTrue(expectedOptional.IsPresent);
            Assert.AreEqual(expectedOptional.Value, actualOptional.Value);
        }
Пример #7
0
        private LinguisticVariable PrepareLinguisticVariable()
        {
            MembershipFunctionList functionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Cold", 0, 20, 25, 30),
                new TrapezoidalMembershipFunction("Warm", 28, 40, 45, 50)
            };

            return(new LinguisticVariable("Temperature", functionList, isInitialData: true));
        }
        private Dictionary <int, LinguisticVariable> PrepateLinguisticVariables()
        {
            MembershipFunctionList firstMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Cold", 0, 20, 20, 30),
                new TrapezoidalMembershipFunction("Hot", 50, 60, 60, 80)
            };
            LinguisticVariable firstLinguisticVariable = new LinguisticVariable("Temperature", firstMembershipFunctionList, isInitialData: true);

            MembershipFunctionList secondMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Low", 20, 50, 50, 60),
                new TrapezoidalMembershipFunction("High", 80, 100, 100, 150)
            };
            LinguisticVariable secondLinguisticVariable = new LinguisticVariable("Pressure", secondMembershipFunctionList, isInitialData: false);

            MembershipFunctionList thirdMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Small", 100, 200, 200, 600),
                new TrapezoidalMembershipFunction("Big", 800, 1000, 1000, 1500)
            };
            LinguisticVariable thirdLinguisticVariable = new LinguisticVariable("Volume", thirdMembershipFunctionList, isInitialData: true);

            MembershipFunctionList fourthMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Blue", 5, 10, 10, 20),
                new TrapezoidalMembershipFunction("Red", 50, 60, 60, 80)
            };
            LinguisticVariable fourthLinguisticVariable = new LinguisticVariable("Color", fourthMembershipFunctionList, isInitialData: true);

            MembershipFunctionList fifthMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Low", 5, 10, 10, 20),
                new TrapezoidalMembershipFunction("High", 50, 60, 60, 80)
            };
            LinguisticVariable fifthLinguisticVariable = new LinguisticVariable("Danger", fifthMembershipFunctionList, isInitialData: false);

            MembershipFunctionList sixthMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("True", 5, 10, 10, 20),
                new TrapezoidalMembershipFunction("False", 50, 60, 60, 80)
            };
            LinguisticVariable sixthLinguisticVariable = new LinguisticVariable("Evacuate", sixthMembershipFunctionList, isInitialData: false);

            return(new Dictionary <int, LinguisticVariable>
            {
                { 1, firstLinguisticVariable },
                { 2, secondLinguisticVariable },
                { 3, thirdLinguisticVariable },
                { 4, fourthLinguisticVariable },
                { 5, fifthLinguisticVariable },
                { 6, sixthLinguisticVariable }
            });
        }
        private LinguisticVariable CreateLinguisticVariableEntity(LinguisticVariableStrings linguisticVariableStrings)
        {
            var isInitial           = linguisticVariableStrings.DataOrigin.ToEnum <DataOriginType>() == DataOriginType.Initial;
            var membershipFunctions = new MembershipFunctionList();

            foreach (var membershipFunctionStrings in linguisticVariableStrings.MembershipFunctions)
            {
                var functionType       = membershipFunctionStrings.MembershipFunctionType.ToEnum <MembershipFunctionType>();
                var membershipFunction = _membershipFunctionCreator.CreateMembershipFunctionEntity(
                    functionType, membershipFunctionStrings.MembershipFunctionName, membershipFunctionStrings.MembershipFunctionValues);
                membershipFunctions.Add(membershipFunction);
            }
            return(new LinguisticVariable(linguisticVariableStrings.VariableName, membershipFunctions, isInitial));
        }
Пример #10
0
        public static bool MembershipFunctionListsAreEqual(
            MembershipFunctionList membershipFunctionListToCompare,
            MembershipFunctionList membershipFunctionListToCompareWith)
        {
            if (membershipFunctionListToCompare.Count != membershipFunctionListToCompareWith.Count)
            {
                return(false);
            }

            for (int i = 0; i < membershipFunctionListToCompare.Count; i++)
            {
                if (!MembershipFunctionsAreEqual(membershipFunctionListToCompare[i], membershipFunctionListToCompareWith[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #11
0
        private Dictionary <int, LinguisticVariable> PrepareExpectedLinguisticVariables()
        {
            // Water variable
            MembershipFunctionList firstMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Cold", 0, 20, 20, 30),
                new TrapezoidalMembershipFunction("Hot", 50, 60, 60, 80)
            };
            LinguisticVariable firstLinguisticVariable = new LinguisticVariable("Water", firstMembershipFunctionList, isInitialData: true);

            // Pressure variable
            MembershipFunctionList secondsMembershipFunctionList = new MembershipFunctionList
            {
                new TrapezoidalMembershipFunction("Low", 20, 50, 50, 60),
                new TrapezoidalMembershipFunction("High", 80, 100, 100, 150)
            };
            LinguisticVariable secondLinguisticVariable = new LinguisticVariable("Pressure", secondsMembershipFunctionList, isInitialData: false);

            return(new Dictionary <int, LinguisticVariable>
            {
                { 1, firstLinguisticVariable },
                { 2, secondLinguisticVariable }
            });
        }