-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
106 lines (86 loc) · 1.7 KB
/
types.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package fsp
import (
"fmt"
"sort"
"time"
)
type City uint32
type Money uint32
func (m Money) String() string {
return fmt.Sprintf("%d", m)
}
type Day uint16
type FlightIndex uint32
type Flight struct {
From City
To City
Day Day
Cost Money
Heuristic Money
Penalty float64
}
type FlightStats struct {
FlightCount uint16
BestPrice Money
BestDay Day
BestDest City
AvgPrice float32
}
type FlightStatistics struct {
ByDest [][]FlightStats
ByDay [][]FlightStats
TotalFlights uint32
AvgPrice float32
}
type Problem struct {
flights []Flight
start City
n int //size = number of cities/days
//stats [][]FlightStats
stats FlightStatistics
}
func (p Problem) Solve(timeout <-chan time.Time) (Solution, error) {
sol, err := kickTheEngines(p, timeout)
/*for _, f := range p.flights {
if f.Penalty != 0 {
printInfo(f)
}
}*/
return sol, err
}
func (p Problem) FlightsCnt() int {
return len(p.flights)
}
func (p Problem) FlightStats() FlightStatistics {
return p.stats
}
func (p Problem) CitiesCnt() int {
return p.n
}
func NewProblem(flights []Flight, n int, stats FlightStatistics) Problem {
return Problem{flights, 0, n, stats}
}
type Solution struct {
flights []Flight
totalCost Money
}
func (s Solution) GetFlights() []Flight {
return s.flights
}
func (s Solution) GetTotalCost() Money {
return s.totalCost
}
func NewSolution(flights []Flight) Solution {
sort.Sort(ByDay(flights))
return Solution{flights, Cost(flights)}
}
type ByDay []Flight
func (f ByDay) Len() int {
return len(f)
}
func (f ByDay) Swap(i, j int) {
f[i], f[j] = f[j], f[i]
}
func (f ByDay) Less(i, j int) bool {
return f[i].Day < f[j].Day
}