main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 5 2013 22:37:12 for Gecode by
doxygen
1.8.3.1
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: 2011-07-08 20:09:31 +1000 (Fri, 08 Jul 2011) $ by $Author: schulte $
11
* $Revision: 12164 $
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
52
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
) : 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_SIZE_AFC_MIN
,
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