Commit 2a28144f authored by Alexandre Delanoë's avatar Alexandre Delanoë

Diff -> Xor on lists

parent c18571d9
......@@ -4,7 +4,8 @@
This implementation is more generic that this [definition on
wikipedia](https://en.wikipedia.org/wiki/Majority_judgment), even if it
reuses the same application example: if two ballots have the same score,
then diff of vote is computed to compute a new score.
then xor of votes is computed to then compute a new score on these same
ballots.
Not really tested yet, feedbacks welcome, just to better understand how
it works.
......
......@@ -87,20 +87,20 @@ instance Ord Ballot where
False -> compare (score v1) (score v2)
True -> compare (score v1') (score v2')
where
(v1', v2') = diff (v1, v2)
(v1', v2') = xor (v1, v2)
score :: [Vote] -> Maybe Rational
score = median . map voteToRational
------------------------------------------------------------------------
diff :: Ord a => ([a],[a]) -> ([a],[a])
diff (m1,m2) = (fromMap m1', fromMap m2')
xor :: Ord a => ([a],[a]) -> ([a],[a])
xor (m1,m2) = (fromMap m1', fromMap m2')
where
(m1', m2') = diffMap (toMap m1, toMap m2)
(m1', m2') = xorMap (toMap m1, toMap m2)
diffMap :: Ord a => (Map a Int, Map a Int) -> (Map a Int, Map a Int)
diffMap (m1,m2) = (m1',m2')
xorMap :: Ord a => (Map a Int, Map a Int) -> (Map a Int, Map a Int)
xorMap (m1,m2) = (m1',m2')
where
m1' = DM.unionWith outer m1 m13
m2' = DM.unionWith outer m2 m23
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment