Skip to content

Commit

Permalink
Rank histograms added
Browse files Browse the repository at this point in the history
  • Loading branch information
skosch committed May 19, 2018
1 parent 6cbfc41 commit 71c9539
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 85 deletions.
4 changes: 4 additions & 0 deletions src/App.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function make() {
var value = _event.target.value;
var matchStrategy;
switch (value) {
case "" :
case "mcmf" :
matchStrategy = /* MCMF */2;
break;
Expand Down Expand Up @@ -488,6 +489,8 @@ var IntCmp = SampleData.IntCmp;

var StrCmp = SampleData.StrCmp;

var PairingCmp = SampleData.PairingCmp;

var OptIntCmp = SampleData.OptIntCmp;

var imperialPositions = SampleData.imperialPositions;
Expand Down Expand Up @@ -519,6 +522,7 @@ exports.parseSingleRow = parseSingleRow;
exports.parseData = parseData;
exports.IntCmp = IntCmp;
exports.StrCmp = StrCmp;
exports.PairingCmp = PairingCmp;
exports.OptIntCmp = OptIntCmp;
exports.imperialPositions = imperialPositions;
exports.imperialCandidates = imperialCandidates;
Expand Down
1 change: 1 addition & 0 deletions src/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ let make = _children => {
| "selecting-break-ties" => SelectingBreakTies
| "selected-break-ties" => SelectedBreakTies
| "mcmf" => MCMF
| "" => MCMF
};
self.send(UpdateMatchStrategy(matchStrategy));
}
Expand Down
7 changes: 6 additions & 1 deletion src/SharedTypes.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ var StrCmp = Belt_Id.MakeComparable(/* module */[/* cmp */cmp$1]);

var cmp$2 = Caml_obj.caml_compare;

var OptIntCmp = Belt_Id.MakeComparable(/* module */[/* cmp */cmp$2]);
var PairingCmp = Belt_Id.MakeComparable(/* module */[/* cmp */cmp$2]);

var cmp$3 = Caml_obj.caml_compare;

var OptIntCmp = Belt_Id.MakeComparable(/* module */[/* cmp */cmp$3]);

exports.IntCmp = IntCmp;
exports.StrCmp = StrCmp;
exports.PairingCmp = PairingCmp;
exports.OptIntCmp = OptIntCmp;
/* IntCmp Not a pure module */
10 changes: 9 additions & 1 deletion src/SharedTypes.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Belt;

type pairing = (string, string);
module IntCmp =
Id.MakeComparable(
{
Expand All @@ -14,6 +15,14 @@ module StrCmp =
let cmp = (i1, i2) => compare(i1, i2);
},
);

module PairingCmp =
Id.MakeComparable(
{
type t = pairing;
let cmp = (i1, i2) => compare(i1, i2);
},
);
module OptIntCmp =
Id.MakeComparable(
{
Expand All @@ -39,7 +48,6 @@ type sideDataEntry = {
selectedNames: list(selectedNameWithRank),
};

type pairing = (string, string);

type state = {
selectingName: string,
Expand Down
3 changes: 3 additions & 0 deletions src/dataImporter/SampleData.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ var IntCmp = SharedTypes.IntCmp;

var StrCmp = SharedTypes.StrCmp;

var PairingCmp = SharedTypes.PairingCmp;

var OptIntCmp = SharedTypes.OptIntCmp;

var imperialPositions = /* :: */[
Expand Down Expand Up @@ -1368,6 +1370,7 @@ var marriageWomen = /* :: */[

exports.IntCmp = IntCmp;
exports.StrCmp = StrCmp;
exports.PairingCmp = PairingCmp;
exports.OptIntCmp = OptIntCmp;
exports.imperialPositions = imperialPositions;
exports.imperialCandidates = imperialCandidates;
Expand Down
3 changes: 3 additions & 0 deletions src/dataImporter/SideDataImporter.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ var IntCmp = SharedTypes.IntCmp;

var StrCmp = SharedTypes.StrCmp;

var PairingCmp = SharedTypes.PairingCmp;

var OptIntCmp = SharedTypes.OptIntCmp;

exports.IntCmp = IntCmp;
exports.StrCmp = StrCmp;
exports.PairingCmp = PairingCmp;
exports.OptIntCmp = OptIntCmp;
exports.applyChanges = applyChanges;
exports.component = component;
Expand Down
4 changes: 1 addition & 3 deletions src/matching/PopularManyToMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,10 @@ const twoLevelGaleShapley = (studentsWithChoices, coursesWithChoices, studentCap
const pairings = [];
for (const course in matchesByCourse) {
for (const student of [...matchesByCourse[course]]) {
pairings.push([course, student.slice(1)]);
pairings.push([student.slice(1), course]);
}
}
return pairings;
}



export default twoLevelGaleShapley;
25 changes: 19 additions & 6 deletions src/matching/RunMatch.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function rankSortedArray(selectedNames) {
}));
}

function popularManyToMany(currentState) {
function popularManyToMany(currentState, swapParties) {
var selectingSelected = Js_dict.fromList(Belt_List.map(currentState[/* selectingParsedData */9], (function (e) {
return /* tuple */[
e[/* name */0],
Expand All @@ -47,7 +47,16 @@ function popularManyToMany(currentState) {
e[/* canMatchWith */1]
];
})));
return Belt_List.fromArray(Curry._4(PopularManyToMany.default, selectingSelected, selectedSelected, selectingCanMatchWith, selectedCanMatchWith));
if (swapParties) {
return Belt_List.map(Belt_List.fromArray(Curry._4(PopularManyToMany.default, selectedSelected, selectingSelected, selectedCanMatchWith, selectingCanMatchWith)), (function (param) {
return /* tuple */[
param[1],
param[0]
];
}));
} else {
return Belt_List.fromArray(Curry._4(PopularManyToMany.default, selectingSelected, selectedSelected, selectingCanMatchWith, selectedCanMatchWith));
}
}

function minCostMaxFlow(currentState) {
Expand Down Expand Up @@ -239,10 +248,14 @@ function suggestStrategy(selectingParsedData, selectedParsedData, mutualMatch) {

function runMatch(currentState) {
var match = currentState[/* matchStrategy */4];
if (match >= 2) {
return minCostMaxFlow(currentState);
} else {
return popularManyToMany(currentState);
switch (match) {
case 0 :
return popularManyToMany(currentState, false);
case 1 :
return popularManyToMany(currentState, true);
case 2 :
return minCostMaxFlow(currentState);

}
}

Expand Down
15 changes: 9 additions & 6 deletions src/matching/RunMatch.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let rankSortedArray = selectedNames =>
|> Js.Array.sortInPlaceWith(((_n1, r1), (_n2, r2)) => compare(r1, r2))
|. Array.map(((sn, _)) => sn);

let popularManyToMany = (currentState: SharedTypes.state) => {
let popularManyToMany = (currentState: SharedTypes.state, swapParties: bool) => {
let selectingSelected =
currentState.selectingParsedData
|. List.map(e => (e.name, rankSortedArray(e.selectedNames)))
Expand All @@ -42,11 +42,14 @@ let popularManyToMany = (currentState: SharedTypes.state) => {
|. List.map(e => (e.name, e.canMatchWith))
|. Js.Dict.fromList;

let res =
if (swapParties) {
runPopularManyToMany(selectedSelected, selectingSelected, selectedCanMatchWith, selectingCanMatchWith)
|. List.fromArray
|. List.map(((a, b)) => (b, a));
} else {
runPopularManyToMany(selectingSelected, selectedSelected, selectingCanMatchWith, selectedCanMatchWith)
|. List.fromArray;

res;
}
};

let minCostMaxFlow = (currentState: SharedTypes.state) => {
Expand Down Expand Up @@ -272,8 +275,8 @@ let suggestStrategy = (selectingParsedData: list(SharedTypes.sideDataEntry),
let runMatch = (currentState: SharedTypes.state) => {
/* First decide on Gale-Shapley vs MinCostMaxFlow. */
switch(currentState.matchStrategy) {
| SharedTypes.SelectingBreakTies => popularManyToMany(currentState);
| SharedTypes.SelectedBreakTies => popularManyToMany(currentState);
| SharedTypes.SelectingBreakTies => popularManyToMany(currentState, false);
| SharedTypes.SelectedBreakTies => popularManyToMany(currentState, true);
| SharedTypes.MCMF => minCostMaxFlow(currentState);
}
};
Expand Down
Loading

0 comments on commit 71c9539

Please sign in to comment.