/*

                foreach (var subgoal in anchor.Refinements().SelectMany(x => x.SubGoals())) {
                    var assumption = new ObstacleNegativeAssumption {
                        Assumed = obstacle,
                        Implicit = true
                    };
                    Propagate (assumption, subgoal);
                }

        */
        static void DownPropagate(ObstacleAssumption assumption, Goal goal)
        {
            foreach (var children in goal.Refinements().SelectMany (x => x.SubGoals()).ToArray()) {

                Console.WriteLine ("<pre> -- " + children.FriendlyName + " -- " + assumption.Obstacle().FriendlyName);

                Console.WriteLine (string.Join ("\n", children.Obstacles ().Select (x => x.Identifier)));

                Console.WriteLine ("</pre><hr />");

                if (children.Obstacles ().Select (x => x.Identifier).Contains (assumption.ResolvedObstacleIdentifier)) {

                var obstacleAssumption = (ObstacleAssumption) assumption.Copy ();
                obstacleAssumption.Identifier = Guid.NewGuid().ToString ();
                obstacleAssumption.SetAnchorGoal (children);
                children.model.Add (obstacleAssumption);

                DownPropagate (obstacleAssumption, children);

                }
            }
            /*
            foreach (var obstacle in goal.Obstructions()) {
                var obstacleAssumption = assumption.Copy ();
                obstacleAssumption.SetAnchorGoal (children);
                DownPropagate (obstacleAssumption, obstacle.Obstacle());
            }
            */
        }
 static Goal FinalAnchor(Goal goal)
 {
     if (goal.Replacements ().Any ()) { // todo shall be single
         return FinalAnchor (goal.Replacements ().First ().AnchorGoal ());
     }
     return goal;
 }
        private void DownPropagate(Goal parent, GoalRefinement refinement)
        {
            IList<AlternativeSystem> alternatives_to_add;
            if (refinement.SystemReference() != null) {
                var alternatives_to_filter_on = GetAllSubsystems(new HashSet<AlternativeSystem> (), refinement.SystemReference());
                alternatives_to_add = new List<AlternativeSystem> (parent.InSystems.Where(r => alternatives_to_filter_on.Contains(r)));

            } else {
                alternatives_to_add = new List<AlternativeSystem> (parent.InSystems);
            }

            if (refinement.InSystems == null)
                refinement.InSystems = new HashSet<AlternativeSystem> ();

            foreach (var a in alternatives_to_add) {
                refinement.InSystems.Add (a);
            }

            foreach (var child in refinement.SubGoals()) {
                if (child.InSystems == null)
                    child.InSystems = new HashSet<AlternativeSystem> ();

                foreach (var a in alternatives_to_add) {
                   child.InSystems.Add (a);
                }

                DownPropagate (child);
            }
        }
        private void DownPropagate(Goal parent, AgentAssignment assignment)
        {
            if (assignment.InSystems == null)
                assignment.InSystems = new HashSet<AlternativeSystem> ();

            IEnumerable<AlternativeSystem> systems_to_add;
            if (assignment.SystemReference != null) {
                systems_to_add = parent.InSystems.Where (a => a.Equals(assignment.SystemReference));
            } else {
                systems_to_add = parent.InSystems;
            }

            foreach (var s in systems_to_add) {
                assignment.InSystems.Add (s);
            }

            foreach (var agent in assignment.Agents()) {
                if (agent.InSystems == null)
                    agent.InSystems = new HashSet<AlternativeSystem> ();

                foreach (var a in systems_to_add) {
                    agent.InSystems.Add (a);
                }
            }
        }
 public void Render(Goal g, KAOSModel model)
 {
     Render (g);
     foreach (var e in g.Provided ()) {
         Render (e.Obstacle ());
         Render (e);
     }
 }
        void DownPropagate(Goal goal)
        {
            foreach (var childRefinement in goal.Refinements()) {
                DownPropagate (goal, childRefinement);
            }

            foreach (var agent in goal.AgentAssignments()) {
                DownPropagate (goal, agent);
            }

            foreach (var obstacle in goal.Obstructions()) {
                DownPropagate (goal, obstacle.Obstacle());
            }
        }
示例#7
0
        public void ExportAssignment(Goal g, AgentAssignment assignement)
        {
            var tempGUID = Guid.NewGuid().ToString();
            writer.WriteLine (@"""{0}""[shape=circle,width=.1,fixedsize=true,label=""""];", tempGUID);
            writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=onormal, label=""  {2}""];",
                              g.Identifier,
                              tempGUID,
                              g.InSystems.SetEquals(model.RootSystems()) ? "" : string.Join (", ", assignement.InSystems.Select (x => x.FriendlyName)));

            foreach (var agent in assignement.Agents()) {
                writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=none];",
                                  tempGUID,
                    agent.Identifier);

            }
        }
示例#8
0
        public static string GetPartialGoalDiagram(Goal g)
        {
            var sw = new StringWriter ();
            var exporter = new DotExport (g.model, sw);
            exporter.ExportGoal (g, true);

            foreach (var r in g.ParentRefinements ()) {
                foreach (var g2 in r.SubGoals ().Where (c => c != g)) {
                    exporter.ExportGoal (g2);
                }
                exporter.ExportGoal (r.ParentGoal ());
                exporter.ExportRefinement (r.ParentGoal (), r);
            }

            foreach (var r in g.Refinements()) {
                foreach (var g2 in r.SubGoals ()) {
                    exporter.ExportGoal (g2);
                }
                exporter.ExportRefinement (g, r);
            }

            foreach (var r in g.AgentAssignments()) {
                foreach (var g2 in r.Agents ()) {
                    exporter.ExportAgent (g2);
                }
                exporter.ExportAssignment (g, r);
            }

            foreach (var r in g.Obstructions()) {
                exporter.ExportObstacle (r.Obstacle ());
                exporter.ExportObstruction (g, r);
            }

            foreach (var r in g.Resolutions ()) {
                exporter.ExportObstacle (r.Obstacle ());
                exporter.ExportResolution (r.Obstacle (), r);
            }

            exporter.Close ();

            return GetImage (sw.ToString (), LayoutAlgorithm.Dot);
        }
        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);
            }
            */
        }
示例#10
0
        public static string GetExceptionDiagramSource(Goal g)
        {
            var sw = new StringWriter ();
            var exporter = new DotExport (g.model, sw, ranksep:2.5f, nodesep:2.5f, margin:0);
            exporter.ExportGoal (g, true);

            foreach (var r in g.Exceptions ()) {
                exporter.ExportGoal (r.ResolvingGoal());
                exporter.ExportException (r);
            }

            foreach (var r in g.model.Exceptions().Where (x => x.ResolvingGoalIdentifier == g.Identifier)) {
                exporter.ExportGoal (r.ResolvingGoal());
                exporter.ExportException (r);
            }

            exporter.Close ();

            return sw.ToString ();
        }
        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);
            }
        }
示例#12
0
 public void ExportObstruction(Goal g, Obstruction o)
 {
     writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=onormaltee];",
                       g.Identifier,
                       o.Obstacle ().Identifier);
 }
示例#13
0
 private static void AddElementsFor(this IList<string> alphabet, Goal goal)
 {
     alphabet.AddElementsFor (goal.FormalSpec);
 }
        static void Integrate(Goal obstructedGoal, Obstacle obstacle, Resolution resolution)
        {
            var anchor = obstructedGoal;
            if (resolution.Parameters.Count > 0) {
                anchor = resolution.Parameters[0];
            }
            anchor = FinalAnchor (anchor);

            if (resolution.ResolutionPattern == ResolutionPattern.GoalSubstitution
                | resolution.ResolutionPattern == ResolutionPattern.GoalWeakening) {

                var goalReplacement = new GoalReplacement (obstructedGoal.model) {
                    Implicit = true
                };
                goalReplacement.SetObstacle (obstacle);
                goalReplacement.SetResolvingGoal (resolution.ResolvingGoal ());
                goalReplacement.SetAnchorGoal (anchor);

                obstructedGoal.model.Add (goalReplacement);

                // Replace in refinements
                var resolving_goal = resolution.ResolvingGoal ();
                foreach (var r in anchor.ParentRefinements ().ToArray ()) {
                    r.Remove (anchor);
                    r.Add (resolving_goal);
                }

                // Replace children refinements
                foreach (var r in anchor.Refinements ().ToArray ()) {
                    anchor.model.Remove (r);
                    var r2 = (GoalRefinement) r.Copy ();
                    r2.Identifier = Guid.NewGuid ().ToString ();
                    r2.SetParentGoal (resolving_goal);
                    resolution.model.Add (r2);
                }

                // Replace in exceptions
                foreach (var r in anchor.Exceptions ().ToArray ()) {
                    r.SetAnchorGoal (resolving_goal);
                }

                // Replace in provided
                foreach (var r in anchor.Provided ().ToArray ()) {
                    r.SetAnchorGoal (resolving_goal);
                }

                // Replace in agent assignements
                foreach (var r in anchor.AgentAssignments ().ToArray ()) {
                    r.GoalIdentifier = resolving_goal.Identifier;
                }

            } else {

                var goalException = new GoalException (obstructedGoal.model) {
                    Implicit = true
                };
                goalException.SetObstacle (obstacle);
                goalException.SetResolvingGoal (resolution.ResolvingGoal ());
                goalException.SetAnchorGoal (anchor);

                obstructedGoal.model.Add (goalException);

                /*
                var obstacleAssumption = new ObstacleAssumption (resolution.model);
                obstacleAssumption.SetAnchorGoal (anchor);
                obstacleAssumption.SetObstacle (obstacle);

                if (anchor.Identifier != obstructedGoal.Identifier) {
                Console.WriteLine ("DownPropagate " + obstacle.FriendlyName + " ("+obstructedGoal.FriendlyName +") on " + anchor.FriendlyName );
                }
                */

                // DownPropagate (obstacleAssumption, anchor);
            }
        }
 public void Remove(Goal goal)
 {
     this.SubGoalIdentifiers.Remove (goal.Identifier);
 }
