Generated on Thu Jan 31 2019 20:56:30 for Gecode by doxygen 1.8.15
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  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/driver.hh>
39 #include <gecode/int.hh>
40 #include <gecode/minimodel.hh>
41 
42 using namespace Gecode;
43 
48 class SchurOptions : public Options {
49 public:
50  int c, n;
51  SchurOptions(const char* s, int c0, int n0)
53  : Options(s), c(c0), n(n0) {}
55  void parse(int& argc, char* argv[]) {
56  Options::parse(argc,argv);
57  if (argc < 3)
58  return;
59  c = atoi(argv[1]);
60  n = atoi(argv[2]);
61  }
63  virtual void help(void) {
64  Options::help();
65  std::cerr << "\t(unsigned int) default: " << c << std::endl
66  << "\t\tparameter c (number of boxes)" << std::endl
67  << "\t(unsigned int) default: " << n << std::endl
68  << "\t\tparameter n (number of balls)" << std::endl;
69  }
70 };
71 
72 
87 class Schur : public Script {
88 protected:
91 public:
94  : Script(opt), box(*this,opt.n,1,opt.c) {
95  int n = opt.n;
96 
97  IntVarArgs triple(3);
98 
99  // Iterate over balls and find triples
100  for (int i=1; i<=n; i++) {
101  triple[0] = box[i-1];
102  for (int j=1; i+j<=n; j++) {
103  triple[1] = box[j-1];
104  triple[2] = box[i+j-1];
105  rel(*this, triple, IRT_NQ);
106  }
107  }
108 
109  // Break value symmetries
110  precede(*this, box, IntArgs::create(opt.c, 1));
111 
112  branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
113  }
115  virtual void
116  print(std::ostream& os) const {
117  os << "\t" << box << std::endl;
118  }
119 
121  Schur(bool share, Schur& s) : Script(share,s) {
122  box.update(*this, share, s.box);
123  }
125  virtual Space*
126  copy(bool share) {
127  return new Schur(share,*this);
128  }
129 };
130 
134 int
135 main(int argc, char* argv[]) {
136  SchurOptions opt("Schur's Lemma",3,13);
137  opt.parse(argc,argv);
138  Script::run<Schur,DFS,SchurOptions>(opt);
139  return 0;
140 }
141 
142 // STATISTICS: example-any
143 
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Definition: array.hpp:72
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
virtual Space * copy(bool share)
Copy during cloning.
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:43
virtual void help(void)
Print help message.
Integer variable array.
Definition: int.hh:744
Computation spaces.
Definition: core.hpp:1748
Parametric base-class for scripts.
Definition: driver.hh:703
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1072
Gecode::FloatVal c(-8, 8)
Schur(bool share, Schur &s)
Constructor for cloning s.
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:240
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual void print(std::ostream &os) const
Print solution.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Options opt
The options.
Definition: test.cpp:101
IntVarArray box
Array of box per ball.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:59
Example: Schur's lemma
Passing integer variables.
Definition: int.hh:639
int main(int argc, char *argv[])
Main-function.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition: options.cpp:510
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition: precede.cpp:47
Options for Schur's Lemma
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Schur(const SchurOptions &opt)
Actual model.
Gecode toplevel namespace
Disequality ( )
Definition: int.hh:908
Options for scripts
Definition: driver.hh:366
int n
Parameters to be given on command line Initialize options for example with name s.
virtual void help(void)
Print help text.
Definition: options.cpp:463