-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmap.go
More file actions
63 lines (51 loc) · 1.39 KB
/
cmap.go
File metadata and controls
63 lines (51 loc) · 1.39 KB
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
package gatsman
import "fmt"
//cityMap that stores the loaded cities from file or ranomdly generated
var cityMap map[int]*City
//distanceMap maps a pair of city indexes to the distance between them
var distanceMap map[CityPair]float64
//GetDistance If the distance has been calculated it is retrieved, else it is added and then returned
func GetDistance(cp CityPair) float64 {
val, ok := distanceMap[cp]
if !ok {
fmt.Printf("error\n")
}
return val
}
//LenDistanceMap returns length of distance map
func LenDistanceMap() int {
return len(distanceMap)
}
func init() {
//CityMap = make(map[int]*City)
}
//RandInitCMap initializes the CMap with a random map defined by a size and citycount
func RandInitCMap(size int, citycount int) {
cityMap = RandMap(size, citycount)
}
//InitCMap initializes the cityMap with a map from file
func InitCMap(filename string) {
if filename == "" {
RandInitCMap(1000, 50)
} else {
cityMap = LoadMap(filename)
}
}
//InitDMap Initializes the DMap
func InitDMap() {
distanceMap = make(map[CityPair]float64)
for i := 1; i <= CityCount(); i++ {
for j := i + 1; j <= CityCount(); j++ {
d := Distance(cityMap[i], cityMap[j])
distanceMap[NewCityPair(i, j)] = d
}
}
}
//GetCity function to return the city with the given index
func GetCity(key int) *City {
return cityMap[key]
}
//CityCount returns the amount of cities
func CityCount() int {
return len(cityMap)
}