Exemplo n.º 1
0
        public void Render(KAOSModel model)
        {
            //var goalsInRefinements = model.GoalRefinements ().SelectMany (x => x.SubGoals ().Union (new[] {
            //    x.ParentGoal ()
            //})).Distinct ();

            foreach (var g in model.Goals())
            {
                Render(g);
            }

            foreach (var d in model.GoalRefinements().SelectMany(x => x.DomainProperties()).Distinct())
            {
                Render(d);
            }

            foreach (var d in model.GoalRefinements().SelectMany(x => x.DomainHypotheses()).Distinct())
            {
                Render(d);
            }

            foreach (var r in model.GoalRefinements())
            {
                Render(r);
            }

            foreach (var r in model.GoalAgentAssignments())
            {
                Render(r, true);
            }
        }
Exemplo n.º 2
0
        public KAOSModel Parse(string input, string filename)
        {
            KAOSModel       model   = new KAOSModel();
            GoalModelParser _parser = new GoalModelParser();

            Uri RelativePath = null;

            if (!string.IsNullOrEmpty(filename))
            {
                RelativePath = new Uri(Path.GetFullPath(Path.GetDirectoryName(filename) + "/"));
            }

            FirstStageBuilder  FSB = new FirstStageBuilder(model, RelativePath);
            FormulaBuilder     FB  = new FormulaBuilder(model, RelativePath);
            SecondStageBuilder SSB = new SecondStageBuilder(model, RelativePath);
            ThirdStageBuilder  TSB = new ThirdStageBuilder(model, FB, RelativePath);

            var elements = _parser.Parse(input, filename) as ParsedElements;

            FSB.BuildElementWithKeys(elements);
            SSB.BuildElement(elements);
            TSB.BuildElement(elements);

            return(model);
        }
Exemplo n.º 3
0
 public ModelMonitor(KAOSModel model, IEnumerable <Goal> roots)
 {
     obstacleMonitors = new Dictionary <string, ObstacleMonitor>();
     _model_running   = model;
     _roots           = new HashSet <Goal>(roots);
     Initialize();
 }
Exemplo n.º 4
0
        public SingleValueCriticalObstacles(KAOSModel model, Goal root) : base(model, root)
        {
            _propagator = new BDDBasedPropagator(model);
            _propagator.PreBuildObstructionSet(root);

            rsr = root.RDS;
        }
Exemplo n.º 5
0
 public GoalRelaxedTo(KAOSModel model, string goalIdentifier, string obstacleIdentifier, Formula formula)
     : base(model)
 {
     GoalIdentifier     = goalIdentifier;
     ObstacleIdentifier = obstacleIdentifier;
     Formula            = formula;
 }
Exemplo n.º 6
0
        public override void Handle(Relation element, ParsedLinkAttribute attribute, KAOSModel model)
        {
            Entity entity;

            if (attribute.Target is IdentifierExpression)
            {
                string id = ((IdentifierExpression)attribute.Target).Value;
                if ((entity = model.entityRepository.GetEntity(id)) == null)
                {
                    entity = new Entity(model, id)
                    {
                        Implicit = true
                    };
                    model.entityRepository.Add(entity);
                }

                element.Links.Add(new Link(model)
                {
                    Target = entity, Multiplicity = attribute.Multiplicity
                });
            }
            else
            {
                throw new UnsupportedValue(element, attribute, attribute.Target);
            }
        }
Exemplo n.º 7
0
 public RandomModelGenerator(RandomModelOptions options)
 {
     this._options = options;
     _model        = new KAOSModel();
     _random       = new Random();
     _faker        = new Faker();
 }
Exemplo n.º 8
0
        public ThirdStageBuilder(KAOSModel model,
                                 FormulaBuilder fb,
                                 Uri relativePath)
            : base(model, relativePath)
        {
            declareBuilders.Add(new AgentDeclareBuilder());
            declareBuilders.Add(new AssociationDeclareBuilder());
            declareBuilders.Add(new CalibrationDeclareBuilder());
            declareBuilders.Add(new DomainHypothesisDeclareBuilder());
            declareBuilders.Add(new DomainPropertyDeclareBuilder());
            declareBuilders.Add(new EntityDeclareBuilder());
            declareBuilders.Add(new ExpertDeclareBuilder());
            declareBuilders.Add(new GoalDeclareBuilder());
            declareBuilders.Add(new SoftGoalDeclareBuilder());
            declareBuilders.Add(new TypeDeclareBuilder());
            declareBuilders.Add(new ObstacleDeclareBuilder());
            declareBuilders.Add(new PredicateDeclareBuilder());
            declareBuilders.Add(new ContextDeclareBuilder());

            attributeBuilders.Add(new ArgumentAttributeBuilder());
            attributeBuilders.Add(new FormalSpecAttributeBuilder(fb));

            attributeBuilders.Add(new ProvidedNotAttributeBuilder(fb));
            attributeBuilders.Add(new ProvidedAttributeBuilder(fb));
            attributeBuilders.Add(new RelaxedToAttributeBuilder(fb));
        }
