-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dorm.py
50 lines (39 loc) · 1.04 KB
/
Dorm.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
import random
import math
dorms = ['Zeus', 'Athena', 'Hercules', 'Bacchus', 'Pluto']
prefs = [('Toby', ('Bacchus', 'Hercules')),
('Steve', ('Zeus', 'Pluto')),
('Andrea', ('Athena', 'Zeus')),
('Sarah', ('Zeus', 'Pluto')),
('Dave', ('Athena', 'Bacchus')),
('Jeff', ('Hercules', 'Pluto')),
('Fred', ('Pluto', 'Athena')),
('Suzie', ('Bacchus', 'Hercules')),
('Laura', ('Bacchus', 'Hercules')),
('Neil', ('Hercules', 'Athena'))]
# [(0, 9), (0, 8), (0, 7), ...... (0, 1), (0, 0)]
domain = [(0, (len(dorms) * 2) - i - 1) for i in range(0, len(dorms) * 2)]
def printSolution(vec):
slots = []
for i in range(len(dorms)):
slots += [i , i]
for i in range(len(vec)):
x = int(vec[i])
dorm = dorms[slots[x]]
print prefs[i][0], dorm
del slots[x]
def dormCost(vec):
cost = 0
slots = [0 , 0 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4]
for i in range(len(vec)):
x = int(vec[i])
dorm = dorms[slots[x]]
pref = prefs[i][1]
if pref[0] == dorm:
cost += 0
elif pref[1] == dorm:
cost += 1
else:
cost += 3
del slots[x]
return cost