/*

                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());
            }
            */
        }
Пример #2
0
        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());
            }
        }
Пример #3
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);
            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);
            }
        }
Пример #5
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);
                }
            }
        }
Пример #6
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());
        }
Пример #7
0
        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);
                    }
                }
            }
        }
Пример #8
0
        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);
                }
            }
        }