Exemplo n.º 9
0
        public PatternBasedPropagator(KAOSModel model)
        {
            _model = model;

            goalCache     = new Dictionary <Goal, ISatisfactionRate>();
            obstacleCache = new Dictionary <Obstacle, ISatisfactionRate>();
        }
Exemplo n.º 10
0
        public override void Handle(Goal element, ParsedExceptAttribute attribute, KAOSModel model)
        {
            var exception = new GoalException(model);

            exception.AnchorGoalIdentifier       = element.Identifier;
            exception.ResolvingGoalIdentifier    = attribute.CountermeasureIdentifier;
            exception.ResolvedObstacleIdentifier = attribute.ObstacleIdentifier;

            if (!model.goalRepository.GoalExists(attribute.CountermeasureIdentifier))
            {
                model.Add(new Goal(model)
                {
                    Identifier = attribute.CountermeasureIdentifier,
                    Implicit   = true
                });
            }

            if (!model.obstacleRepository.ObstacleExists(attribute.ObstacleIdentifier))
            {
                model.Add(new Obstacle(model)
                {
                    Identifier = attribute.ObstacleIdentifier,
                    Implicit   = true
                });
            }

            model.Add(exception);
        }
        public void Render(Goal g, KAOSModel model)
        {
            Render(g);
            foreach (var e in g.Replacements())
            {
                Render(e.AnchorGoal());
                Render(e);
            }

            foreach (var r in g.ParentRefinements().Union(g.Refinements()))
            {
                if (!shapes.ContainsKey(r.ParentGoalIdentifier))
                {
                    Render(r.ParentGoal());
                }

                foreach (var sg in r.SubGoals())
                {
                    if (!shapes.ContainsKey(sg.Identifier))
                    {
                        Render(sg);
                    }
                }

                Render(r);
            }
        }
Exemplo n.º 12
0
 public NaiveCountermeasureSelectionOptimizerWithUncertainty(KAOSModel model, double threshold)
 {
     _model         = model;
     stats          = new OptimizationStatistics();
     integrator     = new SoftResolutionIntegrator(model);
     this.threshold = threshold;
 }
Exemplo n.º 13
0
 public GoalProvidedNot(KAOSModel model, string goalIdentifier, string obstacleIdentifier, Formula formula)
     : base(model)
 {
     GoalIdentifier     = goalIdentifier;
     ObstacleIdentifier = obstacleIdentifier;
     Formula            = formula;
 }
        public CriticalUncertainObstacles(KAOSModel model, Goal root) : base(model, root)
        {
            _propagator = new BDDBasedUncertaintyPropagator(model, n_samples);
            _propagator.PreBuildObstructionSet(root);

            rsr = root.RDS;
        }
Exemplo n.º 15
0
        public void Render(KAOSModel model)
        {
            var goals = model.Exceptions().SelectMany(x => new[] { x.AnchorGoal(), x.ResolvingGoal() });

            goals = goals.Union(model.ObstacleAssumptions().SelectMany(x => new[] { x.Anchor() })).Distinct();

            var obstacles = model.ObstacleAssumptions().SelectMany(x => new[] { x.Obstacle() });

            foreach (var g in goals)
            {
                Render(g);
            }

            foreach (var o in obstacles)
            {
                Render(o);
            }

            foreach (var e in model.Exceptions())
            {
                Render(e);
            }

            foreach (var e in model.ObstacleAssumptions())
            {
                Render(e);
            }
        }
        public override void Handle(Goal element, ParsedReplacesAttribute attribute, KAOSModel model)
        {
            var goalReplacement = new GoalReplacement(model);

            goalReplacement.AnchorGoalIdentifier       = element.Identifier;
            goalReplacement.ResolvingGoalIdentifier    = attribute.ReplacedGoalIdentifier;
            goalReplacement.ResolvedObstacleIdentifier = attribute.ObstacleIdentifier;
            model.Add(goalReplacement);
        }
