main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
examples
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
:
90
IntVarArray
box
;
91
public
:
93
Schur
(
const
SchurOptions
&
opt
)
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
minimodel.hh
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:72
SchurOptions::n
int n
Parameters to be given on command line Initialize options for example with name s.
Definition:
schurs-lemma.cpp:50
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
int.hh
Gecode::VarArray::update
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition:
array.hpp:1072
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
SchurOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition:
schurs-lemma.cpp:55
Gecode::branch
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
Gecode::INT_VAL_MIN
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition:
val.hpp:59
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
driver.hh
Schur::Schur
Schur(bool share, Schur &s)
Constructor for cloning s.
Definition:
schurs-lemma.cpp:121
Schur::print
virtual void print(std::ostream &os) const
Print solution.
Definition:
schurs-lemma.cpp:116
Gecode
Gecode toplevel namespace
Test::opt
Options opt
The options.
Definition:
test.cpp:101
Gecode::Options
Options for scripts
Definition:
driver.hh:366
Gecode::Driver::ScriptBase
Parametric base-class for scripts.
Definition:
driver.hh:703
SchurOptions
Options for Schur's Lemma
Definition:
schurs-lemma.cpp:48
Schur::box
IntVarArray box
Array of box per ball.
Definition:
schurs-lemma.cpp:90
Gecode::BaseOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition:
options.cpp:510
Gecode::BaseOptions::help
virtual void help(void)
Print help text.
Definition:
options.cpp:463
Schur::main
int main(int argc, char *argv[])
Main-function.
Definition:
schurs-lemma.cpp:135
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:47
Gecode::precede
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition:
precede.cpp:47
Schur::Schur
Schur(const SchurOptions &opt)
Actual model.
Definition:
schurs-lemma.cpp:93
Gecode::INT_VAR_AFC_SIZE_MAX
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::IRT_NQ
@ IRT_NQ
Disequality ( )
Definition:
int.hh:908
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Schur
Example: Schur's lemma
Definition:
schurs-lemma.cpp:87
Schur::copy
virtual Space * copy(bool share)
Copy during cloning.
Definition:
schurs-lemma.cpp:126
SchurOptions::help
virtual void help(void)
Print help message.
Definition:
schurs-lemma.cpp:63