-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver.py
70 lines (56 loc) · 1.88 KB
/
solver.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
import inPassage
import simple_example
import CityScapes
import Oz
from scheduler import *
import helper
import sys
def solve(dancers, pieces, domain, algorithm, randomness = False):
problem = Scheduler(dancers, pieces, domain)
problem.set_initial(pieces, dancers)
invalid_pieces = helper.check_empty(problem)
if invalid_pieces:
relax_constraints_before(problem, invalid_pieces)
print ("num of violations", len(problem.violations))
algo = {
'naive': problem.set_times,
'heuristic': problem.heuristic,
'DFS': problem.DFS,
'random': problem.random_SA
}
output = helper.eval(algo[algorithm], pieces)
while not output:
problem.relax_constraints_after(randomness)
output = helper.eval(algo[algorithm], pieces)
problem.set_slots()
score = problem.evaluate()
for p in pieces:
if p.slot:
print ("the assigned time for {} piece is {}".format(p.choreographer.name, p.slot))
else:
print ("Unable to assign time slot to {} rehearsal".format(p.choreographer.name))
for d in dancers:
if d.times:
print ("{} has these times scheduled: {}".format(d.name, d.times))
print ('This solution has {} violations'.format(len(problem.violations)))
if problem.violations:
for v in problem.violations:
print ("{} cannot attend {}'s piece at {}".format(v[0], v[1].choreographer.name, v[1].slot))
print ('Score: {}'.format(score))
if __name__ == '__main__':
datasets = {
'Oz' : [Oz.dancers, Oz.pieces, Oz.domain3],
'InPassage': [inPassage.dancers, inPassage.pieces, inPassage.domain],
'CityScapes': [CityScapes.dancers, CityScapes.pieces, CityScapes.domain],
'simple':[simple_example.dancers, simple_example.pieces,simple_example.domain]
}
args = sys.argv[1:]
show = args[0]
algorithm = args[1]
if show in datasets:
dancers = datasets[show][0]
pieces = datasets[show][1]
domain = datasets[show][2]
solve(dancers,pieces, domain, algorithm)
else:
print ('Show not found')