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);
        }
示例#2
0
        public void Add(GoalReplacement replacement)
        {
            if (GoalReplacements.ContainsKey(replacement.Identifier))
            {
                throw new ArgumentException(string.Format("Goal replacement identifier already exist: {0}", replacement.Identifier));
            }

            GoalReplacements.Add(replacement.Identifier, replacement);
        }
        void RemoveObstructedGoal(Resolution resolution)
        {
            // Get the obstructed goals
            var obstructed = resolution.GetObstructedGoalIdentifiers();

            // Get the obstructed goals in the refinment of the anchor goal
            var anchorRefinements = _model.GoalRefinements(x => x.ParentGoalIdentifier == resolution.AnchorIdentifier);

            if (anchorRefinements.Count() > 1)
            {
                throw new IntegrationException(IntegrationException.SINGLE_REFINEMENT_ONLY);
            }
            if (anchorRefinements.Count() == 0)
            {
                throw new IntegrationException(IntegrationException.ANCHOR_NO_REFINEMENT);
            }
            var anchorRefinement   = anchorRefinements.Single();
            var obstructedChildren = anchorRefinement.SubGoalIdentifiers.Select(x => x.Identifier)
                                     .Intersect(obstructed);

            // Remove these
            anchorRefinement.SubGoalIdentifiers
                = new HashSet <GoalRefinee> (
                      anchorRefinement.SubGoalIdentifiers.Where(
                          x => !obstructedChildren.Contains(x.Identifier)));

            // Adds the countermeasure goal to the refinement
            anchorRefinement.Add(resolution.ResolvingGoalIdentifier);

            Console.WriteLine("Anchor goal : " + anchorRefinement.ParentGoalIdentifier);
            Console.WriteLine("New refinement = " + string.Join(",", anchorRefinement.SubGoalIdentifiers.Select(x => x.Identifier)));

            // Add replacement annotation
            var replacement = new GoalReplacement(_model);

            replacement.AnchorGoalIdentifier       = resolution.AnchorIdentifier;
            replacement.ResolvedObstacleIdentifier = resolution.ObstacleIdentifier;
            replacement.ResolvingGoalIdentifier    = resolution.ResolvingGoalIdentifier;
            replacement.ReplacedGoals = obstructedChildren.ToList();
            _model.Add(replacement);
        }
        protected void Render(GoalReplacement exception)
        {
            if (!shapes.ContainsKey(exception.ResolvingGoalIdentifier))
            {
                return;
            }

            if (!shapes.ContainsKey(exception.AnchorGoalIdentifier))
            {
                return;
            }

            var anchorGoalGraphic    = shapes [exception.AnchorGoalIdentifier].First();
            var resolvingGoalGraphic = shapes [exception.ResolvingGoalIdentifier].First();

            var topArrow = GetArrow(resolvingGoalGraphic, anchorGoalGraphic);

            topArrow.Style.Stroke.Pattern = StrokePattern.Dashed;
            AddText(topArrow, @"\b Replace \b0" + exception.Obstacle().FriendlyName);
            Add(exception.Identifier, topArrow);
        }