Beispiel #1
0
        public override void Handle(KAOSCoreElement element, ParsedProbabilityAttribute attribute, KAOSModel model)
        {
            var doubleSatisfactionRate = new DoubleSatisfactionRate(attribute.Value);

            if (attribute.ExpertIdentifier != null)
            {
                if (model.modelMetadataRepository.ExpertExists(attribute.ExpertIdentifier))
                {
                    doubleSatisfactionRate.ExpertIdentifier = attribute.ExpertIdentifier;
                }
                else
                {
                    throw new BuilderException("Expert '" + attribute.ExpertIdentifier + "' is not defined.", attribute);
                }
            }

            if (element is Obstacle)
            {
                model.satisfactionRateRepository.AddObstacleSatisfactionRate(element.Identifier, doubleSatisfactionRate);
            }
            else if (element is DomainProperty)
            {
                model.satisfactionRateRepository.AddDomPropSatisfactionRate(element.Identifier, doubleSatisfactionRate);
            }
            else if (element is Calibration)
            {
                model.satisfactionRateRepository.AddCalibrationSatisfactionRate(element.Identifier, doubleSatisfactionRate);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #2
0
        protected void TestCase(double o1_esr, double o2_esr, double c1, double c2, double expected_root_esr)
        {
            Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
            const string filename = "./Examples/CaseModel.kaos";

            ModelBuilder parser = new ModelBuilder();
            string       input  = File.ReadAllText(filename);
            var          model  = parser.Parse(input, filename);

            var root = model.Goal("root");

            var refinement = model.GoalRefinements().Single();
            var p1         = (PrimitiveRefineeParameter <double>)refinement.SubGoalIdentifiers.Single(x => x.Identifier == "m1").Parameters;
            var p2         = (PrimitiveRefineeParameter <double>)refinement.SubGoalIdentifiers.Single(x => x.Identifier == "m2").Parameters;

            p1.Value = c1;
            p2.Value = c2;

            model.satisfactionRateRepository.AddObstacleSatisfactionRate("o1", new DoubleSatisfactionRate(o1_esr));
            model.satisfactionRateRepository.AddObstacleSatisfactionRate("o2", new DoubleSatisfactionRate(o2_esr));

            var _propagator       = GetPropagator(model);
            ISatisfactionRate esr = _propagator.GetESR(root);

            Assert.IsInstanceOf(typeof(DoubleSatisfactionRate), esr);
            DoubleSatisfactionRate esrd = (DoubleSatisfactionRate)esr;

            Assert.AreEqual(expected_root_esr, esrd.SatisfactionRate, 0.0001);
        }
Beispiel #3
0
        public static void Main(string [] args)
        {
            Console.WriteLine("*** This is Propagator from KAOSTools. ***");
            Console.WriteLine("*** For more information on KAOSTools see <https://github.com/ancailliau/KAOSTools> ***");
            Console.WriteLine("*** Please report bugs to <https://github.com/ancailliau/KAOSTools/issues> ***");
            Console.WriteLine();
            Console.WriteLine("*** Copyright (c) 2017, Université catholique de Louvain ***");
            Console.WriteLine("");

            string rootname = "root";

            options.Add("root=", "Specify the root goal for which to compute the satisfaction rate. (Default: root)", v => rootname = v);

            bool bdd = true;

            options.Add("bdd", "Uses the BDD-Based propagation (Default)", v => bdd = true);
            options.Add("pattern", "Uses the Pattern-Based propagation", v => bdd   = false);

            Init(args);

            var root = model.Goal(rootname);

            if (root == null)
            {
                PrintError("The goal '" + rootname + "' was not found");
            }

            try {
                IPropagator _propagator;
                if (bdd)
                {
                    _propagator = new BDDBasedPropagator(model);
                }
                else
                {
                    _propagator = new PatternBasedPropagator(model);
                }

                ISatisfactionRate      esr  = _propagator.GetESR(root);
                DoubleSatisfactionRate esrd = (DoubleSatisfactionRate)esr;

                Console.WriteLine(root.FriendlyName + ": {0:P}", esrd.SatisfactionRate);
            } catch (Exception e) {
                PrintError("An error occured during the computation. (" + e.Message + ").\n"
                           + "Please report this error to <https://github.com/ancailliau/KAOSTools/issues>.\n"
                           + "----------------------------\n"
                           + e.StackTrace
                           + "\n----------------------------\n");
            }
        }
Beispiel #4
0
        protected void TestDivideAndConquer(double o1_esr, double o2_esr, double expected_root_esr)
        {
            Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
            const string filename = "./Examples/DivideAndConquerModel.kaos";

            ModelBuilder parser = new ModelBuilder();
            string       input  = File.ReadAllText(filename);
            var          model  = parser.Parse(input, filename);

            var root = model.Goal("root");

            model.satisfactionRateRepository.AddObstacleSatisfactionRate("o1", new DoubleSatisfactionRate(o1_esr));
            model.satisfactionRateRepository.AddObstacleSatisfactionRate("o2", new DoubleSatisfactionRate(o2_esr));

            var _propagator       = GetPropagator(model);
            ISatisfactionRate esr = _propagator.GetESR(root);

            Assert.IsInstanceOf(typeof(DoubleSatisfactionRate), esr);
            DoubleSatisfactionRate esrd = (DoubleSatisfactionRate)esr;

            Assert.AreEqual(expected_root_esr, esrd.SatisfactionRate, 0.0001);
        }