main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Aug 31 2012 16:20:36 for Gecode by
doxygen
1.8.1.2
examples
magic-sequence.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
* Guido Tack <tack@gecode.org>
6
*
7
* Copyright:
8
* Christian Schulte, 2001
9
* Guido Tack, 2006
10
*
11
* Last modified:
12
* $Date: 2010-10-07 20:52:01 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $
13
* $Revision: 11473 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/driver.hh
>
41
#include <
gecode/int.hh
>
42
#include <
gecode/minimodel.hh
>
43
44
using namespace
Gecode;
45
63
class
MagicSequence
:
public
Script
{
64
private
:
66
const
int
n;
68
IntVarArray
s;
69
public
:
71
enum
{
72
PROP_COUNT
,
73
PROP_GCC
74
};
76
MagicSequence
(
const
SizeOptions
&
opt
)
77
: n(opt.
size
()), s(*this,n,0,n-1) {
78
switch
(opt.
propagation
()) {
79
case
PROP_COUNT:
80
for
(
int
i
=n;
i
--; )
81
count
(*
this
, s,
i
,
IRT_EQ
, s[
i
]);
82
linear
(*
this
, s,
IRT_EQ
, n);
83
break
;
84
case
PROP_GCC:
85
count
(*
this
, s, s, opt.
icl
());
86
break
;
87
}
88
linear
(*
this
,
IntArgs::create
(n,-1,1), s,
IRT_EQ
, 0);
89
branch
(*
this
, s,
INT_VAR_NONE
,
INT_VAL_MAX
);
90
}
91
93
MagicSequence
(
bool
share,
MagicSequence
& e) :
Script
(share,e), n(e.n) {
94
s.update(*
this
, share, e.s);
95
}
97
virtual
Space
*
98
copy
(
bool
share) {
99
return
new
MagicSequence
(share,*
this
);
100
}
102
virtual
103
void
print
(std::ostream& os)
const
{
104
os <<
"\t"
;
105
for
(
int
i
= 0;
i
<n;
i
++) {
106
os << s[
i
] <<
", "
;
107
if
((
i
+1) % 20 == 0)
108
os << std::endl <<
"\t"
;
109
}
110
os << std::endl;
111
}
112
113
};
114
118
int
119
main
(
int
argc,
char
* argv[]) {
120
SizeOptions
opt
(
"MagicSequence"
);
121
opt.
solutions
(0);
122
opt.
iterations
(4);
123
opt.
size
(500);
124
opt.
propagation
(
MagicSequence::PROP_COUNT
);
125
opt.
propagation
(
MagicSequence::PROP_COUNT
,
"count"
);
126
opt.
propagation
(
MagicSequence::PROP_GCC
,
"gcc"
);
127
opt.
parse
(argc,argv);
128
Script::run<MagicSequence,DFS,SizeOptions>(
opt
);
129
return
0;
130
}
131
132
// STATISTICS: example-any
133