-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpdvrp_data_problem.py
57 lines (48 loc) · 1.81 KB
/
pdvrp_data_problem.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
class DataProblem():
"""Stores the data for the problem"""
def __init__(self, num_vehicles, depot, orders, maximum_distance, maximum_parcels, distance_calculation):
"""Initializes the data for the problem"""
self._num_vehicles = num_vehicles
self._maximum_distance = maximum_distance
self._maximum_parcels = maximum_parcels
# flatten the orders into a number of pairs
# order:[pickup, deli1, deli2]
# -> locations: [pickup, deli1, pickup, deli2]
self._locations = depot
# a dictionary map the index in locations to the original "orders" array
self._orders_index = {}
for index, pair in enumerate(orders):
for i in range(1, len(pair)):
self._locations.append(pair[0])
self._orders_index[len(self._locations) - 1] = str(index) + "-" + str(0)
self._locations.append(pair[i])
self._orders_index[len(self._locations) - 1] = str(index) + "-" + str(i)
self._depot = 0
self._distance_calculation = distance_calculation
@property
def num_vehicles(self):
"""Gets number of vehicles"""
return self._num_vehicles
@property
def locations(self):
return self._locations
@property
def orders_index(self):
return self._orders_index
@property
def num_locations(self):
"""Gets number of locations"""
return len(self._locations)
@property
def depot(self):
"""Gets depot location index"""
return self._depot
@property
def maximum_distance(self):
return self._maximum_distance
@property
def maximum_parcels(self):
return self._maximum_parcels
@property
def distance_calculation(self):
return self._distance_calculation