/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2004 * * Bugfixes provided by: * Olof Sivertsson * * Last modified: * $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $ * $Revision: 11473 $ * * 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 #include using namespace Gecode; /** * \brief %Options for %BIBD problems * */ class BIBDOptions : public Options { public: int v, k, lambda; ///< Parameters to be given on command line int b, r; ///< Derived parameters /// Derive additional parameters void derive(void) { b = (v*(v-1)*lambda)/(k*(k-1)); r = (lambda*(v-1)) / (k-1); } /// Initialize options for example with name \a s BIBDOptions(const char* s, int v0, int k0, int lambda0) : Options(s), v(v0), k(k0), lambda(lambda0) { derive(); } /// Parse options from arguments \a argv (number is \a argc) void parse(int& argc, char* argv[]) { Options::parse(argc,argv); if (argc < 4) return; v = atoi(argv[1]); k = atoi(argv[2]); lambda = atoi(argv[3]); derive(); } /// Print help message virtual void help(void) { Options::help(); std::cerr << "\t(unsigned int) default: " << v << std::endl << "\t\tparameter v" << std::endl << "\t(unsigned int) default: " << k << std::endl << "\t\tparameter k" << std::endl << "\t(unsigned int) default: " << lambda << std::endl << "\t\tparameter lambda" << std::endl; } }; /** * \brief %Example: Balanced incomplete block design (%BIBD) * * See problem 28 at http://www.csplib.org/. * * \ingroup Example * */ class BIBD : public Script { protected: /// Options providing access to parameters const BIBDOptions& opt; /// Matrix of Boolean variables BoolVarArray _p; public: /// Actual model BIBD(const BIBDOptions& o) : opt(o), _p(*this,opt.v*opt.b,0,1) { Matrix p(_p,opt.b,opt.v); // r ones per row for (int i=0; i p(_p,opt.b,opt.v); for (int i = 0; i(opt); return 0; } // STATISTICS: example-any