-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneric_strategy.py
56 lines (51 loc) · 1.92 KB
/
generic_strategy.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
import math
import copy
def add_additional_point_generic(remaining_points, selected_coord_list):
remaining_points = copy.deepcopy(remaining_points)
selected_coord_list = copy.deepcopy(selected_coord_list)
while True:
point_costs = {}
for key, value in remaining_points.items():
try:
min_value = min(value)
except ValueError:
min_value = math.inf
point_costs[key] = min_value
try:
temp = min(point_costs, key=point_costs.get)
except Exception as e:
print(e)
#print("point_costs:",point_costs)
#print("remaining_points:",remaining_points)
return remaining_points, selected_coord_list
# check if point was already selected
# make sure this point was not selected yet
exists = False
for k in range(len(selected_coord_list)):
if temp == selected_coord_list[k]:
exists = True
break
# if point was selected already, delete it
if exists == True:
try:
#remaining_points[temp].remove(point_costs[temp])
del remaining_points[temp]
except ValueError as e:
print(e)
print("temp:",temp)
print("selected_coord_list:",selected_coord_list)
print("remaining_points:",remaining_points)
return 0
# if point was not selected yet, break the loop and add this point
else:
break
# if point was not selected yet, use it
# add the point to the selected list
selected_coord_list.append(temp)
# remove this point from the remaining points list
try:
#remaining_points[temp].remove(point_costs[temp])
del remaining_points[temp]
except ValueError as e:
print(e)
return remaining_points, selected_coord_list, temp