/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Copyright: * Guido Tack, 2004 * * Last modified: * $Date: 2008-07-11 10:37:06 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $ * $Revision: 7340 $ * * 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 "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 ExProblem * */ class Golf : public Example { public: /// Model variants enum { MODEL_PLAIN, ///< A simple model MODEL_SYMMETRY ///< Model with symmetry breaking }; enum { PROP_PLAIN, ///< Propagation using intersection propagators PROP_DECOMPOSE ///< Propagation using union and complement propagators }; int groups; ///< Number of groups in a week int playersInGroup; ///< Number of players in a group int weeks; ///< Number of weeks int players; ///< Overall number of players /// The sets representing the groups SetVarArray groupsS; /// Return group number \a g in week \a w SetVar& group(int w, int g) { return groupsS[w*groups+g]; } /// Actual model Golf(const SizeOptions& opt) : groups(t[opt.size()].groups), playersInGroup(t[opt.size()].playersInGroup), weeks(t[opt.size()].weeks), players(groups*playersInGroup), groupsS(this,groups*weeks,IntSet::empty,0,players-1, playersInGroup,playersInGroup) { 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) os << std::endl << " "; } os << std::endl; } } /// Constructor for copying \a s Golf(bool share, Golf& s) : Example(share,s), groups(s.groups), playersInGroup(s.playersInGroup), weeks(s.weeks), players(s.players) { groupsS.update(this, share, s.groupsS); } /// Copy during cloning virtual Space* copy(bool share) { return new Golf(share,*this); } /// Make variables available for visualisation virtual void getVars(Gecode::Reflection::VarMap& vm, bool registerOnly) { vm.putArray(this, groupsS, "groupsS", registerOnly); } }; /** \brief Main-function * \relates Golf */ int main(int argc, char* argv[]) { SizeOptions opt("Golf"); opt.model(Golf::MODEL_PLAIN); opt.model(Golf::MODEL_PLAIN, "none", "no symmetry breaking"); opt.model(Golf::MODEL_SYMMETRY, "symmetry", "static symmetry breaking"); opt.propagation(Golf::PROP_PLAIN); opt.propagation(Golf::PROP_PLAIN, "plain", "intersection constraints"); opt.propagation(Golf::PROP_DECOMPOSE, "decompose", "union and complement constraints"); opt.solutions(1); opt.parse(argc,argv); if (opt.size() >= n_examples) { std::cerr << "Error: size must be between 0 and " << n_examples - 1 << std::endl; return 1; } Example::run(opt); return 0; } // STATISTICS: example-any