Ejemplo n.º 1
0
        Option CreateOptionB()
        {
            var optionRootB = new Option();

            optionRootB.Measure = new Chebyshev();
            optionRootB.NameId  = "Root Option B";
            optionRootB.SetAction(new MockAction());
            var optionL1B = new CompositeConsideration {
                Measure = new Chebyshev()
            };

            optionL1B.NameId = "l1b";
            var optionL2B = new CompositeConsideration {
                Measure = new Chebyshev()
            };

            optionL2B.NameId = "l2b";
            optionRootB.AddConsideration(optionL1B);
            optionRootB.AddConsideration(optionL2B);
            optionL1B.AddConsideration(_c5);
            optionL1B.AddConsideration(_c6);
            optionL2B.AddConsideration(_c7);
            optionL2B.AddConsideration(_c8);
            return(optionRootB);
        }
Ejemplo n.º 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 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));
        }
Ejemplo n.º 3
0
        Option CreateOptionA()
        {
            var optionRootA = new Option();

            optionRootA.Measure = new Chebyshev();
            optionRootA.SetAction(new MockAction());
            optionRootA.NameId = "Root Option A";

            var optionL1A = new CompositeConsideration {
                Measure = new Chebyshev()
            };

            optionL1A.NameId = "l1a";
            var optionL2A = new CompositeConsideration {
                Measure = new Chebyshev()
            };

            optionL2A.NameId = "l2a";
            optionRootA.AddConsideration(optionL1A);
            optionRootA.AddConsideration(optionL2A);
            optionL1A.AddConsideration(_c1);
            optionL1A.AddConsideration(_c2);
            optionL2A.AddConsideration(_c3);
            optionL2A.AddConsideration(_c4);
            return(optionRootA);
        }
Ejemplo n.º 4
0
        void SetupOptions()
        {
            _options.Clear();
            IOption tmpo;

            tmpo = new Option("o1", _options);
            tmpo.SetAction("a1");
            tmpo.AddConsideration("c1");
            tmpo.AddConsideration("c2");

            tmpo = new Option("o2", _options);
            tmpo.SetAction("a2");
            tmpo.AddConsideration("c3");
            tmpo.AddConsideration("c4");
        }
Ejemplo n.º 5
0
        public void ConsiderationsCanUseParameterValues([Range(0.0f, 10.0f, 5f)] float util)
        {
            _aiConstructor.AIs.ClearAll();
            SetupActionsAndConsiderations();
            OptionParameters linear = new OptionParameters();

            linear.Power = false;
            var linearOption = new Option("o2", _aiConstructor.Options, linear);

            Assert.That(linearOption.SetAction("a2"), Is.True);
            Assert.That(linearOption.AddConsideration("c1"), Is.True);
            OptionParameters power = new OptionParameters();

            power.Power = true;
            var powerOption = new Option("o1", _aiConstructor.Options, power);

            Assert.That(powerOption.SetAction("a1"), Is.True);
            Assert.That(powerOption.AddConsideration("c1"), Is.True);
            var context = new OptionContext();

            context.XVal9 = util;
            linearOption.Consider(context);
            powerOption.Consider(context);
            if (util == 0.0f || util == 10.0f)
            {
                Assert.AreEqual(linearOption.Utility.Value, powerOption.Utility.Value);
            }
            else
            {
                Assert.Greater(linearOption.Utility.Value, powerOption.Utility.Value);
            }
        }
Ejemplo n.º 6
0
        public void ClonedOptionHasAllPreviousConsiderationsTest()
        {
            _aiConstructor.AIs.ClearAll();
            SetupActionsAndConsiderations();
            var o = new Option("o1", _aiConstructor.Options);

            o.AddConsideration("c1");
            o.AddConsideration("c2");
            o.AddConsideration("c3");
            o.AddConsideration("c4");
            var oc = o.Clone() as IOption;

            Assert.IsNotNull(oc);
            Assert.That(oc.AddConsideration("c1"), Is.False);
            Assert.That(oc.AddConsideration("c2"), Is.False);
            Assert.That(oc.AddConsideration("c3"), Is.False);
            Assert.That(oc.AddConsideration("c4"), Is.False);
            Assert.That(oc.AddConsideration("c5"), Is.True);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        protected override void DefineOptions()
        {
            O = new Option(OptionDefs.Drink, Options);
            O.SetAction(ActionDefs.Drink);
            O.AddConsideration(ConsiderationDefs.Thirst);

            O = new Option(OptionDefs.Eat, Options);
            O.SetAction(ActionDefs.Eat);
            O.AddConsideration(ConsiderationDefs.Hunger);

            O = new Option(OptionDefs.Shower, Options);
            O.SetAction(ActionDefs.Shower);
            O.AddConsideration(ConsiderationDefs.Shower);

            O = new Option(OptionDefs.Sleep, Options);
            O.SetAction(ActionDefs.Sleep);
            O.AddConsideration(ConsiderationDefs.Tiredness);

            O = new Option(OptionDefs.Toilet, Options);
            O.SetAction(ActionDefs.Toilet);
            O.AddConsideration(ConsiderationDefs.Bladder);

            O = new Option(OptionDefs.Exercise, Options);
            O.SetAction(ActionDefs.PhysicalExercise);
            O.AddConsideration(ConsiderationDefs.HowUnfit);
            O.AddConsideration(ConsiderationDefs.Energy);
            O.Measure = new MultiplicativePseudoMeasure();

            O = new Option(OptionDefs.Work, Options);
            O.SetAction(ActionDefs.Work);
            O.AddConsideration(ConsiderationDefs.Greed);

            O = new Option(OptionDefs.Read, Options);
            O.SetAction(ActionDefs.Read);
            O.AddConsideration(ConsiderationDefs.Curiosity);

            O = new ConstantUtilityOption(OptionDefs.Idle, Options);
            O.SetAction(ActionDefs.Idle);
            O.DefaultUtility = new Utility(0.01f, 1f);
        }
Ejemplo n.º 9
0
        protected override void DefineOptions()
        {
            O = new Option(EatOption, Options);
            O.SetAction(EatAction);
            IsOkay(O.AddConsideration(HungerConsideration));

            O = new Option(DrinkOption, Options);
            O.SetAction(DrinkAction);
            IsOkay(O.AddConsideration(ThirstConsideration));

            O = new Option(ToiletOption, Options);
            O.SetAction(ToiletAction);
            IsOkay(O.AddConsideration(BladderConsideration));

            O = new Option(ShowerOption, Options);
            O.SetAction(ShowerAction);
            IsOkay(O.AddConsideration(CleanlinessConsideration));
        }
Ejemplo n.º 10
0
        public void EnsureClonedOptionHasResultsInSameUtilityTest([Range(0.0f, 10.0f, 1f)] float util)
        {
            _aiConstructor.AIs.ClearAll();
            SetupActionsAndConsiderations();
            var context = new OptionContext();
            var o       = new Option("o1", _aiConstructor.Options);

            Assert.IsNotNull(o);
            Assert.That(o.SetAction("a1"), Is.True);
            o.AddConsideration("c1");
            var oc = o.Clone() as IOption;

            Assert.IsNotNull(oc);

            context.XVal1 = util;
            o.Consider(context);
            oc.Consider(context);
            Assert.AreEqual(o.Utility.Value, oc.Utility.Value);
            Assert.AreEqual(o.Utility.Weight, oc.Utility.Weight);
            Console.WriteLine("{0}", o.Utility.Value);
        }