49 using namespace Gecode;
58 Play(
void) : h(0),
a(0), g(0) {}
77 int gn(
int h,
int a)
const {
78 return teams*(h-1) + a;
82 return plays[p*weeks() + w];
110 RRS(
int t) : teams(t), plays(new
Play[periods()*weeks()]) {
117 for (
int p=1; p<periods(); p++) {
118 play(p,0).h = (p + 1) + 1;
119 play(p,0).a = teams - (p + 1 - 2);
120 play(p,0).g = gn(play(p,0).h,play(p,0).
a);
124 for (
int w=1; w<weeks(); w++) {
125 for (
int p=0; p<periods(); p++) {
126 if (play(p,w-1).h == teams)
128 else if (play(p,w-1).h == 1)
131 play(p,w).h = play(p,w-1).h + 1;
132 if (play(p,w-1).
a == teams)
135 play(p,w).a = play(p,w-1).a + 1;
138 if (play(p,w).h > play(p,w).
a)
139 std::swap(play(p,w).h,play(p,w).a);
141 play(p,w).g = gn(play(p,w).h,play(p,w).a);
148 for (
int p=0; p<periods(); p++) {
195 return home[p*teams + w];
199 return home[p*teams + w];
203 return away[p*teams + w];
207 return away[p*teams + w];
211 return game[p*weeks() + w];
215 return game[p*weeks() + w];
222 home(*this, periods() * teams, 1, weeks()),
223 away(*this, periods() * teams, 2, weeks()+1),
224 game(*this, weeks()*periods(), 2, teams*weeks())
230 for (
int w=0; w<weeks(); w++) {
231 IntArgs rh(periods()),
ra(periods()), rg(periods());
238 for (
int p=0; p<periods(); p++) {
239 element(*
this, rh, n[p], h(p,w));
241 element(*
this, rg, n[p], g(p,w));
246 for (
int p=0; p<periods(); p++)
247 for (
int w=0; w<teams; w++)
253 for (
int p=0; p<periods(); p++)
263 for (
int w=0; w<teams; w++) {
265 for (
int p=0; p<periods(); p++) {
266 c[2*p] = h(p,w); c[2*p+1] =
a(p,w);
272 for (
int p=0; p<periods(); p++) {
274 for (
int t=0; t<teams; t++) {
279 for (
int i=1;
i<=teams;
i++)
285 for (
int p=0; p<periods(); p++)
286 for (
int w=0; w<weeks(); w ++)
287 rel(*
this, teams * h(p,w) +
a(p,w) - g(p,w) == teams);
295 :
Script(share, s), teams(s.teams) {
296 home.update(*
this, share, s.
home);
297 away.update(*
this, share, s.
away);
298 game.update(*
this, share, s.
game);
306 virtual void print(std::ostream& os)
const {
309 for (
int p=0; p<periods(); p++) {
316 for (
int w=0; w<weeks(); w++) {
320 for (
int p=0; p<periods(); p++) {
322 os << h(p,w).val() <<
'-';
324 os <<
a(p,w).val() <<
" ";
340 opt.
parse(argc,argv);
341 if (opt.
size() < 5) {
342 std::cerr<<
"No Solution for less than 5 teams!" << std::endl;
345 if (opt.
size() % 2 != 0) {
346 std::cerr <<
"Number of teams has to be even!" << std::endl;
349 Script::run<SportsLeague, DFS,SizeOptions>(
opt);