-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheds.js
47 lines (38 loc) · 1.57 KB
/
eds.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
var deliveryCost = require('./ekoDeliveryService');
var availableRoutes = require('./ekoDeliveryService-2');
var fromCity =[],
toCity = [],
cost = [];
var fullRoute = process.argv[2];
var eachRoute = fullRoute.split(",");
var graph = {};
eachRoute.forEach(function(route){
fromCity.push(route.substring(0,1));
graph[route.substring(0,1)] = [];
toCity.push(route.substring(1,2));
cost.push(route.substring(2));
});
for(var i = 0; i < fromCity.length; i++){
graph[fromCity[i]].push(toCity[i]);
}
if(process.argv[3] == "deliveryCost"){
var routingCost = deliveryCost.getDeliveryCost(fromCity, toCity, cost, process.argv[4]);
console.log("The delivery cost for " + process.argv[4] + " is : " + routingCost);
}else if(process.argv[3] == "availableRoutes"){
var availablePaths = availableRoutes.getAvailableRoutes(graph, process.argv[4], process.argv[5]);
console.log("The available routes from " + process.argv[4] + " To " + process.argv[5] + " is : " + availablePaths.length);
}else if(process.argv[3] == "cheapestRoutes"){
var availablePaths = availableRoutes.getAvailableRoutes(graph, process.argv[4], process.argv[5]);
var cheapestPath = 0;
availablePaths.forEach(function(path){
var pathInDetail = path[0];
for(var i = 1; i < path.length; i++){
pathInDetail += "-" + path[i];
}
var pathCost = deliveryCost.getDeliveryCost(fromCity, toCity, cost, pathInDetail);
if(pathCost < cheapestPath || cheapestPath == 0){
cheapestPath = pathCost;
}
});
console.log("The cheapest route from " + process.argv[4] + " to " + process.argv[5] + " is : " + cheapestPath);
}