def __init__(self, priority_size=100, priority_init=None, replace=True): # Experience_ID to Priority_ID (the node number in Heap) mapping self.e2p = {} # Priority_ID (the node number in Heap) to Experience_ID mapping self.p2e = {} # If the node should be replaced when inserting self.replace = replace if priority_init is None: self.priority_queue = {} self.size = 0 self.max_size = priority_size else: # not yet tested self.priority_queue = priority_init self.size = len(self.priority_queue) self.max_size = None or self.size # map(func, list) returns a list after applying the function to all the elements # The following is a list of (priority_IDs, experience_IDs) experience_list = list( map(lambda x: self.priority_queue[x], self.priority_queue)) # Create the node_number --> Experience_ID and Experience_ID --> node_number mapping self.p2e = utility.list_to_dict(experience_list) self.e2p = utility.exchange_key_value(self.p2e) for i in range(int(self.size / 2), -1, -1): self.down_heap(i)
def reload(self): # not yet test self.priority_queue = priority_init self.size = len(self.priority_queue) self.max_size = None or self.size experience_list = list( map(lambda x: self.priority_queue[x], self.priority_queue)) self.p2e = utility.list_to_dict(experience_list) self.e2p = utility.exchange_key_value(self.p2e) for i in range(int(self.size / 2), -1, -1): self.down_heap(i)
def __init__(self, priority_size=100, priority_init=None, replace=True): self.e2p = {} self.p2e = {} self.replace = replace if priority_init is None: self.priority_queue = {} self.size = 0 self.max_size = priority_size else: # not yet test self.priority_queue = priority_init self.size = len(self.priority_queue) self.max_size = None or self.size experience_list = list(map(lambda x: self.priority_queue[x], self.priority_queue)) self.p2e = utility.list_to_dict(experience_list) self.e2p = utility.exchange_key_value(self.p2e) for i in range(int(self.size / 2), -1, -1): self.down_heap(i)