-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel_objective_vehicles.go
66 lines (55 loc) · 1.6 KB
/
model_objective_vehicles.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
// © 2019-present nextmv.io inc
package nextroute
// VehiclesObjective is an objective that uses the number of vehicles as an
// objective. Each vehicle that is not empty is scored by the given expression.
// A vehicle is empty if it has no stops assigned to it (except for the first
// and last visit).
type VehiclesObjective interface {
ModelObjective
// ActivationPenalty returns the activation penalty expression.
ActivationPenalty() VehicleTypeExpression
}
// NewVehiclesObjective returns a new VehiclesObjective.
func NewVehiclesObjective(
expression VehicleTypeExpression,
) VehiclesObjective {
return &vehiclesObjectiveImpl{
expression: expression,
}
}
type vehiclesObjectiveImpl struct {
expression VehicleTypeExpression
}
func (t *vehiclesObjectiveImpl) ModelExpressions() ModelExpressions {
return ModelExpressions{}
}
func (t *vehiclesObjectiveImpl) EstimateDeltaValue(move SolutionMoveStops) float64 {
vehicle := move.(*solutionMoveStopsImpl).vehicle()
if vehicle.NumberOfStops() == 0 {
return t.expression.Value(
vehicle.ModelVehicle().VehicleType(),
nil,
nil,
)
}
return 0.0
}
func (t *vehiclesObjectiveImpl) Value(solution Solution) float64 {
vehicleCost := 0.0
for _, vehicle := range solution.(*solutionImpl).vehiclesMutable() {
if vehicle.NumberOfStops() > 0 {
vehicleCost += t.expression.Value(
vehicle.ModelVehicle().VehicleType(),
nil,
nil,
)
}
}
return vehicleCost
}
func (t *vehiclesObjectiveImpl) String() string {
return "vehicle_activation_penalty"
}
func (t *vehiclesObjectiveImpl) ActivationPenalty() VehicleTypeExpression {
return t.expression
}