-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmodel_objective_stop_balancing.go
More file actions
55 lines (47 loc) · 1.28 KB
/
model_objective_stop_balancing.go
File metadata and controls
55 lines (47 loc) · 1.28 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
// © 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) {
maximum := 0
maximumBefore := 0
moveExists := move != nil
var vehicle SolutionVehicle
if moveExists {
vehicle = move.Vehicle()
}
for _, v := range solution.(*solutionImpl).vehicles {
numberOfStops := v.NumberOfStops()
if maximum < numberOfStops {
maximum = numberOfStops
}
if maximumBefore < numberOfStops {
maximumBefore = numberOfStops
}
if moveExists && v.Index() == vehicle.Index() {
length := move.StopPositionsLength()
if maximum < numberOfStops+length {
maximum = numberOfStops + length
}
}
}
return maximumBefore, maximum
}
func (t *balanceObjectiveImpl) String() string {
return "stop_balance"
}