main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Feb 8 2021 00:00:00 for Gecode by
doxygen
1.8.20
examples
all-interval.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, 2006
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include <
gecode/driver.hh
>
35
#include <
gecode/int.hh
>
36
#include <
gecode/minimodel.hh
>
37
38
#include <cstdlib>
39
40
using namespace
Gecode
;
41
62
class
AllInterval
:
public
Script
{
63
private
:
65
IntVarArray
x
;
67
IntVarArray
d
;
68
public
:
70
AllInterval
(
const
SizeOptions
&
opt
) :
71
Script
(
opt
),
72
x
(*this,
opt
.
size
(), 0,
opt
.
size
()-1),
73
d
(*this,
opt
.
size
()-1, 1,
opt
.
size
()-1) {
74
const
int
n
=
x
.size();
75
76
// Set up variables for distance
77
for
(
int
i
=0;
i
<
n
-1;
i
++)
78
rel
(*
this
,
d
[
i
] ==
abs
(
x
[
i
+1]-
x
[
i
]),
opt
.ipl());
79
80
distinct
(*
this
,
x
,
opt
.ipl());
81
distinct
(*
this
,
d
,
opt
.ipl());
82
83
// Break mirror symmetry
84
rel
(*
this
,
x
[0],
IRT_LE
,
x
[1]);
85
// Break symmetry of dual solution
86
rel
(*
this
,
d
[0],
IRT_GR
,
d
[
n
-2]);
87
88
branch
(*
this
,
x
,
INT_VAR_SIZE_MIN
(),
INT_VAL_SPLIT_MIN
());
89
}
91
AllInterval
(
AllInterval
& s)
92
:
Script
(s) {
93
x
.
update
(*
this
, s.x);
94
d
.update(*
this
, s.d);
95
}
97
virtual
Space
*
98
copy
(
void
) {
99
return
new
AllInterval
(*
this
);
100
}
102
virtual
void
103
print
(std::ostream& os)
const
{
104
const
int
n
=
x
.size();
105
os <<
"\tx["
<<
n
<<
"] = {"
;
106
for
(
int
i
= 0;
i
<
n
-1;
i
++)
107
os <<
x
[
i
] <<
"("
<<
d
[
i
] <<
"),"
;
108
os <<
x
[
n
-1] <<
"}"
<< std::endl;
109
}
110
};
111
112
116
int
117
main
(
int
argc,
char
* argv[]){
118
SizeOptions
opt
(
"AllInterval"
);
119
opt
.size(1000);
120
opt
.
iterations
(5);
121
opt
.
ipl
(
IPL_BND
);
122
opt
.
parse
(argc, argv);
123
if
(
opt
.size() < 2) {
124
std::cerr <<
"size must be at least 2!"
<< std::endl;
125
return
-1;
126
}
127
Script::run<AllInterval,DFS,SizeOptions>(
opt
);
128
return
0;
129
}
130
131
// STATISTICS: example-any
132
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
minimodel.hh
AllInterval::main
int main(int argc, char *argv[])
Main-function.
Definition:
all-interval.cpp:117
int.hh
AllInterval::print
virtual void print(std::ostream &os) const
Print solution.
Definition:
all-interval.cpp:103
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::IRT_LE
@ IRT_LE
Less ( )
Definition:
int.hh:929
Gecode::Options::ipl
void ipl(IntPropLevel i)
Set default integer propagation level.
Definition:
options.hpp:216
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
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
driver.hh
Gecode
Gecode toplevel namespace
AllInterval::copy
virtual Space * copy(void)
Copy during cloning.
Definition:
all-interval.cpp:98
Test::opt
Options opt
The options.
Definition:
test.cpp:97
AllInterval::AllInterval
AllInterval(AllInterval &s)
Constructor for cloning e.
Definition:
all-interval.cpp:91
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
AllInterval
Example: All-interval series
Definition:
all-interval.cpp:62
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition:
int.hh:978
Gecode::abs
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
arithmetic.cpp:41
Gecode::INT_VAR_SIZE_MIN
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition:
var.hpp:206
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:43
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
AllInterval::AllInterval
AllInterval(const SizeOptions &opt)
Actual model.
Definition:
all-interval.cpp:70
Gecode::VarImpVar::update
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition:
var.hpp:116
Gecode::distinct
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl)
Post propagator for for all .
Definition:
distinct.cpp:46
Gecode::INT_VAL_SPLIT_MIN
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition:
val.hpp:75
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IRT_GR
@ IRT_GR
Greater ( )
Definition:
int.hh:931
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::SizeOptions
Options for scripts with additional size parameter
Definition:
driver.hh:675