Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumingpassional authored Nov 20, 2024
1 parent 5bca7ae commit 08fb6cd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
6 changes: 3 additions & 3 deletions rlsolver/methods/VRPTW_algs/ESPPRC_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import copy
from typing import List, Tuple, Set, Dict


class Label:
path = []
travel_time = 0
dist = 0


# dominance rule
def dominate(labels: List[Label], path_dict: Dict[int, Label]):
labels_copy = copy.deepcopy(labels)
Expand All @@ -37,6 +35,8 @@ def dominate(labels: List[Label], path_dict: Dict[int, Label]):
return labels, path_dict




# labeling algorithm
def labeling_SPPRC(graph, orig, dest):
# initial Q
Expand Down Expand Up @@ -135,6 +135,6 @@ def main():
print('optimal path : ', opt_path[1].path)
print('optimal path (dist): ', opt_path[1].dist)


if __name__ == '__main__':
main()

6 changes: 3 additions & 3 deletions rlsolver/methods/VRPTW_algs/ESPPRC_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import copy
from typing import List, Tuple, Set, Dict


class Label:
path = []
duration = 0
Expand Down Expand Up @@ -43,7 +42,6 @@ def make_unique(labels) -> List:
res.append(labels[i])
return res


# dominance rule
def EFF(labels2: List[Label]):
labels = Label.make_unique(labels2)
Expand Down Expand Up @@ -77,6 +75,8 @@ def EFF(labels2: List[Label]):
return filtered_labels




# labeling algorithm
def labeling_SPPRC(graph, orig, dest):
# initial Q
Expand Down Expand Up @@ -175,6 +175,6 @@ def main():
print(f'The {i + 1}-th optimal path (time): {opt_label.duration}')
print()


if __name__ == '__main__':
main()

1 change: 1 addition & 0 deletions rlsolver/methods/VRPTW_algs/ESPPRC_demo3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
rlsolver_path = os.path.join(cur_path, '../../../rlsolver')
sys.path.append(os.path.dirname(rlsolver_path))

import numpy as np
import networkx as nx
import copy
from typing import List, Tuple, Union, Dict
Expand Down
1 change: 0 additions & 1 deletion rlsolver/methods/VRPTW_algs/Label.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def dominate(self, another, forward: bool):
return False

@staticmethod
# keep non-dominated labels
def EFF(labels2: List, forward: bool) -> List:
labels = Label.make_unique(labels2)
if len(labels) <= 1:
Expand Down
1 change: 0 additions & 1 deletion rlsolver/methods/VRPTW_algs/Vehicle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import os

cur_path = os.path.dirname(os.path.abspath(__file__))
rlsolver_path = os.path.join(cur_path, '../../../rlsolver')
sys.path.append(os.path.dirname(rlsolver_path))
Expand Down
23 changes: 11 additions & 12 deletions rlsolver/methods/VRPTW_algs/impact_heuristic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# The impact heuristic is implemented based on the paper "A greedy look-ahead heuristic for the vehicle routing problem with time windows"
import sys
import os

cur_path = os.path.dirname(os.path.abspath(__file__))
rlsolver_path = os.path.join(cur_path, '../../../rlsolver')
sys.path.append(os.path.dirname(rlsolver_path))
Expand All @@ -13,19 +12,19 @@
import networkx as nx

from rlsolver.methods.VRPTW_algs.Customer import (Customer,
)
)
from rlsolver.methods.VRPTW_algs.Vehicle import Vehicle
from rlsolver.methods.VRPTW_algs.util import (read_data,
read_data_as_nxdigraph,
generate_vehicles,
generate_vehicles_and_assign_paths,
obtain_paths_based_on_vehicles,
calc_demands_of_paths,
calc_durations_of_paths,
calc_dists_of_paths,
write_result,
write_result_based_on_vehicles,
)
read_data_as_nxdigraph,
generate_vehicles,
generate_vehicles_and_assign_paths,
obtain_paths_based_on_vehicles,
calc_demands_of_paths,
calc_durations_of_paths,
calc_dists_of_paths,
write_result,
write_result_based_on_vehicles,
)

from rlsolver.methods.VRPTW_algs.config import Config

Expand Down
24 changes: 24 additions & 0 deletions rlsolver/methods/VRPTW_algs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,30 @@ def filter_vehicles_based_on_paths(vehicles2: List[Vehicle], paths: List[str], c
vehicle.path_denoted_by_customers.append(this)
return vehicles

# vehicles = generate_vehicles(num_vehicles, customers)
# res = []
# dest = Customer.obtain_by_name(Config.DEST_NAME, customers)
# if dest is None:
# return []
# dest.labels.sort(key=operator.attrgetter('cumulative_travel_cost'))
# num = min(len(dest.labels), len(vehicles))
# for i in range(num):
# label = dest.labels[i]
# vehicle = vehicles[i]
# vehicle.path_denoted_by_names = label.path_denoted_by_names
# vehicle.departure_time_list = label.departure_time_list
# vehicle.arrival_time_list = label.arrival_time_list
# vehicle.departure_time_dict = {}
# vehicle.arrival_time_dict = {}
# vehicle.path_denoted_by_customers = []
# for k in range(len(vehicle.path_denoted_by_names)):
# this_name = vehicle.path_denoted_by_names[k]
# customer = Customer.obtain_by_name(this_name, customers)
# vehicle.path_denoted_by_customers.append(customer)
# vehicle.departure_time_dict[this_name] = vehicle.departure_time_list[k]
# vehicle.arrival_time_dict[this_name] = vehicle.arrival_time_list[k]
# res.append(vehicle)
# return res

def obtain_var_vals(model, var_name: str):
theta_vals = []
Expand Down

0 comments on commit 08fb6cd

Please sign in to comment.