/* * Main authors: * Christian Schulte * Guido Tack * * Copyright: * Christian Schulte, 2004 * Guido Tack, 2004 * * Last modified: * $Date: 2006-08-04 16:06:52 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $ * $Revision: 3517 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * See the file "LICENSE" for information on usage and * redistribution of this file, and for a * DISCLAIMER OF ALL WARRANTIES. * */ #include "gecode/set.hh" #include "examples/support.hh" /** * \name Parameters for golf tournaments * * \relates Golf */ //@{ /// Tournament parameters struct Tournament { /// Number of groups int groups; /// Number of players in each group int playersInGroup; /// Number of weeks int weeks; }; /// Tournaments static const Tournament t[]= { {8,4,9}, {5,3,7}, {4,3,2} }; /// Number of tournaments static const unsigned int n_examples = sizeof(t) / sizeof(Tournament); //@} /** * \brief %Example: Golf tournament * * Schedule a golf tournament. This is problem 010 from csplib. * * \ingroup Example * */ class Golf : public Example { public: int groups; int playersInGroup; int weeks; int players; SetVarArray groupsS; IntVarArray groupsSInv; SetVar& group(int w, int g) { return groupsS[w*groups+g]; } IntVar& groupInv(int w, int p) { return groupsSInv[w*players+p]; } Golf(const Options& o) : groups(t[o.size].groups), playersInGroup(t[o.size].playersInGroup), weeks(t[o.size].weeks), players(groups*playersInGroup), groupsS(this,groups*weeks,IntSet::empty,0,players-1, playersInGroup,playersInGroup), groupsSInv(this, weeks*players, 0, groups-1) { SetVar allPlayers(this, 0, players-1, 0, players-1); // Groups in one week must be disjoint for (int w=0; w 0 && g % 4 == 0) std::cout << std::endl << " "; } std::cout << std::endl; } } }; int main(int argc, char** argv) { Options o("Golf"); o.parse(argc,argv); o.solutions = 1; if (o.size >= n_examples) { std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; return 1; } Example::run(o); return 0; } // STATISTICS: example-any