SlideShare une entreprise Scribd logo
1  sur  19
A Dating Algorithm
    Implementing the Simplex Algorithm
       Implementing Euclid’s GCD
Presented in partial fulfillment of the requirements for Project 2

              By: David Poeschl & Tim Reynolds
A Quick Preview
• The Problem: Weighted Bipartite Matching
   – Given a group of n (heterosexual) boys and n (heterosexual)
     girls, each of whom has previously assigned values to each
     member of the opposite gender, find a matching of boys with
     girls which maximizes happiness (which can be defined many
     ways). To do this, we designed the…
• Reynolds-Poeschl Matching Algorithm (RPMA)
   – Works by converting the data into a linear programming problem
     which can then be solved by…
• The Simplex Algorithm
   – A well known algorithm for solving linear programming problems.
      Since Simplex uses a lot of operations on rational numbers,
     we’ve created our own Rational Number Class which
     implements
• Euclid’s GCD
Obligatory Diagram
  Input:                                                        Output:
Preferences                                                An optimal matching




              LP Problem         (only once…)     Solution to the LP Problem




                Integers x & y    (repeatedly…)   The GCD of x and y
Algorithm – Simplex
• The Simplex Algorithm portion of the project is a stand-
  alone application which solves any linear programming
  problem with a feasible solution.

   – Input: A LP Problem P = (c[ ], b[ ], A[ ][ ]) in n variables
     {x1 ,… xn} and m constraints:

       Maximize c1x1 + … + cnxn (the objective function) subject to:
        A1,1x1 + … + A1,nxn ≤ b1
          …
       Am,1x1 + … + Am,nxn ≤ bm

   – Output: An array representing a setting of the values of
     {x1 ,… xn} which maximizes the objective function (if possible).
Algorithm – Simplex
• Simplex Algorithm
   – If you honestly want us to drag you through the details of the Simplex
     Algorithm and you ∈ Class–{Mike, Jarod, Will}, raise your hand…
   – No takers?
   – Last chance…
   – Jarod, put your hand down.
   – Seriously, put your hand down.

• Everybody* knows how to implement the Simplex Algorithm by now,
  so we’ll move on to the mildly interesting** portion.

   * Unless you’re a dirty*** cheater
   ** Interesting is a relative term
   *** Dirty means “of low academic integrity”
Algorithm – RPMA
• Input: Two n by n matrices PBG and PGB
  – PBGi, j = The value that boy i assigned girl j
  – PGBi, j = The value that girl i assigned boy j


• Output: A set of n boy-girl pairs which produce
  the optimal happiness.
  – Each boy and girl appears exactly once in the set of
    pairings.

• The values assigned are positive integers. The
  lower a value is, the more (for example) the boy
  likes that particular girl.
Algorithm – RPMA
•   What is happiness?
     – The happiness of a complete matching is defined as the                         PBG      Lisa Jess
       sum of the happiness of each individual pair. The
       happiness of a pair can be defined in several ways.                            Joe       1         4
       Consider the following matrices:
                                                                                      Bob       3         7
         • Maximizing Happiness (Higher value = happier)
              – Define max_happy as the highest value appearing in either matrix,     P GB
                                                                                                 Joe Bob
                and min_happy similarly. Then…
              – Additive Happiness                                                    Lisa       2       6
                   • Happiness(Boy b, Girl g) =
                           [max_happy + min_happy – PBGb, g ] +                      Jess 1             5
                           [max_happy + min_happy – PGBg, b ]
              – Multiplicative Happiness
                   • Happiness(Boy b, Girl g) =                                   Note: Lower values = more attraction
                           [max_happy + min_happy – P b, g ] *
                                                     BG

                           [max_happy + min_happy – PGBg, b ]
                                                                                Ex. Multiplicative Happiness (Bob, Lisa)
         • Minimizing Unhappiness (Higher value = less happy)
              – Additive Unhappiness                                                = [7+1-3] * [7+1-6] = 5 * 2 = 10
                   • Happiness(Boy b, Girl g) = -1 * (PBGb, g + PGBg, b)
              – Multiplicative Unhappiness
                   • Happiness(Boy b, Girl g) = -1 * (PBGb, g * PGBg, b)
