-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 897 Bytes
/
main.go
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
package main
import (
"flag"
"fmt"
"os"
"strings"
)
func usage() {
_, err := fmt.Fprintf(os.Stderr, "usage: %s <input file> <output file> [{cost} / time]\n", os.Args[0])
if err != nil {
return
}
flag.PrintDefaults()
os.Exit(2)
}
func main() {
if len(os.Args) < 3 || len(os.Args) > 4 ||
(len(os.Args) == 4 && !(strings.ToLower(os.Args[3]) == "cost" || strings.ToLower(os.Args[3]) == "time")) {
usage()
}
file := openFile(os.Args[1])
defer func(file *os.File) {
err := file.Close()
if err != nil {
}
}(file)
data := readCsv(file)
tickets := createTicketList(data)
graph := generateGraph(tickets)
ticketsLists := make([]TicketsWithAlternatives, 0)
if len(os.Args) == 4 && strings.ToLower(os.Args[3]) == "time" {
ticketsLists = graph.optimalRoutes(ByDuration)
} else {
ticketsLists = graph.optimalRoutes(ByCost)
}
writeToFile(os.Args[2], ticketsLists)
}