Repository navigation
Expand file tree
/
Copy pathmodel_vehicle_type.go
More file actions
183 lines (147 loc) · 4.82 KB
/
Copy pathmodel_vehicle_type.go
File metadata and controls
183 lines (147 loc) · 4.82 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// © 2019-present nextmv.io inc
package nextroute
import (
"errors"
)
// ModelVehicleType is a vehicle type. A vehicle type is a definition of a
// vehicle. It contains the process duration and travel duration expressions
// that are used to calculate the travel and process duration of a stop
// assignment to a vehicle of this type.
type ModelVehicleType interface {
ModelData
// TemporalValues calculates the temporal values if the vehicle
// would depart at departure going from stop to stop. If from or to is
// invalid, the returned travelDuration will be 0.
TemporalValues(
departure float64,
from ModelStop,
to ModelStop,
) (travelDuration, arrival, start, end float64)
// Index returns the index of the vehicle type.
Index() int
// Model returns the model of the vehicle type.
Model() Model
// ID returns the identifier of the vehicle.
ID() string
// DurationExpression returns the process duration expression of the
// vehicle type. Is set in the factory method of the vehicle type
// Model.NewVehicleType.
DurationExpression() DurationExpression
// SetDurationExpression modifies the process duration expression of
// the vehicle type.
SetDurationExpression(expression DurationExpression) error
// SetID sets the identifier of the stop. This identifier is not used by
// nextroute and therefore it does not have to be unique for nextroute
// internally. However to make this ID useful for debugging and reporting it
// should be made unique.
SetID(string)
// TravelDurationExpression returns the duration expression of the
// vehicle type. Is set in the factory method of the vehicle type
// Model.NewVehicleType.
TravelDurationExpression() TimeDependentDurationExpression
// SetTravelDurationExpression modifies the duration expression of the
// vehicle type.
SetTravelDurationExpression(expression TimeDependentDurationExpression) error
// DistanceExpression returns the distance expression of the vehicle type.
DistanceExpression() DistanceExpression
// SetDistanceExpression modifies the distance expression of the vehicle type.
SetDistanceExpression(expression DistanceExpression) error
// Vehicles returns the vehicles of this vehicle type.
Vehicles() ModelVehicles
}
// ModelVehicleTypes is a slice of vehicle types.
type ModelVehicleTypes []ModelVehicleType
type vehicleTypeImpl struct {
modelDataImpl
model Model
travelDuration TimeDependentDurationExpression
duration DurationExpression
distance DistanceExpression
id string
vehicles ModelVehicles
index int
}
func (v *vehicleTypeImpl) Vehicles() ModelVehicles {
vehicles := make(ModelVehicles, len(v.vehicles))
copy(vehicles, v.vehicles)
return vehicles
}
func (v *vehicleTypeImpl) Index() int {
return v.index
}
func (v *vehicleTypeImpl) ID() string {
return v.id
}
func (v *vehicleTypeImpl) SetID(id string) {
v.id = id
}
func (v *vehicleTypeImpl) Model() Model {
return v.model
}
func (v *vehicleTypeImpl) TravelDurationExpression() TimeDependentDurationExpression {
return v.travelDuration
}
func (v *vehicleTypeImpl) DurationExpression() DurationExpression {
return v.duration
}
func (v *vehicleTypeImpl) DistanceExpression() DistanceExpression {
return v.distance
}
func (v *vehicleTypeImpl) TemporalValues(
departure float64,
from ModelStop,
to ModelStop,
) (travelDuration, arrival, start, end float64) {
if from.Location().IsValid() && to.Location().IsValid() {
travelDuration = v.travelDuration.ValueAtValue(
departure,
v,
from,
to,
)
}
arrival = departure + travelDuration
processDuration := v.duration.Value(
v,
from,
to,
)
stopImpl := to.(*stopImpl)
start = arrival
earliestStart := stopImpl.ToEarliestStartValue(arrival)
if earliestStart > start {
start = earliestStart
}
end = start + processDuration
return travelDuration, arrival, start, end
}
func (v *vehicleTypeImpl) SetTravelDurationExpression(e TimeDependentDurationExpression) error {
if v.model.IsLocked() {
return errors.New("cannot modify vehicle type (set travel duration expression) after model is locked")
}
if e == nil {
return errors.New("cannot set travel duration expression to nil")
}
v.travelDuration = e
return nil
}
func (v *vehicleTypeImpl) SetDurationExpression(e DurationExpression) error {
if v.model.IsLocked() {
return errors.New("cannot modify vehicle type (set process duration expression) after model is locked")
}
if e == nil {
return errors.New("cannot set process duration expression to nil")
}
v.duration = e
return nil
}
func (v *vehicleTypeImpl) SetDistanceExpression(expression DistanceExpression) error {
if v.model.IsLocked() {
return errors.New("cannot modify vehicle type (set distance expression) after model is locked")
}
if expression == nil {
return errors.New("cannot set distance expression to nil")
}
v.distance = expression
return nil
}