Algorithm – RPMA
• We now proceed to creating an LP:
   – We have n * n variables {x1 ,… xn*n}
       • Variable xi represents whether the boy-girl pair of (Boy (i-1) / n + 1,
         Girl [(i -1) mod n]+1) is part of our matching
   – We have 2n constraints…
       • Constraints 1 through n ensure that each boy is paired with no more than
         one girl.
       • Constraints n+1 through 2n ensure that each girl is paired with no more than
         one boy.
       • If we are minimizing unhappiness, then we need one additional constraint
                   -1*x1 + -1*x2 + … + -1*xn*n ≤ -1*n
            – This causes any matching with less than n pairs to be infeasible.
   – The objective function
       • Happiness(Boy (1-1) / n + 1, Girl [(1-1) mod n]+1)*x1 +
         Happiness(Boy (2-1) / n + 1, Girl [(2-1) mod n]+1)*x2 +
         …+
         Happiness(Boy (n*n-1) / n + 1, Girl [(n*n-1) mod n]+1)*xn*n
Algorithm – RPMA
• A (potentially) big problem
   – What if somebody assigns their favorite person a value of 1,
     but assigns everybody else very large values like 999,937 or
     827,399?
       • This person is selfishly trying to hack our algorithm to guarantee
         they get their number one choice.
   – Solution: Convert values to rankings, then calculate
     happiness values.

      PBG    Lisa    Jess                   PBG    Lisa    Jess
      Joe     1       4                      Joe     1       2
      Bob     3       7                      Bob     1       2
Illustrative Example
      PBG         G1    G2     G3      G4   G5       PGB   B1      B2     B3    B4          B5
      B1           1     2      3       8    10       G1     10      8      3     2           1
      B2           1     2      2       2    15       G2     15      2      2     2           1
      B3           7     5      3       1    1        G3     5       6      3     1           1
      B4           9     2      9       10   4        G4     4       5      12    8           6
      B5           7     7      6       2    1        G5     3       12     7     2           9


• Ex. Additive Happiness(2, 3) = (15+1-2) + (15+1-6) = 14 + 10 = 24
• Ex. Multiplicative Unhappiness(2, 3) = -1 * (2 + 6) = -8
           MIN          MAX         MIN      MAX     MIN     MAX          MIN         MAX
           ADD          ADD         ADD      ADD     MUL     MUL          MUL         MUL
                                    RANK     RANK                         RANK        RANK

           (1,3)        (1,3)       (1,1)    (1,3)   (1,1)   (1,4)        (1,5)       (1,1)
           (2,4)        (2,4)       (2,4)    (2,4)   (2,4)   (2,2)        (2,4)       (2,4)
           (3,5)        (3,5)       (3,3)    (3,1)   (3,5)   (3,3)        (3,3)       (3,3)
           (4,2)        (4,2)       (4,2)    (4,2)   (4,2)   (4,5)        (4,2)       (4,2)
           (5,1)        (5,1)       (5,5)    (5,5)   (5,3)   (5,1)        (5,1)       (5,5)
Analysis, Testing & Results
• Data Structures
  – We used Arrays instead of ArrayLists…
     • Because we did not use iterative structures, this
       improved our performance.
  – The implementation of our Rational Number
    Class greatly decreased our performance.
    Every time two rational numbers are added,
    we actually perform 3 integer multiplications,
    then run GCD to reduce the new rational.
Analysis, Testing & Results
•   Testing the Simplex Algorithm
     – A test case for which there is no feasible solution
     – A test case for which the solution is unbounded
     – A test case for which the initial basic solution is not feasible, but there
       exists a feasible solution somewhere
     – A large test case with 3600 variables and 121 constraints.
•   Testing the RPMA (Matching)
     – Wrote a program that, given an integer n, generates random data sets
       of for 2*n people
          • Two n x n arrays of positive integers in [1, 100]
     – We then have n2 variables and 2*n constraints