示例#16
0
 public static MvcHtmlString GetLink(this HtmlHelper helper, Goal goal)
 {
     return helper.ActionLink (goal.FriendlyName, "GoalModel");
 }
        private static void RecursiveGetResponsibilities(ResponsibilityNode current, Goal goal)
        {
            var hasAlternatives = (goal.Refinements().Count() + goal.AgentAssignments().Count()) > 1;

            if (hasAlternatives) {
                foreach (var refinement in goal.Refinements()) {
                    var newNode = new ResponsibilityNode (current);
                    foreach (var childGoal in refinement.SubGoals())
                        RecursiveGetResponsibilities (newNode, childGoal);
                }

                foreach (var assignment in goal.AgentAssignments()) {
                    foreach (var agent in assignment.Agents()) {
                        var newNode = new ResponsibilityNode (current);

                        if (!newNode.Responsibility.ContainsKey(agent))
                            newNode.Responsibility.Add (agent, new List<Goal> ());
                        newNode.Responsibility[agent].Add (goal);
                    }
                }

            } else {
                foreach (var refinement in goal.Refinements()) {
                    foreach (var childGoal in refinement.SubGoals())
                        RecursiveGetResponsibilities (current, childGoal);
                }

                foreach (var assignment in goal.AgentAssignments()) {
                    foreach (var agent in assignment.Agents()) {
                        if (!current.Responsibility.ContainsKey(agent))
                            current.Responsibility.Add (agent, new List<Goal> ());
                        current.Responsibility[agent].Add (goal);
                    }
                }
            }
        }
 public void Add(Goal goal)
 {
     this.SubGoalIdentifiers.Add (goal.Identifier);
 }
 public void SetResolvingGoal(Goal goal)
 {
     ResolvingGoalIdentifier = goal.Identifier;
 }
 public void SetAnchorGoal(Goal goal)
 {
     AnchorGoalIdentifier = goal.Identifier;
 }
 public void SetObstructedGoal(Goal goal)
 {
     this.ObstructedGoalIdentifier = goal.Identifier;
 }
 public void SetParentGoal(Goal element)
 {
     this.ParentGoalIdentifier = element.Identifier;
 }
