static void ProcessNodes(Dictionary <DrawingObject, IViewerObjectX> vObjectsMapping, Graph g, Dictionary <string, Subgraph> subgraphTable, Microsoft.Msagl.Drawing.Graph drawingGraph) { foreach (GraphNode gn in g.Nodes) { Node drawingNode; if (subgraphTable.ContainsKey(gn.Id.LiteralValue)) { var subgraph = new Subgraph(gn.Id.LiteralValue); subgraphTable[subgraph.Id] = subgraph; drawingNode = subgraph; } else { drawingNode = drawingGraph.AddNode(gn.Id.LiteralValue); } drawingNode.Label = new Label(gn.Label); string category = null; if (gn.Categories.Any()) { category = gn.Categories.ElementAt(0).ToString().Replace("CodeSchema_", ""); } XNode vNode = new XNode(drawingNode, gn); vObjectsMapping[drawingNode] = vNode; } }
public static Graph CreateDrawingGraph(GeometryGraph gg) { counter = 0; localMap = new Dictionary <GeometryNode, Node>(); dg = new Graph(counter++.ToString()) { GeometryGraph = gg }; foreach (GeometryNode n in gg.Nodes) { Node node = new Node(counter++.ToString()); node.Attr.Shape = Shape.Ellipse; node.GeometryNode = n; dg.AddNode(node); localMap[n] = node; } Subgraph cluster = new Subgraph(counter++.ToString()); cluster.GeometryNode = gg.RootCluster; dg.RootSubgraph = cluster; PopulateClusters(cluster, gg.RootCluster); foreach (GeometryEdge e in gg.Edges) { Edge edge = new Edge(localMap[e.Source], localMap[e.Target], ConnectionToGraph.Disconnected); edge.Attr.ArrowheadAtSource = e.ArrowheadAtSource ? ArrowStyle.Normal : ArrowStyle.None; edge.Attr.ArrowheadAtTarget = e.ArrowheadAtTarget ? ArrowStyle.Normal : ArrowStyle.None; edge.GeometryEdge = e; dg.AddPrecalculatedEdge(edge); } //PopulateClusterEdges(dg.RootSubgraph, gg.RootCluster); return(dg); }
public void CreateAndLayoutAndDisplayGraph() { try { Graph graph = new Graph(); graph.AddEdge("47", "58"); graph.AddEdge("70", "71"); var subgraph = new Subgraph("subgraph1"); graph.RootSubgraph.AddSubgraph(subgraph); subgraph.AddNode(graph.FindNode("47")); subgraph.AddNode(graph.FindNode("58")); var subgraph2 = new Subgraph("subgraph2"); subgraph2.Attr.Color = Color.Black; subgraph2.Attr.FillColor = Color.Yellow; subgraph2.AddNode(graph.FindNode("70")); subgraph2.AddNode(graph.FindNode("71")); subgraph.AddSubgraph(subgraph2); graph.AddEdge("58", subgraph2.Id); graph.Attr.LayerDirection = LayerDirection.LR; graphViewer.Graph = graph; } catch (Exception e) { MessageBox.Show(e.ToString(), "Load Failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
void CreateGraphClustersSmall() { Graph graph = new Graph("clusters"); var receivers_growth = new Subgraph("Receivers_growth"); var receiver0_growth = new Node("Receiver0_growth"); receivers_growth.AddNode(receiver0_growth); var receivers_control = new Subgraph("Receivers_control"); var receiver0_control = new Node("Receiver0_control"); receivers_control.AddNode(receiver0_control); var receivers = new Subgraph("Receivers"); var receiver0 = new Node("Receiver0"); receivers.AddNode(receiver0); graph.RootSubgraph.AddSubgraph(receivers_growth); graph.AddNode(receiver0_growth); graph.RootSubgraph.AddSubgraph(receivers_control); graph.AddNode(receiver0_control); graph.RootSubgraph.AddSubgraph(receivers); graph.AddNode(receiver0); graph.AddEdge(receivers_growth.Id, receivers_control.Id); graph.AddEdge(receiver0_control.Id, receiver0.Id); graph.AddEdge(receiver0_growth.Id, receiver0.Id); gViewer.Graph = graph; this.propertyGrid1.SelectedObject = graph; }
private ICurve GetClusterCollapsedBoundary(Subgraph subgraph) { double width, height; FrameworkElement fe; if (drawingObjectsToFrameworkElements.TryGetValue(subgraph, out fe)) { width = fe.Width + 2 * subgraph.Attr.LabelMargin + subgraph.DiameterOfOpenCollapseButton; height = Math.Max(fe.Height + 2 * subgraph.Attr.LabelMargin, subgraph.DiameterOfOpenCollapseButton); } else { return(GetApproximateCollapsedBoundary(subgraph)); } if (width < drawingGraph.Attr.MinNodeWidth) { width = drawingGraph.Attr.MinNodeWidth; } if (height < drawingGraph.Attr.MinNodeHeight) { height = drawingGraph.Attr.MinNodeHeight; } return(NodeBoundaryCurves.GetNodeBoundaryCurve(subgraph, width, height)); }
private ICurve GetApproximateCollapsedBoundary(Subgraph subgraph) { if (textBoxForApproxNodeBoundaries == null) { SetUpTextBoxForApproxNodeBoundaries(); } double width, height; if (String.IsNullOrEmpty(subgraph.LabelText)) { height = width = subgraph.DiameterOfOpenCollapseButton; } else { double a = ((double)subgraph.LabelText.Length) / textBoxForApproxNodeBoundaries.Text.Length * subgraph.Label.FontSize / Label.DefaultFontSize; width = textBoxForApproxNodeBoundaries.Width * a + subgraph.DiameterOfOpenCollapseButton; height = Math.Max( textBoxForApproxNodeBoundaries.Height * subgraph.Label.FontSize / Label.DefaultFontSize, subgraph.DiameterOfOpenCollapseButton); } if (width < drawingGraph.Attr.MinNodeWidth) { width = drawingGraph.Attr.MinNodeWidth; } if (height < drawingGraph.Attr.MinNodeHeight) { height = drawingGraph.Attr.MinNodeHeight; } return(NodeBoundaryCurves.GetNodeBoundaryCurve(subgraph, width, height)); }
public override void Parse() { _nAtom = Molecule.AtomList.Length; // 取出原子个数,性能分析指出:此项使用调用极为频繁,若调用属性(函数)将大大拖慢程序 _lock = new bool[_nAtom]; DefinedFragment = new Dictionary <string, int>(); AddAttribute(); // 标记属性 _sign = 1; foreach (Subgraph redical in _radicalToMatch) { _radical = redical; List <string> lastResults = new List <string>(); var count = 0; MatchCore(() => { int[] tempIntArray = null; if (_radical.SpecialAtom.Length == _radical.AtomCodeList.Length) // 全虚拟:虚拟原子不可相同 { tempIntArray = _matched; } else if (_radical.SpecialAtom.Length != 0) // 部分虚拟:非虚拟原子不可相同,虚拟原子可以相同 { tempIntArray = new int[_radical.AtomCodeList.Length - _radical.SpecialAtom.Length]; for (int j = 0, p = 0; j < _matched.Length; j++) { if (!_radical.SpecialAtom.Contains(j)) { tempIntArray[p++] = _matched[j]; } } } string strResultSort = ""; if (tempIntArray != null) { Array.Sort(tempIntArray); strResultSort = tempIntArray.Aggregate(strResultSort, (current, t) => current + (t + "/")); } if (!lastResults.Contains(strResultSort)) { count++; if (strResultSort != "") { lastResults.Add(strResultSort); } } if (_isLockingBond) { LockingBond(); } // do some other things. }); for (int j = 0; j < count; j++) { var tempName = (_radical.Name).Replace("*", ""); if (!DefinedFragment.ContainsKey(tempName)) { DefinedFragment.Add(tempName, 0); } DefinedFragment[tempName]++; // 装入结果 } } }
private void AddAttribute() { _sign = -1; foreach (var redical in _radicalToRename) { _radical = redical; MatchCore(() => { if (_radical.Name[0] == '_') // 属性添加 { foreach (var specialAtom in redical.SpecialAtom) { Molecule.AtomList[_matched[specialAtom]] += _radical.Name; } } else // 全名重载 { foreach (var specialAtom in redical.SpecialAtom) { Molecule.AtomList[_matched[specialAtom]] = _radical.Name; } } }); Molecule.AtomState = new int[_nAtom]; } }
private Subgraph FindSubgraph(Node node) { Subgraph subgraph = new Subgraph(graph); AddReachable(node, subgraph); return(subgraph); }
void QueueSubgraph(Subgraph a, int b) { Subgraph s = new Subgraph(); s.nodes = new bool[n]; s.touching = new bool[n]; if (a != null) { a.nodes.CopyTo(s.nodes, 0); a.touching.CopyTo(s.touching, 0); } s.nodes[b] = true; s.sum = unchecked ((a != null ? a.sum : 0) + b); if (processed.ContainsKey(s)) { return; } for (int i = 0; i < n; i++) { if (conn[b, i]) { s.touching[i] = true; } } processed[s] = processed; queue.Enqueue(s); }
internal static string Example_Simple03() { var drawingGraph = new Graph(); drawingGraph.AddNode(new ComponentNode("CRM", "CRM", "some cloud service", "This is the CRM component with which we are going to serve customers.")); drawingGraph.AddNode(new ComponentNode("Database", "Database", "mssql", "The database which will hold the data.")); drawingGraph.AddEdge("CRM", "ole db", "Database"); var subgraph1 = new Subgraph("Cloud"); subgraph1.AddNode(drawingGraph.FindNode("CRM")); var subgraph2 = new Subgraph("On Prem"); subgraph2.AddNode(drawingGraph.FindNode("Database")); drawingGraph.RootSubgraph.AddSubgraph(subgraph1); drawingGraph.RootSubgraph.AddSubgraph(subgraph2); var diagram = new Diagram(drawingGraph); diagram.Run(); return(diagram.ToString()); }
void PopCurrentSubgraph() { currentSubgraph = currentSubgraph.ParentSubgraph; if (currentSubgraph == graph.RootSubgraph) { currentSubgraph = null; } }
/// <summary> /// Adds all nodes and edges reachable from this node to the subgraph. /// Uses an explicit stack to avoid a large depth of recursion. /// </summary> /// <param name="startNode"></param> /// <param name="subgraph"></param> private void AddReachable(Node startNode, Subgraph subgraph) { Stack<Node> nodeStack = new Stack<Node>(); nodeStack.Push(startNode); while (nodeStack.Count != 0) { Node node = nodeStack.Pop(); AddEdges(node, nodeStack, subgraph); } }
/// <summary> /// Adds all nodes and edges reachable from this node to the subgraph. /// Uses an explicit stack to avoid a large depth of recursion. /// </summary> /// <param name="startNode"></param> /// <param name="subgraph"></param> private void AddReachable(Node startNode, Subgraph subgraph) { Stack nodeStack = new Stack(); nodeStack.Push(startNode); while (!(nodeStack.Count == 0)) { Node node = (Node)nodeStack.Pop(); AddEdges(node, nodeStack, subgraph); } }
/// <summary> /// Adds all nodes and edges reachable from this node to the subgraph. /// Uses an explicit stack to avoid a large depth of recursion. /// </summary> /// <param name="startNode"></param> /// <param name="subgraph"></param> private void AddReachable(Node startNode, Subgraph subgraph) { Stack nodeStack = new Stack(); nodeStack.Push(startNode); while (!(nodeStack.Count == 0)) { Node node = (Node)nodeStack.Pop(); AddEdges(node, nodeStack, subgraph); } }
/// <summary> /// Adds the argument node and all its out edges to the subgraph. /// </summary> /// <param name="node"></param> /// <param name="nodeStack"></param> /// <param name="subgraph"></param> private static void AddEdges(Node node, Stack<Node> nodeStack, Subgraph subgraph) { node.Visited = true; foreach (DirectedEdge de in node.OutEdges) { subgraph.Add(de.Edge); Node toNode = de.ToNode; if (!toNode.IsVisited) nodeStack.Push(toNode); } }
/// <summary> /// Adds all nodes and edges reachable from this node to the subgraph. /// Uses an explicit stack to avoid a large depth of recursion. /// </summary> /// <param name="startNode"></param> /// <param name="subgraph"></param> private void AddReachable(Node startNode, Subgraph subgraph) { Stack <Node> nodeStack = new Stack <Node>(); nodeStack.Push(startNode); while (nodeStack.Count != 0) { Node node = nodeStack.Pop(); AddEdges(node, nodeStack, subgraph); } }
/// <summary> /// Adds the argument node and all its out edges to the subgraph. /// </summary> /// <param name="node"></param> /// <param name="nodeStack"></param> /// <param name="subgraph"></param> private void AddEdges(Node node, Stack nodeStack, Subgraph subgraph) { node.Visited = true; IEnumerator i = ((DirectedEdgeStar)node.OutEdges).GetEnumerator(); while(i.MoveNext()) { DirectedEdge de = (DirectedEdge)i.Current; subgraph.Add(de.Edge); Node toNode = de.ToNode; if (!toNode.IsVisited) nodeStack.Push(toNode); } }
public override bool Equals(object o) { Subgraph g = (Subgraph)o; for (int i = 0; i < nodes.Length; i++) { if (nodes[i] != g.nodes[i]) { return(false); } } return(true); }
/// <summary> /// Adds the argument node and all its out edges to the subgraph. /// </summary> /// <param name="node"></param> /// <param name="nodeStack"></param> /// <param name="subgraph"></param> private static void AddEdges(Node node, Stack <Node> nodeStack, Subgraph subgraph) { node.Visited = true; foreach (DirectedEdge de in node.OutEdges) { subgraph.Add(de.Edge); Node toNode = de.ToNode; if (!toNode.IsVisited) { nodeStack.Push(toNode); } } }
private void button_SubGraph_Click(object sender, RoutedEventArgs e) { string rootName = tb_RootName.Text; string childName = tb_ChildName.Text; masterGraph.AddEdge(rootName, childName); Subgraph subgraph = new Subgraph("Master"); masterGraph.RootSubgraph.AddSubgraph(subgraph); subgraph.AddNode(masterGraph.FindNode(rootName)); subgraph.AddNode(masterGraph.FindNode(childName)); graphViewer.Graph = masterGraph; }
void CreateNewCurrentSubgraph(string subgraphId) { var sg = new Subgraph(subgraphId); if (currentSubgraph == null) { graph.RootSubgraph.AddSubgraph(sg); } else { currentSubgraph.AddSubgraph(sg); } currentSubgraph = sg; }
private bool _isLockingBond; // 是否启用基于键的屏蔽 // --------------------------------------------------------------------------------- public override void Load(string text) { _radicalToMatch = new List <Subgraph>(); _radicalToRename = new List <Subgraph>(); var item = text.Split(new[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries); var r = new Regex(@"=\((.+?)\)", RegexOptions.Compiled); int i = 0; if (item[0] == "LOCKING_BOND") { _isLockingBond = true; i = 1; } for (; i < item.Length; i++) { string[] temp = r.Match(item[i]).Groups[1].Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // 提取附加坐标 int[] tempInt = new int[temp.Length]; for (int j = 0; j < temp.Length; j++) { tempInt[j] = int.Parse(temp[j]); } string tempInfo = r.Replace(item[i], ""); var tempRadical = new Subgraph(tempInfo) { SpecialAtom = tempInt }; switch (item[i][0]) { case '_': _radicalToRename.Add(tempRadical); break; case '*': _radicalToMatch.Add(tempRadical); break; default: if (tempInt.Length > 0) { _radicalToRename.Add(tempRadical); } else { _radicalToMatch.Add(tempRadical); } break; } } }
static void ProcessNodes(DgmlGraph g, Dictionary<string, Subgraph> subgraphTable, Microsoft.Msagl.Drawing.Graph drawingGraph) { foreach (GraphNode gn in g.Nodes) { Node drawingNode; if (subgraphTable.ContainsKey(gn.Id.LiteralValue)) { var subgraph = new Subgraph(gn.Id.LiteralValue); subgraphTable[subgraph.Id] = subgraph; drawingNode = subgraph; } else drawingNode = drawingGraph.AddNode(gn.Id.LiteralValue); drawingNode.Label = new Label(gn.Label) {Owner = drawingNode}; } }
/// <summary> /// Tests whether a complete unique path exists in a graph /// using Euler's Theorem. /// </summary> /// <param name="graph">The <see cref="Subgraph" /> containing the edges.</param> /// <returns><c>true</c> if a sequence exists.</returns> private bool HasSequence(Subgraph graph) { int oddDegreeCount = 0; IEnumerator i = graph.GetNodeEnumerator(); while (i.MoveNext()) { Node node = (Node)i.Current; if (node.Degree % 2 == 1) { oddDegreeCount++; } } return(oddDegreeCount <= 2); }
private static void PopulateClusters(Subgraph cluster, GeometryCluster c) { foreach (GeometryNode n in c.Nodes) { cluster.AddNode(localMap[n]); } foreach (GeometryCluster c2 in c.Clusters) { Subgraph cluster2 = new Subgraph(counter++.ToString()); cluster2.GeometryNode = c2; localMap[c2] = cluster2; cluster.AddSubgraph(cluster2); PopulateClusters(cluster2, c2); } }
void AddMachineInternal(string machine) { if (Machines.Contains(machine)) { return; } Machines.Add(machine); States.Add(machine, new HashSet <string>()); var subgraph = new Subgraph(machine); subgraph.Label.FontSize = SubgraphFontSize; graph.RootSubgraph.AddSubgraph(subgraph); MachineToSubgraph.Add(machine, subgraph); }
/// <summary> /// Adds the argument node and all its out edges to the subgraph. /// </summary> /// <param name="node"></param> /// <param name="nodeStack"></param> /// <param name="subgraph"></param> private void AddEdges(Node node, Stack nodeStack, Subgraph subgraph) { node.Visited = true; IEnumerator i = ((DirectedEdgeStar)node.OutEdges).GetEnumerator(); while (i.MoveNext()) { DirectedEdge de = (DirectedEdge)i.Current; subgraph.Add(de.Edge); Node toNode = de.ToNode; if (!toNode.IsVisited) { nodeStack.Push(toNode); } } }
/// <summary> /// /// </summary> /// <param name="graph"></param> /// <returns></returns> private static Node FindLowestDegreeNode(Subgraph graph) { int minDegree = Int32.MaxValue; Node minDegreeNode = null; IEnumerator i = graph.GetNodeEnumerator(); while (i.MoveNext()) { Node node = (Node)i.Current; if (minDegreeNode == null || node.Degree < minDegree) { minDegree = node.Degree; minDegreeNode = node; } } return(minDegreeNode); }
public OptimalSubgraph(IGraph graph) { Graph = graph; DegreeWeight = null; MinInDegree = null; MaxInDegree = null; MinOutDegree = null; MaxOutDegree = null; MinDegree = null; MaxDegree = null; MinArcCount = 0; MaxArcCount = int.MaxValue; ArcCountWeight = 0; CostFunctions = new List <CostFunction>(); SolutionType = SolutionType.Invalid; ResultGraph = null; }
private static List <Subgraph> FindSubgraphs(int[] bffs) { var subgraphs = new List <Subgraph>(); var indexes = new List <int>(); for (var i = 0; i < bffs.Length; i++) { indexes.Clear(); var bff = i; while (!indexes.Contains(bff)) { indexes.Add(bff); bff = bffs[bff] - 1; } var cycleStartIndex = indexes.IndexOf(bff); var subgraph = subgraphs.FirstOrDefault(s => s.Cycle.Contains(bff)); if (subgraph == null) { subgraph = new Subgraph { Cycle = indexes.Skip(cycleStartIndex).ToArray() }; subgraphs.Add(subgraph); } if (cycleStartIndex >= 1) { var endNode = indexes[cycleStartIndex]; var chain = subgraph.Chains.FirstOrDefault(c => c.EndNode == endNode); if (chain == null) { chain = new Chain { EndNode = endNode }; subgraph.Chains.Add(chain); } chain.MaxLength = Math.Max(chain.MaxLength, cycleStartIndex); } } return(subgraphs); }
/// <summary> /// /// </summary> /// <param name="graph"></param> /// <returns></returns> private IList FindSequence(Subgraph graph) { GraphComponent.SetVisited(graph.GetEdgeEnumerator(), false); Node startNode = FindLowestDegreeNode(graph); // HACK: we need to reverse manually the order: maybe sorting error? ArrayList list = (ArrayList)startNode.OutEdges.Edges; list.Reverse(); IEnumerator ie = list.GetEnumerator(); ie.MoveNext(); DirectedEdge startDE = (DirectedEdge)ie.Current; DirectedEdge startDESym = startDE.Sym; LinkedList <DirectedEdge> seq = new LinkedList <DirectedEdge>(); LinkedListNode <DirectedEdge> pos = AddReverseSubpath(startDESym, null, seq, false); while (pos != null) { DirectedEdge prev = pos.Value; DirectedEdge unvisitedOutDE = FindUnvisitedBestOrientedDE(prev.FromNode); if (unvisitedOutDE != null) { DirectedEdge toInsert = unvisitedOutDE.Sym; pos = AddReverseSubpath(toInsert, pos, seq, true); } else { pos = pos.Previous; } } /* * At this point, we have a valid sequence of graph DirectedEdges, but it * is not necessarily appropriately oriented relative to the underlying geometry. */ IList orientedSeq = Orient(new ArrayList(seq)); return(orientedSeq); }
public async Task <Subgraph> GetVisualisationSubgraph( string contentItemId, string graphName, IContentItemVersion contentItemVersion) { var relationshipCommands = await BuildVisualisationCommands(contentItemId, contentItemVersion !); // get all results atomically var result = await _neoGraphCluster.Run(graphName, relationshipCommands.ToArray()); var inAndOutResults = result.OfType <INodeAndOutRelationshipsAndTheirInRelationships?>(); //todo: should really always return the source node (until then, the subgraph will pull it if the main results don't) Subgraph subgraph; if (inAndOutResults.Any()) { // get all outgoing relationships from the query and add in any source nodes subgraph = new Subgraph( inAndOutResults .SelectMany(x => x !.OutgoingRelationships.Select(x => x.outgoingRelationship.DestinationNode)) .Union(inAndOutResults.GroupBy(x => x !.SourceNode).Select(z => z.FirstOrDefault() !.SourceNode)), inAndOutResults ! .SelectMany(y => y !.OutgoingRelationships.Select(z => z.outgoingRelationship.Relationship)) .ToHashSet(), inAndOutResults.FirstOrDefault()?.SourceNode); } else { subgraph = new Subgraph(); } ISubgraph?inResults = result.OfType <ISubgraph>().FirstOrDefault(); if (inResults != null) { subgraph.Add(inResults); } return(subgraph); }
bool IsAncesterAndDecendant(DrawingNode node1, DrawingNode node2) { if (node1 is Subgraph) { Subgraph subg = (Subgraph)node1; if (subg.Nodes.Contains(node2)) { return(true); } foreach (Subgraph subsubg in subg.Subgraphs) { if (subsubg == node2 || IsAncesterAndDecendant(subsubg, node2)) { return(true); } } } return(false); }
private Subgraph FindSubgraph(Node node) { Subgraph subgraph = new Subgraph(graph); AddReachable(node, subgraph); return subgraph; }
void QueueSubgraph(Subgraph a, int b) { Subgraph s = new Subgraph(); s.nodes = new bool[n]; s.touching = new bool[n]; if (a != null) { a.nodes.CopyTo(s.nodes, 0); a.touching.CopyTo(s.touching, 0); } s.nodes[b] = true; s.sum = unchecked((a != null ? a.sum : 0) + b); if (processed.ContainsKey(s)) return; for (int i = 0; i < n; i++) if (conn[b,i]) s.touching[i] = true; processed[s] = processed; queue.Enqueue(s); }