forked from algorithm-archivists/algorithm-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
67 lines (60 loc) · 1.9 KB
/
Program.cs
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
// submitted by Julian Schacher (jspp) with great help by gustorn and Marius Becker
using System;
using System.Collections.Generic;
namespace StableMarriageProblem
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("GaleShapleyAlgorithm");
// Using men and women as an example.
var men = new List<Man>()
{
new Man("A"),
new Man("B"),
new Man("C"),
new Man("D"),
new Man("E")
};
var women = new List<Woman>()
{
new Woman("F"),
new Woman("G"),
new Woman("H"),
new Woman("I"),
new Woman("J"),
};
var random = new Random();
foreach (var man in men)
{
man.Choices = new List<Woman>(women).Shuffle(random);
Console.WriteLine(man.Name + ":");
foreach (var choice in man.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}
foreach (var woman in women)
{
woman.Choices = new List<Man>(men).Shuffle(random);
Console.WriteLine(woman.Name + ":");
foreach (var choice in woman.Choices)
Console.Write(choice.Name);
Console.WriteLine();
}
GaleShapleyAlgorithm<Woman, Man>.RunGaleShapleyAlgorithm(women, men);
foreach (var woman in women)
{
Console.WriteLine(woman.Name + " : " + woman?.Partner.Name);
}
}
}
public class Man : Person<Man, Woman>
{
public Man(string name) : base(name) { }
}
public class Woman : Person<Woman, Man>
{
public Woman(string name) : base(name) { }
}
}