-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
415 lines (415 loc) · 15.1 KB
/
index.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0, user-scalable=no"/>
<title>Gale-Shapley Deferred Acceptance Algorithm</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/introjs.css" rel="stylesheet" type="text/css" />
<link href="css/vis.min.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Lato:400italic,400,900,900italic' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="script/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="script/intro.js"></script>
<script type="text/javascript" src="script/vis.min.js"></script>
</head>
<body>
<!--- Github fork ribbon --->
<a href="https://github.com/UnKnoWn-Consortium/Gale-Shapley_Deferred_Acceptance_Algorithm"><img style="position: absolute; top: 0; right: 0; border: 0; z-index: 99;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
<div class="header">
<h1>Gale-Shapley Deferred Acceptance Algorithm</h1>
<div class="pin top left"></div><div class="pin top right"></div><div class="pin bottom left"></div><div class="pin bottom right"></div>
</div>
<div class="container">
<div class="pin top left"></div><div class="pin top right"></div><div class="pin bottom left"></div><div class="pin bottom right"></div>
<fieldset id="inputField">
<legend>Input</legend>
<div class="switch">
<input id="cmn-toggle" class="cmn-toggle cmn-toggle-round" type="checkbox">
<label for="cmn-toggle" data-on="M " data-off=" F"></label>
<h3>Man Proposing Mode</h3>
</div>
<fieldset>
<p>Number of Men : <input id="numMan" type="number" value=3 min=2 step=1></p>
<p>Number of Women : <input id="numWoman" type="number" value=3 min=2 step=1></p>
</fieldset>
<div id="prefList">
<fieldset class="pref man">
<legend>Preference Order for Man 1 : </legend>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2" selected>Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1" selected>Woman 1</option>
<option value="2">Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2">Woman 2</option>
<option value="3" selected>Woman 3</option>
</select>
</fieldset>
<fieldset class="pref man">
<legend>Preference Order for Man 2 : </legend>
<select>
<option value=""></option>
<option value="1" selected>Woman 1</option>
<option value="2">Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2" selected>Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2">Woman 2</option>
<option value="3" selected>Woman 3</option>
</select>
</fieldset>
<fieldset class="pref man">
<legend>Preference Order for Man 3 : </legend>
<select>
<option value=""></option>
<option value="1" selected>Woman 1</option>
<option value="2">Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2" selected>Woman 2</option>
<option value="3">Woman 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Woman 1</option>
<option value="2">Woman 2</option>
<option value="3" selected>Woman 3</option>
</select>
</fieldset>
<fieldset class="pref woman">
<legend>Preference Order for Woman 1 : </legend>
<select>
<option value=""></option>
<option value="1" selected>Man 1</option>
<option value="2">Man 2</option>
<option value="3">Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2" selected>Man 2</option>
<option value="3">Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2">Man 2</option>
<option value="3" selected>Man 3</option>
</select>
</fieldset>
<fieldset class="pref woman">
<legend>Preference Order for Woman 2 : </legend>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2">Man 2</option>
<option value="3" selected>Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1" selected>Man 1</option>
<option value="2">Man 2</option>
<option value="3">Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2" selected>Man 2</option>
<option value="3">Man 3</option>
</select>
</fieldset>
<fieldset class="pref woman">
<legend>Preference Order for Woman 3 : </legend>
<select>
<option value=""></option>
<option value="1" selected>Man 1</option>
<option value="2">Man 2</option>
<option value="3">Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2" selected>Man 2</option>
<option value="3">Man 3</option>
</select>
>
<select>
<option value=""></option>
<option value="1">Man 1</option>
<option value="2">Man 2</option>
<option value="3" selected>Man 3</option>
</select>
</fieldset>
</div>
<div class="inputControl">
<button id="default"> Load 3v3 Default</button>
<button id="importTXT" disabled>Import from TXT</button>
</div>
</fieldset>
<fieldset id="control">
<legend>Control</legend>
<p>(1) Press <b>SETUP</b> for resetting or initializing.</p>
<button id="setup">SETUP</button>
<p>(2) Press <b>RUN ONCE</b> for advancing the algorithm for one step.</p>
<button id="runOnce">RUN ONCE</button>
<fieldset id="runOnceDis">
<div><p><b>RUN ONCE</b> includes basically two child steps.
<ol type="1">
<li>Proposers <b>propose</b></li>
<li>Receivers <b>evaluate</b></li>
</ol></p>
<p>So pressing <b>RUN ONCE</b> is equivalent to pressing <b>PROPOSE</b> once, then <b>EVALUATE</b> once. </p><div>
<div style="text-align: center;">
<button id="propose">PROPOSE</button>
<button id="evaluate" disabled>EVALUATE</button>
</div>
</fieldset>
<p>(3) Press <b>RUN</b> for running the algorithm till stop conditions fulfilled.</p>
<button id="run">RUN</button>
<p>(4) Press <b>SUMMARY</b> for a report on the current step.</p>
<button id="summary">SUMMARY</button>
<p>(5) Press <b>CLEAR OUTPUT</b> to reset the output area.</p>
<button id="clearOutput">CLEAR OUTPUT</button>
</fieldset>
<fieldset id="outputField">
<legend>Output</legend>
<textarea id="output" rows="25" cols="75" readonly></textarea>
</fieldset>
<fieldset id="graph">
<legend>Graphical Representation</legend>
<div id="iteration">ITERATION 00</div>
<div id="graphContainer"></div>
</fieldset>
</div>
<div class="footer">
<div class="pin top left"></div><div class="pin top right"></div><div class="pin bottom left"></div><div class="pin bottom right"></div>
<div id="powered">
<h3>Powered by: </h3>
<a href="http://visjs.org/"><img src="img/vis_logo.png" alt="vis.js logo" height="150" width="160"></a>
<a href="http://jquery.com/"><img src="img/jquery_logo.png" alt="jquery logo" height="130" width="175.5"></a>
</div>
<div id="designed">
<h3>Coded by: </h3>
<img src="img/unknown_logo.png" alt="unknown logo" height="80" width="275">
</div>
</div>
<script>
var mode = "M";
var manArray = ["2,1,3", "1,2,3", "1,2,3"], womanArray= ["1,2,3", "3,1,2", "1,2,3"];
var graphIndex = {
'Man 1': 1,
'Man 2': 2,
'Man 3': 3,
'Woman 1': 4,
'Woman 2': 5,
'Woman 3': 6
};
var graphObj = {
nodes : [
{id: 1, label: 'Man 1', group: 'man'},
{id: 2, label: 'Man 2', group: 'man'},
{id: 3, label: 'Man 3', group: 'man'},
{id: 4, label: 'Woman 1', group: 'woman'},
{id: 5, label: 'Woman 2', group: 'woman'},
{id: 6, label: 'Woman 3', group: 'woman'}
],
edges : []
}
var graphOptions = {
stabilize: false,
edges: {
width: 2,
style: 'arrow',
color: 'gray'
},
physics: {
barnesHut:{springLength:200}
},
groups: {
man: {
color: 'blue',
fontColor: 'white',
fontSize: 18
},
woman: {
color: 'red',
fontColor: 'white',
fontSize: 18
}
}
};
var outputArea = document.getElementById("output");
var graphArea = document.getElementById("graphContainer");
var worker = new Worker("script/worker.js");
var network = new vis.Network(graphArea, graphObj, graphOptions);
$("#output").val("Gale-Shapley Deferred Acceptance Algorithm for Two-Sided Matching");
worker.addEventListener("message", function(e){
$("#output").val($("#output").val() + "\n" + e.data.output);
outputArea.scrollTop = outputArea.scrollHeight;
// Update counter
if (e.data.steps !== undefined){
var steps = e.data.steps;
if (steps.length < 2){steps = "0" + steps;}
$('fieldset#graph #iteration').html("ITERATION " + steps);
}
// Update graph
var temp_edges = [];
if (e.data.edges !== undefined){
for (var i = 0; i < e.data.edges.length; i++){
var temp = e.data.edges[i];
temp.from = graphIndex[e.data.edges[i].from];
temp.to = graphIndex[e.data.edges[i].to];
temp_edges.push(temp);
}
}
graphObj.edges = temp_edges;
if (graphObj.edges.length > 0){network.setData(graphObj);}
});
$('#runOnce').on('click',function(){worker.postMessage({status:"runOnce"});});
$('#propose').on('click',function(){
worker.postMessage({status:"propose"});
$('#run').prop('disabled', true);
$('#runOnce').prop('disabled', true);
$('#propose').prop('disabled', true);
$('#evaluate').prop('disabled', false);
});
$('#evaluate').on('click',function(){
worker.postMessage({status:"evaluate"});
$('#run').prop('disabled', false);
$('#runOnce').prop('disabled', false);
$('#evaluate').prop('disabled', true);
$('#propose').prop('disabled', false);
});
$('#run').on('click',function(){worker.postMessage({status:"run"});});
$('#summary').on('click',function(){worker.postMessage({status:"summary"});});
$('#clearOutput').on('click',function(){
$("#output").val("");
$("#output").val("Gale-Shapley Deferred Acceptance Algorithm for Two-Sided Matching");
outputArea.scrollTop = outputArea.scrollHeight;
});
$('#setup').on('click', function(){
$('#runOnce').prop('disabled', false);
$('#evaluate').prop('disabled', true);
$('#propose').prop('disabled', false);
var numWoman = Number($('input#numWoman').val());
var numMan = Number($('input#numMan').val());
var prefM = [];
var prefF = [];
$('#prefList .pref.man').each(function(index) {
var order = "";
$(this).find('select').each(function(index, element) {if (String($(this).val()) != ""){order += String($(this).val()) + ",";}});
order = order.substring(0, order.length-1);
prefM.push(order);
});
$('#prefList .pref.woman').each(function(index) {
var order = "";
$(this).find('select').each(function(index, element) {if (String($(this).val()) != ""){order += String($(this).val()) + ",";}});
order = order.substring(0, order.length-1);
prefF.push(order);
});
manArray = prefM;
womanArray = prefF;
worker.postMessage({status:"setup", Mode: mode, ListM: manArray, ListF: womanArray});
$('fieldset#graph #iteration').html("ITERATION 00");
graphObj = updateGraph(numMan, numWoman, graphIndex);
network.setData(graphObj);
});
$('fieldset#inputField input#cmn-toggle').on('change', function(){
if (this.checked) {mode = "F";$('fieldset#inputField .switch h3').html("Woman Proposing Mode");}else {mode = "M";$('fieldset#inputField .switch h3').html("Man Proposing Mode");}
});
$('input#numMan').on('change', updateInput);
$('input#numWoman').on('change', updateInput);
function updateInput(){
var numWoman = Number($('input#numWoman').val());
var numMan = Number($('input#numMan').val());
var result = contentHelper(numMan, "man");
var recastDiv = result.recastDiv;
var recastSelectM = result.recastSelect;
var recastOptionsM = result.recastOptions;
var result = contentHelper(numWoman, "woman");
recastDiv += result.recastDiv;
var recastSelectF = result.recastSelect;
var recastOptionsF = result.recastOptions;
$('#prefList').empty();
$('#prefList').append(recastDiv);
appendHelper(recastSelectF, recastOptionsF, recastSelectM, recastOptionsM);
graphObj = updateGraph(numMan, numWoman, graphIndex);
network.setData(graphObj);
}
function contentHelper(count, classT){
var divT = "", selectT = "";
var temp = classT[0].toUpperCase() + classT.slice(1);
var optionT = '<option value=""></option>';
for (var i = 1; i < count + 1; i++){
divT += '<fieldset class="pref ' + classT + '"><legend>Preference Order for ' + temp + ' '+ i +' : </legend></fieldset>';
selectT += ' > <select></select>';
optionT += '<option value="'+ i +'">'+ temp +' ' + i + '</option>';
}
var package = {recastDiv : divT, recastSelect : selectT, recastOptions : optionT};
return package;
}
function appendHelper(recastSelectF, recastOptionsF, recastSelectM, recastOptionsM){
recastSelectM = recastSelectM.slice(3);
recastSelectF = recastSelectF.slice(3);
$('.pref.man').append(recastSelectF);
$('.pref.man select').append(recastOptionsF);
$('.pref.woman').append(recastSelectM);
$('.pref.woman select').append(recastOptionsM);
}
function updateGraph(countM, countF, index){
// On change in number of man or woman agents, update the network and index
var data = {};
data.nodes = [];
data.edges = [];
for (var i = 1; i < countM + 1; i++){
var nodeObj = {};
nodeObj.id = i;
nodeObj.label = "Man " + String(i);
nodeObj.group = 'man';
data.nodes.push(nodeObj);
index[nodeObj.label] = i;
}
for (var i = countM + 1; i < (countM + countF) + 1; i++){
var nodeObj = {};
nodeObj.id = i;
nodeObj.label = "Woman " + String(i - countM);
nodeObj.group = 'woman';
data.nodes.push(nodeObj);
index[nodeObj.label] = i;
}
return data;
}
</script>
</body>
</html>