private void ExploreAdjacentEdges([NotNull] TVertex u) { foreach (TEdge edge in VisitedGraph.AdjacentEdges(u)) { bool reversed = edge.Target.Equals(u); TVertex v = reversed ? edge.Source : edge.Target; OnExamineEdge(edge); GraphColor vColor = VerticesColors[v]; if (vColor == GraphColor.White) { OnTreeEdge(edge, reversed); VerticesColors[v] = GraphColor.Gray; OnDiscoverVertex(v); _vertexQueue.Enqueue(v); } else { OnNonTreeEdge(edge, reversed); if (vColor == GraphColor.Gray) { OnGrayTarget(edge, reversed); } else { OnBlackTarget(edge, reversed); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void WriteVertex(Object sender, VertexEventArgs args) { if (m_Colors != null && m_Colors.Contains(args.Vertex)) { GraphColor c = (GraphColor)m_Colors[args.Vertex]; VertexFormatter.FillColor = GraphColorConverter.Convert(c); if (c == GraphColor.Black) { VertexFormatter.FontColor = Color.White; } else { VertexFormatter.FontColor = Color.Black; } } else { VertexFormatter.StrokeColor = Color.White; } if (m_VertexLabels != null) { VertexFormatter.Label = m_VertexLabels[args.Vertex].ToString(); } ((GraphvizAlgorithm)sender).Output.Write(VertexFormatter.ToDot()); }
private void VisitEdges(IEdgeEnumerable outEdges, bool forward) { IVertex target = null; foreach (IEdge e in outEdges) { OnExamineEdge(e); if (forward) { target = e.Target; } else { target = e.Source; } GraphColor vc = Colors[target]; GraphColor ec = EdgeColors[e]; EdgeColors[e] = GraphColor.Black; if (vc == GraphColor.White) // tree edge { OnTreeEdge(e); Visit(target); } else if (vc == GraphColor.Gray && ec == GraphColor.White) { OnBackEdge(e); } } }
public void Visit(TVertex root, int depth) { if ((object)root == null) { throw new ArgumentNullException("root"); } Stack <SearchFrame> todo = new Stack <SearchFrame>(); this.VertexColors[root] = GraphColor.Gray; OnDiscoverVertex(root); var cancelManager = this.Services.CancelManager; todo.Push(new SearchFrame(root, this.VisitedGraph.OutEdges(root).GetEnumerator())); while (todo.Count > 0) { if (cancelManager.IsCancelling) { return; } var frame = todo.Pop(); var u = frame.Vertex; var edges = frame.Edges; while (edges.MoveNext()) { TEdge e = edges.Current; if (cancelManager.IsCancelling) { return; } this.OnExamineEdge(e); TVertex v = e.Target; GraphColor c = this.VertexColors[v]; switch (c) { case GraphColor.White: OnTreeEdge(e); todo.Push(new SearchFrame(u, edges)); u = v; edges = this.VisitedGraph.OutEdges(u).GetEnumerator(); this.VertexColors[u] = GraphColor.Gray; this.OnDiscoverVertex(u); break; case GraphColor.Gray: OnBackEdge(e); break; case GraphColor.Black: OnForwardOrCrossEdge(e); break; } } this.VertexColors[u] = GraphColor.Black; this.OnFinishVertex(u); } }
public static string AsString(this GraphColor obj) { switch (obj) { case GraphColor.Shibafu: return("shibafu"); case GraphColor.Momiji: return("momiji"); case GraphColor.Sora: return("sora"); case GraphColor.Ichou: return("ichou"); case GraphColor.Ajisai: return("ajisai"); case GraphColor.Kuro: return("kuro"); default: throw new ArgumentOutOfRangeException(nameof(obj), obj, null); } }
public static DirectedGraph ToDirectedGraphML <TVertex, TEdge>( [NotNull] this IVertexAndEdgeListGraph <TVertex, TEdge> graph, [NotNull] Func <TVertex, GraphColor> verticesColors) where TEdge : IEdge <TVertex> { if (verticesColors is null) { throw new ArgumentNullException(nameof(verticesColors)); } return(ToDirectedGraphML( graph, graph.GetVertexIdentity(), graph.GetEdgeIdentity(), (vertex, node) => { GraphColor color = verticesColors(vertex); switch (color) { case GraphColor.Black: node.Background = "Black"; break; case GraphColor.Gray: node.Background = "LightGray"; break; case GraphColor.White: node.Background = "White"; break; } }, null)); }
/// <summary> /// Create a merged path. /// </summary> /// <remarks> /// <para> /// This method creates an edge path that stops if an edge is not white /// or the edge has no more predecessors. /// </para> /// </remarks> /// <param name="se">end edge</param> /// <param name="colors">edge color dictionary</param> /// <returns>path to edge</returns> public EdgeCollection MergedPath(IEdge se, EdgeColorDictionary colors) { EdgeCollection path = new EdgeCollection(); IEdge ec = se; GraphColor c = colors[ec]; if (c != GraphColor.White) { return(path); } else { colors[ec] = GraphColor.Black; } path.Insert(0, ec); while (EdgePredecessors.Contains(ec)) { IEdge e = EdgePredecessors[ec]; c = colors[e]; if (c != GraphColor.White) { return(path); } else { colors[e] = GraphColor.Black; } path.Insert(0, e); ec = e; } return(path); }
public ICollection <TEdge> MergedPath(TEdge se, IDictionary <TEdge, GraphColor> colors) { List <TEdge> path = new List <TEdge>(); TEdge ec = se; GraphColor c = colors[ec]; if (c != GraphColor.White) { return(path); } else { colors[ec] = GraphColor.Black; } path.Insert(0, ec); while (EdgePredecessors.ContainsKey(ec)) { TEdge e = EdgePredecessors[ec]; c = colors[e]; if (c != GraphColor.White) { return(path); } else { colors[e] = GraphColor.Black; } path.Insert(0, e); ec = e; } return(path); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void WriteEdge(Object sender, EdgeEventArgs args) { if (m_EdgeColors != null && m_EdgeColors.Contains(args.Edge)) { GraphColor c = (GraphColor)m_EdgeColors[args.Edge]; switch (c) { case GraphColor.White: EdgeFormatter.Style = GraphvizEdgeStyle.Unspecified; EdgeFormatter.StrokeColor = Color.Black; break; case GraphColor.Gray: EdgeFormatter.Style = GraphvizEdgeStyle.Bold; EdgeFormatter.StrokeColor = Color.Gray; break; case GraphColor.Black: EdgeFormatter.Style = GraphvizEdgeStyle.Bold; EdgeFormatter.StrokeColor = Color.Black; break; } } else { EdgeFormatter.Style = GraphvizEdgeStyle.Unspecified; } if (EdgeLabels != null) { EdgeFormatter.Label.Value = EdgeLabels[args.Edge].ToString(); } ((GraphvizAlgorithm)sender).Output.Write(EdgeFormatter.ToDot()); }
/// <summary> /// 初始化指定大小的组图容器 /// </summary> /// <param name="subSize"></param> public SubChart(Size subSize) { totalChartArea = new Rectangle(0, 0, subSize.Width, subSize.Height); totalChartColor = new GraphColor(Color.White, Color.White); subCharts = new Chart2D[rows, cols]; subRectangles = SetSubChart(); }
/// <summary> /// 初始化默认组图容器(默认长宽为800*500,行列数均为1,边距为0) /// </summary> public SubChart() { totalChartArea = new Rectangle(0, 0, 500, 800); totalChartColor = new GraphColor(Color.White, Color.White); subCharts = new Chart2D[rows, cols]; subRectangles = SetSubChart(); }
public static DirectedGraph ToDirectedGraphML <TVertex, TEdge>( [NotNull] this IVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph, [NotNull] Func <TVertex, GraphColor> vertexColors) where TEdge : IEdge <TVertex> { return(ToDirectedGraphML( visitedGraph, visitedGraph.GetVertexIdentity(), visitedGraph.GetEdgeIdentity(), (vertex, node) => { GraphColor color = vertexColors(vertex); switch (color) { case GraphColor.Black: node.Background = "Black"; break; case GraphColor.Gray: node.Background = "LightGray"; break; case GraphColor.White: node.Background = "White"; break; } }, null)); }
public void Visit(TVertex u, int depth) { if (depth > this.maxDepth) { return; } if (u == null) { throw new ArgumentNullException("u"); } var cancelManager = this.Services.CancelManager; if (cancelManager.IsCancelling) { return; } VertexColors[u] = GraphColor.Gray; OnDiscoverVertex(u); TVertex v = default(TVertex); foreach (var e in VisitedGraph.AdjacentEdges(u)) { if (cancelManager.IsCancelling) { return; } OnExamineEdge(e); if (u.Equals(e.Source)) { v = e.Target; } else { v = e.Source; } GraphColor c = VertexColors[v]; if (c == GraphColor.White) { OnTreeEdge(e); Visit(v, depth + 1); } else if (c == GraphColor.Gray) { OnBackEdge(e); } else { OnForwardOrCrossEdge(e); } } VertexColors[u] = GraphColor.Black; OnFinishVertex(u); }
/// <summary> /// Does a depth first search on the vertex u /// </summary> /// <param name="u">vertex to explore</param> /// <param name="depth">current recursion depth</param> /// <exception cref="ArgumentNullException">u cannot be null</exception> public void Visit(IVertex u, int depth) { if (depth > this.maxDepth) { return; } if (u == null) { throw new ArgumentNullException("u"); } Colors[u] = GraphColor.Gray; OnDiscoverVertex(u); IVertex v = null; foreach (IEdge e in VisitedGraph.OutEdges(u)) { OnExamineOutEdge(e); v = e.Target; GraphColor c = Colors[v]; if (c == GraphColor.White) { OnTreeOutEdge(e); Visit(v, depth + 1); } else if (c == GraphColor.Gray) { OnBackOutEdge(e); } else { OnForwardOrCrossOutEdge(e); } } foreach (IEdge e in VisitedGraph.InEdges(u)) { OnExamineInEdge(e); v = e.Source; GraphColor c = Colors[v]; if (c == GraphColor.White) { OnTreeInEdge(e); Visit(v, depth + 1); } else if (c == GraphColor.Gray) { OnBackInEdge(e); } else { OnForwardOrCrossInEdge(e); } } Colors[u] = GraphColor.Black; OnFinishVertex(u); }
internal ChartStyle(Chart2D ct2d) { chart2d = ct2d; chartArea = new Rectangle(new Point(0, 0), chart2d.ChartSize); chartAreaColor = new GraphColor(Color.White, Color.White); plotAreaColor = new GraphColor(); XOffset = ChartArea.Width / 30.0f; YOffset = ChartArea.Height / 30.0f; }
/// <summary> /// Converts GraphColor to System.Drawing.Color /// </summary> /// <param name="c">graph color to convert</param> /// <returns>corresponding Color</returns> public static Color Convert(GraphColor c) { switch(c) { case GraphColor.Gray: return Color.Gray; case GraphColor.Black: return Color.Black; default: return Color.White; } }
/// <summary> /// Determines whether this EdgeGraphColorDictionary contains a specific value. /// </summary> /// <param name="value"> /// The GraphColor value to locate in this EdgeGraphColorDictionary. /// </param> /// <returns> /// true if this EdgeGraphColorDictionary contains an element with the specified value; /// otherwise, false. /// </returns> public bool ContainsValue(GraphColor value) { foreach (GraphColor item in this.Dictionary.Values) { if (item == value) { return(true); } } return(false); }
/// <summary> /// Converts GraphColor to System.Drawing.Color /// </summary> /// <param name="c">graph color to convert</param> /// <returns>corresponding Color</returns> public static Color Convert(GraphColor c) { switch (c) { case GraphColor.Gray: return(Color.Gray); case GraphColor.Black: return(Color.Black); default: return(Color.White); } }
public bool PaintBlack() { if (Color == GraphColor.Gray) { if (Exits.Any(x => x.Color == GraphColor.Black)) { Color = GraphColor.Black; return(true); } } return(false); }
/// <summary> /// Does a depth first search on the vertex u /// </summary> /// <param name="se">edge to explore</param> /// <param name="depth">current exploration depth</param> /// <exception cref="ArgumentNullException">se cannot be null</exception> private void Visit(TEdge se, int depth) { if (depth > this.maxDepth) { return; } if (se == null) { throw new ArgumentNullException("se"); } if (this.IsAborting) { return; } // mark edge as gray this.EdgeColors[se] = GraphColor.Gray; // add edge to the search tree OnTreeEdge(se); // iterate over out-edges foreach (TEdge e in this.VisitedGraph.OutEdges(se.Target)) { if (this.IsAborting) { return; } // check edge is not explored yet, // if not, explore it. if (!this.EdgeColors.ContainsKey(e)) { OnDiscoverTreeEdge(se, e); Visit(e, depth + 1); } else { GraphColor c = this.EdgeColors[e]; if (EdgeColors[e] == GraphColor.Gray) { OnBackEdge(e); } else { OnForwardOrCrossEdge(e); } } } // all out-edges have been explored this.EdgeColors[se] = GraphColor.Black; OnFinishEdge(se); }
public void Visit(TVertex s) { if (this.IsAborting) { return; } this.VertexColors[s] = GraphColor.Gray; OnDiscoverVertex(s); this.vertexQueue.Push(s); while (this.vertexQueue.Count != 0) { if (this.IsAborting) { return; } TVertex u = this.vertexQueue.Pop(); OnExamineVertex(u); foreach (TEdge e in VisitedGraph.AdjacentEdges(u)) { TVertex v = (e.Source.Equals(u)) ? e.Target : e.Source; OnExamineEdge(e); GraphColor vColor = VertexColors[v]; if (vColor == GraphColor.White) { OnTreeEdge(e); VertexColors[v] = GraphColor.Gray; OnDiscoverVertex(v); this.vertexQueue.Push(v); } else { OnNonTreeEdge(e); if (vColor == GraphColor.Gray) { OnGrayTarget(e); } else { OnBlackTarget(e); } } } VertexColors[u] = GraphColor.Black; OnFinishVertex(u); } }
public State(XElement element, StateMachine machine) { this.Element = element; this.Machine = machine; Color = GraphColor.White; Exits = new List <State>(); ReferenceID = Element.Attribute(XName.Get("Name", Machine.Namespaces.LookupNamespace("x")))?.Value ?? DateTime.Now.Ticks.ToString(); DisplayName = Element.Attribute("DisplayName")?.Value ?? "State"; string isFinalValue = Element.Attribute("IsFinal")?.Value ?? string.Empty; IsFinal = isFinalValue.Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase); }
public Legend() { //chart2d = ct2d; isLegendVisible = true; isInside = true; legendPosition = LegendPositionEnum.NorthEast; isVertical = true; isBorderVisible = true; legendColor = new GraphColor(); textStyle = new TextStyle(); textStyle.TextSize = 8f; xLgOffSet = 8f; yLgOffSet = 8f; }
/// <summary> /// Does a depth first search on the vertex u /// </summary> /// <param name="se">edge to explore</param> /// <param name="depth">current exploration depth</param> /// <exception cref="ArgumentNullException">se cannot be null</exception> private void Visit(TEdge se, int depth) { Contract.Requires(se != null); Contract.Requires(depth >= 0); if (depth > this.maxDepth) { return; } // mark edge as gray this.EdgeColors[se] = GraphColor.Gray; // add edge to the search tree OnTreeEdge(se); var cancelManager = this.Services.CancelManager; // iterate over out-edges foreach (var e in this.VisitedGraph.OutEdges(se.Target)) { if (cancelManager.IsCancelling) { return; } // check edge is not explored yet, // if not, explore it. if (!this.EdgeColors.ContainsKey(e)) { OnDiscoverTreeEdge(se, e); Visit(e, depth + 1); } else { GraphColor c = this.EdgeColors[e]; if (EdgeColors[e] == GraphColor.Gray) { OnBackEdge(e); } else { OnForwardOrCrossEdge(e); } } } // all out-edges have been explored this.EdgeColors[se] = GraphColor.Black; OnFinishEdge(se); }
/// <summary> /// Computes the bfs starting at s without initalization. /// </summary> /// <param name="s">starting vertex</param> /// <param name="depth">current depth</param> /// <exception cref="ArgumentNullException">s is null</exception> public void Visit(IVertex s) { if (s == null) { throw new ArgumentNullException("Start vertex is null"); } Colors[s] = GraphColor.Gray; OnDiscoverVertex(s); m_Q.Push(s); while (m_Q.Count != 0) { IVertex u = (IVertex)m_Q.Peek(); m_Q.Pop(); OnExamineVertex(u); foreach (IEdge e in VisitedGraph.OutEdges(u)) { IVertex v = e.Target; OnExamineEdge(e); GraphColor vColor = Colors[v]; if (vColor == GraphColor.White) { OnTreeEdge(e); Colors[v] = GraphColor.Gray; OnDiscoverVertex(v); m_Q.Push(v); } else { OnNonTreeEdge(e); if (vColor == GraphColor.Gray) { OnGrayTarget(e); } else { OnBlackTarget(e); } } } Colors[u] = GraphColor.Black; OnFinishVertex(u); } }
public void AddNode( object identity, string label = null, Style style = Style.Default, Shape shape = Shape.Default, GraphColor color = GraphColor.Default) { Node node = GetOrAddNode(identity, label, style, shape, color); if (node.PostponeGeneration) { return; } GenerateNode(node); }
/// <summary> /// Visits vertex s /// </summary> /// <param name="u">vertex to visit</param> public void Visit(IVertex u) { VertexEventArgs uArgs = new VertexEventArgs(u); Colors[u] = GraphColor.Gray; if (DiscoverVertex != null) { DiscoverVertex(this, uArgs); } foreach (IEdge e in VisitedGraph.OutEdges(u)) { EdgeEventArgs eArgs = new EdgeEventArgs(e); if (ExamineEdge != null) { ExamineEdge(this, eArgs); } GraphColor vc = Colors[e.Target]; GraphColor ec = EdgeColors[e]; EdgeColors[e] = GraphColor.Black; if (vc == GraphColor.White) // tree edge { if (TreeEdge != null) { TreeEdge(this, eArgs); } Visit(e.Target); } else if (vc == GraphColor.Gray && ec == GraphColor.White) { if (BackEdge != null) { BackEdge(this, eArgs); } } } Colors[u] = GraphColor.Black; if (FinishVertex != null) { FinishVertex(this, uArgs); } }
private void Visit(TVertex u, int depth) { if (depth > this.MaxDepth) { return; } if (this.IsAborting) { return; } VertexColors[u] = GraphColor.Gray; OnDiscoverVertex(u); foreach (TEdge e in VisitedGraph.OutEdges(u)) { if (this.IsAborting) { return; } OnExamineEdge(e); TVertex v = e.Target; if (!this.VertexColors.ContainsKey(v)) { OnTreeEdge(e); Visit(v, depth + 1); } else { GraphColor c = VertexColors[v]; if (c == GraphColor.Gray) { OnBackEdge(e); } else { OnForwardOrCrossEdge(e); } } } VertexColors[u] = GraphColor.Black; OnFinishVertex(u); }
private void FlushVisitQueue() { var cancelManager = this.Services.CancelManager; while (this.vertexQueue.Count != 0) { if (cancelManager.IsCancelling) { return; } TVertex u = this.vertexQueue.Dequeue(); OnExamineVertex(u); foreach (var e in VisitedGraph.AdjacentEdges(u)) { TVertex v = (e.Source.Equals(u)) ? e.Target : e.Source; OnExamineEdge(e); GraphColor vColor = VertexColors[v]; if (vColor == GraphColor.White) { OnTreeEdge(e); VertexColors[v] = GraphColor.Gray; OnDiscoverVertex(v); this.vertexQueue.Enqueue(v); } else { OnNonTreeEdge(e); if (vColor == GraphColor.Gray) { OnGrayTarget(e); } else { OnBlackTarget(e); } } } VertexColors[u] = GraphColor.Black; OnFinishVertex(u); } }
private void ProcessEdge(int depth, [NotNull] TVertex vertex, [NotNull] TEdge edge) { GraphColor color = VerticesColors[vertex]; if (color == GraphColor.White) { OnTreeEdge(edge); Visit(vertex, depth + 1); } else if (color == GraphColor.Gray) { OnBackEdge(edge); } else { OnForwardOrCrossEdge(edge); } }
/// <summary> /// Converts GraphColor to System.Drawing.Color /// </summary> /// <param name="c">graph color to convert</param> /// <param name="alpha">alpha component</param> /// <returns>corresponding Color</returns> public static Color Convert(GraphColor c, int alpha) { Color col; switch(c) { case GraphColor.Gray: col=Color.Gray; break; case GraphColor.Black: col=Color.Black; break; default: col=Color.White; break; } return Color.FromArgb(alpha,col.R,col.G,col.B); }
private void ProcessEdge(int depth, TVertex v, TEdge e) { GraphColor c = VertexColors[v]; if (c == GraphColor.White) { OnTreeEdge(e); Visit(v, depth + 1); } else if (c == GraphColor.Gray) { OnBackEdge(e); } else { OnForwardOrCrossEdge(e); } }
/// <summary> /// Adds an element with the specified key and value to this EdgeGraphColorDictionary. /// </summary> /// <param name="key"> /// The Edge key of the element to add. /// </param> /// <param name="value"> /// The GraphColor value of the element to add. /// </param> public void Add(IEdge key, GraphColor value) { this.Dictionary.Add(key, value); }
/// <summary> /// Determines whether this VertexColorDictionary contains a specific value. /// </summary> /// <param name="value"> /// The GraphColor value to locate in this VertexColorDictionary. /// </param> /// <returns> /// true if this VertexColorDictionary contains an element with the specified value; /// otherwise, false. /// </returns> public virtual bool ContainsValue(GraphColor value) { foreach (GraphColor item in this.Dictionary.Values) { if (item == value) return true; } return false; }
/// <summary> /// Adds an element with the specified key and value to this VertexColorDictionary. /// </summary> /// <param name="key"> /// The Vertex key of the element to add. /// </param> /// <param name="value"> /// The GraphColor value of the element to add. /// </param> public virtual void Add(IVertex key, GraphColor value) { this.Dictionary.Add(key, value); }
private Node GetOrAddNode(object identity, string label, Style style, Shape shape, GraphColor color) { Node node; if (!nodes.TryGetValue(identity, out node)) { int index = nodes.Count; node = new Node { Index = index, Label = label, Style = style, Shape = shape, Color = color, PostponeGeneration = label == null, }; nodes.Add(identity, node); } else { if (node.Label == null) { node.Label = label; } if (node.Style == Style.Default) { node.Style = style; } if (node.Shape == Shape.Default) { node.Shape = shape; } if (node.Color == GraphColor.Default) { node.Color = color; } } return node; }
private string ColorToText(GraphColor color) { string name = Enum.GetName(typeof(GraphColor), color); return name.ToLower(); }