diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 196043f27546d4901fa791e1ae473291936a2b48..e94b17551f979481f3ff884b9c3adf1f088cfbe1 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -274,107 +274,107 @@ namespace FlowForge private string GenerateTikzCode_Curved() { - if (_flowGraph == null) - throw new InvalidOperationException("Flow graph is not initialized."); - - var tikzBuilder = new System.Text.StringBuilder(); - tikzBuilder.AppendLine("\\documentclass[tikz,border=3mm]{standalone}"); - tikzBuilder.AppendLine("\\usetikzlibrary{arrows.meta,positioning}"); - tikzBuilder.AppendLine("\\usepackage{amsmath}"); - tikzBuilder.AppendLine("\\begin{document}"); - - // Global scaling and styles for smaller nodes and text - tikzBuilder.AppendLine("\\begin{tikzpicture}[scale=3,->,>=stealth,shorten >=1pt,auto,node distance=2cm,thick,"); - tikzBuilder.AppendLine("main node/.style={circle,draw,minimum size=1mm,inner sep=1pt,font=\\scriptsize}]"); - - // Nodes - foreach (var vertex in _flowGraph.Graph.Vertices) - { - if (_nodePositions.ContainsKey(vertex.Id)) + if (_flowGraph == null) + throw new InvalidOperationException("Flow graph is not initialized."); + + var tikzBuilder = new System.Text.StringBuilder(); + tikzBuilder.AppendLine("\\documentclass[tikz,border=3mm]{standalone}"); + tikzBuilder.AppendLine("\\usetikzlibrary{arrows.meta,positioning}"); + tikzBuilder.AppendLine("\\usepackage{amsmath}"); + tikzBuilder.AppendLine("\\begin{document}"); + + // Global scaling and styles for smaller nodes and text + tikzBuilder.AppendLine("\\begin{tikzpicture}[scale=3,->,>=stealth,shorten >=1pt,auto,node distance=2cm,thick,"); + tikzBuilder.AppendLine("main node/.style={circle,draw,minimum size=5mm,inner sep=1pt,font=\\scriptsize}]"); + + // Nodes + foreach (var vertex in _flowGraph.Graph.Vertices) { - var position = _nodePositions[vertex.Id]; - // Format x and y as floating-point values with two decimal places - string formattedX = (position.X / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); - string formattedY = (position.Y / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); + if (_nodePositions.ContainsKey(vertex.Id)) + { + var position = _nodePositions[vertex.Id]; + // Format x and y as floating-point values with two decimal places + string formattedX = (position.X / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); + string formattedY = (position.Y / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); - tikzBuilder.AppendLine($"\\node[main node] ({vertex.Id}) at ({formattedX},{formattedY}) {{{vertex.Id}}};"); + tikzBuilder.AppendLine($"\\node[main node] ({vertex.Id}) at ({formattedX},{formattedY}) {{{vertex.Id}}};"); + } } - } - - // Edges - foreach (var edge in _flowGraph.GetEdges()) - { - string label = $"{edge.Residual}/{edge.MaxFlow}"; - if (edge.IsBackwards) + // Edges + foreach (var edge in _flowGraph.GetEdges()) { - // Reverse edge styling (curved, dashed, different color) - tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}},bend right,dashed,red] ({edge.Source.Id}) edge [pos=0.5,sloped] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); - } - else - { - // Normal edge styling - tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}}] ({edge.Source.Id}) edge [pos=0.5,sloped] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); - } - } - - tikzBuilder.AppendLine("\\end{tikzpicture}"); - tikzBuilder.AppendLine("\\end{document}"); + string label = $"{edge.Residual}/{edge.MaxFlow}"; - return tikzBuilder.ToString(); -} + if (edge.IsBackwards) + { + // Reverse edge styling (curved, dashed, different color) + tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}},bend right,dashed,red] ({edge.Source.Id}) edge [pos=0.5,sloped] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + } + else + { + // Normal edge styling + tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}}] ({edge.Source.Id}) edge [pos=0.5,sloped] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + } + } - private string GenerateTikzCode() -{ - if (_flowGraph == null) - throw new InvalidOperationException("Flow graph is not initialized."); - - var tikzBuilder = new System.Text.StringBuilder(); - tikzBuilder.AppendLine("\\documentclass[tikz,border=3mm]{standalone}"); - tikzBuilder.AppendLine("\\usetikzlibrary{arrows.meta,positioning}"); - tikzBuilder.AppendLine("\\usepackage{amsmath}"); - tikzBuilder.AppendLine("\\begin{document}"); - - // Global scaling and styles for smaller nodes and text - tikzBuilder.AppendLine("\\begin{tikzpicture}[scale=3,->,>=stealth,shorten >=1pt,auto,node distance=2cm,thick,"); - tikzBuilder.AppendLine("main node/.style={circle,draw,minimum size=1mm,inner sep=1pt,font=\\scriptsize}]"); - - // Nodes - foreach (var vertex in _flowGraph.Graph.Vertices) - { - if (_nodePositions.ContainsKey(vertex.Id)) - { - var position = _nodePositions[vertex.Id]; - // Format x and y as floating-point values with two decimal places - string formattedX = (position.X / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); - string formattedY = (position.Y / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); + tikzBuilder.AppendLine("\\end{tikzpicture}"); + tikzBuilder.AppendLine("\\end{document}"); - tikzBuilder.AppendLine($"\\node[main node] ({vertex.Id}) at ({formattedX},{formattedY}) {{{vertex.Id}}};"); - } + return tikzBuilder.ToString(); } - // Edges - foreach (var edge in _flowGraph.GetEdges()) + private string GenerateTikzCode() { - string label = $"{edge.Residual}/{edge.MaxFlow}"; + if (_flowGraph == null) + throw new InvalidOperationException("Flow graph is not initialized."); + + var tikzBuilder = new System.Text.StringBuilder(); + tikzBuilder.AppendLine("\\documentclass[tikz,border=3mm]{standalone}"); + tikzBuilder.AppendLine("\\usetikzlibrary{arrows.meta,positioning}"); + tikzBuilder.AppendLine("\\usepackage{amsmath}"); + tikzBuilder.AppendLine("\\begin{document}"); + + // Global scaling and styles for smaller nodes and text + tikzBuilder.AppendLine("\\begin{tikzpicture}[scale=3,->,>=stealth,shorten >=1pt,auto,node distance=2cm,thick,"); + tikzBuilder.AppendLine("main node/.style={circle,draw,minimum size=1mm,inner sep=1pt,font=\\scriptsize}]"); - if (edge.IsBackwards) + // Nodes + foreach (var vertex in _flowGraph.Graph.Vertices) { - // Reverse edge styling: offset slightly above forward edges - tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}},dashed,red] ({edge.Source.Id}) edge [pos=0.5,above] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + if (_nodePositions.ContainsKey(vertex.Id)) + { + var position = _nodePositions[vertex.Id]; + // Format x and y as floating-point values with two decimal places + string formattedX = (position.X / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); + string formattedY = (position.Y / 100.0).ToString("F2", System.Globalization.CultureInfo.InvariantCulture); + + tikzBuilder.AppendLine($"\\node[main node] ({vertex.Id}) at ({formattedX},{formattedY}) {{{vertex.Id}}};"); + } } - else + + // Edges + foreach (var edge in _flowGraph.GetEdges()) { - // Normal edge styling - tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}}] ({edge.Source.Id}) edge [pos=0.5,below] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + string label = $"{edge.Residual}/{edge.MaxFlow}"; + + if (edge.IsBackwards) + { + // Reverse edge styling: offset slightly above forward edges + tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}},dashed,red] ({edge.Source.Id}) edge [pos=0.5,above] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + } + else + { + // Normal edge styling + tikzBuilder.AppendLine($"\\path[every node/.style={{font=\\tiny}}] ({edge.Source.Id}) edge [pos=0.5,below] node {{\\texttt{{{label}}}}} ({edge.Target.Id});"); + } } - } - tikzBuilder.AppendLine("\\end{tikzpicture}"); - tikzBuilder.AppendLine("\\end{document}"); + tikzBuilder.AppendLine("\\end{tikzpicture}"); + tikzBuilder.AppendLine("\\end{document}"); - return tikzBuilder.ToString(); -} + return tikzBuilder.ToString(); + } private void ExportGraphToLatex(string filePath)