-
Notifications
You must be signed in to change notification settings - Fork 0
/
TT.js
75 lines (45 loc) · 2.37 KB
/
TT.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
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
const railway = require('./Railway');
function main(){
const exmGraph1 = '\'AL5, LC4, CW8, WC8, WG6, AW5, CG2, GL3, AG7\'';
const exmGraph2 = 'AL5,LC4,CW8,WC8,WG6,AW5,CG2,GL3,AG7';
const exmRoute = 'C-W-G-L';
if( process.argv.length >= 4 ){
const graph = process.argv[2];
const route = process.argv[3];
const params = {maxLength: process.argv[4] || 30, maxStop: process.argv[5] || 7} ;
railway.parseGraph(graph, (parsedGraph)=>{
if( parsedGraph ){
railway.formatParsedGraph( parsedGraph, (formattedGraph) => {
railway.parseRoute(route, (parsedRoute) => {
if(parsedRoute){
railway.formatParsedRoute(parsedRoute, (formattedRoute) => {
if(formattedRoute){
railway.distance( formattedGraph, formattedRoute, (distance) => {
console.log('Distance: ' , distance);
});
railway.diffRoutes( formattedGraph, formattedRoute, params, (diffroutes) => {
console.log(`Different routes count: ${diffroutes.length}`);
railway.findShortRouteLength(diffroutes, (shortRouteLength) => {
console.log(`Short Route Length: ${shortRouteLength}`);
});
});
}
});
}else{
console.log('Unclear Route Data');
console.log(`Route example:\n ${exmRoute}`);
}
});
});
}else{
console.log('Unclear Graph Data');
console.log(`Graph examples:\n ${exmGraph1}`);
console.log(`or:\n ${exmGraph2}`);
}
});
}else{
console.log(`Input examples:\n ${exmGraph1} ${exmRoute} `);
console.log(`or:\n ${exmGraph2} ${exmRoute}`);
}
}
main();