-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathexample.py
122 lines (115 loc) · 4.14 KB
/
example.py
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
import vrp_cli
import pragmatic_types as prg
import config_types as cfg
import json
from pydantic.json import pydantic_encoder
# if you want to use approximation, you can skip this definition and pass empty list later
# also there is a get_locations method to get list of locations in expected order.
# you can use this list to fetch routing matrix externally
matrix = prg.RoutingMatrix(
profile='normal_car',
durations=[0, 609, 981, 906, 813, 0, 371, 590, 1055, 514, 0, 439, 948, 511, 463, 0],
distances=[0, 3840, 5994, 5333, 4696, 0, 2154, 3226, 5763, 2674, 0, 2145, 5112, 2470, 2152, 0]
)
# specify termination criteria: max running time in seconds or max amount of refinement generations
config = cfg.Config(
termination=cfg.Termination(
maxTime=5,
maxGenerations=1000
)
)
# specify test problem
problem = prg.Problem(
plan=prg.Plan(
jobs=[
prg.Job(
id='delivery_job1',
deliveries=[
prg.JobTask(
places=[
prg.JobPlace(
location=prg.Location(lat=52.52599, lng=13.45413),
duration=300,
times=[['2019-07-04T09:00:00Z', '2019-07-04T18:00:00Z']]
),
],
demand=[1]
)
]
),
prg.Job(
id='pickup_job2',
pickups=[
prg.JobTask(
places=[
prg.JobPlace(
location=prg.Location(lat=52.5225, lng=13.4095),
duration=240,
times=[['2019-07-04T10:00:00Z', '2019-07-04T16:00:00Z']]
)
],
demand=[1]
)
]
),
prg.Job(
id="pickup_delivery_job3",
pickups=[
prg.JobTask(
places=[
prg.JobPlace(
location=prg.Location(lat=52.5225, lng=13.4095),
duration=300,
tag="p1"
)
],
demand=[1]
)
],
deliveries=[
prg.JobTask(
places=[
prg.JobPlace(
location=prg.Location(lat=52.5165, lng=13.3808),
duration=300,
tag="d1"
),
],
demand=[1]
)
]
)
]
),
fleet=prg.Fleet(
vehicles=[
prg.VehicleType(
typeId='vehicle',
vehicleIds=['vehicle_1'],
profile=prg.VehicleProfile(matrix='normal_car'),
costs=prg.VehicleCosts(fixed=22, distance=0.0002, time=0.005),
shifts=[
prg.VehicleShift(
start=prg.VehicleShiftStart(
earliest="2019-07-04T09:00:00Z",
location=prg.Location(lat=52.5316, lng=13.3884),
),
end=prg.VehicleShiftEnd(
latest="2019-07-04T18:00:00Z",
location=prg.Location(lat=52.5316, lng=13.3884),
)
)
],
capacity=[10]
)
],
profiles=[prg.RoutingProfile(name='normal_car')]
)
)
# run solver and deserialize result into solution model
solution = prg.Solution(**json.loads(vrp_cli.solve_pragmatic(
problem=json.dumps(problem, default=pydantic_encoder),
matrices=[json.dumps(matrix, default=pydantic_encoder)],
config=json.dumps(config, default=pydantic_encoder),
)))
print(solution)