Generated on Mon Feb 8 2021 00:00:00 for Gecode by doxygen 1.8.20
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 
38 using namespace Gecode;
39 
44 class SchurOptions : public Options {
45 public:
46  int c, n;
47  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 
83 class Schur : public Script {
84 protected:
87 public:
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 
123 int
124 main(int argc, char* argv[]) {
125  SchurOptions opt("Schur's Lemma",3,13);
126  opt.parse(argc,argv);
127  Script::run<Schur,DFS,SchurOptions>(opt);
128  return 0;
129 }
130 
131 // STATISTICS: example-any
132 
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Definition: array.hpp:76
int n
Parameters to be given on command line Initialize options for example with name s.
Computation spaces.
Definition: core.hpp:1742
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition: branch.cpp:39
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:55
Integer variable array.
Definition: int.hh:763
virtual void print(std::ostream &os) const
Print solution.
Gecode toplevel namespace
Options opt
The options.
Definition: test.cpp:97
Options for scripts
Definition: driver.hh:366
Parametric base-class for scripts.
Definition: driver.hh:729
Options for Schur's Lemma
IntVarArray box
Array of box per ball.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:548
Schur(Schur &s)
Constructor for cloning s.
virtual Space * copy(void)
Copy during cloning.
virtual void help(void)
Print help text.
Definition: options.cpp:494
int main(int argc, char *argv[])
Main-function.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition: precede.cpp:43
Schur(const SchurOptions &opt)
Actual model.
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition: var.hpp:236
@ IRT_NQ
Disequality ( )
Definition: int.hh:927
Gecode::FloatVal c(-8, 8)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Example: Schur's lemma
Gecode::IntArgs i({1, 2, 3, 4})
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1013
virtual void help(void)
Print help message.