public List<MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { CollectWorkingNodes(nodeGroup); FindDestinations(); if (m_destinations.Count == 0 && m_nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } //force last node as destination (must be here due possible cycle) foreach (MyOutput networkOutput in nodeGroup.GroupOutputNodes) { if (networkOutput.Input != null) { m_destinations.Add(networkOutput.Input.Owner); } } currentOrder = 1; foreach (MyNode destNode in m_destinations) { VisitNode(destNode); } m_orderedNodes.Clear(); m_orderedNodes.AddRange(m_nodes); m_orderedNodes.Sort((i1, i2) => i1.TopologicalOrder.CompareTo(i2.TopologicalOrder)); return m_orderedNodes; }
internal void ReloadGraphLayout(MyNodeGroup target) { if (GraphViews.ContainsKey(target)) { GraphViews[target].ReloadContent(); } }
internal void CloseGraphLayout(MyNodeGroup target) { if (GraphViews.ContainsKey(target)) { GraphViews[target].Close(); } }
public List<MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { HashSet<MyNode> nodes = CollectWorkingNodes(nodeGroup); HashSet<MyNode> destinations = FindDestinations(nodeGroup, nodes); if (destinations.Count == 0 && nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } List<MyNode> orderedNodes = new List<MyNode>(); foreach (MyNode destNode in destinations) { VisitNode(destNode, nodes, orderedNodes); } int currentOrder = 1; foreach (MyNode node in orderedNodes) { node.TopologicalOrder = currentOrder; currentOrder++; } return orderedNodes; }
private HashSet<MyNode> FindDestinations(MyNodeGroup nodeGroup, HashSet<MyNode> nodes) { HashSet<MyNode> destinations = new HashSet<MyNode>(nodes); foreach (MyNode node in nodes) { for (int i = 0; i < node.InputBranches; i++) { MyConnection connection = node.InputConnections[i]; if (connection != null && nodes.Contains(connection.From)) { destinations.Remove(connection.From); } } } //force nodes before output nodes as destinations (must be here due possible cycle) foreach (MyOutput groupOutput in nodeGroup.GroupOutputNodes) { if (groupOutput.InputConnections[0] != null) { MyNode beforeOutput = groupOutput.InputConnections[0].From; if (nodes.Contains(beforeOutput) && !destinations.Contains(beforeOutput)) { destinations.Add(beforeOutput); } } } return destinations; }
private HashSet <MyNode> FindDestinations(MyNodeGroup nodeGroup, HashSet <MyNode> nodes) { HashSet <MyNode> destinations = new HashSet <MyNode>(nodes); foreach (MyNode node in nodes) { for (int i = 0; i < node.InputBranches; i++) { MyConnection connection = node.InputConnections[i]; if (connection != null && nodes.Contains(connection.From)) { destinations.Remove(connection.From); } } } //force nodes before output nodes as destinations (must be here due possible cycle) foreach (MyOutput groupOutput in nodeGroup.GroupOutputNodes) { if (groupOutput.InputConnections[0] != null) { MyNode beforeOutput = groupOutput.InputConnections[0].From; if (nodes.Contains(beforeOutput) && !destinations.Contains(beforeOutput)) { destinations.Add(beforeOutput); } } } return(destinations); }
public List <MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { HashSet <MyNode> nodes = CollectWorkingNodes(nodeGroup); HashSet <MyNode> destinations = FindDestinations(nodeGroup, nodes); if (destinations.Count == 0 && nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } List <MyNode> orderedNodes = new List <MyNode>(); foreach (MyNode destNode in destinations) { VisitNode(destNode, nodes, orderedNodes); } int currentOrder = 1; foreach (MyNode node in orderedNodes) { node.TopologicalOrder = currentOrder; currentOrder++; } return(orderedNodes); }
public List <MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { CollectWorkingNodes(nodeGroup); FindDestinations(); if (m_destinations.Count == 0 && m_nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } //force last node as destination (must be here due possible cycle) foreach (MyOutput networkOutput in nodeGroup.GroupOutputNodes) { if (networkOutput.Input != null) { m_destinations.Add(networkOutput.Input.Owner); } } currentOrder = 1; foreach (MyNode destNode in m_destinations) { VisitNode(destNode); } m_orderedNodes.Clear(); m_orderedNodes.AddRange(m_nodes); m_orderedNodes.Sort((i1, i2) => i1.TopologicalOrder.CompareTo(i2.TopologicalOrder)); return(m_orderedNodes); }
private List <IMyExecutable> GetTasks(MyWorkingNode node) { List <IMyExecutable> tasks = new List <IMyExecutable>(); foreach (string taskName in node.GetInfo().KnownTasks.Keys) { MyTask task = node.GetTaskByPropertyName(taskName); tasks.Add(task); } MyNodeGroup nodeGroup = node as MyNodeGroup; if (nodeGroup != null) { foreach (MyNode childNode in nodeGroup.Children) { MyWorkingNode childWorkingNode = childNode as MyWorkingNode; if (childWorkingNode != null) { tasks.AddRange(GetTasks(childWorkingNode)); } } } return(tasks); }
public GraphLayoutForm(MainForm mainForm, MyNodeGroup target) { InitializeComponent(); m_mainForm = mainForm; Target = target; Text = target.Name; Desktop.CreateConnection = delegate() { return(new MyNodeViewConnection()); }; }
public string GetParents() { string parent = Name; MyNodeGroup p = Parent; while (p != null) { parent = p.Name + "->" + parent; p = p.Parent; } return(parent); }
public GraphLayoutForm(MainForm mainForm, MyNodeGroup target) { InitializeComponent(); m_mainForm = mainForm; Target = target; Text = target.Name; Desktop.CreateConnection = delegate() { return new MyNodeViewConnection(); }; }
private void groupButton_Click(object sender, EventArgs e) { Desktop.FocusElement = null; MyNodeGroup group = this.Target; m_mainForm.NodePropertyView.Target = group; m_mainForm.MemoryBlocksView.Target = group; m_mainForm.TaskView.Target = group; m_mainForm.HelpView.Target = group; worldButtonPanel.BackColor = SystemColors.Control; groupButtonPanel.BackColor = Color.DarkOrange; }
private HashSet <MyNode> CollectWorkingNodes(MyNodeGroup nodeGroup) { var nodes = new HashSet <MyNode>(); nodeGroup.Iterate(false, node => { if (node is MyWorkingNode) { node.TopologicalOrder = -1; nodes.Add(node); } }); return(nodes); }
private HashSet<MyNode> CollectWorkingNodes(MyNodeGroup nodeGroup) { HashSet<MyNode> nodes = new HashSet<MyNode>(); MyNodeGroup.IteratorAction action = delegate(MyNode node) { if (node is MyWorkingNode) { node.TopologicalOrder = -1; nodes.Add(node); } }; nodeGroup.Iterate(false, action); return nodes; }
private HashSet <MyNode> CollectWorkingNodes(MyNodeGroup nodeGroup) { HashSet <MyNode> nodes = new HashSet <MyNode>(); MyNodeGroup.IteratorAction action = delegate(MyNode node) { if (node is MyWorkingNode) { node.TopologicalOrder = -1; nodes.Add(node); } }; nodeGroup.Iterate(false, action); return(nodes); }
public GraphLayoutForm OpenGraphLayout(MyNodeGroup target) { GraphLayoutForm graphForm; if (GraphViews.ContainsKey(target)) { graphForm = GraphViews[target]; } else { graphForm = new GraphLayoutForm(this, target); graphForm.FormClosed += GraphLayoutForm_FormClosed; GraphViews.Add(target, graphForm); } graphForm.Show(dockPanel, DockState.Document); return(graphForm); }
private void CollectWorkingNodes(MyNodeGroup nodeGroup) { m_nodes.Clear(); MyNodeGroup.IteratorAction action = delegate(MyNode node) { if (node is MyWorkingNode) { if (node.Parent != null) { node.Sequential = node.Parent.Sequential; } node.TopologicalOrder = -1; m_nodes.Add(node); } }; nodeGroup.Iterate(true, action); }
private void Desktop_DoubleClick(object sender, EventArgs e) { MyNodeView nodeView = Desktop.FocusElement as MyNodeView; if (nodeView != null) { MyNodeGroup group = nodeView.Node as MyNodeGroup; IScriptableNode scriptable = nodeView.Node as IScriptableNode; if (scriptable != null && group == null || scriptable != null && group != null && (Control.ModifierKeys & Keys.Shift) != 0) { m_mainForm.OpenTextEditor(scriptable); } else if (group != null) { m_mainForm.OpenGraphLayout(group); } } }
public List <MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { IList <MyConnection> lowPriorityConnections = new List <MyConnection>(); HashSet <MyNode> nodes = CollectWorkingNodes(nodeGroup); HashSet <MyNode> destinations = FindDestinations(nodeGroup, nodes, ref lowPriorityConnections); if (destinations.Count == 0 && nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } List <MyNode> orderedNodes = new List <MyNode>(); foreach (MyNode destNode in destinations) { VisitNode(destNode, nodes, orderedNodes); } int currentOrder = 1; foreach (MyNode node in orderedNodes) { node.TopologicalOrder = currentOrder; currentOrder++; } var edgesChanged = false; foreach (MyConnection connection in lowPriorityConnections.Where( connection => !connection.From.CheckForCycle(connection.To))) { connection.IsLowPriority = false; edgesChanged = true; } return(edgesChanged ? EvaluateOrder(nodeGroup) : orderedNodes); }
public List<MyNode> EvaluateOrder(MyNodeGroup nodeGroup) { IList<MyConnection> lowPriorityConnections = new List<MyConnection>(); HashSet<MyNode> nodes = CollectWorkingNodes(nodeGroup); HashSet<MyNode> destinations = FindDestinations(nodeGroup, nodes, ref lowPriorityConnections); if (destinations.Count == 0 && nodes.Count > 0) { MyLog.WARNING.WriteLine("Topological ordering failed in node group \"" + nodeGroup.Name + "\"! (no natural destination node of execution graph)"); } List<MyNode> orderedNodes = new List<MyNode>(); foreach (MyNode destNode in destinations) { VisitNode(destNode, nodes, orderedNodes); } int currentOrder = 1; foreach (MyNode node in orderedNodes) { node.TopologicalOrder = currentOrder; currentOrder++; } var edgesChanged = false; foreach (MyConnection connection in lowPriorityConnections.Where( connection => !connection.From.CheckForCycle(connection.To))) { connection.IsLowPriority = false; edgesChanged = true; } return edgesChanged ? EvaluateOrder(nodeGroup) : orderedNodes; }
private static void TrySetParent(MyNode node, MyNodeGroup nodeGroup, bool showWarning = true) { try { // Setting parent may fail since v0.4. Handle it to allow loading of old [incorrect] projects. node.Parent = nodeGroup; } catch (InvalidOperationException e) { // TODO(HonzaS): Remove the switch - this is here only for copy+paste to work with neural layers if (showWarning) MyLog.ERROR.WriteLine("Unable to update node ({0}): {1}", node.Name, e.Message); } }
public GraphLayoutForm OpenGraphLayout(MyNodeGroup target) { GraphLayoutForm graphForm; if (GraphViews.ContainsKey(target)) { graphForm = GraphViews[target]; } else { graphForm = new GraphLayoutForm(this, target); graphForm.FormClosed += GraphLayoutForm_FormClosed; GraphViews.Add(target, graphForm); } graphForm.Show(dockPanel, DockState.Document); RefreshConnections(graphForm); SimulationHandler.Simulation.ModelChanged += graphForm.OnModelChanged; return graphForm; }
public MyExecutionBlock CreateNodeExecutionPlan(MyWorkingNode node, bool initPhase) { List <IMyExecutable> defaultPlanContent = new List <IMyExecutable>(); if (!initPhase && PlanSignalTasks) { defaultPlanContent.Add(new MyIncomingSignalTask(node)); } foreach (var taskPropertyInfo in node.GetInfo().OrderedTasks) { MyTask task = node.GetTaskByPropertyName(taskPropertyInfo.Name); if ((task != null) && !task.DesignTime && (initPhase && task.OneShot || !initPhase && !task.OneShot)) { defaultPlanContent.Add(task); } } MyNodeGroup nodeGroup = node as MyNodeGroup; if (nodeGroup != null) { foreach (MyNode childNode in nodeGroup.Children.OrderBy(x => x.TopologicalOrder)) { MyWorkingNode childWorkingNode = childNode as MyWorkingNode; if (childWorkingNode != null) { defaultPlanContent.Add(CreateNodeExecutionPlan(childWorkingNode, initPhase)); } } } if (!initPhase && PlanSignalTasks) { defaultPlanContent.Add(new MyOutgoingSignalTask(node)); } var defaultPlan = new MyExecutionBlock(defaultPlanContent.ToArray()) { Name = node.Name }; MyExecutionBlock resultPlan = defaultPlan; IMyCustomExecutionPlanner executionPlannerNode = node as IMyCustomExecutionPlanner; if (executionPlannerNode != null) { resultPlan = initPhase ? executionPlannerNode.CreateCustomInitPhasePlan(defaultPlan) : executionPlannerNode.CreateCustomExecutionPlan(defaultPlan); resultPlan.Name = defaultPlan.Name; } if (resultPlan.Name == null) { resultPlan.Name = node.GetType().Name; } if (node is MyNodeGroup) { resultPlan.Name += " (group)"; } // TODO(HonzaS): Rethink this. It's only used in profiling results. node.ExecutionBlock = resultPlan; return(resultPlan); }
private void PrepareConnections(MyNodeGroup nodeGroup) { foreach(MyOutput outputNode in nodeGroup.GroupOutputNodes) { PrepareConnections(outputNode); } foreach (MyNode node in nodeGroup.Children) { PrepareConnections(node); } }
private int CollectNodesAndUpdate(MyNodeGroup nodeGroup, Dictionary<int, MyNode> nodes, int topId) { foreach (MyParentInput inputNode in nodeGroup.GroupInputNodes) { nodes[inputNode.Id] = inputNode; inputNode.Parent = nodeGroup; inputNode.Owner = Owner; if (topId < inputNode.Id) { topId = inputNode.Id; } } foreach (MyOutput outputNode in nodeGroup.GroupOutputNodes) { nodes[outputNode.Id] = outputNode; outputNode.Parent = nodeGroup; outputNode.Owner = Owner; if (topId < outputNode.Id) { topId = outputNode.Id; } } foreach (MyNode node in nodeGroup.Children) { nodes[node.Id] = node; //parent link node.Parent = nodeGroup; node.Owner = Owner; //topId collect if (topId < node.Id) { topId = node.Id; } //task owner update if (node is MyWorkingNode) { (node as MyWorkingNode).FinalizeTasksDeserialization(); } if (node is MyNodeGroup) { topId = CollectNodesAndUpdate(node as MyNodeGroup, nodes, topId); } //obsolete check MyObsoleteAttribute obsolete = node.GetType().GetCustomAttribute<MyObsoleteAttribute>(true); if (obsolete != null) { string message = "You are using obsolete node type (" + node.GetType().Name + ") "; if (obsolete.ReplacedBy != null) { message += "Use " + obsolete.ReplacedBy.Name + " instead."; } MyLog.WARNING.WriteLine(message); } } return topId; }
public static List <MyNode> OrderNetworkNodes(MyNodeGroup network) { IMyOrderingAlgorithm topoOps = new MyHierarchicalOrdering(); return(topoOps.EvaluateOrder(network)); }
public GraphLayoutForm OpenGraphLayout(MyNodeGroup target) { GraphLayoutForm graphForm; if (GraphViews.ContainsKey(target)) { graphForm = GraphViews[target]; } else { graphForm = new GraphLayoutForm(this, target); graphForm.FormClosed += GraphLayoutForm_FormClosed; GraphViews.Add(target, graphForm); } graphForm.Show(dockPanel, DockState.Document); return graphForm; }
public static List<MyNode> OrderNetworkNodes(MyNodeGroup network) { IMyOrderingAlgorithm topoOps = new MyHierarchicalOrdering(); return topoOps.EvaluateOrder(network); }
private static void IterateNodes(IEnumerable<MyWorkingNode> nodes, MyNodeGroup.IteratorAction action) { foreach (MyWorkingNode node in nodes) { action(node); var group = node as MyNodeGroup; if (group != null) group.Iterate(true, action); } }