schurs-lemma.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2011
*
* 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/driver.hh>
#include <gecode/int.hh>
#include <gecode/minimodel.hh>
using namespace Gecode;
class SchurOptions : public Options {
public:
int c, n;
SchurOptions(const char* s, int c0, int n0)
: Options(s), c(c0), n(n0) {}
void parse(int& argc, char* argv[]) {
Options::parse(argc,argv);
if (argc < 3)
return;
c = atoi(argv[1]);
n = atoi(argv[2]);
}
virtual void help(void) {
Options::help();
std::cerr << "\t(unsigned int) default: " << c << std::endl
<< "\t\tparameter c (number of boxes)" << std::endl
<< "\t(unsigned int) default: " << n << std::endl
<< "\t\tparameter n (number of balls)" << std::endl;
}
};
class Schur : public Script {
protected:
IntVarArray box;
public:
Schur(const SchurOptions& opt)
: Script(opt), box(*this,opt.n,1,opt.c) {
int n = opt.n;
// Iterate over balls and find triples
for (int i=1; i<=n; i++)
for (int j=1; i+j<=n; j++)
rel(*this, {box[i-1],box[j-1],box[i+j-1]}, IRT_NQ);
// Break value symmetries
precede(*this, box, IntArgs::create(opt.c, 1));
branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
}
virtual void
print(std::ostream& os) const {
os << "\t" << box << std::endl;
}
Schur(Schur& s) : Script(s) {
box.update(*this, s.box);
}
virtual Space*
copy(void) {
return new Schur(*this);
}
};
int
main(int argc, char* argv[]) {
SchurOptions opt("Schur's Lemma",3,13);
opt.parse(argc,argv);
Script::run<Schur,DFS,SchurOptions>(opt);
return 0;
}
// STATISTICS: example-any
Gecode::BaseOptions::help
virtual void help(void)
Print help text.
Definition options.cpp:494
Gecode::BaseOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
Definition options.cpp:548
Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >::run
static void run(const Options &opt, Script *s=NULL)
Gecode::IntArgs::create
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Definition array.hpp:76
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Options::Options
Options(const char *s)
Initialize options for script with name s.
Definition options.cpp:576
Gecode::Space
Computation spaces.
Definition core.hpp:1742
SchurOptions
Options for Schur's Lemma
Definition schurs-lemma.cpp:44
SchurOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc).
Definition schurs-lemma.cpp:51
SchurOptions::help
virtual void help(void)
Print help message.
Definition schurs-lemma.cpp:59
SchurOptions::n
int n
Parameters to be given on command line Initialize options for example with name s.
Definition schurs-lemma.cpp:46
SchurOptions::SchurOptions
SchurOptions(const char *s, int c0, int n0)
Definition schurs-lemma.cpp:48
SchurOptions::c
int c
Definition schurs-lemma.cpp:46
Schur::main
int main(int argc, char *argv[])
Main-function.
Definition schurs-lemma.cpp:124
Schur::print
virtual void print(std::ostream &os) const
Print solution.
Definition schurs-lemma.cpp:105
Schur::copy
virtual Space * copy(void)
Copy during cloning.
Definition schurs-lemma.cpp:115
Schur::box
IntVarArray box
Array of box per ball.
Definition schurs-lemma.cpp:86
Schur::Schur
Schur(const SchurOptions &opt)
Actual model.
Definition schurs-lemma.cpp:89
Schur::Schur
Schur(Schur &s)
Constructor for cloning s.
Definition schurs-lemma.cpp:110
Test::Options::parse
void parse(int argc, char *argv[])
Parse commandline arguments.
Definition test.cpp:120
driver.hh
int.hh
Gecode::Script
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition driver.hh:801
Gecode::branch
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Branch over x with variable selection vars and value selection vals.
Definition branch.cpp:39
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::precede
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel=IPL_DEF)
Post propagator that s precedes t in x.
Definition precede.cpp:43
Gecode::IRT_NQ
@ IRT_NQ
Disequality ( ).
Definition int.hh:927
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::INT_VAR_AFC_SIZE_MAX
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:236
Gecode::INT_VAL_MIN
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55