main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
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
* This file is part of Gecode, the generic constraint
12
* development environment:
13
* http://www.gecode.org
14
*
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files (the
17
* "Software"), to deal in the Software without restriction, including
18
* without limitation the rights to use, copy, modify, merge, publish,
19
* distribute, sublicense, and/or sell copies of the Software, and to
20
* permit persons to whom the Software is furnished to do so, subject to
21
* the following conditions:
22
*
23
* The above copyright notice and this permission notice shall be
24
* included in all copies or substantial portions of the Software.
25
*
26
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
*
34
*/
35
36
#include <
gecode/driver.hh
>
37
#include <
gecode/int.hh
>
38
#include <
gecode/minimodel.hh
>
39
40
using namespace
Gecode
;
41
59
class
MagicSequence
:
public
Script
{
60
private
:
62
const
int
n
;
64
IntVarArray
s;
65
public
:
67
enum
{
68
PROP_COUNT
,
69
PROP_GCC
70
};
72
MagicSequence
(
const
SizeOptions
&
opt
)
73
:
Script
(
opt
),
n
(
opt
.
size
()), s(*this,
n
,0,
n
-1) {
74
switch
(
opt
.propagation()) {
75
case
PROP_COUNT:
76
for
(
int
i
=
n
;
i
--; )
77
count
(*
this
, s,
i
,
IRT_EQ
, s[
i
]);
78
linear
(*
this
, s,
IRT_EQ
,
n
);
79
break
;
80
case
PROP_GCC:
81
count
(*
this
, s, s,
opt
.ipl());
82
break
;
83
}
84
linear
(*
this
,
IntArgs::create
(
n
,-1,1), s,
IRT_EQ
, 0);
85
branch
(*
this
, s,
INT_VAR_NONE
(),
INT_VAL_MAX
());
86
}
87
89
MagicSequence
(
MagicSequence
& e) :
Script
(e),
n
(e.
n
) {
90
s.
update
(*
this
, e.s);
91
}
93
virtual
Space
*
94
copy
(
void
) {
95
return
new
MagicSequence
(*
this
);
96
}
98
virtual
99
void
print
(std::ostream& os)
const
{
100
os <<
"\t"
;
101
for
(
int
i
= 0;
i
<
n
;
i
++) {
102
os << s[
i
] <<
", "
;
103
if
((
i
+1) % 20 == 0)
104
os << std::endl <<
"\t"
;
105
}
106
os << std::endl;
107
}
108
109
};
110
114
int
115
main
(
int
argc,
char
* argv[]) {
116
SizeOptions
opt
(
"MagicSequence"
);
117
opt
.
solutions
(0);
118
opt
.
iterations
(4);
119
opt
.size(500);
120
opt
.
propagation
(
MagicSequence::PROP_COUNT
);
121
opt
.
propagation
(
MagicSequence::PROP_COUNT
,
"count"
);
122
opt
.
propagation
(
MagicSequence::PROP_GCC
,
"gcc"
);
123
opt
.
parse
(argc,argv);
124
Script::run<MagicSequence,DFS,SizeOptions>(
opt
);
125
return
0;
126
}
127
128
// STATISTICS: example-any
129
MagicSequence::PROP_GCC
@ PROP_GCC
Use single global cardinality constraint.
Definition:
magic-sequence.cpp:69
Gecode::Options::propagation
void propagation(int v)
Set default propagation value.
Definition:
options.hpp:203
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:76
Gecode::INT_VAR_NONE
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition:
var.hpp:96
MagicSequence::PROP_COUNT
@ PROP_COUNT
Use count constraints.
Definition:
magic-sequence.cpp:68
int.hh
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
MagicSequence
Example: Magic sequence
Definition:
magic-sequence.cpp:59
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
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:39
Gecode::Options::iterations
void iterations(unsigned int i)
Set default number of iterations.
Definition:
options.hpp:461
MagicSequence::print
virtual void print(std::ostream &os) const
Print sequence.
Definition:
magic-sequence.cpp:99
MagicSequence::MagicSequence
MagicSequence(const SizeOptions &opt)
The actual model.
Definition:
magic-sequence.cpp:72
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
driver.hh
Gecode
Gecode toplevel namespace
Test::opt
Options opt
The options.
Definition:
test.cpp:97
Gecode::Driver::ScriptBase
Parametric base-class for scripts.
Definition:
driver.hh:729
Gecode::BaseOptions::parse
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition:
options.cpp:548
Gecode::linear
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition:
linear.cpp:41
Gecode::count
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Definition:
count.cpp:40
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:926
Gecode::Options::solutions
void solutions(unsigned int n)
Set default number of solutions to search for.
Definition:
options.hpp:283
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
MagicSequence::copy
virtual Space * copy(void)
Copy during cloning.
Definition:
magic-sequence.cpp:94
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
MagicSequence::main
int main(int argc, char *argv[])
Main-function.
Definition:
magic-sequence.cpp:115
Gecode::INT_VAL_MAX
IntValBranch INT_VAL_MAX(void)
Select largest value.
Definition:
val.hpp:65
Gecode::VarArray::update
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition:
array.hpp:1013
Gecode::SizeOptions
Options for scripts with additional size parameter
Definition:
driver.hh:675
MagicSequence::MagicSequence
MagicSequence(MagicSequence &e)
Constructor for cloning e.
Definition:
magic-sequence.cpp:89