-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdependent_by_index.go
63 lines (56 loc) · 1.32 KB
/
dependent_by_index.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
package measure
import (
"encoding/json"
)
// DependentIndexed is a measure that uses a custom cost function to calculate
// parameter dependent costs for connecting two points by index. If the measures
// are time dependent all future stops in the sequence will be fully
// recalculated. Otherwise there will be a constant shift to achieve better
// performance.
func DependentIndexed(
timeDependent bool,
cost func(
from,
to int,
data *VehicleData,
) float64,
) DependentByIndex {
return &dependentIndexed{
cost: cost,
timeDependent: timeDependent,
}
}
// VehicleData holds vehicle specific data, including times by index (ETA, ETD
// and ETS), a vehicle id, the vehicle's route and the solution value for that
// vehicle.
type VehicleData struct {
VehicleID string
Times Times
Route []int
Index int
RouteValue int
}
type dependentIndexed struct {
cost func(
from,
to int,
data *VehicleData,
) float64
timeDependent bool
}
func (b *dependentIndexed) Cost(
from,
to int,
data *VehicleData,
) float64 {
return b.cost(from, to, data)
}
func (b *dependentIndexed) TimeDependent() bool {
return b.timeDependent
}
func (b *dependentIndexed) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"type": "dependentIndexed",
"timeDependent": b.timeDependent,
})
}