Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
schurs-lemma.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2011
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/driver.hh>
35#include <gecode/int.hh>
36#include <gecode/minimodel.hh>
37
38using namespace Gecode;
39
44class SchurOptions : public Options {
45public:
46 int c, n;
48 SchurOptions(const char* s, int c0, int n0)
49 : Options(s), c(c0), n(n0) {}
51 void parse(int& argc, char* argv[]) {
52 Options::parse(argc,argv);
53 if (argc < 3)
54 return;
55 c = atoi(argv[1]);
56 n = atoi(argv[2]);
57 }
59 virtual void help(void) {
60 Options::help();
61 std::cerr << "\t(unsigned int) default: " << c << std::endl
62 << "\t\tparameter c (number of boxes)" << std::endl
63 << "\t(unsigned int) default: " << n << std::endl
64 << "\t\tparameter n (number of balls)" << std::endl;
65 }
66};
67
68
83class Schur : public Script {
84protected:
87public:
89 Schur(const SchurOptions& opt)
90 : Script(opt), box(*this,opt.n,1,opt.c) {
91 int n = opt.n;
92
93 // Iterate over balls and find triples
94 for (int i=1; i<=n; i++)
95 for (int j=1; i+j<=n; j++)
96 rel(*this, {box[i-1],box[j-1],box[i+j-1]}, IRT_NQ);
97
98 // Break value symmetries
99 precede(*this, box, IntArgs::create(opt.c, 1));
100
101 branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
102 }
104 virtual void
105 print(std::ostream& os) const {
106 os << "\t" << box << std::endl;
107 }
108
110 Schur(Schur& s) : Script(s) {
111 box.update(*this, s.box);
112 }
114 virtual Space*
115 copy(void) {
116 return new Schur(*this);
117 }
118};
119
123int
124main(int argc, char* argv[]) {
125 SchurOptions opt("Schur's Lemma",3,13);
126 opt.parse(argc,argv);
128 return 0;
129}
130
131// STATISTICS: example-any
132
int n
Number of negative literals for node type.
Parametric base-class for scripts.
Definition driver.hh:729
static void run(const Options &opt, Script *s=NULL)
Definition script.hpp:290
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Definition array.hpp:76
Integer variable array.
Definition int.hh:763
Options for scripts
Definition driver.hh:366
Computation spaces.
Definition core.hpp:1742
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition array.hpp:1013
Options for Schur's Lemma
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
virtual void help(void)
Print help message.
int n
Parameters to be given on command line Initialize options for example with name s.
SchurOptions(const char *s, int c0, int n0)
Example: Schur's lemma
int main(int argc, char *argv[])
Main-function.
virtual void print(std::ostream &os) const
Print solution.
virtual Space * copy(void)
Copy during cloning.
IntVarArray box
Array of box per ball.
Schur(const SchurOptions &opt)
Actual model.
Schur(Schur &s)
Constructor for cloning s.
void parse(int argc, char *argv[])
Parse commandline arguments.
Definition test.cpp:120
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
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
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
@ IRT_NQ
Disequality ( )
Definition int.hh:927
Gecode toplevel namespace
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
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55