Analysis, Testing & Results
•   Results
     – Ran timings on random data sets for n boys & n girls
         • n = 1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60.


                                   Time versus n (Logarithmic Scale)

                      100000
                      10000
                       1000
           Time (s)




                         100                                                                  RPMA
                         10
                          1
                         0.1
                               5   10   15   20   25   30       35   40   45   50   55   60
                                                            n
Extension: The Poeschl-Reynolds Gender
 Preference Neutral Matching Algorithm

                      (or NAMbLA)
•   Thus far, we have only considered cases with n boys and n girls, each of
    whom is heterosexual…
     – But what if some boys like other boys? What if some girls like boys and
       girls?
• Consider a new, non-heterocentric problem which considers n
  people, each of whom rates everybody else.
     – Creates an n x n matrix P
     – Lower rating values mean more attraction
     – A value of 0 at Pi, j to indicates that person i is not attracted to person j
       at all and should not be matched with them.
         • We can then support heterosexual, bisexual, or homosexual users.
• Alternatively, if you think homosexuality is immoral, we could be
  trying to find an optimal seating of n friends/enemies on a 2 seat
  wide rollercoaster train.
Extension: The Poeschl-Reynolds Gender
     Preference Neutral Matching Algorithm
•   This new version will have (n C 2) variables and n+1 constraints.                      Xi    p1   p2   p3   P4
     – Variables                                                                           p1         0    1    2
           •   Variable X0 represents whether person 1 and 2 are paired together
                                                                                           p2              3    4
           •   Variable X1 represents whether person 1 and 3 are paired together …
           •   Variable Xn-2 represents whether person 1 and n are paired together         p3                   5
           •   …                                                                           p4
           •   Variable Xn-1 represents whether person 2 and 3 are paired together
           •   Variable Xn represents whether person 2 and 4 are paired together ……
     –   Constraints
           •  Constraint i is made up of all 0’s except where person i is part of that pairing
                  – Constraint 1: 1 1 1 0 0 0 [ p1 is part of pairings 0, 1, and 2]
                  – Constraint 2: 1 0 0 1 1 0
                  – Constraint 3: 0 1 0 1 0 1
                  – Constraint 4: 0 0 1 0 1 1
     –   Objective Function (Minimizing Additive Unhappiness Only)
           • The coefficient on Xi is
                  – If both people involved in Xi have non-0 entries for each other, -1 * (summed
                    happiness)
                  – Else, -1 * (an arbitrarily large value)
The Poeschl-Reynolds Gender Preference
 Neutral Matching Algorithm - EXAMPLE
Objective Function:
-5X0 -6X1 -5X2 -100000X3 -13X4 -9X5 -6X6 -6X7 -7X8 -4X9

b values:                                          P        p1   p2    p3   p4   p5
1 1 1 1 1 -2
                                                   p1       0    2     5    1    0
                                                   p2       3    0     5    2    1
Normal Constraints
1111000000                                         p3       1    8     0    4    5
1000111000                                         p4       4    7     2    0    3
0100100110                                         p5       8    5     2    1    0
0010010101
0001001011
                                                          Results
Constraint to Force Pairings                              (1, 2), (4, 5), (3)
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
The Poeschl-Reynolds Gender Preference
          Neutral Matching Algorithm
•   Why is this interesting?
     – You mean besides the political statement?
     – The constraints in this generalization are much more complicated than in the
       heterocentric version
     – We also have to consider what happens if a person absolutely cannot be paired with
       somebody else. We might end up with several singletons
     – It really is an extension of the original problem.
                                                              P         {Boys}   {Girls}
          • Given PBG and PGB , create our new matrix P =
          • This gives the same solution as our original
            algorithm.                                        {Boys}    0…0      PBG
                                                                        . .
                                                                        . .
                                                                        0…0

                                                              {Girls}   PGB     0…0
                                                                                 . .
                                                                                 . .
                                                                                 0…0
Demo in (3-1)D!!!
References & Thanks
-   Introduction to Algorithms, Second Edition Cormen, Leiserson, Rivest, Stein
-   Thanks to Mike & Jarod for fun discussions about rounding errors
     -   We told you so.
-   Wikipedia
     -   It’s always correct.

Contenu connexe

