Loading [Contrib]/a11y/accessibility-menu.js
Download
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
"""
PyCSP3 Model (see pycsp.org)
 
Data can come:
 - either directly from a JSON file
 - or from an intermediate parser
 
Examples:
  python Rehearsal.py -data=rehearsalSmith.json
  python Rehearsal.py -data=rehearsalSmith.json -variant=bis
"""
 
from pycsp3 import *
 
durations, playing = data
nPieces, nPlayers = len(durations), len(playing)
 
# o[i] is the piece played in slot (order) i
o = VarArray(size=nPieces, dom=range(nPieces))
 
# a[p] is the (beginning of the) slot  when the player p arrives
a = VarArray(size=nPlayers, dom=range(nPieces))
 
# l[p] is the (end of the) slot when the player p leaves
l = VarArray(size=nPlayers, dom=range(nPieces))
 
if not variant():
 
    satisfy(
        # all pieces of music must be played in some order
        AllDifferent(o),
 
        # a player must be present when a piece of music requires him/her
        [(playing[p][o[i]] == 0) | (a[p] <= i) & (i <= l[p]) for p in range(nPlayers) for i in range(nPieces)]
    )
 
    minimize(
        # minimizing the waiting time of players (i.e. without playing)
        Sum(durations[o[i]] * ((playing[p][o[i]] == 0) & (a[p] <= i) & (i <= l[p])) for p in range(nPlayers) for i in range(nPieces))
    )
 
elif variant("bis"):
 
    # ep[p][i] is 1 iff the player p must effectively play in slot i
    ep = VarArray(size=[nPlayers, nPieces], dom={0, 1})
 
    satisfy(
        # all pieces of music must be played in some order
        AllDifferent(o),
 
        # determining when players must effectively play
        [ep[p][i] == playing[p][o[i]] for p in range(nPlayers) for i in range(nPieces)],
 
        # a player must be present when a piece of music requires him/her
        [(ep[p][i] == 0) | (a[p] <= i) & (i <= l[p]) for p in range(nPlayers) for i in range(nPieces)]
    )
 
    minimize(
        # minimizing the waiting time of players (i.e. without playing)
        Sum(durations[o[i]] * ((ep[p][i] == 0) & (a[p] <= i) & (i <= l[p])) for p in range(nPlayers) for i in range(nPieces))
    )
 
""" Comments
1) the first model variant is very compact. The second model variant explicitly introduces some auxiliary variables
   which, to som respect, allows a better control of the generated instances. Here, however, the outputs  are not
   so different for this problem.
"""