示例#23
0
        public void ExportRefinement(Goal parent, GoalRefinement refinement)
        {
            var tempGUID = Guid.NewGuid().ToString();
            writer.WriteLine (@"""{0}""[shape=circle,width=.1,fixedsize=true,label=""""];", tempGUID);
            writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=onormal,label=""  {2}""];",
                              parent.Identifier,
                              tempGUID,
                refinement.SystemReference() != null ? refinement.SystemReference().FriendlyName : string.Empty);

            foreach (var child in refinement.SubGoals()) {
                writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=none];",
                                  tempGUID,
                                  child.Identifier);
            }

            foreach (var domprop in refinement.DomainProperties()) {
                writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=none];",
                                  tempGUID,
                                  domprop.Identifier);
            }

            foreach (var domhyp in refinement.DomainHypotheses()) {
                writer.WriteLine (@"""{0}"" -> ""{1}"" [arrowtail=none];",
                                  tempGUID,
                                  domhyp.Identifier);
            }
        }
        static void RecursiveIntegration(Goal obstructedGoal, Obstacle obstacle)
        {
            foreach (var resolution in obstacle.Resolutions().ToArray ()) {
                Integrate (obstructedGoal, obstacle, resolution);
            }

            foreach (var subobstacle in obstacle.Refinements().SelectMany (x => x.SubObstacles()).ToArray ()) {
                RecursiveIntegration (obstructedGoal, subobstacle);
            }
        }
示例#25
0
        public void ExportRefinementRecursively(Goal g)
        {
            if (g.Refinements().Count() > 0) {
                writer.WriteLine ();
                writer.WriteLine ("# Refinement for goal '{0}'", g.Name);
                writer.WriteLine ();
            }

            foreach (var r in g.Refinements()) {
                ExportRefinement (g, r);

                foreach (var child in r.SubGoals()) {
                    ExportRefinementRecursively (child);
                }
            }
        }
示例#26
0
 public static string GetExceptionDiagram(Goal g)
 {
     return GetImage (GetExceptionDiagramSource (g), LayoutAlgorithm.Twopi);
 }
示例#27
0
 public void ExportGoal(Goal g, bool bold = false)
 {
     bool assignedToSoftwareAgents = (from assignments in g.AgentAssignments()
                                      from agent in assignments.Agents()
                                      select agent.Type == AgentType.Software).Count () > 0;
     var name = new StringBuilder (g.FriendlyName);
     if (name.Length > 30) {
         var midspace = g.Name.IndexOf (' ', (g.Name.Length / 3) - 1);
         if (midspace > 0) {
             if (bold) {
                 name.Replace (" ", "<BR/>", midspace, 1);
             } else {
                 name.Replace (" ", @"\n", midspace, 1);
             }
         }
     }
     writer.WriteLine (@"""{0}"" [shape=polygon,skew=.05,label={1},style=filled,fillcolor=""{2}"",penwidth={3},fontname=""HelveticaNeue"",fontsize=9,margin=""0,0""];",
         g.Identifier, bold ? "<<FONT COLOR=\"red\"><B>" + name + "</B></FONT>>" : "\"" + name + "\"",
                       assignedToSoftwareAgents ? "#fff9c1" : "#d8ebfd",
                       g.AgentAssignments().Count() > 0 ? 2 : 1);
 }
示例#28
0
        public static IEncodedString GetPartialGoalDiagram(Goal g)
        {
            var view = new PartialModelView ();
            view.Add (g);

            foreach (var r in g.ParentRefinements ()) {
                view.Add (r);
                view.Add (r.ParentGoal ());
            }

            foreach (var r in g.Refinements()) {
                view.Add (r);
                foreach (var gg in r.SubGoals ()) {
                    view.Add (gg);
                }
                foreach (var gg in r.DomainProperties ()) {
                    view.Add (gg);
                }
                foreach (var gg in r.DomainHypotheses ()) {
                    view.Add (gg);
                }
            }

            foreach (var o in g.Obstructions ()) {
                view.Add (o);
                view.Add (o.Obstacle ());
            }

            foreach (var a in g.AgentAssignments ()) {
                view.Add (a);
                foreach (var agent in a.Agents ()) {
                    view.Add (agent);
                }
            }

            foreach (var r in g.Resolutions ()) {
                view.Add (r);
                view.Add (r.Obstacle ());
            }
            /*
            foreach (var r in g.Exceptions ()) {
                view.Add (r);
                view.Add (r.Obstacle ());
                view.Add (r.ResolvingGoal ());
            }
            */
            var stream1 = new MemoryStream();
            var ser = new DataContractJsonSerializer(typeof(PartialModelView));
            ser.WriteObject(stream1, view);
            stream1.Position = 0;
            StreamReader sr = new StreamReader(stream1);
            return new RawString (sr.ReadToEnd());
        }
 public GoalRefinement(KAOSModel model, Goal goal)
     : this(model)
 {
     SubGoalIdentifiers.Add (goal.Identifier);
 }
示例#30
0
 public void Add(Goal goal)
 {
     Goals.Add (goal);
 }