En vedette

Decoding The Facebook News Feed
Decoding The Facebook News FeedDecoding The Facebook News Feed
Decoding The Facebook News FeedMMI Agency
 
Finding Love with MongoDB
Finding Love with MongoDBFinding Love with MongoDB
Finding Love with MongoDBMongoDB
 
The autodiscover algorithm for locating the source of information part 05#36
The autodiscover algorithm for locating the source of information  part 05#36The autodiscover algorithm for locating the source of information  part 05#36
The autodiscover algorithm for locating the source of information part 05#36Eyal Doron
 
Fucking with algorithms
Fucking with algorithmsFucking with algorithms
Fucking with algorithmsMyriam Jessier
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentationlourdes_rpma
 
Automating Tinder w/ Eigenfaces and StanfordNLP
Automating Tinder w/ Eigenfaces and StanfordNLPAutomating Tinder w/ Eigenfaces and StanfordNLP
Automating Tinder w/ Eigenfaces and StanfordNLPJustin Long
 
UX: internal search for e-commerce
UX: internal search for e-commerceUX: internal search for e-commerce
UX: internal search for e-commerceMyriam Jessier
 
9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update
9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update
9 Tips to Avoid Getting Penalized by the Facebook Algorithm UpdateInside Social
 
Big Dating at eHarmony
Big Dating at eHarmonyBig Dating at eHarmony
Big Dating at eHarmonyMongoDB
 
Facebook News Feed Algorithm: Facebook User Awareness
Facebook News Feed Algorithm: Facebook User AwarenessFacebook News Feed Algorithm: Facebook User Awareness
Facebook News Feed Algorithm: Facebook User AwarenessJakub Ruzicka
 
Online Dating Insider Online Dating Summit Keynote Miami 2013
Online Dating Insider Online Dating Summit Keynote Miami 2013Online Dating Insider Online Dating Summit Keynote Miami 2013
Online Dating Insider Online Dating Summit Keynote Miami 2013Digicraft
 
Kdd 2014 Tutorial - the recommender problem revisited
Kdd 2014 Tutorial -  the recommender problem revisitedKdd 2014 Tutorial -  the recommender problem revisited
Kdd 2014 Tutorial - the recommender problem revisitedXavier Amatriain
 
The secret of Tinder
The secret of TinderThe secret of Tinder
The secret of TinderDori Adar
 
Balancing Discovery and Continuation in Recommendations
Balancing Discovery and Continuation in RecommendationsBalancing Discovery and Continuation in Recommendations
Balancing Discovery and Continuation in RecommendationsMohammad Hossein Taghavi
 
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...Dawen Liang
 
(Some) pitfalls of distributed learning
(Some) pitfalls of distributed learning(Some) pitfalls of distributed learning
(Some) pitfalls of distributed learningYves Raimond
 
Genetic Algorithm by Example
Genetic Algorithm by ExampleGenetic Algorithm by Example
Genetic Algorithm by ExampleNobal Niraula
 
Past, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry PerspectivePast, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry PerspectiveJustin Basilico
 

En vedette (18)

Decoding The Facebook News Feed
Decoding The Facebook News FeedDecoding The Facebook News Feed
Decoding The Facebook News Feed
 
Finding Love with MongoDB
Finding Love with MongoDBFinding Love with MongoDB
Finding Love with MongoDB
 
The autodiscover algorithm for locating the source of information part 05#36
The autodiscover algorithm for locating the source of information  part 05#36The autodiscover algorithm for locating the source of information  part 05#36
The autodiscover algorithm for locating the source of information part 05#36
 
Fucking with algorithms
Fucking with algorithmsFucking with algorithms
Fucking with algorithms
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Automating Tinder w/ Eigenfaces and StanfordNLP
Automating Tinder w/ Eigenfaces and StanfordNLPAutomating Tinder w/ Eigenfaces and StanfordNLP
Automating Tinder w/ Eigenfaces and StanfordNLP
 
UX: internal search for e-commerce
UX: internal search for e-commerceUX: internal search for e-commerce
UX: internal search for e-commerce
 
