-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (40 loc) · 1.37 KB
/
index.js
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
const colors = require('colors');
const StableMarriageProblem = require('./modules/stable-marriage-problem.js');
const Generator = require('./modules/generator.js');
try {
var n = 20,
path = '';
process.argv.forEach((v, i) => {
if (v.indexOf('f=') == 0) {
path = v.slice(2);
}
if (v.indexOf('n=') == 0) {
let parsed = parseInt(v.slice(2));
if (!isNaN(parsed)) n = parsed;
}
});
let json = null;
if (path === '') {
console.log('Generating stable marriage problem of size n=' + n + '...');
json = Generator.randomStandardSMP(n);
} else {
if (path.indexOf('/') != 0 && path.indexOf('./') != 0) {
path = './' + path;
}
console.log('Reading stable marriage instance from file "' + path + '"...');
try {
json = require(path);
} catch (e) {
throw new Error('Failed to read file "' + path + '": ' + e.message);
}
}
let smp = new StableMarriageProblem(json);
smp.match();
console.log('\n\n\n');
console.log('* * * * * * * * * * * * * * * * * * *');
console.log('* * * * Matching Overview * * * *');
console.log('* * * * * * * * * * * * * * * * * * *\n');
console.log(smp.printPriorityTable());
} catch (e) {
console.error(colors.bold.red('Error: ' + e.message));
}