diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-05-31 11:40:49 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-05-31 11:40:49 +0200 |
commit | ca4d88e67d39d3071304508017e6543ab19d160d (patch) | |
tree | 7493f12c58c6e32fd518f24e007da1b24aa4d3ff | |
parent | 334ea750eb86da45764fd22d25524a80a5531597 (diff) | |
download | uni-ca4d88e67d39d3071304508017e6543ab19d160d.tar uni-ca4d88e67d39d3071304508017e6543ab19d160d.tar.gz uni-ca4d88e67d39d3071304508017e6543ab19d160d.tar.bz2 uni-ca4d88e67d39d3071304508017e6543ab19d160d.tar.xz uni-ca4d88e67d39d3071304508017e6543ab19d160d.zip |
Move stable-marriage-problem to submodule
-rw-r--r-- | .gitmodules | 3 | ||||
m--------- | ss2017/stable-marriage-problem | 0 | ||||
-rw-r--r-- | ss2017/stable_marriage_problem/ausarbeitung.lhs | 127 | ||||
-rw-r--r-- | ss2017/stable_marriage_problem/orga.md | 21 | ||||
-rw-r--r-- | ss2017/stable_marriage_problem/structure.md | 35 |
5 files changed, 3 insertions, 183 deletions
diff --git a/.gitmodules b/.gitmodules index ce4696e..91b1fd1 100644 --- a/.gitmodules +++ b/.gitmodules | |||
@@ -4,3 +4,6 @@ | |||
4 | [submodule "ss2017/ffp"] | 4 | [submodule "ss2017/ffp"] |
5 | path = ss2017/ffp | 5 | path = ss2017/ffp |
6 | url = gitlab.cip.ifi.lmu.de:jost/FFP_SoSe17.git | 6 | url = gitlab.cip.ifi.lmu.de:jost/FFP_SoSe17.git |
7 | [submodule "ss2017/stable-marriage-problem"] | ||
8 | path = ss2017/stable-marriage-problem | ||
9 | url = git@gitlab.cip.ifi.lmu.de:kleen/stable-marriage-problem | ||
diff --git a/ss2017/stable-marriage-problem b/ss2017/stable-marriage-problem new file mode 160000 | |||
Subproject 7a5f8b61fc7caf45f038007613db254660554b4 | |||
diff --git a/ss2017/stable_marriage_problem/ausarbeitung.lhs b/ss2017/stable_marriage_problem/ausarbeitung.lhs deleted file mode 100644 index ca03280..0000000 --- a/ss2017/stable_marriage_problem/ausarbeitung.lhs +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | Preliminaries | ||
2 | ============= | ||
3 | |||
4 | - Efficient finite maps | ||
5 | |||
6 | > import Data.Map (Map, (!)) | ||
7 | > import qualified Data.Map as Map | ||
8 | |||
9 | - Efficient finite sets | ||
10 | |||
11 | > import Data.Set (Set) | ||
12 | > import qualified Data.Set as Set | ||
13 | |||
14 | - Some convenience functions for manipulating lists and endomorphisms | ||
15 | |||
16 | > import Control.Monad (guard, when) | ||
17 | > import Data.Monoid (Endo(..)) | ||
18 | |||
19 | - An arbitrary representation of a person | ||
20 | |||
21 | > type Person = Integer | ||
22 | |||
23 | Utilities | ||
24 | --------- | ||
25 | |||
26 | > (&!) :: a -> [a -> a] -> a | ||
27 | > -- ^ Reverse application of a list of endomorphisms | ||
28 | > x &! fs = foldMap Endo fs `appEndo` x | ||
29 | > | ||
30 | > infix 3 ==> | ||
31 | > -- | Logical implication | ||
32 | > (==>) :: Bool -> Bool -> Bool | ||
33 | > False ==> _ = True | ||
34 | > True ==> True = True | ||
35 | > True ==> False = False | ||
36 | |||
37 | <!-- | ||
38 | |||
39 | > pPrint :: PreferenceTable -> IO () | ||
40 | > pPrint = putStr . unlines . map (\(k, prefs) -> show k ++ ": " ++ unwords (map show prefs)) . Map.toList | ||
41 | > | ||
42 | > stepPhase1 :: PreferenceTable -> IO (Maybe PreferenceTable) | ||
43 | > stepPhase1 = phase1Iter Set.empty | ||
44 | > where | ||
45 | > phase1Iter :: Set Person -> PreferenceTable -> IO (Maybe PreferenceTable) | ||
46 | > -- ^ Call `phase1'` until no person is free | ||
47 | > phase1Iter engaged table = do | ||
48 | > let r = phase1' engaged table | ||
49 | > case r of | ||
50 | > Just (engaged', table') -> do | ||
51 | > when (table' /= table) $ do | ||
52 | > pPrint table' | ||
53 | > () <$ getLine | ||
54 | > if engaged' == Map.keysSet table' | ||
55 | > then return (Just table') | ||
56 | > else phase1Iter engaged' table' | ||
57 | > Nothing -> return Nothing | ||
58 | |||
59 | |||
60 | --> | ||
61 | |||
62 | Definitions | ||
63 | =========== | ||
64 | |||
65 | \begin{def*} | ||
66 | A \emph{preference table} is a finite set of persons, each associated with a list of other persons, ordered by preference. | ||
67 | \end{def*} | ||
68 | |||
69 | > type PreferenceTable = Map Person [Person] | ||
70 | |||
71 | \begin{def*} | ||
72 | We call a pair ${a, b}$ \emph{embedded} in a preference table if $a$ occurs in $b$s preference list and vice versa. | ||
73 | \end{def*} | ||
74 | |||
75 | Deleting a pair from a table means removing each from the others preference list: | ||
76 | |||
77 | > delPair :: (Person, Person) -> (PreferenceTable -> PreferenceTable) | ||
78 | > delPair (p1, p2) = Map.mapWithKey delPair' | ||
79 | > where | ||
80 | > delPair' k v = do | ||
81 | > z <- v | ||
82 | > guard $ k == p1 ==> z /= p2 | ||
83 | > guard $ k == p2 ==> z /= p1 | ||
84 | > return z | ||
85 | |||
86 | \begin{def*} | ||
87 | An ordered pair $(a, b)$ is said to be \emph{semiengaged} if $a$ occurs last in $b$s preference table and $b$ occurs first in $a$s. | ||
88 | |||
89 | This means that, while $b$ is $a$s best choice of partner, $a$ has no worse choice in partner than $a$ | ||
90 | \end{def*} | ||
91 | |||
92 | > semiEngaged :: (Person, Person) -> PreferenceTable -> Bool | ||
93 | > -- ^ `semiEngaged (x, y)`; is `x` last in `y`s preference list? | ||
94 | > semiEngaged (x, y) table = x == (last $ table ! y) | ||
95 | |||
96 | Phase 1 | ||
97 | ======= | ||
98 | |||
99 | > phase1' :: Set Person -> PreferenceTable -> Maybe (Set Person, PreferenceTable) | ||
100 | > phase1' engaged table | ||
101 | > | any null (Map.elems table) | ||
102 | > = Nothing -- If a preference list became empty: fail | ||
103 | > | Set.null free | ||
104 | > = Just (engaged, table) -- If nobody is free, we have nobody left to engage | ||
105 | > | otherwise | ||
106 | > = let x = Set.findMin free -- Arbitrary choice of free person | ||
107 | > y = head $ table ! x -- Best choice of engagement for x | ||
108 | > adjTable = [ delPair (x', y) | x' <- dropWhile (/= x) (table ! y), x' /= x ] | ||
109 | > -- ^ For all worse (than x) choices x' for y; drop them from y's preference list | ||
110 | > adjEngaged = [ Set.insert x -- x is now engaged | ||
111 | > ] ++ [ Set.delete z | z <- Map.keys table, semiEngaged (z, y) table, z /= x ] -- Nobody else is engaged to y | ||
112 | > in Just (engaged &! adjEngaged, table &! adjTable) | ||
113 | > where | ||
114 | > free = Map.keysSet table `Set.difference` engaged | ||
115 | |||
116 | The algorithm is iterated until all participants are engaged | ||
117 | |||
118 | > phase1 :: PreferenceTable -> Maybe PreferenceTable | ||
119 | > phase1 = phase1Iter Set.empty | ||
120 | > where | ||
121 | > phase1Iter :: Set Person -> PreferenceTable -> Maybe PreferenceTable | ||
122 | > -- ^ Call `phase1'` until no person is free | ||
123 | > phase1Iter engaged table = do | ||
124 | > (engaged', table') <- phase1' engaged table | ||
125 | > if engaged' == Map.keysSet table' | ||
126 | > then return table' | ||
127 | > else phase1Iter engaged' table' | ||
diff --git a/ss2017/stable_marriage_problem/orga.md b/ss2017/stable_marriage_problem/orga.md deleted file mode 100644 index d664ac6..0000000 --- a/ss2017/stable_marriage_problem/orga.md +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | Präsentation/Ausarbeitung: <name/thema>.pdf | ||
2 | Avg von Note auf erstabgabe und jeweils Verbesserung nach Korrektor | ||
3 | |||
4 | Vertraut machen mit Material bis Vorbesprechung (Inhaltsangabe/Struktur mitbringen) | ||
5 | |||
6 | Vortrag semi-interaktiv | ||
7 | Eigene Beispiele | ||
8 | Sauberes Zitieren. | ||
9 | |||
10 | 1.) Einführung für lehramt | ||
11 | 2.) implementierung, erweiterung und eigenschaften | ||
12 | 3.) !!!! | ||
13 | 4.) Eigenschaften v. Lösung v. 3. | ||
14 | 5.) Strategische präferenzen | ||
15 | 6.) 2n Personen auf n 2-Person zimmer (stable marriage mit 2n-1 langen präferenzlisten) !!! This one. !!! | ||
16 | 7.) 6.) angewandt auf Schach | ||
17 | 8.) Alle Lösungen zu 1 | ||
18 | 9.) Gütertransport in einem Graph !! | ||
19 | 10.) 9 fortsetzung | ||
20 | 11.) Bipartites Matching als Netzwerkfluss | ||
21 | 12.) One-sided matching ! | ||
diff --git a/ss2017/stable_marriage_problem/structure.md b/ss2017/stable_marriage_problem/structure.md deleted file mode 100644 index fa9ac96..0000000 --- a/ss2017/stable_marriage_problem/structure.md +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | - Implement algorithm in haskell, split over single steps | ||
2 | - During presentation show steps working on examples of the problem (one solves during step 1, one fails during step 1, one that requires multiple rotations to be eliminated), within `ghci` | ||
3 | - For most important proofs (tbd) show applicable step in haskell code with sketch of proof | ||
4 | |||
5 | |||
6 | # Tables | ||
7 | - Definition: Tables, embedded tables, embedded pairs, embedded matchings | ||
8 | - Definition: stable tables | ||
9 | - Matchings embedded in stable tables are stable (4.2.4 ii) | ||
10 | - Stable tables are determined by all first OR all last entries (4.2.4 iii) | ||
11 | - No pair absent from a stable table can block any of it's embedded matchings (4.2.4 i) | ||
12 | |||
13 | # Phase 1 | ||
14 | - Removal of pairs from tables | ||
15 | - Engagement | ||
16 | - Present algorithm and demonstrate | ||
17 | - Phase 1 has no effect on the embeddedness of stable pairs (4.2.3 i) | ||
18 | - Phase 1 stabilizes a table, when it doesn't fail (4.2.2 + 4.2.3 ii) | ||
19 | - Phase 1 results in the largest stable table (4.2.4 iv) | ||
20 | |||
21 | # Rotations | ||
22 | - Definition: rotation, exposure of rotations in stable tables | ||
23 | - Directed graphs & tails | ||
24 | - (Rotations exposed in a stable T are either identical or disjunct (4.2.5)) | ||
25 | |||
26 | # Phase 2 | ||
27 | - Stable tables that are not already matchings expose at least one rotation and how to find it (4.2.6) | ||
28 | - Elimination of rotations from stable tables | ||
29 | - ignores non-elements of rotation (4.2.7 iii) | ||
30 | - results in table consistent with rotation (4.2.7 i, ii) | ||
31 | - Thus: produce stable subtables (4.2.8) | ||
32 | - Subtables that don't agree with an exposed rotation have at least that rotation removed entirely (4.2.9) | ||
33 | - Any subtable can be created by removing a series of exposed rotations (Cor 4.2.2) | ||
34 | - Removal of rotations preserve matchings (Thm 4.2.1) | ||
35 | - Present derived algorithm and demonstrate | ||