Go to the documentation of this file.
57 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)
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];
223 home(*this, periods() * teams, 1, weeks()),
224 away(*this, periods() * teams, 2, weeks()+1),
225 game(*this, weeks()*periods(), 2, teams*weeks())
231 for (
int w=0; w<weeks(); w++) {
232 IntArgs rh(periods()),
ra(periods()), rg(periods());
239 for (
int p=0;
p<periods();
p++) {
247 for (
int p=0;
p<periods();
p++)
248 for (
int w=0; w<teams; w++)
254 for (
int p=0;
p<periods();
p++)
264 for (
int w=0; w<teams; w++) {
266 for (
int p=0;
p<periods();
p++) {
267 c[2*
p] = h(
p,w);
c[2*
p+1] =
a(
p,w);
273 for (
int p=0;
p<periods();
p++) {
275 for (
int t=0;
t<teams;
t++) {
280 for (
int i=1;
i<=teams;
i++)
286 for (
int p=0;
p<periods();
p++)
287 for (
int w=0; w<weeks(); w ++)
288 rel(*
this, teams * h(
p,w) +
a(
p,w) - g(
p,w) == teams);
296 :
Script(share, s), teams(s.teams) {
307 virtual void print(std::ostream& os)
const {
310 for (
int p=0;
p<periods();
p++) {
317 for (
int w=0; w<weeks(); w++) {
321 for (
int p=0;
p<periods();
p++) {
323 os << h(
p,w).val() <<
'-';
325 os <<
a(
p,w).val() <<
" ";
342 if (
opt.size() < 5) {
343 std::cerr<<
"No Solution for less than 5 teams!" << std::endl;
346 if (
opt.size() % 2 != 0) {
347 std::cerr <<
"Number of teams has to be even!" << std::endl;
350 Script::run<SportsLeague, DFS,SizeOptions>(
opt);
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl=IPL_DEF)
Post constraint .
IntVar & a(int p, int w)
Away team in period p and week w.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
int periods(void) const
Return number of periods.
SportsLeague(bool share, SportsLeague &s)
Constructor for cloning s.
Passing integer variables.
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntPropLevel)
Post domain consistent propagator for .
unsigned int size(I &i)
Size of all ranges of range iterator i.
const IntVar & h(int p, int w) const
Home team in period p and week w.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void ipl(IntPropLevel i)
Set default integer propagation level.
const int teams
number of teams
IntVar & h(int p, int w)
Home team in period p and week w.
const int teams
Number of teams.
void hag(int w, IntArgs &h, IntArgs &a, IntArgs &g)
Home, away, and game information.
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
IntVarArray away
away teams
virtual Space * copy(bool share)
Copy during cloning.
Gecode toplevel namespace
RRS(int t)
Build a feasible schedule.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Parametric base-class for scripts.
Post propagator for SetVar SetOpType SetVar SetRelType r
@ IPL_DOM
Domain propagation Preferences: prefer speed or memory.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
int weeks(void) const
Return number of weeks.
IntRelType swap(IntRelType irt)
Return swapped relation type of irt.
int weeks(void) const
Return number of weeks.
IntVarArray game
game numbers
const IntVar & a(int p, int w) const
Away team in period p and week w.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Example: Sports league scheduling
Play * plays
Play information.
Play & play(int p, int w)
Play for period p and week w.
int periods(void) const
Return number of periods.
IntVar & g(int p, int w)
Return game number for game in period p and week w.
int gn(int h, int a) const
Game number for game between home team h and away team a.
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Entry in round robin schedule.
Gecode::FloatVal c(-8, 8)
int n
Number of negative literals for node type.
IntVarArray home
home teams
Passing integer arguments.
SportsLeague(const SizeOptions &opt)
Setup model.
int g
game number Default constructor
const IntVar & g(int p, int w) const
Return game number for game in period p and week w.
~RRS(void)
Delete schedule.
int p
Number of positive literals for node type.
int main(int argc, char *argv[])
Main-function.
virtual void print(std::ostream &os) const
Print solution.
Options for scripts with additional size parameter