Skip to content
Snippets Groups Projects
Select Git revision
  • a43c3bc5d807b4400c202895e9fb06d8d23fa5e1
  • main default protected
  • ravaflow3g
  • docs
  • v0.1.2
  • v0.1.1
  • v0.1.0
7 results

plot_ppgasp.py

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;
        }
    }