forked from satvikel4/TestOrderPrioritizationPrototype
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.py
More file actions
69 lines (55 loc) · 2.15 KB
/
coverage.py
File metadata and controls
69 lines (55 loc) · 2.15 KB
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
from itertools import permutations
import math
from itertools import combinations
def get_seq(order, t):
return list(combinations(order, t))
def count_unique_seq(order_list, t):
seq_list = [get_seq(order, t) for order in order_list]
unique_subsequences = set(seq for sublist in seq_list for seq in sublist)
""" print("Input order list:")
for order in order_list:
print(order)
print("\nAll unique subsequences of length", t, "that can be formed from the given orders:")
for subsequence in unique_subsequences:
print(list(subsequence)) """
return len(unique_subsequences)
def max_cover_order(orders, selected_orders, t):
max_cover = 0
max_order = None
for order in orders:
if order not in selected_orders:
temp_orders = selected_orders + [order]
temp_cover = count_unique_seq(temp_orders, t)
cover = count_unique_seq(selected_orders + [order], t)
print(f"Temp coverage after adding {order}: {temp_cover}")
#print(f"Cover after adding {order}: {cover}")
if cover > max_cover:
max_cover = cover
max_order = order
return max_order
def sort_orders(orders, t):
total_possibilities = math.factorial(len(orders[0])) / math.factorial(len(orders[0]) - t) # total possibilities
#print(f"Total possibilities with permutations: {total_possibilities}")
sorted_orders = [orders[0]] # start with the first order
orders.remove(orders[0])
print(f"{sorted_orders[0]} - {count_unique_seq(sorted_orders, t) / total_possibilities * 100:.2f}% coverage")
while orders:
next_order = max_cover_order(orders, sorted_orders, t)
sorted_orders.append(next_order)
orders.remove(next_order)
print(f"{next_order} - {min(count_unique_seq(sorted_orders, t) / total_possibilities * 100, 100):.2f}% coverage")
return sorted_orders
"""
orders = [
[0, 1, 2, 3, 4],
[1, 0, 3, 2, 4],
[4, 3, 0, 2, 1],
[1, 4, 2, 0, 3],
[0, 4, 1, 3, 2],
[4, 0, 3, 1, 2]
]
t = 3
sorted_orders = sort_orders(orders, t)
print("Sorted Orders: ")
for order in sorted_orders:
print(order) """