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());
            }
        }
        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);
        }
Exemple #3
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);
 }
        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());
        }
        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);
                    }
                }
            }
        }
        private void Simplify(Goal g)
        {
            g.InSystems = Simplify (g.InSystems);
            foreach (var refinement in g.Refinements()) {
                refinement.InSystems = Simplify(refinement.InSystems);
                foreach (var child in refinement.SubGoals()) {
                    Simplify (child);
                }
            }

            foreach (var assignement in g.AgentAssignments()) {
                assignement.InSystems = Simplify (assignement.InSystems);
                foreach (var agent in assignement.Agents()) {
                    agent.InSystems = Simplify (agent.InSystems);
                }
            }
        }
        protected void Render(Goal goal)
        {
            int lineWidth = 1;

            bool assignedToEnvAgents = (
                from a in goal.AgentAssignments().SelectMany (x => x.Agents())
                where a.Type != AgentType.Software select a).Count () > 0;

            if (goal.AgentAssignments().Count() > 0)
                lineWidth = 2;

            if (assignedToEnvAgents)
                AddParallelogram (goal.Identifier, goal.FriendlyName,
                    lineWidth, 1, 0.979841, 0.672223);
            else
                AddParallelogram (goal.Identifier, goal.FriendlyName,
                    lineWidth, 0.810871, 0.896814, 1);
        }