Skip to content
Snippets Groups Projects
Select Git revision
  • 20525c4e5bb12c43f962809040b2847c488f2d72
  • master default protected
2 results

GraphVisualizer.cs

Blame
  • GraphVisualizer.cs 1.10 KiB
    using Microsoft.Msagl.Drawing;
    
    namespace FlowForge;
    
    public static class GraphVisualizer
    {
        public static Graph ConvertToMsaglGraph(FlowGraph? flowGraph)
        {
            Graph msaglGraph = new Graph();
    
            foreach (var vertex in flowGraph.Graph.Vertices)
            {
                var msaglNode = msaglGraph.AddNode(vertex.Id);
                msaglNode.LabelText = vertex.Label; // Use the label from FlowNode
            }
    
            foreach (var edge in flowGraph.Graph.Edges)
            {
                //if(edge.IsBackwards) continue;
                
                var msaglEdge = msaglGraph.AddEdge(edge.Source.Id, edge.Target.Id);
    
                if (edge.IsBackwards)
                {
                    msaglEdge.LabelText = $"{0}/{edge.Residual}";
                    msaglEdge.Attr.Color = Color.Gray;
                }
                else
                {
                    msaglEdge.LabelText = $"{edge.MaxFlow-edge.Residual}/{edge.MaxFlow}";
    
                    if (edge.MaxFlow-edge.Residual > 0)
                    {
                        msaglEdge.Attr.Color = Color.Orange;
                    }
                }
            }
    
            return msaglGraph;
        }
    }