/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Patrick Pekczynski * * Contributing authors: * Christian Schulte * * Copyright: * Patrick Pekczynski, 2004 * Christian Schulte, 2007 * * Last modified: * $Date: 2008-02-01 11:40:25 +0100 (Fri, 01 Feb 2008) $ by $Author: tack $ * $Revision: 6033 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "examples/support.hh" #include "gecode/minimodel.hh" #include #include /// Entry in round robin schedule class Play { public: int h; ///< home team int a; ///< away team int g; ///< game number }; /// Round robin schedule class RRS { protected: /// Number of teams const int teams; /// Play information Play* plays; /// Return number of weeks int weeks(void) const { return teams-1; } /// Return number of periods int periods(void) const { return teams/2; } /// Game number for game between home team \a h and away team \a a int gn(int h, int a) const { return teams*(h-1) + a; } /// Play for period \a p and week \a w Play& play(int p, int w) { return plays[p*weeks() + w]; } public: /** * \brief Build a feasible schedule * * The games of the first week are fixed as: * \f$ \langle 1,2 \rangle \cup * \{\langle p + 2, t - p + 1\rangle | p \geq 1\}\f$. \n * The remaining games are computed by transforming a game * \f$ \langle h, a, g \rangle \f$ from the previous week * in a new game \f$ \langle h', a'\rangle \f$, where: \n * \f$ h' = \left\{ * \begin{tabular}{l c l} * 1 & & if $h = 1$ \\ * 2 & & if $h = t$ \\ * $h + 1$ & & otherwise * \end{tabular}\right. * \f$ and * \f$ a' = \left\{ * \begin{tabular}{l c l} * 2 & & if $h = t$ \\ * a + 1 & & otherwise * \end{tabular}\right. * \f$ * * */ RRS(int t) : teams(t), plays(new Play[periods()*weeks()]) { // Initialize array for (int p=0; p play(p,w).a) std::swap(play(p,w).h,play(p,w).a); play(p,w).g = gn(play(p,w).h,play(p,w).a); } } } /// Home, away, and game information void hag(int w, IntArgs& h, IntArgs& a, IntArgs& g) { for (int p=0; p(opt); return 0; } // STATISTICS: example-any