Пример #1
0
        public void ConsiderTest(
            [Range(0.0f, 10.0f, 2.5f)] float xval1,
            [Range(0.0f, 10.0f, 2.5f)] float xval2)
        {
            // NEVER use the derived class to call
            // Consider otherwise the machinery in the base
            // class is never called!
            IOption option = new Option();

            (option as Option).SetAction(new MockAction());
            var cd1 = new OptionConsideration1();

            cd1.NameId = "cd1";
            var cd2 = new OptionConsideration2();

            cd2.NameId = "cd2";
            option.AddConsideration(cd1);
            option.AddConsideration(cd2);
            _optionContext.XVal1 = xval1;
            _optionContext.XVal2 = xval2;
            cd1.Consider(_optionContext);
            cd2.Consider(_optionContext);
            var cUtil1 = cd1.Utility;
            var cUtil2 = cd2.Utility;
            var cUtilL = new List <Utility>();

            cUtilL.Add(cUtil1);
            cUtilL.Add(cUtil2);
            var cNorm = cUtilL.WeightedMetrics();

            option.Consider(_optionContext);
            Assert.That(option.Utility.Value, Is.EqualTo(cNorm).Within(Tolerance));
        }
Пример #2
0
        public void ConsiderTest(
            [Range(0.0f, 10.0f, 2.5f)] float xval1,
            [Range(0.0f, 10.0f, 2.5f)] float xval2)
        {
            // NEVER use the derived class to call
            // Consider otherwise the machinery in the base
            // class is never called!
            IOption option = new ConstantUtilityOption();

            option.DefaultUtility = xval1;
            (option as Option).SetAction(new MockAction());
            var cd1 = new OptionConsideration1();
            var cd2 = new OptionConsideration2();

            option.AddConsideration(cd1);
            option.AddConsideration(cd2);
            _optionContext.XVal1 = xval1;
            _optionContext.XVal2 = xval2;
            cd1.Consider(_optionContext);
            cd2.Consider(_optionContext);
            var cUtil1 = cd1.Utility;
            var cUtil2 = cd2.Utility;
            var cUtilL = new List <Utility>();

            cUtilL.Add(cUtil1);
            cUtilL.Add(cUtil2);

            option.Consider(_optionContext);
            Assert.That(option.Utility.Value, Is.EqualTo(xval1.Clamp01()).Within(1e-6f));
        }
Пример #3
0
        public void ConsiderTest2(
            [Range(0.0f, 10.0f, 2.5f)] float xval1,
            [Range(0.0f, 10.0f, 2.5f)] float xval2,
            [Values(0.1f, 0.5f, 0.8f)] float threshold)
        {
            // NEVER use the derived class to call
            // Consider otherwise the machinery in the base
            // class is never called!
            var option  = new Option() as IOption;
            var measure = new ConstrainedChebyshev();

            option.Measure     = measure;
            measure.LowerBound = threshold;

            (option as Option).SetAction(new MockAction());
            var cd1 = new OptionConsideration1();
            var cd2 = new OptionConsideration2();

            cd1.NameId = "cd1";
            cd2.NameId = "cd2";
            option.AddConsideration(cd1);
            option.AddConsideration(cd2);
            _optionContext.XVal1 = xval1;
            _optionContext.XVal2 = xval2;
            cd1.Consider(_optionContext);
            cd2.Consider(_optionContext);
            var cUtil1 = cd1.Utility;
            var cUtil2 = cd2.Utility;
            var cUtilL = new List <Utility>();

            cUtilL.Add(cUtil1);
            cUtilL.Add(cUtil2);
            var cNorm = cUtilL.Chebyshev();

            if (cUtil1.Combined < threshold ||
                cUtil2 < threshold)
            {
                cNorm = 0.0f;
            }
            option.Consider(_optionContext);
            Assert.That(option.Utility.Value, Is.EqualTo(cNorm).Within(1e-6f));
        }