-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (70 loc) · 3 KB
/
Program.cs
File metadata and controls
81 lines (70 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//#define EULER
#define MM
//#define HUNGARY
//#define TSP
//#define COLOR
//#define KNAPSACK
using OptimizationMethods.Algorithms;
using OptimizationMethods.Graphs;
class Program
{
static void Main(string[] args)
{
// Euler Cycle
#if EULER
var graphE = GraphParser.LoadGraphFromFile("TestData/euler-yes.txt");
graphE.PrintGraph();
EulerCycle.RunAndPrint(graphE, "euler-output.dot");
Console.WriteLine("----");
graphE = GraphParser.LoadGraphFromFile("TestData/euler-no.txt");
graphE.PrintGraph();
EulerCycle.RunAndPrint(graphE);
Console.WriteLine("-----------------");
#endif
#if MM
var (graphM, initialMatching) = GraphParser.LoadGraphAndInitialMatching("TestData/maksymalne_skojarzenie1.txt");
graphM.PrintGraph();
// Run without initial matching (pure algorithm)
MaximumMatching.RunAndPrint(graphM, toDotPath: "max-output2.dot");
// Run with initial matching from file weights (e.g. weight == 2)
MaximumMatching.RunAndPrint(graphM, initialMatching: initialMatching, toDotPath: "max-output.dot");
Console.WriteLine("-----------------");
#endif
#if HUNGARY
var graphH = GraphParser.LoadGraphFromFile("TestData/algorytm_wegierski1.txt");
graphH.PrintGraph();
GraphPrinter.WriteDotFile(graphH, "hungarian-input.dot");
HungarianAlgorithm.Run(graphH, "hungarian-output.dot");
Console.WriteLine("-----------------");
#endif
#if TSP
var graphTSP = GraphParser.LoadGraphFromFile("TestData/komiwojazer.txt");
graphTSP.PrintGraph();
TravelingSalesmanProblem.RunBranchAndBound(graphTSP, "komiwojazer-bb-output.dot");
TravelingSalesmanProblem.RunMstApproximation(graphTSP, "komiwojazer-mst-output.dot");
TravelingSalesmanProblem.RunGenetic(graphTSP, "komiwojazer-ga1-output.dot");
#endif
#if COLOR
var graphC = GraphParser.LoadGraphFromFile("TestData/graph_coloring.txt");
graphC.PrintGraph();
var coloringResult = GraphColoring.Color(graphC);
Console.WriteLine($"Used {coloringResult.NumberOfColorsUsed} colors.");
foreach (var kv in coloringResult.VertexColors.OrderBy(k => k.Key))
Console.WriteLine($"Vertex {kv.Key} -> Color {kv.Value}");
GraphPrinter.ExportWithColoring(graphC, coloringResult.VertexColors, "graph-coloring-output.dot");
Console.WriteLine("-----------------");
#endif
#if KNAPSACK
var values = new List<float> { 4f, 3f, 6f, 4f };
var weights = new List<float> { 1f, 2f, 5f, 4f };
float capacity = 5f;
var selected = HorowitzSahniKnapsack.Solve(values, weights, capacity);
Console.WriteLine("Selected item indices:");
foreach (var index in selected)
Console.WriteLine($"Item {index} -> Value: {values[index]}, Weight: {weights[index]}");
float total = selected.Sum(i => values[i]);
Console.WriteLine($"Total value: {total}");
Console.WriteLine("-----------------");
#endif
}
}