Skip to content

Commit

Permalink
[drtORTools] add soft time window constraint for old reservations, ref.
Browse files Browse the repository at this point in the history
  • Loading branch information
rummel123 committed Sep 4, 2023
1 parent 29d25ce commit 293ff97
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions tools/drt/drtOrtools.py
Expand Up @@ -195,6 +195,7 @@ def create_data_model(reservations, fleet, cost_type, drf, waiting_time, end, fi
time_windows = get_time_windows(reservations, fleet, end)

data = {}
data['depot'] = 0 # node_id of the depot
data['cost_matrix'] = cost_matrix
data['time_matrix'] = time_matrix
data['pickups_deliveries'] = dp_reservations
Expand Down
27 changes: 21 additions & 6 deletions tools/drt/ortools_pdp.py
Expand Up @@ -258,16 +258,31 @@ def add_time_windows_constraint(data, time_dimension, manager, verbose):
if verbose:
print(' Add time windows constraints...')

depot = data['depot']
new_requests_nodes = [node for req in data['pickups_deliveries'] for node in (req.from_node, req.to_node) if req.is_new]
old_requests_nodes = ([req.to_node for req in data['dropoffs']] +
[node for req in data['pickups_deliveries'] for node in (req.from_node, req.to_node) if not req.is_new])
# Add time window constraints for each location except depot.
for location_idx, time_window in enumerate(data['time_windows']):
# if location_idx == data['depot']:
# if location_idx in data['starts'] or location_idx == 0:
if location_idx == 0:
# no time window for depot:
if location_idx == depot:
continue
index = manager.NodeToIndex(location_idx)
if verbose:
print('window for node %s: [%s, %s]' % (location_idx, time_window[0], time_window[1]))
time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1]) # TODO: check if set, else ignore it
# hard time window for vehicles and new requests:
if location_idx in data['starts'] + new_requests_nodes:
if verbose:
print(f'hard time window for node {location_idx}: [{time_window[0]}, {time_window[1]}]')
time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1]) # TODO: check if set, else ignore it
# soft time window for old requests:
if location_idx in old_requests_nodes:
if verbose:
print(f'soft time window for node {location_idx}: [{time_window[0]}, {time_window[1]}]')
time_dimension.SetCumulVarSoftLowerBound(index, time_window[0], 100)
time_dimension.SetCumulVarSoftUpperBound(index, time_window[1], 100)
#time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1])



# TODO: check if the followwing is needed
# # Add time window constraints for each vehicle start node.
# depot_idx = data['depot']
Expand Down

0 comments on commit 293ff97

Please sign in to comment.