9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update
9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update
9 Tips to Avoid Getting Penalized by the Facebook Algorithm Update
 
Big Dating at eHarmony
Big Dating at eHarmonyBig Dating at eHarmony
Big Dating at eHarmony
 
Facebook News Feed Algorithm: Facebook User Awareness
Facebook News Feed Algorithm: Facebook User AwarenessFacebook News Feed Algorithm: Facebook User Awareness
Facebook News Feed Algorithm: Facebook User Awareness
 
Online Dating Insider Online Dating Summit Keynote Miami 2013
Online Dating Insider Online Dating Summit Keynote Miami 2013Online Dating Insider Online Dating Summit Keynote Miami 2013
Online Dating Insider Online Dating Summit Keynote Miami 2013
 
Kdd 2014 Tutorial - the recommender problem revisited
Kdd 2014 Tutorial -  the recommender problem revisitedKdd 2014 Tutorial -  the recommender problem revisited
Kdd 2014 Tutorial - the recommender problem revisited
 
The secret of Tinder
The secret of TinderThe secret of Tinder
The secret of Tinder
 
Balancing Discovery and Continuation in Recommendations
Balancing Discovery and Continuation in RecommendationsBalancing Discovery and Continuation in Recommendations
Balancing Discovery and Continuation in Recommendations
 
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...
Factorization Meets the Item Embedding: Regularizing Matrix Factorization wit...
 
(Some) pitfalls of distributed learning
(Some) pitfalls of distributed learning(Some) pitfalls of distributed learning
(Some) pitfalls of distributed learning
 
Genetic Algorithm by Example
Genetic Algorithm by ExampleGenetic Algorithm by Example
Genetic Algorithm by Example
 
Past, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry PerspectivePast, Present & Future of Recommender Systems: An Industry Perspective
Past, Present & Future of Recommender Systems: An Industry Perspective
 

Similaire à Reynolds-Poeschl

NumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptNumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptIshwariKhanal
 
Factorising for 3um
Factorising for 3umFactorising for 3um
Factorising for 3ummathssng3
 
Thursday, september 26, 2013
Thursday, september 26, 2013Thursday, september 26, 2013
Thursday, september 26, 2013khyps13
 
Integers best ppt
Integers best pptIntegers best ppt
Integers best pptarivuselvi3
 
Class 6 - Maths (Integers).pptx
Class 6 - Maths (Integers).pptxClass 6 - Maths (Integers).pptx
Class 6 - Maths (Integers).pptxSadiqHameed2
 
Integers.(Addition, Subtraction, Multiplication, Division)ppt
Integers.(Addition, Subtraction, Multiplication, Division)pptIntegers.(Addition, Subtraction, Multiplication, Division)ppt
Integers.(Addition, Subtraction, Multiplication, Division)pptJanaicaMarielleDimap
 
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliCRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliharshmacduacin
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmRaihanIslamSonet
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsLearn By Watch
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting classgiridaroori
 
Solving by factoring remediation notes
Solving by factoring remediation notesSolving by factoring remediation notes
Solving by factoring remediation notesMichelle Barnhill
 
Sept. 20
Sept. 20Sept. 20
Sept. 20khyps13
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zerosDaisy933462
 
Theories of continuous optimization
Theories of continuous optimizationTheories of continuous optimization
Theories of continuous optimizationOlivier Teytaud
 

Similaire à Reynolds-Poeschl (20)

NumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.pptNumberTheory explanations in the easiest way.ppt
NumberTheory explanations in the easiest way.ppt
 
Factorising for 3um
Factorising for 3umFactorising for 3um
Factorising for 3um
 
Presentation1
Presentation1Presentation1
Presentation1
 
Thursday, september 26, 2013
Thursday, september 26, 2013Thursday, september 26, 2013
Thursday, september 26, 2013
 
Integers
Integers Integers
Integers
 
Integers best ppt
Integers best pptIntegers best ppt
Integers best ppt
 
Class 6 - Maths (Integers).pptx
Class 6 - Maths (Integers).pptxClass 6 - Maths (Integers).pptx
Class 6 - Maths (Integers).pptx
 
