Generated on Sat Feb 7 2015 02:01:12 for Gecode by doxygen 1.8.9.1
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: 2013-07-08 14:22:40 +0200 (Mon, 08 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13820 $
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:
93  Schur(const SchurOptions& opt) : box(*this,opt.n,1,opt.c) {
94  int n = opt.n;
95 
96  IntVarArgs triple(3);
97 
98  // Iterate over balls and find triples
99  for (int i=1; i<=n; i++) {
100  triple[0] = box[i-1];
101  for (int j=1; i+j<=n; j++) {
102  triple[1] = box[j-1];
103  triple[2] = box[i+j-1];
104  rel(*this, triple, IRT_NQ);
105  }
106  }
107 
108  // Break value symmetries
109  precede(*this, box, IntArgs::create(opt.c, 1));
110 
111  branch(*this, box, INT_VAR_AFC_SIZE_MAX(opt.decay()), INT_VAL_MIN());
112  }
114  virtual void
115  print(std::ostream& os) const {
116  os << "\t" << box << std::endl;
117  }
118 
120  Schur(bool share, Schur& s) : Script(share,s) {
121  box.update(*this, share, s.box);
122  }
124  virtual Space*
125  copy(bool share) {
126  return new Schur(share,*this);
127  }
128 };
129 
133 int
134 main(int argc, char* argv[]) {
135  SchurOptions opt("Schur's Lemma",3,13);
136  opt.parse(argc,argv);
137  Script::run<Schur,DFS,SchurOptions>(opt);
138  return 0;
139 }
140 
141 // STATISTICS: example-any
142 
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.
virtual void help(void)
Print help message.
Integer variable array.
Definition: int.hh:741
Computation spaces.
Definition: core.hpp:1362
Parametric base-class for scripts.
Definition: driver.hh:622
void decay(double d)
Set default decay factor.
Definition: options.hpp:216
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.
Gecode::IntArgs i(4, 1, 2, 3, 4)
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:68
void precede(Home home, const IntVarArgs &x, int s, int t, IntConLevel)
Post propagator that s precedes t in x.
Definition: precede.cpp:47
Example: Schur's lemma
Passing integer variables.
Definition: int.hh:636
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:331
Options for Schur's Lemma
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
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:242
Schur(const SchurOptions &opt)
Actual model.
Gecode toplevel namespace
Disequality ( )
Definition: int.hh:905
BrancherHandle 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
Options for scripts
Definition: driver.hh:326
int n
Parameters to be given on command line Initialize options for example with name s.
virtual void print(std::ostream &os) const
Print solution.
virtual void help(void)
Print help text.
Definition: options.cpp:284