MCPcopy Create free account
hub / github.com/Gecode/gecode / Golf

Method Golf

examples/golf.cpp:101–198  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

99
100 /// Actual model
101 Golf(const GolfOptions& opt)
102 : Script(opt),
103 g(opt.g()), s(opt.s()), w(opt.w()),
104 groups(*this,g*w,IntSet::empty,0,g*s-1,
105 static_cast<unsigned int>(s),static_cast<unsigned int>(s)) {
106 Matrix<SetVarArray> schedule(groups,g,w);
107
108 // Groups in one week must be disjoint
109 SetVar allPlayers(*this, 0,g*s-1, 0,g*s-1);
110 for (int i=0; i<w; i++)
111 rel(*this, setdunion(schedule.row(i)) == allPlayers);
112
113 // No two golfers play in the same group more than once
114 if (opt.propagation() == PROP_SET || opt.propagation() == PROP_MIXED) {
115 // Cardinality of intersection between two groups is at most one
116 for (int i=0; i<groups.size()-1; i++)
117 for (int j=i+1; j<groups.size(); j++)
118 rel(*this, cardinality(groups[i] & groups[j]) <= 1);
119 }
120 if (opt.propagation() == PROP_INT || opt.propagation() == PROP_MIXED) {
121 // Set up table mapping from pairs (p1,p2) (where p1<p2) of players to
122 // unique integer identifiers
123 int playerCount = g * s;
124 TupleSet ts(3);
125 int pairCount=0;
126 for (int p1=0; p1<playerCount-1; p1++)
127 for (int p2=p1+1; p2<playerCount; p2++)
128 ts.add({p1, p2, pairCount++});
129 ts.finalize();
130
131 // Collect pairs of golfers into pairs
132 IntVarArgs pairs;
133 for (int i=0; i<groups.size()-1; i++) {
134 // Channel sorted will ensure that for i<j, group[i]<group[j],
135 // ensuring that the tuple set has a valid mapping.
136 IntVarArgs group(*this, s, 0, playerCount-1);
137 channelSorted(*this, group, groups[i]);
138 // Collect all pairs in current group
139 for (int p1=0; p1<group.size()-1; ++p1) {
140 for (int p2=p1+1; p2<group.size(); ++p2) {
141 IntVar pair(*this, 0, pairCount);
142
143 IntVarArgs args;
144 args << group[p1] << group[p2] << pair;
145 extensional(*this, args, ts);
146
147 pairs << pair;
148 }
149 }
150 }
151
152 // All pairs of golfers (using the unique identifiers) must be different
153 distinct(*this, pairs, opt.ipl());
154 }
155
156 if (opt.model() == MODEL_SYMMETRY) {
157
158 /*

Callers

nothing calls this directly

Calls 15

setdunionFunction · 0.85
channelSortedFunction · 0.85
distinctFunction · 0.85
IntSetClass · 0.85
SET_VAR_MIN_MINFunction · 0.85
SET_VAL_MIN_INCFunction · 0.85
gMethod · 0.80
sMethod · 0.80
wMethod · 0.80
propagationMethod · 0.80
modelMethod · 0.80
relFunction · 0.50

Tested by

no test coverage detected