Integers
IntegersIntegers
Integers
 
Integers
IntegersIntegers
Integers
 
Integers.ppt
Integers.pptIntegers.ppt
Integers.ppt
 
Integers.(Addition, Subtraction, Multiplication, Division)ppt
Integers.(Addition, Subtraction, Multiplication, Division)pptIntegers.(Addition, Subtraction, Multiplication, Division)ppt
Integers.(Addition, Subtraction, Multiplication, Division)ppt
 
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huliCRYPTOGRAPHY AND NUMBER THEORY, he ha huli
CRYPTOGRAPHY AND NUMBER THEORY, he ha huli
 
Dynamic programming (dp) in Algorithm
Dynamic programming (dp) in AlgorithmDynamic programming (dp) in Algorithm
Dynamic programming (dp) in Algorithm
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Solving by factoring remediation notes
Solving by factoring remediation notesSolving by factoring remediation notes
Solving by factoring remediation notes
 
Sept. 20
Sept. 20Sept. 20
Sept. 20
 
3. aplicaciones de la derivada
3. aplicaciones de la derivada3. aplicaciones de la derivada
3. aplicaciones de la derivada
 
Factoring Polynomials to find its zeros
Factoring Polynomials to find its zerosFactoring Polynomials to find its zeros
Factoring Polynomials to find its zeros
 
Theories of continuous optimization
Theories of continuous optimizationTheories of continuous optimization
Theories of continuous optimization
 

