-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel_plan_stops_unit_test.go
155 lines (132 loc) · 3.01 KB
/
model_plan_stops_unit_test.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
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
// © 2019-present nextmv.io inc
package nextroute_test
import (
"context"
"slices"
"testing"
"time"
"github.com/nextmv-io/nextroute"
"github.com/nextmv-io/nextroute/common"
)
func TestPlanMultipleStops(t *testing.T) {
model, err := nextroute.NewModel()
if err != nil {
t.Fatal(err)
}
warehouse, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
warehouse.SetID("warehouse")
s1, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
s1.SetID("s1")
s2, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
s2.SetID("s2")
s3, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
s3.SetID("s3")
s4, err := model.NewStop(common.NewInvalidLocation())
if err != nil {
t.Fatal(err)
}
s4.SetID("s4")
dag1 := nextroute.NewDirectedAcyclicGraph()
if err := dag1.AddArc(s1, s2); err != nil {
t.Fatal(err)
}
if err := dag1.AddArc(s1, s3); err != nil {
t.Fatal(err)
}
if err := dag1.AddArc(s3, s4); err != nil {
t.Fatal(err)
}
ms1, err := model.NewPlanMultipleStops(nextroute.ModelStops{
s1,
s2,
s3,
s4,
}, dag1)
if err != nil {
t.Fatal(err)
}
if ms1 == nil {
t.Fatal("ms1 should not be nil")
}
if len(ms1.Stops()) != 4 {
t.Fatal("ms1 should have 4 stops")
}
if slices.IndexFunc(ms1.Stops(), func(stop nextroute.ModelStop) bool {
return stop == s1
}) == -1 {
t.Fatal("ms1 should have s1")
}
if slices.IndexFunc(ms1.Stops(), func(stop nextroute.ModelStop) bool {
return stop == s2
}) == -1 {
t.Fatal("ms1 should have s2")
}
if slices.IndexFunc(ms1.Stops(), func(stop nextroute.ModelStop) bool {
return stop == s3
}) == -1 {
t.Fatal("ms1 should have s3")
}
if slices.IndexFunc(ms1.Stops(), func(stop nextroute.ModelStop) bool {
return stop == s4
}) == -1 {
t.Fatal("ms1 should have s4")
}
vehicleType, err := model.NewVehicleType(
nextroute.NewTimeIndependentDurationExpression(
nextroute.NewDurationExpression(
"travelDuration",
nextroute.NewHaversineExpression(),
common.Second,
),
),
nextroute.NewConstantDurationExpression("processing_time", 1*time.Hour),
)
if err != nil {
t.Fatal(err)
}
vehicle, err := model.NewVehicle(vehicleType, model.Epoch(), warehouse, warehouse)
if err != nil {
t.Fatal(err)
}
solution, err := nextroute.NewSolution(model)
if err != nil {
t.Fatal(err)
}
if solution == nil {
t.Fatal("solution should not be nil")
}
if solution.UnPlannedPlanUnits().Size() != 1 {
t.Fatal("solution should have 1 un-planned plan units")
}
solutionVehicle := solution.SolutionVehicle(vehicle)
_ = solutionVehicle
move := solution.BestMove(
context.Background(),
solution.UnPlannedPlanUnits().SolutionPlanUnit(ms1),
)
if move == nil {
t.Fatal("move should not be nil")
}
if !move.IsExecutable() {
t.Fatal("move should be executable")
}
success, err := move.Execute(context.Background())
if err != nil {
t.Fatal(err)
}
if !success {
t.Fatal("move should be successful")
}
}