45 using namespace Gecode;
54 Play(
void) : h(0),
a(0), g(0) {}
73 int gn(
int h,
int a)
const {
74 return teams*(h-1) +
a;
78 return plays[
p*weeks() + w];
106 RRS(
int t) : teams(
t), plays(new
Play[periods()*weeks()]) {
113 for (
int p=1;
p<periods();
p++) {
114 play(
p,0).h = (
p + 1) + 1;
115 play(
p,0).a = teams - (
p + 1 - 2);
116 play(
p,0).g = gn(play(
p,0).h,play(
p,0).
a);
120 for (
int w=1; w<weeks(); w++) {
121 for (
int p=0;
p<periods();
p++) {
122 if (play(
p,w-1).h == teams)
124 else if (play(
p,w-1).h == 1)
127 play(
p,w).h = play(
p,w-1).h + 1;
128 if (play(
p,w-1).
a == teams)
131 play(
p,w).a = play(
p,w-1).a + 1;
134 if (play(
p,w).h > play(
p,w).
a)
135 std::swap(play(
p,w).h,play(
p,w).
a);
137 play(
p,w).g = gn(play(
p,w).h,play(
p,w).
a);
144 for (
int p=0;
p<periods();
p++) {
191 return home[
p*teams + w];
195 return home[
p*teams + w];
199 return away[
p*teams + w];
203 return away[
p*teams + w];
207 return game[
p*weeks() + w];
211 return game[
p*weeks() + w];
219 home(*this, periods() * teams, 1, weeks()),
220 away(*this, periods() * teams, 2, weeks()+1),
221 game(*this, weeks()*periods(), 2, teams*weeks())
227 for (
int w=0; w<weeks(); w++) {
228 IntArgs rh(periods()),
ra(periods()), rg(periods());
235 for (
int p=0;
p<periods();
p++) {
243 for (
int p=0;
p<periods();
p++)
244 for (
int w=0; w<teams; w++)
250 for (
int p=0;
p<periods();
p++)
260 for (
int w=0; w<teams; w++) {
262 for (
int p=0;
p<periods();
p++) {
263 c[2*
p] = h(
p,w);
c[2*
p+1] =
a(
p,w);
269 for (
int p=0;
p<periods();
p++) {
271 for (
int t=0;
t<teams;
t++) {
276 for (
int i=1;
i<=teams;
i++)
282 for (
int p=0;
p<periods();
p++)
283 for (
int w=0; w<weeks(); w ++)
284 rel(*
this, teams * h(
p,w) +
a(
p,w) - g(
p,w) == teams);
292 :
Script(s), teams(s.teams) {
303 virtual void print(std::ostream& os)
const {
306 for (
int p=0;
p<periods();
p++) {
313 for (
int w=0; w<weeks(); w++) {
317 for (
int p=0;
p<periods();
p++) {
319 os << h(
p,w).val() <<
'-';
321 os <<
a(
p,w).val() <<
" ";
338 if (
opt.size() < 5) {
339 std::cerr<<
"No Solution for less than 5 teams!" << std::endl;
342 if (
opt.size() % 2 != 0) {
343 std::cerr <<
"Number of teams has to be even!" << std::endl;
346 Script::run<SportsLeague, DFS,SizeOptions>(
opt);
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl)
Post constraint .
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Parametric base-class for scripts.
Passing integer arguments.
Passing integer variables.
void ipl(IntPropLevel i)
Set default integer propagation level.
Options for scripts with additional size parameter
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Entry in round robin schedule.
int g
game number Default constructor
void hag(int w, IntArgs &h, IntArgs &a, IntArgs &g)
Home, away, and game information.
RRS(int t)
Build a feasible schedule.
const int teams
Number of teams.
Play & play(int p, int w)
Play for period p and week w.
int weeks(void) const
Return number of weeks.
~RRS(void)
Delete schedule.
int gn(int h, int a) const
Game number for game between home team h and away team a.
Play * plays
Play information.
int periods(void) const
Return number of periods.
Example: Sports league scheduling
virtual Space * copy(void)
Copy during cloning.
int main(int argc, char *argv[])
Main-function.
int weeks(void) const
Return number of weeks.
SportsLeague(const SizeOptions &opt)
Setup model.
const IntVar & g(int p, int w) const
Return game number for game in period p and week w.
IntVar & a(int p, int w)
Away team in period p and week w.
virtual void print(std::ostream &os) const
Print solution.
const IntVar & h(int p, int w) const
Home team in period p and week w.
SportsLeague(SportsLeague &s)
Constructor for cloning s.
const IntVar & a(int p, int w) const
Away team in period p and week w.
int periods(void) const
Return number of periods.
const int teams
number of teams
IntVar & h(int p, int w)
Home team in period p and week w.
IntVarArray away
away teams
IntVarArray game
game numbers
IntVarArray home
home teams
IntVar & g(int p, int w)
Return game number for game in period p and week w.
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i({1, 2, 3, 4})