/
schedule.py
executable file
·94 lines (73 loc) · 3.2 KB
/
schedule.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
#!/usr/bin/python
import sys
import argparse
import config
from config import set_config, compute_bitwidths, validate_config
from z3 import Z3
from qfbv import QFBV
from qfaufbv import QFAUFBV
args = argparse.ArgumentParser(description="Produce an SMT forumla representing a schedule for teams competing in SR")
form = args.add_mutually_exclusive_group()
form.add_argument("--z3", action="store_true", default=False, dest="z3", help="Produce a formula using Z3 enumerations")
form.add_argument("--qfbv", action="store_true", default=False, dest="qfbv", help="Produce a formula with enumerated bitvector variables")
form.add_argument("--qfaufbv", action="store_true", default=False, dest="qfaufbv", help="Produce a formula using an uninterpreted function")
args.add_argument("--rounds", type=int, help="Number of rounds", default=13)
args.add_argument("--teams", type=int, help="Number of teams", default=32)
args.add_argument("--closeness", type=int, help="Closeness constraint", default=5)
args.add_argument("--slots", type=int, help="Slots per match", default=4)
the_args = args.parse_args()
set_config(the_args.rounds, the_args.teams, the_args.closeness, the_args.slots)
compute_bitwidths()
validate_config()
print "(set-info :status unknown)"
print "(set-option :produce-models true)"
output_object = None
if the_args.z3:
output_object = Z3()
elif the_args.qfaufbv:
output_object = QFAUFBV()
elif the_args.qfbv:
output_object = QFBV()
else:
output_object = QFBV()
output_object.preamble()
# Ensure all slots over all matchs per round are distinct.
for i in range(config.NUMROUNDS):
print "; round {0}".format(i)
print "(assert (distinct "
for j in range(config.NUMMATCHES):
for k in range(config.NUMSLOTS):
print output_object.project(i, j, k)
print "))"
# For each round boundry,
for r in range(config.NUMROUNDS-1):
print "; Goodness for round boundry {0}".format(r)
# Each CLOSENESS+1 matches across the round boundry must have
# distinct participants to ensure they always have CLOSENESS
# matches between each match of theirs. Each CLOSENESS+1 number
# of matches is a span, in which those matches must be distinct.
for span in range(config.CLOSENESS):
start_match = config.NUMMATCHES - config.CLOSENESS + span
print "; Span goodness {0}".format(span)
print "(assert (distinct"
for offs in range(config.CLOSENESS + 1):
# The range of matches we're interested in is
# from `start_match` in the earlier round
# through to round `span` in the later round.
this_match = (start_match + offs) % config.NUMMATCHES
this_round = r
if this_match < start_match:
this_round = r + 1
for i in range(config.NUMSLOTS):
print output_object.project(this_round,this_match,i)
print "))"
print ""
# Instruct solver to check satisfiability at this point
print "(check-sat)"
# Also, fetch the outcome from each point.
print ""
for i in range(config.NUMROUNDS):
for j in range(config.NUMMATCHES):
for k in range(config.NUMSLOTS):
pass
print "(get-value ({0}))".format(output_object.project(i, j, k))