-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhypotheses_queue.py
46 lines (33 loc) · 997 Bytes
/
hypotheses_queue.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
"""Priority queue for hypotheses.
Created on Tue Jun 9 16:05:03 2020
@author: Jonas Beuchert
"""
import heapq
class Queue:
"""Priority queue for hypotheses.
Key element is the estimated upper-bound on the likelihood of the
hypothesis.
Author: Jonas Beuchert
"""
def __init__(self):
"""Create empty priority queue."""
self.q = []
def add(self, h):
"""Insert hypothesis into priority queue.
Input:
h - Hypothesis to add
"""
heapq.heappush(self.q, h)
def hasElement(self):
"""Check if priority contains an element.
Output:
out - Logical value indicating if queue holds element
"""
return len(self.q) > 0
def popMostLikely(self):
"""Pop element with largest upper bound on psuedo-likelihood.
Return and remove element from priority queue.
Output:
out - Hypothesis
"""
return heapq.heappop(self.q)