Skip to content
Snippets Groups Projects
Commit 0cb31d35 authored by Timon Römer's avatar Timon Römer
Browse files

Init

parents
No related branches found
No related tags found
No related merge requests found
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/contentModel.xml
/projectSettingsUpdater.xml
/.idea.FlowForge.iml
/modules.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<Application x:Class="FlowForge.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!-- Application-level resources, like styles or themes, go here -->
</Application.Resources>
</Application>
\ No newline at end of file
using System.Windows;
namespace FlowForge
{
public partial class App : Application
{
}
}
\ No newline at end of file
using System.Windows;
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
namespace FlowForge;
using QuikGraph;
public class FlowEdge : Edge<FlowNode>
{
public double MaxFlow { get; set; }
public double CurrentFlow { get; set; }
public FlowEdge(FlowNode source, FlowNode target, double maxFlow)
: base(source, target)
{
MaxFlow = maxFlow;
CurrentFlow = 0; // Initially, the current flow is set to zero.
}
public override string ToString()
{
return $"{Source.Id} -> {Target.Id} [CurrentFlow: {CurrentFlow}, MaxFlow: {MaxFlow}]";
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Msagl" Version="1.1.6" />
<PackageReference Include="Microsoft.Msagl.Drawing" Version="1.1.6" />
<PackageReference Include="Microsoft.Msagl.GraphViewerGDI" Version="1.1.7" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="App.xaml">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowForge", "FlowForge.csproj", "{8F0CDC44-7EB3-445B-94DD-E570F2022398}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8F0CDC44-7EB3-445B-94DD-E570F2022398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F0CDC44-7EB3-445B-94DD-E570F2022398}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F0CDC44-7EB3-445B-94DD-E570F2022398}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F0CDC44-7EB3-445B-94DD-E570F2022398}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
using System.Collections.Generic;
using QuikGraph;
namespace FlowForge;
public class FlowGraph
{
public BidirectionalGraph<FlowNode, FlowEdge> Graph { get; private set; }
private readonly Dictionary<string, FlowNode> _nodeLookup;
public FlowGraph()
{
Graph = new BidirectionalGraph<FlowNode, FlowEdge>();
_nodeLookup = new Dictionary<string, FlowNode>();
}
public void AddVertex(string id, string? label = null)
{
var node = new FlowNode(id, label);
Graph.AddVertex(node);
_nodeLookup[id] = node;
}
public FlowNode? GetVertexById(string id)
{
return _nodeLookup.GetValueOrDefault(id);
}
public void AddEdge(string sourceId, string targetId, double maxFlow)
{
var sourceNode = GetVertexById(sourceId);
var targetNode = GetVertexById(targetId);
if (sourceNode == null || targetNode == null) return;
var edge = new FlowEdge(sourceNode, targetNode, maxFlow);
Graph.AddEdge(edge);
}
public IEnumerable<FlowEdge> GetEdges()
{
return Graph.Edges;
}
}
\ No newline at end of file
namespace FlowForge;
public class FlowNode
{
public string Id { get; private set; }
public string Label { get; set; } // Display label for the node.
public FlowNode(string id, string? label = null)
{
Id = id;
Label = label ?? id;
}
public override string ToString()
{
return Label;
}
}
using System;
using System.Collections.Generic;
namespace FlowForge;
public class FordFulkersonAlgorithm
{
private FlowGraph _flowGraph;
public FordFulkersonAlgorithm(FlowGraph flowGraph)
{
_flowGraph = flowGraph;
}
public double Run(string sourceId, string targetId)
{
FlowNode? source = _flowGraph.GetVertexById(sourceId);
FlowNode? target = _flowGraph.GetVertexById(targetId);
if (source == null || target == null)
throw new ArgumentException("Invalid source or target node.");
double maxFlow = 0.0;
// Implement the Ford-Fulkerson algorithm here.
// Update the CurrentFlow in each FlowEdge as necessary.
return maxFlow;
}
private bool FindAugmentingPath(FlowNode source, FlowNode target, Dictionary<FlowEdge, double> pathFlow)
{
// Implement BFS/DFS to find an augmenting path and return true if found.
// This will be used to determine if we can push more flow through the graph.
return false;
}
}
using Microsoft.Msagl.Drawing;
namespace FlowForge;
public 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)
{
var msaglEdge = msaglGraph.AddEdge(edge.Source.Id, edge.Target.Id);
msaglEdge.LabelText = $"{edge.CurrentFlow}/{edge.MaxFlow}";
}
return msaglGraph;
}
}
<Window x:Class="FlowForge.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="FlowForge" Height="600" Width="800">
<Grid x:Name="MainGrid">
<!-- Der WindowsFormsHost wird im Code-Behind hinzugefügt -->
</Grid>
</Window>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms.Integration;
using MsaglDrawing = Microsoft.Msagl.Drawing;
using Microsoft.Msagl.GraphViewerGdi;
namespace FlowForge
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private GViewer? _gViewer;
public MainWindow()
{
InitializeComponent();
SetupGraphViewer();
DisplayGraph();
}
private void SetupGraphViewer()
{
// GViewer initialisieren
_gViewer = new GViewer();
// WindowsFormsHost erstellen
var host = new WindowsFormsHost();
// GViewer dem Host hinzufügen
host.Child = _gViewer;
// Host dem Grid hinzufügen
MainGrid.Children.Add(host);
}
private void DisplayGraph()
{
// Graph erstellen
MsaglDrawing.Graph graph = new MsaglDrawing.Graph();
// Kanten hinzufügen und Beschriftungen setzen
var edge1 = graph.AddEdge("1", "2");
edge1.LabelText = "10/10";
var edge2 = graph.AddEdge("2", "3");
edge2.LabelText = "5/10";
var edge3 = graph.AddEdge("3", "4");
edge3.LabelText = "5/20";
var edge4 = graph.AddEdge("2", "4");
edge4.LabelText = "5/20";
// Knoten Attribute setzen
MsaglDrawing.Node node1 = graph.FindNode("1");
if (node1 != null)
{
node1.Attr.FillColor = MsaglDrawing.Color.Green; // Node 1 grün färben
}
MsaglDrawing.Node node4 = graph.FindNode("4");
if (node4 != null)
{
node4.Attr.FillColor = MsaglDrawing.Color.Red; // Node 4 rot färben
}
// Graph dem GViewer zuweisen
if (_gViewer != null)
{
_gViewer.Graph = graph;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment