-
Notifications
You must be signed in to change notification settings - Fork 4
/
model_objective_stop_balancing.go
55 lines (47 loc) · 1.24 KB
/
model_objective_stop_balancing.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
// © 2019-present nextmv.io inc
package nextroute
// NewStopBalanceObjective returns a new StopBalanceObjective.
func NewStopBalanceObjective() ModelObjective {
return &balanceObjectiveImpl{}
}
type balanceObjectiveImpl struct {
}
func (t *balanceObjectiveImpl) EstimateDeltaValue(
move Move,
) float64 {
solution := move.Solution()
oldMax, newMax := t.maxStops(solution, move)
return float64(newMax - oldMax)
}
func (t *balanceObjectiveImpl) Value(solution Solution) float64 {
maxBefore, _ := t.maxStops(solution, nil)
return float64(maxBefore)
}
func (t *balanceObjectiveImpl) maxStops(solution Solution, move SolutionMoveStops) (int, int) {
max := 0
maxBefore := 0
moveExists := move != nil
var vehicle SolutionVehicle
if moveExists {
vehicle = move.Vehicle()
}
for _, v := range solution.(*solutionImpl).vehicles {
numberOfStops := v.NumberOfStops()
if max < numberOfStops {
max = numberOfStops
}
if maxBefore < numberOfStops {
maxBefore = numberOfStops
}
if moveExists && v.Index() == vehicle.Index() {
length := move.StopPositionsLength()
if max < numberOfStops+length {
max = numberOfStops + length
}
}
}
return maxBefore, max
}
func (t *balanceObjectiveImpl) String() string {
return "stop_balance"
}