-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_plan_effective.py
48 lines (40 loc) · 1.66 KB
/
is_plan_effective.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
from neighbourhood import Neighbourhood
from utils import matrix_to_list
import numpy as np
import math
class IsPlanEffective():
def __init__(self, option_len, num_options, neighbourhood_size, probability_sucess = 1, alpha = 0) -> None:
self.type = type
self.option_len = option_len
self.num_options = num_options
self.neighbourhood_size = neighbourhood_size
self.prob_success= probability_sucess
self.alpha = alpha
def T(self, gap_sz, option_sz, num_options):
plan_sz = gap_sz/option_sz
plan_time = num_options**plan_sz
return plan_time
def M(self, S, G): #return the worst case manhattan dist
S = matrix_to_list(S)
G = matrix_to_list(G)
max = - math.inf
for i in S:
for j in G:
manhattan_dist = abs(i[0] - j[0]) + abs(i[1] - j[1])
if manhattan_dist > max:
max = manhattan_dist
return max
def is_plan_effective(self, num_gaps, S, G):
# print("num_gaps: ", num_gaps)
# print("options_len: ", self.option_len)
# print("gap len", self.neighbourhood_size)
dist = self.M(S, G)
# print("dist: ", dist)
# print("num options: ", self.num_options)
t_i = self.T(self.neighbourhood_size, self.option_len, self.num_options)
# print(t_i)
t_n_minus_1 = self.T(dist, self.option_len, self.num_options)
# print(t_n_minus_1)
if num_gaps * t_i - self.alpha * self.prob_success <= t_n_minus_1 - self.alpha: #DIFFERING FROM PROPOSAL FOR PROBABALISTIC CASE HERE, SEE IF THIS WORKS
return True
return False