-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
104 lines (75 loc) · 2.76 KB
/
util.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import copy
import sys
def startingPointIsUnique(csp, usedStartCoursesInPlans):
start_course = copy.deepcopy(csp.semesters[0]['courses'][0])
if start_course not in usedStartCoursesInPlans:
return True
else:
return False
class Stack:
"A container with a last-in-first-out (LIFO) queuing policy."
def __init__(self):
self.list = []
def push(self, item):
"Push 'item' onto the stack"
self.list.append(item)
def pop(self):
"Pop the most recently pushed item from the stack"
return self.list.pop()
def isEmpty(self):
"Returns true if the stack is empty"
return len(self.list) == 0
def length(self):
"Returns stack length"
return len(self.list)
class Stack_optimized:
"A container with a last-in-first-out (LIFO) queuing policy."
def __init__(self):
self.list = []
def push(self, (csp, course)):
"Push 'item' onto the stack"
csp.domain_trim_course_domain()
csp.domain_trim_no_repetition()
csp.domain_trim_no_time_conflict()
zero_domains = csp.get_zero_domains()
if len(zero_domains) > 0:
print 'ZERO DOMAINS FOUND, skipping csp', zero_domains
return True
if csp.check_constraints_optimized_prerequisites():
self.list.append((csp, course))
def pop(self):
"Pop the most recently pushed item from the stack"
return self.list.pop()
def isEmpty(self):
"Returns true if the stack is empty"
return len(self.list) == 0
def length(self):
"Returns stack length"
return len(self.list)
class Stack_optimized_filtering:
"A container with a last-in-first-out (LIFO) queuing policy."
def __init__(self):
self.list = []
def push(self, (csp, course), usedStartCoursesInPlans):
"Push 'item' onto the stack, check that csp is not in usedStartCoursesInPlans"
csp.domain_trim_course_domain()
csp.domain_trim_no_repetition()
csp.domain_trim_no_time_conflict()
zero_domains = csp.get_zero_domains()
if len(zero_domains) > 0:
print 'ZERO DOMAINS FOUND, skipping csp', zero_domains
return True
if not startingPointIsUnique(csp, usedStartCoursesInPlans):
print 'NON UNIQUE STARTING POINT, skipping csp'
return True
if csp.check_constraints_optimized_prerequisites():
self.list.append((csp, course))
def pop(self):
"Pop the most recently pushed item from the stack"
return self.list.pop()
def isEmpty(self):
"Returns true if the stack is empty"
return len(self.list) == 0
def length(self):
"Returns stack length"
return len(self.list)