Reynolds-Poeschl

  • 1. A Dating Algorithm Implementing the Simplex Algorithm Implementing Euclid’s GCD Presented in partial fulfillment of the requirements for Project 2 By: David Poeschl & Tim Reynolds
  • 2. A Quick Preview • The Problem: Weighted Bipartite Matching – Given a group of n (heterosexual) boys and n (heterosexual) girls, each of whom has previously assigned values to each member of the opposite gender, find a matching of boys with girls which maximizes happiness (which can be defined many ways). To do this, we designed the… • Reynolds-Poeschl Matching Algorithm (RPMA) – Works by converting the data into a linear programming problem which can then be solved by… • The Simplex Algorithm – A well known algorithm for solving linear programming problems. Since Simplex uses a lot of operations on rational numbers, we’ve created our own Rational Number Class which implements • Euclid’s GCD
  • 3. Obligatory Diagram Input: Output: Preferences An optimal matching LP Problem (only once…) Solution to the LP Problem Integers x & y (repeatedly…) The GCD of x and y
  • 4. Algorithm – Simplex • The Simplex Algorithm portion of the project is a stand- alone application which solves any linear programming problem with a feasible solution. – Input: A LP Problem P = (c[ ], b[ ], A[ ][ ]) in n variables {x1 ,… xn} and m constraints: Maximize c1x1 + … + cnxn (the objective function) subject to: A1,1x1 + … + A1,nxn ≤ b1 … Am,1x1 + … + Am,nxn ≤ bm – Output: An array representing a setting of the values of {x1 ,… xn} which maximizes the objective function (if possible).
  • 5. Algorithm – Simplex • Simplex Algorithm – If you honestly want us to drag you through the details of the Simplex Algorithm and you ∈ Class–{Mike, Jarod, Will}, raise your hand… – No takers? – Last chance… – Jarod, put your hand down. – Seriously, put your hand down. • Everybody* knows how to implement the Simplex Algorithm by now, so we’ll move on to the mildly interesting** portion. * Unless you’re a dirty*** cheater ** Interesting is a relative term *** Dirty means “of low academic integrity”
  • 6. Algorithm – RPMA • Input: Two n by n matrices PBG and PGB – PBGi, j = The value that boy i assigned girl j – PGBi, j = The value that girl i assigned boy j • Output: A set of n boy-girl pairs which produce the optimal happiness. – Each boy and girl appears exactly once in the set of pairings. • The values assigned are positive integers. The lower a value is, the more (for example) the boy likes that particular girl.
  • 7. Algorithm – RPMA • What is happiness? – The happiness of a complete matching is defined as the PBG Lisa Jess sum of the happiness of each individual pair. The happiness of a pair can be defined in several ways. Joe 1 4 Consider the following matrices: Bob 3 7 • Maximizing Happiness (Higher value = happier) – Define max_happy as the highest value appearing in either matrix, P GB Joe Bob and min_happy similarly. Then… – Additive Happiness Lisa 2 6 • Happiness(Boy b, Girl g) = [max_happy + min_happy – PBGb, g ] + Jess 1 5 [max_happy + min_happy – PGBg, b ] – Multiplicative Happiness • Happiness(Boy b, Girl g) = Note: Lower values = more attraction [max_happy + min_happy – P b, g ] * BG [max_happy + min_happy – PGBg, b ] Ex. Multiplicative Happiness (Bob, Lisa) • Minimizing Unhappiness (Higher value = less happy) – Additive Unhappiness = [7+1-3] * [7+1-6] = 5 * 2 = 10 • Happiness(Boy b, Girl g) = -1 * (PBGb, g + PGBg, b) – Multiplicative Unhappiness • Happiness(Boy b, Girl g) = -1 * (PBGb, g * PGBg, b)
  • 8. Algorithm – RPMA • We now proceed to creating an LP: – We have n * n variables {x1 ,… xn*n} • Variable xi represents whether the boy-girl pair of (Boy (i-1) / n + 1, Girl [(i -1) mod n]+1) is part of our matching – We have 2n constraints… • Constraints 1 through n ensure that each boy is paired with no more than one girl. • Constraints n+1 through 2n ensure that each girl is paired with no more than one boy. • If we are minimizing unhappiness, then we need one additional constraint -1*x1 + -1*x2 + … + -1*xn*n ≤ -1*n – This causes any matching with less than n pairs to be infeasible. – The objective function • Happiness(Boy (1-1) / n + 1, Girl [(1-1) mod n]+1)*x1 + Happiness(Boy (2-1) / n + 1, Girl [(2-1) mod n]+1)*x2 + …+ Happiness(Boy (n*n-1) / n + 1, Girl [(n*n-1) mod n]+1)*xn*n
  • 9. Algorithm – RPMA • A (potentially) big problem – What if somebody assigns their favorite person a value of 1, but assigns everybody else very large values like 999,937 or 827,399? • This person is selfishly trying to hack our algorithm to guarantee they get their number one choice. – Solution: Convert values to rankings, then calculate happiness values. PBG Lisa Jess PBG Lisa Jess Joe 1 4 Joe 1 2 Bob 3 7 Bob 1 2
  • 10. Illustrative Example PBG G1 G2 G3 G4 G5 PGB B1 B2 B3 B4 B5 B1 1 2 3 8 10 G1 10 8 3 2 1 B2 1 2 2 2 15 G2 15 2 2 2 1 B3 7 5 3 1 1 G3 5 6 3 1 1 B4 9 2 9 10 4 G4 4 5 12 8 6 B5 7 7 6 2 1 G5 3 12 7 2 9 • Ex. Additive Happiness(2, 3) = (15+1-2) + (15+1-6) = 14 + 10 = 24 • Ex. Multiplicative Unhappiness(2, 3) = -1 * (2 + 6) = -8 MIN MAX MIN MAX MIN MAX MIN MAX ADD ADD ADD ADD MUL MUL MUL MUL RANK RANK RANK RANK (1,3) (1,3) (1,1) (1,3) (1,1) (1,4) (1,5) (1,1) (2,4) (2,4) (2,4) (2,4) (2,4) (2,2) (2,4) (2,4) (3,5) (3,5) (3,3) (3,1) (3,5) (3,3) (3,3) (3,3) (4,2) (4,2) (4,2) (4,2) (4,2) (4,5) (4,2) (4,2) (5,1) (5,1) (5,5) (5,5) (5,3) (5,1) (5,1) (5,5)
  • 11. Analysis, Testing & Results • Data Structures – We used Arrays instead of ArrayLists… • Because we did not use iterative structures, this improved our performance. – The implementation of our Rational Number Class greatly decreased our performance. Every time two rational numbers are added, we actually perform 3 integer multiplications, then run GCD to reduce the new rational.
  • 12. Analysis, Testing & Results • Testing the Simplex Algorithm – A test case for which there is no feasible solution – A test case for which the solution is unbounded – A test case for which the initial basic solution is not feasible, but there exists a feasible solution somewhere – A large test case with 3600 variables and 121 constraints. • Testing the RPMA (Matching) – Wrote a program that, given an integer n, generates random data sets of for 2*n people • Two n x n arrays of positive integers in [1, 100] – We then have n2 variables and 2*n constraints
  • 13. Analysis, Testing & Results • Results – Ran timings on random data sets for n boys & n girls • n = 1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60. Time versus n (Logarithmic Scale) 100000 10000 1000 Time (s) 100 RPMA 10 1 0.1 5 10 15 20 25 30 35 40 45 50 55 60 n
  • 14. Extension: The Poeschl-Reynolds Gender Preference Neutral Matching Algorithm (or NAMbLA) • Thus far, we have only considered cases with n boys and n girls, each of whom is heterosexual… – But what if some boys like other boys? What if some girls like boys and girls? • Consider a new, non-heterocentric problem which considers n people, each of whom rates everybody else. – Creates an n x n matrix P – Lower rating values mean more attraction – A value of 0 at Pi, j to indicates that person i is not attracted to person j at all and should not be matched with them. • We can then support heterosexual, bisexual, or homosexual users. • Alternatively, if you think homosexuality is immoral, we could be trying to find an optimal seating of n friends/enemies on a 2 seat wide rollercoaster train.
  • 15. Extension: The Poeschl-Reynolds Gender Preference Neutral Matching Algorithm • This new version will have (n C 2) variables and n+1 constraints. Xi p1 p2 p3 P4 – Variables p1 0 1 2 • Variable X0 represents whether person 1 and 2 are paired together p2 3 4 • Variable X1 represents whether person 1 and 3 are paired together … • Variable Xn-2 represents whether person 1 and n are paired together p3 5 • … p4 • Variable Xn-1 represents whether person 2 and 3 are paired together • Variable Xn represents whether person 2 and 4 are paired together …… – Constraints • Constraint i is made up of all 0’s except where person i is part of that pairing – Constraint 1: 1 1 1 0 0 0 [ p1 is part of pairings 0, 1, and 2] – Constraint 2: 1 0 0 1 1 0 – Constraint 3: 0 1 0 1 0 1 – Constraint 4: 0 0 1 0 1 1 – Objective Function (Minimizing Additive Unhappiness Only) • The coefficient on Xi is – If both people involved in Xi have non-0 entries for each other, -1 * (summed happiness) – Else, -1 * (an arbitrarily large value)
  • 16. The Poeschl-Reynolds Gender Preference Neutral Matching Algorithm - EXAMPLE Objective Function: -5X0 -6X1 -5X2 -100000X3 -13X4 -9X5 -6X6 -6X7 -7X8 -4X9 b values: P p1 p2 p3 p4 p5 1 1 1 1 1 -2 p1 0 2 5 1 0 p2 3 0 5 2 1 Normal Constraints 1111000000 p3 1 8 0 4 5 1000111000 p4 4 7 2 0 3 0100100110 p5 8 5 2 1 0 0010010101 0001001011 Results Constraint to Force Pairings (1, 2), (4, 5), (3) -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
  • 17. The Poeschl-Reynolds Gender Preference Neutral Matching Algorithm • Why is this interesting? – You mean besides the political statement? – The constraints in this generalization are much more complicated than in the heterocentric version – We also have to consider what happens if a person absolutely cannot be paired with somebody else. We might end up with several singletons – It really is an extension of the original problem. P {Boys} {Girls} • Given PBG and PGB , create our new matrix P = • This gives the same solution as our original algorithm. {Boys} 0…0 PBG . . . . 0…0 {Girls} PGB 0…0 . . . . 0…0
  • 19. References & Thanks - Introduction to Algorithms, Second Edition Cormen, Leiserson, Rivest, Stein - Thanks to Mike & Jarod for fun discussions about rounding errors - We told you so. - Wikipedia - It’s always correct.