Exemplo n.º 17
0
        public void TestParsedDeclareGoal()
        {
            var model   = new KAOSModel();
            var path    = new Uri("/tmp/fake");
            var builder = new FirstStageBuilder(model, path);

            builder.BuildDeclare(new ParsedGoal("my-goal"));
            model.Goals(x => x.Identifier == "my-goal").ShallBeSingle();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates a new monitoring infrastructure for the specified formulas.
        /// The projection is used to compute the hash of the observed states.
        /// </summary>
        /// <param name="elements">The goals to monitor.</param>
        /// <param name="storage">The storage.</param>
        /// <param name="defaultProjection">Projection.</param>
        public KAOSCoreElementMonitor(KAOSModel model,
                                      KAOSCoreElement elements,
                                      TimeSpan monitoringDelay)
        {
            Ready = false;

            this.model           = model;
            this.MonitoringDelay = monitoringDelay;
        }
 public void Render(Goal g, KAOSModel model)
 {
     Render(g);
     foreach (var e in g.Provided())
     {
         Render(e.Obstacle());
         Render(e);
     }
 }
Exemplo n.º 20
0
        public void TestFailWhenParsedDeclareUnknow()
        {
            var model   = new KAOSModel();
            var path    = new Uri("/tmp/fake");
            var builder = new FirstStageBuilder(model, path);

            Assert.Catch(() => {
                builder.BuildDeclare(new UnknownParsedDeclare("unknown"));
            });
        }
        public void Render(Obstacle o, KAOSModel model)
        {
            Render(o);
            foreach (var obstruction in o.model.Obstructions().Where(x => x.ObstacleIdentifier == o.Identifier))
            {
                Render(obstruction.ObstructedGoal());
                Render(obstruction);
            }

            RenderRefinement(o);
        }
Exemplo n.º 22
0
        public override void BuildDeclare(ParsedDeclare parsedElement, KAOSModel model)
        {
			Entity g = model.entityRepository.GetEntity(parsedElement.Identifier);
			if (g == null)
			{
				g = new Entity(model, parsedElement.Identifier);
				model.entityRepository.Add(g);
			} else if (!parsedElement.Override) {
				throw new BuilderException("Cannot declare twice the same element. Use override instead.", parsedElement);
			}
		}
Exemplo n.º 23
0
        public GoalMonitor(Goal goal,
                           KAOSModel model,
                           HashSet <string> projection,
                           IStateInformationStorage storage,
                           TimeSpan monitoringDelay) : base(model, goal, monitoringDelay)
        {
            this.goal    = goal;
            this.storage = storage;

            Initialize();
        }
Exemplo n.º 24
0
        public ObstacleMonitor(Obstacle obstacle,
                               KAOSModel model,
                               IStateInformationStorage storage,
                               TimeSpan monitoringDelay) : base(model, obstacle, monitoringDelay)
        {
            this.storage  = storage;
            this.obstacle = obstacle;

            SetProjection();
            Initialize();
        }
        public void Render(Goal g, KAOSModel model)
        {
            Render(g);

            // Exceptions
            foreach (var e in g.Exceptions())
            {
                if (!shapes.ContainsKey(e.ResolvingGoalIdentifier))
                {
                    Render(e.ResolvingGoal());
                }
                Render(e);
            }

            // Replacements
            foreach (var e in g.Replacements())
            {
                if (!shapes.ContainsKey(e.AnchorGoalIdentifier))
                {
                    Render(e.AnchorGoal());
                }
                Render(e);
            }

            // Provided
            foreach (var e in g.Provided())
            {
                if (!shapes.ContainsKey(e.ResolvedObstacleIdentifier))
                {
                    Render(e.Obstacle());
                }
                Render(e);
            }

            // Context refinements

            /*
             * foreach (var r in g.ParentRefinements ().Union (g.Refinements ())) {
             *  if (!shapes.ContainsKey (r.ParentGoalIdentifier)) {
             *      Render (r.ParentGoal ());
             *  }
             *
             *  foreach (var sg in r.SubGoals ()) {
             *      if (!shapes.ContainsKey (sg.Identifier)) {
             *          Render (sg);
             *      }
             *  }
             *
             *  Render (r);
             * }
             */
        }
        public void Render(KAOSModel model)
        {
            //var goalsInRefinements = model.GoalRefinements ().SelectMany (x => x.SubGoals ().Union (new[] {
            //    x.ParentGoal ()
            //})).Distinct ();

            foreach (var g in model.Goals())
            {
                Render(g);
            }

            foreach (var d in model.GoalRefinements().SelectMany(x => x.DomainProperties()).Distinct())
            {
                Render(d);
            }

            foreach (var r in model.GoalRefinements())
            {
                Render(r);
            }

            foreach (var o in model.Obstacles())
            {
                Render(o);
            }

            foreach (var o in model.ObstacleRefinements())
            {
                Render(o);
            }

            foreach (var o in model.Obstructions())
            {
                Render(o);
            }

            foreach (var o in model.Resolutions())
            {
                Render(o);
            }

            foreach (var r in model.GoalAgentAssignments())
            {
                Render(r, true);
            }

            foreach (var o in model.Resolutions())
            {
                RenderAnchorArrow(o);
            }
        }
Exemplo n.º 27
0
        public static ResponsibilityNode GetResponsibilities(this KAOSModel model)
        {
            var node = new ResponsibilityNode(null);

            foreach (var rootGoal in model.RootGoals())
            {
                RecursiveGetResponsibilities(node, rootGoal);
            }

            Factorize(node);
            Collapse(node);

            return(node);
        }
Exemplo n.º 28
0
        public override void BuildDeclare(ParsedDeclare parsedElement, KAOSModel model)
        {
            Obstacle g = model.obstacleRepository.GetObstacle(parsedElement.Identifier);

            if (g == null)
            {
                g = new Obstacle(model, parsedElement.Identifier);
                model.obstacleRepository.Add(g);
            }
            else if (!parsedElement.Override)
            {
                throw new BuilderException("Cannot declare twice the same element '" + parsedElement.Identifier + "'. Use override instead.", parsedElement);
            }
        }
Exemplo n.º 29
0
        public override void BuildDeclare(ParsedDeclare parsedElement, KAOSModel model)
        {
            Context context = model.modelMetadataRepository.GetContext(parsedElement.Identifier);

            if (context == null)
            {
                context = new Context(model, parsedElement.Identifier);
                model.modelMetadataRepository.Add(context);
            }
            else if (!parsedElement.Override)
            {
                throw new BuilderException("Cannot declare twice the same element. Use override instead.", parsedElement);
            }
        }
Exemplo n.º 30
0
        public static Document ExportModel(KAOSModel _model)
        {
            mapping = new Dictionary <Omnigraffle.Sheet, Dictionary <string, Omnigraffle.ShapedGraphic> >();

            var document = new Omnigraffle.Document();

            var canvas = new Omnigraffle.Sheet(1, string.Format("Model"));
            var shapes = new Dictionary <string, IList <Graphic> >();

            var u = new GoalModelGenerator(canvas, shapes);

            u.Render(_model);
            document.Canvas.Add(canvas);

            var s2 = new Omnigraffle.Sheet(1, "Goal and Obstacle Model");
            var u2 = new GoalAndObstacleModelGenerator(s2, new Dictionary <string, IList <Graphic> >());

            u2.Render(_model);

            document.Canvas.Add(s2);


            int i = 0;

            foreach (var o in _model.Obstructions().Select(x => x.Obstacle()))
            {
                i++;
                var s  = new Omnigraffle.Sheet(1, string.Format($"Obstacle diagram for '{o.FriendlyName}'"));
                var u3 = new ObstacleDiagramGenerator(s, new Dictionary <string, IList <Graphic> >());
                u3.Render(o, _model);
                document.Canvas.Add(s);
            }

            i = 0;
            foreach (var goalWithException in _model.Exceptions().Select(x => x.AnchorGoal())
                     .Union(_model.Replacements().Select(x => x.ResolvingGoal()))
                     .Union(_model.ObstacleAssumptions().Select(x => x.Anchor()))
                     .Distinct())
            {
                i++;
                var s  = new Omnigraffle.Sheet(1, string.Format($"Exception diagram for '{goalWithException.FriendlyName}'"));
                var u3 = new ExceptionDiagramGenerator(s, new Dictionary <string, IList <Graphic> >());
                u3.Render(goalWithException, _model);
                document.Canvas.Add(s);
            }

            return(document);
        }